@@ -173,7 +173,7 @@ async def upload(self, meta):
173173 data ['season' ] = 'false'
174174
175175 # Anonymous check
176- if meta ['anon' ] == 0 and bool (distutils .util .strtobool (str (self .config ['TRACKERS' ]['HDT' ].get ('anon' , "False" )))) == False :
176+ if meta ['anon' ] == 0 and bool (distutils .util .strtobool (str (self .config ['TRACKERS' ][self . tracker ].get ('anon' , "False" )))) == False :
177177 data ['anonymous' ] = 'false'
178178 else :
179179 data ['anonymous' ] = 'true'
@@ -185,9 +185,9 @@ async def upload(self, meta):
185185 console .print (data )
186186 else :
187187 with requests .Session () as session :
188- cookiefile = os .path .abspath (f"{ meta ['base_dir' ]} /data/cookies/HDT.pkl " )
189- with open ( cookiefile , 'rb' ) as cf :
190- session .cookies .update (pickle . load ( cf ))
188+ cookiefile = os .path .abspath (f"{ meta ['base_dir' ]} /data/cookies/HDT.txt " )
189+
190+ session .cookies .update (await common . parseCookieFile ( cookiefile ))
191191 up = session .post (url = url , data = data , files = files )
192192 torrentFile .close ()
193193
@@ -207,9 +207,9 @@ async def upload(self, meta):
207207 async def search_existing (self , meta ):
208208 dupes = []
209209 with requests .Session () as session :
210- cookiefile = os . path . abspath ( f" { meta [ 'base_dir' ] } /data/cookies/HDT.pkl" )
211- with open ( cookiefile , 'rb' ) as cf :
212- session .cookies .update (pickle . load ( cf ))
210+ common = COMMON ( config = self . config )
211+ cookiefile = os . path . abspath ( f" { meta [ 'base_dir' ] } /data/cookies/HDT.txt" )
212+ session .cookies .update (await common . parseCookieFile ( cookiefile ))
213213
214214 search_url = f"https://hd-torrents.org/torrents.php"
215215 csrfToken = await self .get_csrfToken (session , search_url )
@@ -241,30 +241,21 @@ async def search_existing(self, meta):
241241
242242
243243 async def validate_credentials (self , meta ):
244- cookiefile = os .path .abspath (f"{ meta ['base_dir' ]} /data/cookies/HDT.pkl" )
245- if not os .path .exists (cookiefile ):
246- await self .login (cookiefile )
244+ cookiefile = os .path .abspath (f"{ meta ['base_dir' ]} /data/cookies/HDT.txt" )
247245 vcookie = await self .validate_cookies (meta , cookiefile )
248246 if vcookie != True :
249- console .print ('[red]Failed to validate cookies. Please confirm that the site is up and your passkey is valid.' )
250- recreate = cli_ui .ask_yes_no ("Log in again and create new session?" )
251- if recreate == True :
252- if os .path .exists (cookiefile ):
253- os .remove (cookiefile )
254- await self .login (cookiefile )
255- vcookie = await self .validate_cookies (meta , cookiefile )
256- return vcookie
257- else :
258- return False
247+ console .print ('[red]Failed to validate cookies. Please confirm that the site is up or export a fresh cookie file from the site' )
248+ return False
259249 return True
260250
261251
262252 async def validate_cookies (self , meta , cookiefile ):
253+ common = COMMON (config = self .config )
263254 url = "https://hd-torrents.org/index.php"
255+ cookiefile = f"{ meta ['base_dir' ]} /data/cookies/HDT.txt"
264256 if os .path .exists (cookiefile ):
265257 with requests .Session () as session :
266- with open (cookiefile , 'rb' ) as cf :
267- session .cookies .update (pickle .load (cf ))
258+ session .cookies .update (await common .parseCookieFile (cookiefile ))
268259 res = session .get (url = url )
269260 if meta ['debug' ]:
270261 console .print ('[cyan]Cookies:' )
@@ -276,7 +267,13 @@ async def validate_cookies(self, meta, cookiefile):
276267 return False
277268 else :
278269 return False
279-
270+
271+
272+
273+ """
274+ Old login method, disabled because of site's DDOS protection. Better to use exported cookies.
275+
276+
280277 async def login(self, cookiefile):
281278 with requests.Session() as session:
282279 url = "https://hd-torrents.org/login.php"
@@ -300,17 +297,8 @@ async def login(self, cookiefile):
300297 await asyncio.sleep(1)
301298 console.print(response.url)
302299 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
300+ """
301+
314302
315303 async def get_csrfToken (self , session , url ):
316304 r = session .get (url )
0 commit comments