File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,13 +30,21 @@ def download_all():
3030 discord .send ('Downloaded ' + t [1 ] + ' - ' + t [2 ] + ' / ' + t [3 ] + ' / ' + t [4 ])
3131
3232def download_torrent (torrent_id ):
33- download_link = wat .download_link (torrent_id )
3433 download_path = settings .get ('torrent' )[1 ]
3534 save_to = download_path + torrent_id + ".torrent"
3635
3736 opener = urllib .request .build_opener ()
3837 opener .addheaders = [('User-agent' , 'Mozilla/5.0' )]
39- torrent = opener .open (download_link ).read ()
38+
39+ # First attempt with token (if enabled in settings)
40+ download_url = wat .download_link (torrent_id )
41+ torrent = opener .open (download_url ).read ()
42+
43+ # Check if we ran out of tokens, retry without token
44+ if b'You do not have any freeleech tokens left' in torrent :
45+ print ("No freeleech tokens left, retrying without token" )
46+ download_url = wat .download_link (torrent_id , use_token = False )
47+ torrent = opener .open (download_url ).read ()
4048
4149 output = open (save_to ,'wb' )
4250 output .write (torrent )
Original file line number Diff line number Diff line change @@ -79,14 +79,17 @@ def get_group(group_id):
7979 except :
8080 return "no data"
8181
82- def download_link (torrent_id ):
82+ def download_link (torrent_id , use_token = None ):
8383 domain = settings .get ('domain' )[1 ]
84- use_tokens_setting = settings .get ('use_tokens' )
85- token_count = use_tokens_setting [2 ] if use_tokens_setting [2 ] else '0'
86- use_tokens = use_tokens_setting [1 ] == 'true' and int (token_count ) > 0
84+
85+ # If use_token is explicitly specified, use that; otherwise check settings
86+ if use_token is None :
87+ use_tokens_setting = settings .get ('use_tokens' )
88+ token_count = use_tokens_setting [2 ] if use_tokens_setting [2 ] else '0'
89+ use_token = use_tokens_setting [1 ] == 'true' and int (token_count ) > 0
8790
8891 url = domain + '/torrents.php?action=download&id=' + torrent_id + '&authkey=' + handle ().authkey + '&torrent_pass=' + handle ().passkey
89- if use_tokens :
92+ if use_token :
9093 url += '&usetoken=1'
9194
9295 print (url )
You can’t perform that action at this time.
0 commit comments