Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix v3.2.0: Fix conflict between device metadata and user-agent in the Downloader() class #116

Merged
merged 26 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
36cea72
fix conflict between device metadata and user-agent in the `Downloade…
obervinov Nov 1, 2024
a72747f
added `self.client.set_user_agent()`
obervinov Nov 1, 2024
9c8337a
fixed fix the login strategy for exceptions
obervinov Nov 5, 2024
3823856
modified: CHANGELOG.md
obervinov Nov 5, 2024
3c911ea
small fixes
obervinov Nov 5, 2024
d3ac226
remove `post` and `posts list` buttons from the main menu
obervinov Nov 12, 2024
46b167b
fixed linting issues
obervinov Nov 12, 2024
1efb76f
fixed AttributeError: 'str' object has no attribute 'keys'
obervinov Nov 12, 2024
11eb96e
fixed errors
obervinov Nov 12, 2024
ba70569
fixed json structure with device settings
obervinov Nov 12, 2024
9e69f64
updated documentation
obervinov Nov 12, 2024
a4feef4
updated changelog
obervinov Nov 12, 2024
26bd6e3
small correction in the code
obervinov Nov 12, 2024
a3a2f3b
fixed role mapping
obervinov Nov 12, 2024
c31d1c8
added debug log message for downloader
obervinov Nov 12, 2024
ef1822f
temporarily fix for set country configuation
obervinov Nov 12, 2024
f9028bb
fixed relogin exception handling
obervinov Nov 16, 2024
c546f03
modified: src/modules/downloader.py
obervinov Nov 16, 2024
5f2b488
modified: src/modules/downloader.py
obervinov Nov 16, 2024
218ba81
modified: CHANGELOG.md
obervinov Nov 18, 2024
f385670
fixed confusion between values types in `_validate_session_settings()`
obervinov Nov 18, 2024
80bcb40
modified: src/modules/downloader.py
obervinov Nov 19, 2024
219a0fc
modified: CHANGELOG.md
obervinov Nov 19, 2024
c0848b9
added temprorary fix for load_settings (`self.client.set_country(coun…
obervinov Nov 19, 2024
619133e
removed `time.sleep(3600)`
obervinov Nov 20, 2024
b793c15
finalizing release v3.2.0
obervinov Nov 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading