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

some fixes #165

Merged
merged 7 commits into from
Jan 22, 2025
Merged

some fixes #165

merged 7 commits into from
Jan 22, 2025

Conversation

5hojib
Copy link
Collaborator

@5hojib 5hojib commented Jan 22, 2025

Summary by Sourcery

Refactor torrent search functionality to use qBittorrent search plugins, removing the dependency on an external search API. Update archive handling during extraction to delete split archive files after successful extraction. Embed thumbnails into video files using ffmpeg.

Bug Fixes:

  • Fixed case sensitivity issue in document type extension checks.
  • Fixed channel-related issues for mirror and leech operations.
  • Addressed the issue where thumbnails were removed after a restart.

Enhancements:

  • Updated status message handling to delete old messages and send new ones, improving clarity.
  • Improved flood handling in message sending and editing functions.
  • Simplified status interface by removing "refresh status" and "overview status" buttons.
  • Updated token generation to resolve issues caused by command suffix.
  • Removed limit variables for mirror and leech operations.
  • Updated database interaction to retrieve upstream repository and branch information.

Copy link
Contributor

sourcery-ai bot commented Jan 22, 2025

Reviewer's Guide by Sourcery

This pull request refactors the torrent search functionality by removing the API search method and focusing solely on plugin-based searches. It also includes changes to how thumbnails are handled and fixes some issues with archive extraction.

Sequence diagram for simplified torrent search flow

sequenceDiagram
    actor User
    participant Bot
    participant QBittorrent
    participant SearchPlugins

    User->>Bot: Send search command with key
    alt No search key provided
        Bot-->>User: Request search key
    else Search key provided
        Bot->>Bot: Show plugin selection buttons
        User->>Bot: Select search plugin
        Bot->>QBittorrent: Initialize search with plugin
        QBittorrent->>SearchPlugins: Execute search
        SearchPlugins-->>QBittorrent: Return search results
        QBittorrent-->>Bot: Return results
        Bot->>Bot: Format results
        Bot-->>User: Display formatted results
    end
Loading

Class diagram showing search module structure changes

classDiagram
    class SearchModule {
        -PLUGINS: list
        -TELEGRAPH_LIMIT: int
        +initiate_search_tools()
        +search(key, site, message)
        +get_result(search_results, key, message)
        +plugin_buttons(user_id)
    }

    class FFmpegStatus {
        +STATUS_ETHUMB: str
        +status()
        +task()
    }

    SearchModule --> FFmpegStatus: uses
    note for SearchModule "Removed API search functionality
Simplified to plugin-only searches"
Loading

Flow diagram for archive extraction process

graph TD
    A[Start Extraction] --> B{Check Archive Type}
    B -->|Split Archive| C[Extract First Part]
    B -->|Single Archive| D[Extract File]
    C --> E{Extraction Success?}
    D --> E
    E -->|Yes| F[Delete Original Archives]
    E -->|No| G[Keep Original Files]
    F --> H[Return Extracted Path]
    G --> H
Loading

File-Level Changes

Change Details Files
Removed API search functionality.
  • Removed all code related to API based searching.
  • Removed the SITES global variable.
  • Removed the api_buttons function.
  • Removed the method parameter from the search and get_result functions.
  • Removed the API related logic from the torrent_search and torrent_search_update functions.
bot/modules/search.py
Updated search plugins list.
  • Added a new list of search plugins SEARCH_PLUGINS.
  • Removed the SEARCH_PLUGINS variable from config_sample.py.
  • The bot now installs the plugins from the SEARCH_PLUGINS list.
bot/modules/search.py
config_sample.py
Added embed thumbnail functionality.
  • Added proceed_embed_thumb function to embed thumbnails into mkv files.
  • Added get_embed_thumb_cmd function to generate the ffmpeg command for embedding thumbnails.
  • Added STATUS_ETHUMB to MirrorStatus enum.
  • Added E_thumb status to FFmpegStatus class.
bot/helper/common.py
bot/helper/aeon_utils/metadata_editor.py
bot/helper/mirror_leech_utils/status_utils/ffmpeg_status.py
Fixed archive extraction and thumbnail handling.
  • Fixed an issue where archive split files were not being deleted after extraction.
  • Fixed an issue where thumbnails were removed after a restart.
  • Added a check for archive files in get_document_type function.
  • Removed the thumbnail directory cleanup from clean_all function.
  • Added thumbnail directory cleanup to load_settings function.
bot/helper/common.py
bot/helper/ext_utils/files_utils.py
bot/core/startup.py
Other minor fixes and changes.
  • Removed is_multi_streams function.
  • Added a check for MessageNotModified and MessageEmpty exceptions in edit_message function.
  • Added RSS_CHAT to the list of allowed users.
  • Fixed an issue where status messages were not being deleted properly.
  • Removed SEARCH_API_LINK and SEARCH_LIMIT from Config class.
  • Fixed an issue where the bot would not restart properly.
  • Fixed an issue where the bot would not download files from channels.
  • Fixed an issue where the bot would not properly handle RssShutdownException.
  • Added Thumbnails to .gitignore.
  • Updated the UPSTREAM_BRANCH to beta.
  • Added changelog entries.
bot/helper/ext_utils/media_utils.py
bot/helper/telegram_helper/message_utils.py
bot/helper/aeon_utils/access_check.py
bot/helper/ext_utils/status_utils.py
bot/modules/status.py
bot/core/config_manager.py
bot/modules/restart.py
bot/helper/mirror_leech_utils/download_utils/telegram_download.py
bot/modules/rss.py
.gitignore
update.py
CHANGELOG.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @5hojib - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please use a more descriptive commit message that explains what changes are being made. 'some fixes' does not provide enough context about the changes in this PR.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -46,6 +46,8 @@ def update_aria2_options():


async def load_settings():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Low code quality found in load_settings - 10% (low-code-quality)


ExplanationThe quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

@@ -19,7 +19,8 @@

async def error_check(message):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): We've found these issues:


Explanation
The quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

@@ -1198,3 +1198,66 @@ async def proceed_watermark(self, dl_path, gid):
if checked:
cpu_eater_lock.release()
return dl_path

async def proceed_embed_thumb(self, dl_path, gid):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Low code quality found in TaskConfig.proceed_embed_thumb - 16% (low-code-quality)


ExplanationThe quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

@@ -94,11 +93,10 @@ async def _download(self, message, path):

async def add_download(self, message, path, session):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Low code quality found in TelegramDownloadHelper.add_download - 24% (low-code-quality)


ExplanationThe quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

Comment on lines 89 to 92
# Fallback to environment variables for DATABASE_URL
DATABASE_URL = (
config_file.get("DATABASE_URL", "").strip()
or os.getenv("DATABASE_URL", "").strip()
)
DATABASE_URL = config_file.get("DATABASE_URL", "") or os.getenv("DATABASE_URL", "")

if DATABASE_URL:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Use named expression to simplify assignment and conditional (use-named-expression)

Suggested change
# Fallback to environment variables for DATABASE_URL
DATABASE_URL = (
config_file.get("DATABASE_URL", "").strip()
or os.getenv("DATABASE_URL", "").strip()
)
DATABASE_URL = config_file.get("DATABASE_URL", "") or os.getenv("DATABASE_URL", "")
if DATABASE_URL:
if DATABASE_URL := config_file.get("DATABASE_URL", "") or os.getenv(
"DATABASE_URL", ""
):

@5hojib 5hojib merged commit e023f38 into main Jan 22, 2025
1 check passed
@5hojib 5hojib deleted the beta branch January 22, 2025 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant