Closed ropery closed 10 years ago
OK, this works for me:
from __future__ import unicode_literals, division, absolute_import
import logging
import re
from flexget import plugin
from flexget.event import event
log = logging.getLogger('modify_magnet_btih')
class MagnetBtih(object):
"""Sets torrent_info_hash from magnet url."""
@plugin.priority(255)
def on_task_modify(self, task, config):
for entry in task.accepted:
if entry['url'].startswith('magnet:'):
info_hash_search = re.search('btih:([0-9a-f]+)', entry['url'], re.IGNORECASE)
if info_hash_search:
entry['torrent_info_hash'] = info_hash_search.group(1).upper()
@event('plugin.register')
def register_plugin():
plugin.register(MagnetBtih, 'magnet_btih', builtin=True, api_ver=2)
I put it in flexget/plugins/modify/. This code does not consider the case where the torrent_info_hash of the entry is already set, such as in the case of the torrentz and kat plugins.
BTW, there seems to be a typo in modify/torrent.py, where it says "modif_torrent".
Added in feb9805ff0a827be7aa2052fc50fa73da30bd171, thanks!
I think the info_hash is the best identifier of an entry (much more reliable than title or URL). For example, the seen_info_hash plugin runs during the modify phase after the torrent plugin has set the torrent_info_hash of accepted entries to avoid duplicates. I request a (builtin) magnet plugin that sets
entry['torrent_info_hash']
fromentry['url']
if it's a magnet URI.Since some sites since long have stopped providing torrent files but a simple magnet link only, I think this is a useful feature.