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

Failure when adding already existing torrents to qBittorrent #2701

Closed
grainz opened this issue Jun 18, 2020 · 6 comments · Fixed by #2942
Closed

Failure when adding already existing torrents to qBittorrent #2701

grainz opened this issue Jun 18, 2020 · 6 comments · Fixed by #2942

Comments

@grainz
Copy link

grainz commented Jun 18, 2020

Expected behaviour:

Skip already added torrents

Actual behaviour:

Entire task errors when attempting to add torrents to qBittorrent

Steps to reproduce:

  • Step 1: Add torrents to qBittorrent that are new
  • Step 2: Add the same torrents to qBittorrent

Config:

templates:
  TT:
    if:
      - rss_pubdate|formatdate("%d")|int >= 1 and rss_pubdate|formatdate("%d")|int <= 7:
          qbittorrent:
            label: "{{category|replace('Singles - ','')}}/{{rss_pubdate|formatdate('%Y/%m')}}/01"
            path: /mnt/user/TT/{{category|replace('Singles - ','')}}/{{rss_pubdate|formatdate("%Y/%m")}}/01
      - rss_pubdate|formatdate("%d")|int >= 8 and rss_pubdate|formatdate("%d")|int <= 14:
          qbittorrent:
            label: "{{category|replace('Singles - ','')}}/{{rss_pubdate|formatdate('%Y/%m')}}/02"
            path: /mnt/user/TT/{{category|replace('Singles - ','')}}/{{rss_pubdate|formatdate("%Y/%m")}}/02
      - rss_pubdate|formatdate("%d")|int >= 15 and rss_pubdate|formatdate("%d")|int <= 21:
          qbittorrent:
            label: "{{category|replace('Singles - ','')}}/{{rss_pubdate|formatdate('%Y/%m')}}/03"
            path: /mnt/user/TT/{{category|replace('Singles - ','')}}/{{rss_pubdate|formatdate("%Y/%m")}}/03
      - rss_pubdate|formatdate("%d")|int >= 22 and rss_pubdate|formatdate("%d")|int <= 31:
          qbittorrent:
            label: "{{category|replace('Singles - ','')}}/{{rss_pubdate|formatdate('%Y/%m')}}/04"
            path: /mnt/user/TT/{{category|replace('Singles - ','')}}/{{rss_pubdate|formatdate("%Y/%m")}}/04
      - "now|formatdate('%Y') in title": accept
tasks:
  Trance:
    rss:
      url: <url>
      other_fields: [rss_pubdate,category]
      all_entries: no
    template: TT

Log:

(click to expand)
2020-06-18 07:56:33 CRITICAL plugin        Trance          Error when trying to send request to qBittorrent: Failed to add file to qBittorrent

Additional information:

  • FlexGet version: 3.1.64
  • Python version: Python 3.8.3
  • Installation method: virtualenv from install guide
  • Using daemon (yes/no): both
  • OS and version: Debian unstable
  • Link to crash log:
@grainz
Copy link
Author

grainz commented Jun 18, 2020

I suspect this is an issue on qBittorrent's end because if I try to do this manually through the qBittorrent API, it also fails when a torrent already exists.

A workaround I've discovered is commenting out the download portion of qbittorrent.py and forcing it to add to qbittorrent by URL instead. The RSS feed I am using has direct download links.

is_magnet = True
#@plugin.priority(120)
#def on_task_download(self, task, config):
	"""
	Call download plugin to generate torrent files to load into
	qBittorrent.
	"""
	#config = self.prepare_config(config)
	#if not config['enabled']:
		#return
	#if 'download' not in task.config:
		#download = plugin.get('download', self)
		#download.get_temp_files(task, handle_magnets=True, fail_html=config['fail_html'])

If an additional option would be added to let qBittorrent download the torrent instead of FlexGet then adding it by file then this would be easier to handle. The other way would be to use the qBittorrent API prior to adding the torrents and remove entries that already exist.

@gazpachoking
Copy link
Member

If we can reliably detect that the error was from adding a torrent that already exists, I think it's fine if we just catch and log that the torrent already exists. If not, perhaps we should go the route of pre-checking whether the torrent already exists. Adding by URL is okay most of the time, but not in cases where flexget is managing cookies or other kinds of logins.

@FlexGet-Bot
Copy link
Contributor

This issue has been mentioned on Forum - FlexGet. There might be relevant details there:

https://discuss.flexget.com/t/rss-still-showing-all-entries-with-all-entires-no/5251/1

@festoney8
Copy link

festoney8 commented Nov 14, 2020

Same issue here.

Flexget aborts my task and shows Error when trying to send request to qBittorrent: Failed to add file to qBittorrent. And debug mode shows a CRITICAL log when flexget adding torrent file from temp folder to qbittorrent.

2020-11-15 03:15:25 DEBUG    qbittorrent   Anime           Added torrent file /tmp/tmpa5rbtf10/5066ef7d2252edc28exxxxxxxxxxxxxxx to qBittorrent
2020-11-15 03:15:25 DEBUG    qbittorrent   Anime           Added torrent file /tmp/tmp4ranzweg/69a571f90722dbf33xxxxxxxxxxxxxxx to qBittorrent
2020-11-15 03:15:25 DEBUG    qbittorrent   Anime           Added torrent file /tmp/tmp2w28owir/4adc6bd7fec929c94xxxxxxxxxxxxxxx to qBittorrent
2020-11-15 03:15:25 CRITICAL plugin        Anime           Error when trying to send request to qBittorrent: Failed to add file to qBittorrent
2020-11-15 03:15:25 WARNING  task          Anime           Aborting task (plugin: qbittorrent)
2020-11-15 03:15:25 DEBUG    backlog       Anime           Remembering all entries to backlog because of task abort.

I dumped the network traffic between flexget and qb, the crash happens when add-new-torrent api api/v2/torrents/add return HTTP 200 and response text Fails.. I added that torrent to qb manually via qb original webui and dumped traffic, that api Fails again.
But add-new-torrent api doc doesn't say what Fails mean and what will return when adding existed torrent to qb.

Maybe check HTTP200 instead of check response.text == "Ok." in qbittorrent.py may solve the prob temporarily?

@daomengRen
Copy link

The same problem appeared, does anyone know how to solve it,thanks

@gazpachoking
Copy link
Member

Hmm. I just had a peek at the qbittorrent source, and there is no way via the api to tell the difference if there was a failure adding, or if the torrent was already there. I see 2 ways forward:

  • Always ignore errors adding torrents.
  • Check if the torrent is already in the session explicitly before trying to add.
    Option 2 is probably better. If someone using qbittorrent could submit a PR it would be great. 😃

gazpachoking pushed a commit that referenced this issue Apr 29, 2021
[fix] qbittorrent: handle existing torrent. fix #2701
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 a pull request may close this issue.

5 participants