Skip to content

Commit 408baf9

Browse files
authored
improving HDT (#224)
* Update COMMON.py adding torrent edit function * Update HDT.py modding torrent instead of downloading from site. * Update HDT.py updating to correct source flag * Update example-config.py updating config with personal announce url field * Update HDT.py was looking for hash from meta but meta does not contain has if not passed when l4g is ran * Update HDT.py Commented out download torrent function
1 parent ae2f006 commit 408baf9

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

data/example-config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"announce_url" : "https://hawke.uno/announce/customannounceurl",
7373
# "anon" : False
7474
},
75-
"MTV": {
75+
"MTV": {
7676
'api_key' : 'get from security page',
7777
'username' : '<USERNAME>',
7878
'password' : '<PASSWORD>',
@@ -136,7 +136,7 @@
136136
"announce_url" : "https://lst.gg/announce/customannounceurl",
137137
# "anon" : False
138138
},
139-
"LT" : {
139+
"LT" : {
140140
"api_key" : "LT api key",
141141
"announce_url" : "https://lat-team.com/announce/customannounceurl",
142142
# "anon" : False
@@ -161,6 +161,7 @@
161161
"username" : "username",
162162
"password" : "password",
163163
"announce_url" : "https://hdts-announce.ru/announce.php",
164+
"my_announce_url": "https://hdts-announce.ru/announce.php?pid=<PASS_KEY/PID>",
164165
# "anon" : "False"
165166
},
166167

src/trackers/COMMON.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ async def edit_torrent(self, meta, tracker, source_flag, torrent_filename="BASE"
2323
new_torrent.metainfo['info']['source'] = source_flag
2424
Torrent.copy(new_torrent).write(f"{meta['base_dir']}/tmp/{meta['uuid']}/[{tracker}]{meta['clean_name']}.torrent", overwrite=True)
2525

26+
# used to add tracker url, comment and source flag to torrent file
27+
async def add_tracker_torrent(self, meta, tracker, source_flag, new_tracker, comment):
28+
if os.path.exists(f"{meta['base_dir']}/tmp/{meta['uuid']}/BASE.torrent"):
29+
new_torrent = Torrent.read(f"{meta['base_dir']}/tmp/{meta['uuid']}/BASE.torrent")
30+
new_torrent.metainfo['announce'] = new_tracker
31+
new_torrent.metainfo['comment'] = comment
32+
new_torrent.metainfo['info']['source'] = source_flag
33+
Torrent.copy(new_torrent).write(f"{meta['base_dir']}/tmp/{meta['uuid']}/[{tracker}]{meta['clean_name']}.torrent", overwrite=True)
34+
2635

2736
async def unit3d_edit_desc(self, meta, tracker, signature, comparison=False, desc_header=""):
2837
base = open(f"{meta['base_dir']}/tmp/{meta['uuid']}/DESCRIPTION.txt", 'r', encoding='utf8').read()

src/trackers/HDT.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class HDT():
2121
def __init__(self, config):
2222
self.config = config
2323
self.tracker = 'HDT'
24-
self.source_flag = 'HDT'
24+
self.source_flag = 'hd-torrents.org'
2525
self.username = config['TRACKERS'][self.tracker].get('username', '').strip()
2626
self.password = config['TRACKERS'][self.tracker].get('password', '').strip()
2727
self.signature = None
@@ -194,8 +194,8 @@ async def upload(self, meta):
194194
# Match url to verify successful upload
195195
search = re.search(r"download\.php\?id\=([a-z0-9]+)", up.text).group(1)
196196
if search:
197-
id = search
198-
await self.download_new_torrent(session, id, torrent_path)
197+
# modding existing torrent for adding to client instead of downloading torrent from site.
198+
await common.add_tracker_torrent(meta, self.tracker, self.source_flag, self.config['TRACKERS']['HDT'].get('my_announce_url'), "https://hd-torrents.org/details.php?id=" + search)
199199
else:
200200
console.print(data)
201201
console.print("\n\n")
@@ -300,17 +300,17 @@ async def login(self, cookiefile):
300300
await asyncio.sleep(1)
301301
console.print(response.url)
302302
return
303-
304-
async def download_new_torrent(self, session, id, torrent_path):
305-
download_url = f"https://hd-torrents.org/download.php?id={id}"
306-
r = session.get(url=download_url)
307-
if r.status_code == 200:
308-
with open(torrent_path, "wb") as tor:
309-
tor.write(r.content)
310-
else:
311-
console.print("[red]There was an issue downloading the new .torrent from HDT")
312-
console.print(r.text)
313-
return
303+
# No longer used as torrent is modified instead of downloaded.
304+
# async def download_new_torrent(self, session, id, torrent_path):
305+
# download_url = f"https://hd-torrents.org/download.php?id={id}"
306+
# r = session.get(url=download_url)
307+
# if r.status_code == 200:
308+
# with open(torrent_path, "wb") as tor:
309+
# tor.write(r.content)
310+
# else:
311+
# console.print("[red]There was an issue downloading the new .torrent from HDT")
312+
# console.print(r.text)
313+
# return
314314

315315
async def get_csrfToken(self, session, url):
316316
r = session.get(url)

0 commit comments

Comments
 (0)