Skip to content

Commit

Permalink
Fix v3.2.0: Fix conflict between device metadata and user-agent in th…
Browse files Browse the repository at this point in the history
…e `Downloader()` class (#116)

## v3.2.0 - 2024-11-21
### What's Changed
**Full Changelog**: v3.1.3...v3.2.0 by @obervinov in #116
#### 🐛 Bug Fixes
* fix conflict between device metadata and user-agent in the `Downloader` class
* fix the login strategy for exceptions
#### 💥 Breaking Changes
* `Downloader` class configuration has been changed. **Please, check the new parameters in README.md#bot-configuration-source-and-supported-parameters and update Vault configuration**
* remove `Post` and `Posts List` buttons from the bot commands, because it is have been replaced by the `Posts` button buttons have the same functionality. **Required to update the users roles in the vault and recreate start up message**
#### 🚀 Features
* add validators for session settings in the `Downloader` class
  • Loading branch information
obervinov authored Nov 21, 2024
1 parent 997f16e commit 93582bb
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 109 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).


## v3.2.0 - 2024-11-21
### What's Changed
**Full Changelog**: https://github.com/obervinov/pyinstabot-downloader/compare/v3.1.3...v3.2.0 by @obervinov in https://github.com/obervinov/pyinstabot-downloader/pull/116
#### 🐛 Bug Fixes
* fix conflict between device metadata and user-agent in the `Downloader()` class
* fix the login strategy for exceptions
#### 💥 Breaking Changes
* `Downloader()` class configuration has been changed. **Please, check the new parameters in [README.md](README.md#bot-configuration-source-and-supported-parameters) and update Vault configuration**
* remove `Post` and `Posts List` buttons from the bot commands, because it is have been replaced by the `Posts` button (buttons have the same functionality). **Required to update the users roles in the vault and recreate start up message**
#### 🚀 Features
* add validators for session settings in the `Downloader()` class


## v3.1.3 - 2024-11-01
### What's Changed
**Full Changelog**: https://github.com/obervinov/pyinstabot-downloader/compare/v3.1.2...v3.1.3 by @obervinov in https://github.com/obervinov/pyinstabot-downloader/pull/115
Expand Down
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,43 @@ This project is a Telegram bot that allows you to upload posts from your Instagr
"2fa-enabled": "False",
"2fa-seed": "my_2fa_secret",
"country-code": "1",
"country": "US",
"delay-requests": "1",
"locale": "en_US",
"username": "my_username",
"password": "my_password",
"session-file": "session.json",
"timezone-offset": "10800",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...",
"request-timeout": "10"
"request-timeout": "10",
"device-settings": {"app_version": "269.0.0.18.75", "version_code": "314665256", "manufacturer": "OnePlus", "model": "6T Dev", "device": "devitron", "cpu": "qcom", "dpi": "480dpi", "resolution": "1080x1920", "android_release": "8.0.0", "android_version": "26"}
}

