11import downloader
22import ytdl
3- from utils import Downloader , Session , try_n , LazyUrl , get_ext , format_filename , get_print , get_resolution
3+ from utils import Downloader , Session , try_n , LazyUrl , get_ext , format_filename , get_print , get_resolution , print_error , cut_pair , json
44from io import BytesIO
55import ree as re
66from m3u8_tools import playlist2stream , M3u8_stream
@@ -19,7 +19,8 @@ class Downloader_etc(Downloader):
1919 display_name = 'Etc'
2020 PRIORITY = 10
2121
22- def init (self ):
22+ @try_n (2 )
23+ def read (self ):
2324 self .session = Session ()
2425 name = ytdl .get_extractor_name (self .url )
2526 self .print_ ('extractor: {}' .format (name ))
@@ -28,21 +29,20 @@ def init(self):
2829 #if name == 'generic':
2930 # raise NotImplementedError()
3031
31- def read (self ):
3232 video = get_video (self .url , self .session , self .cw )
3333
3434 if video .artist :
3535 self .artist = video .artist
3636
37- self .urls .append (video .url )
38-
3937 self .print_ ('url_thumb: {}' .format (video .url_thumb ))
4038 self .setIcon (video .thumb )
41- if video .header .lower () not in ['yourporn' , 'spankbang' ]:
39+ if video .header .lower () not in ['yourporn' ]:
4240 self .enableSegment ()#
4341 if isinstance (video .url (), M3u8_stream ):
4442 self .disableSegment ()
4543
44+ self .urls .append (video .url )
45+
4646 self .title = os .path .splitext (video .filename )[0 ].replace (':' , ':' )
4747
4848
@@ -69,17 +69,52 @@ def get_video(url, session, cw, ie_key=None):
6969 if isinstance (video , Exception ):
7070 raise video
7171 if isinstance (video .url (), M3u8_stream ):
72- c = video .url ().segs [0 ].download (2 , cw )
72+ c = video .url ().urls [0 ][ 1 ] .download (cw )
7373 if not c :
7474 raise Exception ('invalid m3u8' )
7575 return video
7676 except Exception as e :
7777 if isinstance (e , UnSupportedError ):
7878 raise e
79- print_ (e )
79+ print_ (print_error ( e ) )
8080 return _get_video (url , session , cw , ie_key , allow_m3u8 = False )
8181
82- @try_n (4 )
82+
83+ def extract_info_spankbang (url , session , cw ): # temp fix
84+ print_ = get_print (cw )
85+ soup = downloader .read_soup (url , session = session )
86+
87+ for script in soup .findAll ('script' ):
88+ script = script .string
89+ if script and 'var stream_data' in script :
90+ s = cut_pair (script .split ('var stream_data' )[- 1 ].strip (' \t =' ).replace ("'" , '"' ))
91+ break
92+ else :
93+ raise Exception ('no stream_data' )
94+
95+ info = {}
96+ info ['url' ] = url
97+ info ['title' ] = soup .find ('h1' ).text .strip ()
98+ info ['id' ] = re .find (r'spankbang\.com/([^/]+)' , soup .find ('meta' , {'property' : 'og:url' })['content' ], err = 'no id' )
99+ info ['thumbnail' ] = soup .find ('meta' , {'property' : 'og:image' })['content' ]
100+ info ['formats' ] = []
101+ data = json .loads (s )
102+ for res , item in data .items ():
103+ if res == 'main' :
104+ continue
105+ if item and isinstance (item , list ):
106+ item = item [0 ]
107+ else :
108+ continue
109+ ext = get_ext_ (item , session , url )
110+ res = {'4k' : '2160p' , '8k' : '4320p' , '16k' : '8640p' }.get (res , res )
111+ f = {'url' : item , 'format' : res }
112+ info ['formats' ].append (f )
113+
114+ return info
115+
116+
117+ @try_n (2 )
83118def _get_video (url , session , cw , ie_key = None , allow_m3u8 = True ):
84119 print_ = get_print (cw )
85120 print_ ('get_video: {}, {}' .format (allow_m3u8 , url ))
@@ -90,14 +125,15 @@ def _get_video(url, session, cw, ie_key=None, allow_m3u8=True):
90125 'writesubtitles' : True ,
91126 }
92127 if ytdl .get_extractor_name (url ) == 'spankbang' :
93- options ['legacyserverconnect' ] = True #6545
94- ydl = ytdl .YoutubeDL (options , cw = cw )
95- try :
96- info = ydl .extract_info (url )
97- except Exception as e :
98- if 'ERROR: Unsupported URL' in str (e ):
99- return UnSupportedError (str (e ))
100- raise e
128+ info = extract_info_spankbang (url , session , cw )
129+ else :
130+ ydl = ytdl .YoutubeDL (options , cw = cw )
131+ try :
132+ info = ydl .extract_info (url )
133+ except Exception as e :
134+ if 'ERROR: Unsupported URL' in str (e ):
135+ return UnSupportedError (str (e ))
136+ raise e
101137 if not ie_key :
102138 ie_key = ytdl .get_extractor_name (url )
103139 info ['ie_key' ] = ie_key
@@ -191,6 +227,7 @@ class Video:
191227 def __init__ (self , f , f_audio , info , session , referer , cw = None ):
192228 self .f_audio = f_audio
193229 self .cw = cw
230+ print_ = get_print (cw )
194231 self .title = title = info ['title' ]
195232 self .id = info ['id' ]
196233 self .url = f ['url' ]
@@ -222,15 +259,19 @@ def foo():
222259
223260 if ext .lower () == '.m3u8' :
224261 res = get_resolution () #4773
225- if info .get ('live_status' ) == 'is_live' :
262+ ls = info .get ('live_status' )
263+ print_ (f'live_status: { ls } ' )
264+ if ls == 'is_live' :
226265 url = foo ()
227266 else :
228267 try :
229- url = playlist2stream (self .url , referer , session = session , n_thread = 4 )
268+ url = playlist2stream (self .url , referer , session = session )
230269 except :
231- url = M3u8_stream (self .url , referer = referer , session = session , n_thread = 4 )
232- if url .live is not None : #5110
233- url = foo ()
270+ url = M3u8_stream (self .url , referer = referer , session = session )
271+ print_ (f'mpegts: { url .mpegts } ' )
272+ if url .ms or url .mpegts == False : #5110
273+ url = url .live
274+ url ._cw = cw
234275 ext = '.mp4'
235276 elif ext .lower () == '.mpd' : # TVer
236277 url = foo ()
0 commit comments