Skip to content

[fix] qbittorrent: handle existing torrent#2942

Merged
gazpachoking merged 4 commits intoFlexget:developfrom
soloam:qbittorrent_duplicated_torrent
Apr 29, 2021
Merged

[fix] qbittorrent: handle existing torrent#2942
gazpachoking merged 4 commits intoFlexget:developfrom
soloam:qbittorrent_duplicated_torrent

Conversation

@soloam
Copy link
Copy Markdown
Contributor

@soloam soloam commented Apr 29, 2021

Motivation for changes:

Handles qbittorrent existing torrent and returns a warning. Avoids plugin crash

Detailed changes:

  • Return torrent hash and search it in qbittorrent, if exists return a warning and skip torrent adding. Please note that this will not work with magnet links, they can be turn off with "magnets: no"

Addressed issues:

Implemented feature requests:

Config usage if relevant (new plugin or updated schema):

tasks:
  qbittorrent_test:
    filesystem: /home/user/torrent
    disable:
      - remember_rejected
      - seen
      - retry_failed
      - seen_info_hash
    accept_all: yes

    qbittorrent:
      path: /media/disk/downloads/
      label: tv
      host: localhost
      port: 8080

Log and/or tests output (preferably both):

2021-04-29 03:24:56 VERBOSE  task          qbittorrent_test ACCEPTED: `Black.Bear.2020.1080p.WEB.h264-RUMOUR` by accept_all plugin
2021-04-29 03:24:56 INFO     download      qbittorrent_test Downloading: Black.Bear.2020.1080p.WEB.h264-RUMOUR
2021-04-29 03:24:56 VERBOSE  details       qbittorrent_test Summary - Accepted: 1 (Rejected: 0 Undecided: 0 Failed: 0)
2021-04-29 03:24:56 WARNING  qbittorrent   qbittorrent_test File with hash b57ad966c12a0ce27b80dca5e056eeb1e575be28 already in qbittorren

To Do:

  • Is it possible to handle magnets? I need to download the file to check the hash. If impossible, ignore this to do

logger.error('Error checking torrent file, file {} does not exist', file_path)
return False

hash_torrent = torrent.info_hash
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We already grab this info from magnets and torrent files, and put it in the torrent_info_hash entry field. I think it would be better to just pull the hash from there rather than repeat that logic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@soloam soloam requested a review from gazpachoking April 29, 2021 17:10
return False

try:
check_file = loads(respose.text)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably just use response.json() here rather than explicitly using json.loads?

)
return False

if len(check_file) > 0:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What sort of data does this endpoint return? Normally rather than doing a len(check_file) >0 it would just be if check_file

if not self.connected:
raise plugin.PluginError('Not connected.')

if self.check_torrent_exists(url, verify_cert, hash_torrent):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we could call this earlier, perhaps hereabouts This would have the advantage of only needing to call it once whether file or magnet, and not having to pass info hash through the add_torrent_X functions.

@soloam soloam requested a review from gazpachoking April 29, 2021 18:20
@soloam
Copy link
Copy Markdown
Contributor Author

soloam commented Apr 29, 2021

@gazpachoking done

@gazpachoking
Copy link
Copy Markdown
Member

LGTM, thanks!

@gazpachoking gazpachoking merged commit d6a74b2 into Flexget:develop Apr 29, 2021
@soloam soloam deleted the qbittorrent_duplicated_torrent branch May 25, 2021 22:05
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.

Failure when adding already existing torrents to qBittorrent

2 participants