3
from flexget.plugin import priority, register_plugin
5
log = logging.getLogger('modify_trackers')
8
class AddTrackers(object):
11
Adds tracker URL to torrent files.
13
Configuration example:
16
- uri://tracker_address:port/
18
This will add all tracker URL uri://tracker_address:port/.
19
TIP: You can use global section in configuration to make this enabled on all feeds.
23
from flexget import validator
24
trackers = validator.factory('list')
25
trackers.accept('url', protocols=['udp', 'http'])
29
def on_feed_modify(self, feed, config):
30
for entry in feed.entries:
31
if 'torrent' in entry:
33
if not url in entry['torrent'].get_multitrackers():
34
entry['torrent'].add_multitracker(url)
35
log.info('Added %s tracker to %s' % (url, entry['title']))
36
if entry['url'].startswith('magnet:'):
37
entry['url'] += ''.join(['&tr=' + url for url in config])
40
class RemoveTrackers(object):
43
Removes trackers from torrent files using regexp matching.
45
Configuration example:
50
This will remove all trackers that contain text moviex in their url.
51
TIP: You can use global section in configuration to make this enabled on all feeds.
55
from flexget import validator
56
trackers = validator.factory('list')
57
trackers.accept('regexp')
61
def on_feed_modify(self, feed, config):
62
for entry in feed.entries:
63
if 'torrent' in entry:
64
trackers = entry['torrent'].get_multitrackers()
65
for tracker in trackers:
66
for regexp in config or []:
67
if re.search(regexp, tracker, re.IGNORECASE | re.UNICODE):
68
log.debug('remove_trackers removing %s because of %s' % (tracker, regexp))
70
entry['torrent'].remove_multitracker(tracker)
71
log.info('Removed %s' % tracker)
72
if entry['url'].startswith('magnet:'):
74
# Replace any tracker strings that match the regexp with nothing
75
tr_search = r'&tr=([^&]*%s[^&]*)' % regexp
76
entry['url'] = re.sub(tr_search, '', entry['url'], re.IGNORECASE | re.UNICODE)
78
register_plugin(AddTrackers, 'add_trackers', api_ver=2)
79
register_plugin(RemoveTrackers, 'remove_trackers', api_ver=2)