1
+ import re
1
2
import requests
2
3
import json
3
4
import os
@@ -120,17 +121,42 @@ def get_download_link(self, url):
120
121
url ,
121
122
cookies = dict (auth = gogoanime .get_gogoanime_auth_cookie (self )),
122
123
)
123
-
124
+ quality_arr = [ "1080" , "720" , "640" , "480" ]
124
125
soup = BeautifulSoup (page .content , "html.parser" )
125
-
126
- for link in soup .find_all ("a" , href = True ):
127
- if self .episode_quality in link .text :
126
+ try :
127
+ for link in soup .find_all (
128
+ "a" , href = True , string = re .compile (self .episode_quality )
129
+ ):
128
130
return link ["href" ]
129
-
130
- def file_downloader (self , file_list : dict ):
131
+ else :
132
+ ep_num = url .rsplit ("-" , 1 )[1 ]
133
+ print (
134
+ f"{ self .episode_quality } not found for ep{ ep_num } checking for next best"
135
+ )
136
+ for q in quality_arr :
137
+ for link in soup .find_all ("a" , href = True , string = re .compile (q )):
138
+ print (f"{ q } found." )
139
+ return link ["href" ]
140
+ except :
141
+ print ("No matching download found" )
142
+
143
+ def file_downloader (self , file_list : dict , overwrite_downloads : bool = None ):
144
+ """[summary]
145
+
146
+ Args:
147
+ file_list (dict): [description]
148
+ overwrite_downloads (bool, optional): [description]. Defaults to None.
149
+
150
+ Returns:
151
+ [type]: [description]
152
+ """
153
+ if overwrite_downloads is None :
154
+ overwrite = self .config ["OverwriteDownloads" ]
155
+ else :
156
+ overwrite = overwrite_downloads
131
157
dl = Downloader (
132
158
max_conn = max_concurrent_downloads (self .config ["MaxConcurrentDownloads" ]),
133
- overwrite = self . config [ "OverwriteDownloads" ] ,
159
+ overwrite = overwrite ,
134
160
headers = dict (
135
161
[
136
162
(
@@ -147,10 +173,11 @@ def file_downloader(self, file_list: dict):
147
173
)
148
174
149
175
for link in file_list :
150
- dl .enqueue_file (
151
- link ,
152
- path = f"./{ self .title } " ,
153
- )
176
+ if link is not None :
177
+ dl .enqueue_file (
178
+ link ,
179
+ path = f"./{ self .title } " ,
180
+ )
154
181
155
182
files = dl .download ()
156
183
return files
0 commit comments