```

Description of parameters
- `delay-requests`: the delay between requests to the instagram api in seconds
- `locale`: the locale of the instagram account
- `session-file`: the path to the file where the session data will be stored
- `timezone-offset`: the offset of the timezone in seconds
- `user-agent`: the user-agent of the instagram account
- `2fa-enabled`: two-factor authentication status
- `2fa-seed`: two-factor authentication secret
- `country-code`: the country code of the instagram account
- `country`: the country of the instagram account
- `enabled`: the status of the downloader module
- `username`: the username of the instagram account
- `password`: the password of the instagram account
- `request-timeout`: the timeout for requests to the instagram api
- `device-settings`: the device settings of the instagram account
- `app_version`: the version of the instagram app
- `version_code`: the version code of the instagram app
- `manufacturer`: the manufacturer of the device
- `model`: the model of the device
- `device`: the device name
- `cpu`: the cpu of the device
- `dpi`: the dpi of the device
- `resolution`: the resolution of the device
- `android_release`: the android release version of the device
- `android_version`: the android api version of the device
</br>

- `configuration/uploader-api`: uploader module configuration (for upload content to the target storage)
Expand Down Expand Up @@ -167,15 +180,15 @@ This project is a Telegram bot that allows you to upload posts from your Instagr

```json
{
"requests": "{\"requests_per_day\": 10, \"requests_per_hour\": 1, \"random_shift_minutes\": 60}",
"roles": "[\"post\", \"posts_list\"]",
"requests": {"requests_per_day": 10, "requests_per_hour": 1, "random_shift_minutes": 60},
"roles": ["posts", "reschedule_queue"],
"status": "allowed"
}
```

Description of parameters
- `requests`: the number of requests that the user can make per day and per hour, as well as the random shift in minutes (scheduling of message processing from the queue works on the basis of this parameter)
- `roles`: list of roles that allow to use the corresponding functionality ([available roles](src/configs/constants.py#L11-L15)).
- `roles`: list of roles that allow to use the corresponding functionality ([available roles](src/configs/constants.py#L11-L14)).
- `status`: allowed or denied user access to the bot


Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ services:
args:
PROJECT_NAME: pyinstabot-downloader
PROJECT_DESCRIPTION: "This project is a Telegram bot that allows you to upload posts from your Instagram profile to clouds like any WebDav compatible cloud storage."
PROJECT_VERSION: 3.1.3
PROJECT_VERSION: 3.2.0
container_name: pyinstabot-downloader
restart: always
environment:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyinstabot-downloader"
version = "3.1.3"
version = "3.2.0"
description = "This project is a Telegram bot that allows you to upload posts from your Instagram profile to clouds like any WebDav compatible cloud storage."
authors = ["Bervinov Oleg <bervinov.ob@gmail.com>"]
maintainers = ["Bervinov Oleg <bervinov.ob@gmail.com>"]
Expand Down
28 changes: 9 additions & 19 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,12 @@ def bot_callback_query_handler(call: telegram.callback_query = None) -> None:
'chat_id': call.message.chat.id, 'message_id': call.message.message_id
}
if users.user_access_check(**requestor).get('permissions', None) == users.user_status_allow:
if call.data == "Post":
help_message = telegram.send_styled_message(
chat_id=call.message.chat.id,
messages_template={'alias': 'help_for_post'}
)
bot.register_next_step_handler(call.message, process_one_post, help_message)

elif call.data == "Posts List":
if call.data == "Posts":
help_message = telegram.send_styled_message(
chat_id=call.message.chat.id,
messages_template={'alias': 'help_for_posts_list'}
)
bot.register_next_step_handler(call.message, process_list_posts, help_message)
bot.register_next_step_handler(call.message, process_posts, help_message)

elif call.data == "Reschedule Queue":
help_message = telegram.send_styled_message(
Expand Down Expand Up @@ -367,6 +360,9 @@ def process_one_post(
"""
Processes an Instagram post link sent by a user and adds it to the queue for download.
Notice: This method will merge with the `process_posts` method in v3.3.0.
After combining the two buttons into a `Posts` button in version 3.2.0, it makes no sense to split one functionality into two methods.
Args:
message (telegram.telegram_types.Message): The Telegram message object containing the post link.
help_message (telegram.telegram_types.Message): The help message to be deleted.
Expand All @@ -376,7 +372,7 @@ def process_one_post(
None
"""
requestor = {
'user_id': message.chat.id, 'role_id': ROLES_MAP['Post'],
'user_id': message.chat.id, 'role_id': ROLES_MAP['Posts'],
'chat_id': message.chat.id, 'message_id': message.message_id
}
user = users_rl.user_access_check(**requestor)
Expand Down Expand Up @@ -407,12 +403,12 @@ def process_one_post(
telegram.delete_message(message.chat.id, help_message.id)


def process_list_posts(
def process_posts(
message: telegram.telegram_types.Message = None,
help_message: telegram.telegram_types.Message = None
) -> None:
"""
Process a list of Instagram post links.
Process a single or multiple posts from the user's message.
Args:
message (telegram.telegram_types.Message, optional): The message containing the list of post links. Defaults to None.
Expand All @@ -422,7 +418,7 @@ def process_list_posts(
None
"""
requestor = {
'user_id': message.chat.id, 'role_id': ROLES_MAP['Posts List'],
'user_id': message.chat.id, 'role_id': ROLES_MAP['Posts'],
'chat_id': message.chat.id, 'message_id': message.message_id
}
user = users.user_access_check(**requestor)
Expand Down Expand Up @@ -611,12 +607,6 @@ def queue_handler_thread() -> None:
def main():
"""
The main entry point of the project.
Args:
None
Returns:
None
"""
# Thread for processing queue
thread_queue_handler = threading.Thread(target=queue_handler_thread, args=(), name="QueueHandlerThread")
Expand Down
3 changes: 1 addition & 2 deletions src/configs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
# permissions roles and buttons mapping
# 'button_title': 'role'
ROLES_MAP = {
'Post': 'post',
'Posts List': 'posts_list',
'Posts': 'posts',
'Reschedule Queue': 'reschedule_queue',
}

Expand Down
4 changes: 0 additions & 4 deletions src/configs/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
"text": "{0} Sorry, you have not permissions for use this feature. Please, check you permission roles.\nMetadata:\n<code>userid: {1}</code>\n<code>username: {2}</code>",
"args": [":no_entry:", "userid", "username"]
},
"help_for_post": {
"text": "{0} <b>For a download post, just send a link to this post.</b>\nfor example:\n<code>https://www.instagram.com/p/QwErtY_1234</code>",
"args": [":link:"]
},
"help_for_posts_list": {
"text": "{0} To get a backup copy of the list of posts, send links to posts in a list (each new link with a new message line). This message will be automatically split into a number of messages equal to the number of links and processed in the order of the queue.\n {1} Example:\n<code>https://www.instagram.com/p/QwEr_tY1234\nhttps://www.instagram.com/p/QwEr_tY1235\nhttps://www.instagram.com/p/QwEr_tY1236</code>",
"args": [":information:", ":link:"]
Expand Down
Loading

0 comments on commit 93582bb

Please sign in to comment.