Skip to content

Commit 5989638

Browse files
committed
add tracker's status checking
1 parent 265b68b commit 5989638

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed
File renamed without changes.
File renamed without changes.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Konkere
3+
Copyright (c) 2024 Konkere
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Torrent updater](/img/TorrUpd.jpg)
1+
![Torrent updater](/.github/img/TorrUpd.jpg)
22
Tool for automatically checking the relevance of torrents and updating them in the torrent client.
33

44
Supports trackers: RuTracker and NNM-Club (hash comparison in topics) and TeamHD (torrent size comparison in RSS, login problem due to reCaptcha).

torrent_updater.py

+34-30
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
import logging
5+
import requests
56
from config import Conf
67
from bencoder import bdecode
78
from urllib.parse import urljoin
@@ -39,38 +40,41 @@ def main():
3940
rss_url = f'{rss_url}{config.auth[tracker]["passkey"]}'
4041
config.tracker_ids[tracker] = rss_parser(rss_url, config.tracker_ids[tracker])
4142
for tracker in config.tracker_ids.keys():
42-
for topic_id in config.tracker_ids[tracker]:
43-
current_torrent = config.client.get_torrent_by_topic(tracker, topic_id)
44-
fresh_tracker = trackers[tracker]['incarnation'](
45-
auth=config.auth[tracker],
46-
topic_id=topic_id,
47-
session=sessions[tracker]
48-
)
49-
current_fingerprint = str(current_torrent[trackers[tracker]['fingerprint']]).lower()
50-
if current_fingerprint != fresh_tracker.fingerprint.lower() and fresh_tracker.fingerprint:
51-
new_torrent = fresh_tracker.download_torrent()
52-
new_torrent_name = bdecode(new_torrent)[b'info'][b'name'].decode('UTF-8')
53-
if not sessions[tracker] and fresh_tracker.session:
54-
sessions[tracker] = fresh_tracker.session
55-
data = {
56-
'category': current_torrent['category'],
57-
'tags': current_torrent['tags'],
58-
'path': current_torrent['save_path'],
59-
'state': current_torrent['state'],
60-
'tracker': tracker,
61-
'topic_id': topic_id,
62-
}
63-
config.client.remove_torrent(current_torrent['hash'])
64-
logging.info(
65-
f'The torrent {trackers[tracker]["fingerprint"]} in topic {fresh_tracker.topic_url} has changed. '
66-
f'Updating the torrent — {current_torrent["name"]}'
43+
response = requests.get(config.auth[tracker]['url'])
44+
tracker_status = response.status_code
45+
if tracker_status == 200:
46+
for topic_id in config.tracker_ids[tracker]:
47+
current_torrent = config.client.get_torrent_by_topic(tracker, topic_id)
48+
fresh_tracker = trackers[tracker]['incarnation'](
49+
auth=config.auth[tracker],
50+
topic_id=topic_id,
51+
session=sessions[tracker]
6752
)
68-
config.client.add_torrent(torrent=new_torrent, data=data)
69-
if new_torrent_name != current_torrent['name']:
70-
logging.warning(
71-
f'The torrent name has changed: {current_torrent["name"]}{new_torrent_name}. '
72-
f'Duplicate files may appear.'
53+
current_fingerprint = str(current_torrent[trackers[tracker]['fingerprint']]).lower()
54+
if current_fingerprint != fresh_tracker.fingerprint.lower() and fresh_tracker.fingerprint:
55+
new_torrent = fresh_tracker.download_torrent()
56+
new_torrent_name = bdecode(new_torrent)[b'info'][b'name'].decode('UTF-8')
57+
if not sessions[tracker] and fresh_tracker.session:
58+
sessions[tracker] = fresh_tracker.session
59+
data = {
60+
'category': current_torrent['category'],
61+
'tags': current_torrent['tags'],
62+
'path': current_torrent['save_path'],
63+
'state': current_torrent['state'],
64+
'tracker': tracker,
65+
'topic_id': topic_id,
66+
}
67+
config.client.remove_torrent(current_torrent['hash'])
68+
logging.info(
69+
f'The torrent {trackers[tracker]["fingerprint"]} in topic {fresh_tracker.topic_url} has changed. '
70+
f'Updating the torrent — {current_torrent["name"]}'
7371
)
72+
config.client.add_torrent(torrent=new_torrent, data=data)
73+
if new_torrent_name != current_torrent['name']:
74+
logging.warning(
75+
f'The torrent name has changed: {current_torrent["name"]}{new_torrent_name}. '
76+
f'Duplicate files may appear.'
77+
)
7478

7579

7680
if __name__ == '__main__':

0 commit comments

Comments
 (0)