def print_stream_info(self, stream_id, show_all = False): stream = self.streams[stream_id] print(" - format: %s" % log.sprint(stream_id, log.NEGATIVE)) if 'container' in stream: print(" container: %s" % stream['container']) if 'video_profile' in stream: print(" video-profile: %s" % stream['video_profile']) if 'quality' in stream: print(" quality: %s" % stream['quality']) if 'size' in stream and stream['size'] != 0 and stream['size'] != float('inf'): print(" size: %s MiB (%s bytes)" % (round(stream['size'] / 1048576, 1), stream['size'])) print(" # download-with: %s" % log.sprint("ykdl --format=%s [URL]" % stream_id, log.UNDERLINE)) if show_all: print("Real urls:") for url in stream['src']: print("%s" % url)
def setup(self, info): # Hot-plug cookie handler ssl_context = HTTPSHandler( context=ssl.SSLContext(ssl.PROTOCOL_TLSv1)) cookie_handler = HTTPCookieProcessor() opener = build_opener(ssl_context, cookie_handler) opener.addheaders = [('Cookie','__ysuid=%d' % time.time())] install_opener(opener) add_header('Referer', 'v.youku.com') install_acode('4', '1', 'b4et', 'boa4', 'o0b', 'poz') if self.url and not self.vid: self.vid = match1(self.url, 'youku\.com/v_show/id_([a-zA-Z0-9=]+)' ,\ 'player\.youku\.com/player\.php/sid/([a-zA-Z0-9=]+)/v\.swf',\ 'loader\.swf\?VideoIDS=([a-zA-Z0-9=]+)',\ 'loader\.swf\?VideoIDS=([a-zA-Z0-9=]+)',\ 'player\.youku\.com/embed/([a-zA-Z0-9=]+)') api_url = 'http://play.youku.com/play/get.json?vid=%s&ct=12' % self.vid api_url1 = 'http://play.youku.com/play/get.json?vid=%s&ct=10' % self.vid try: meta = json.loads(get_content(api_url)) meta1 = json.loads(get_content(api_url1)) data = meta['data'] data1 = meta1['data'] assert 'stream' in data1 except: if 'error' in data1: if data1['error']['code'] == -202: # Password protected self.password_protected = True self.password = input(log.sprint('Password: '******'&pwd={}'.format(self.password) api_url1 += '&pwd={}'.format(self.password) meta1 = json.loads(get_content(api_url1)) meta = json.loads(get_content(api_url)) data1 = meta1['data'] data = meta['data'] else: raise AssertionError('[Failed] ' + data1['error']['note']) else: raise AssertionError('[Failed] Video not found.') info.title = data['video']['title'] self.ep = data['security']['encrypt_string'] self.ip = data['security']['ip'] try: self.stream_data = data1['stream'] except: if self.password_protected: raise AssertionError('incorrect password!!') else: raise AssertionError('No Stream found!!')
def handle_videoinfo(info): i = args.format or '0' if i.isdecimal(): i = int(i) if i > len(info.streams) - 1: i = -1 else: i = info.streams.index(i) stream_id = info.streams.get_id(i) if args.json: print( json.dumps(info.jsonlize(), indent=4, sort_keys=True, ensure_ascii=False)) else: info.print_info(stream_id, args.show_all, args.info) if args.show_all: action = args.player and 'playing' or 'downloading' print('Now %s format ' % action + log.sprint(stream_id, log.NEGATIVE)) if args.info or args.json: return urls = info.streams[stream_id]['src'] name = args.output_name if name: if '\\u' in name: name = literalize(name) if info.index is not None: name = name + '_' + str(info.index) else: name = info.build_file_name(stream_id) ext = info.streams[stream_id]['container'] live = info.live if args.player: player_args = info.extra if player_args['rangefetch']: player_args['rangefetch']['down_rate'] = player_args['rangefetch'][ 'video_rate'].get(stream_id) player_args['rangefetch']['ca_certs'] = args.certs if args.proxy != 'none': player_args['proxy'] = args.proxy if player_args['rangefetch']: player_args['rangefetch']['proxy'] = args.proxy player_args['title'] = info.title player_args['subs'] = args.no_sub or [ sub['src'] for sub in info.subtitles ] launch_player(args.player, urls, ext, **player_args) else: download(urls, name, ext, live) if not args.no_sub: download_subtitles(info.subtitles, name)
def setup(self, info): # Hot-plug cookie handler ssl_context = HTTPSHandler(context=ssl.SSLContext(ssl.PROTOCOL_TLSv1)) cookie_handler = HTTPCookieProcessor() opener = build_opener(ssl_context, cookie_handler) opener.addheaders = [('Cookie', '__ysuid=%d' % time.time())] install_opener(opener) add_header('Referer', 'v.youku.com') install_acode('4', '1', 'b4et', 'boa4', 'o0b', 'poz') if self.url and not self.vid: self.vid = match1(self.url, 'youku\.com/v_show/id_([a-zA-Z0-9=]+)' ,\ 'player\.youku\.com/player\.php/sid/([a-zA-Z0-9=]+)/v\.swf',\ 'loader\.swf\?VideoIDS=([a-zA-Z0-9=]+)',\ 'loader\.swf\?VideoIDS=([a-zA-Z0-9=]+)',\ 'player\.youku\.com/embed/([a-zA-Z0-9=]+)') api_url = 'http://play.youku.com/play/get.json?vid=%s&ct=12' % self.vid api_url1 = 'http://play.youku.com/play/get.json?vid=%s&ct=10' % self.vid try: meta = json.loads(get_content(api_url)) meta1 = json.loads(get_content(api_url1)) data = meta['data'] data1 = meta1['data'] assert 'stream' in data1 except: if 'error' in data1: if data1['error']['code'] == -202: # Password protected self.password_protected = True self.password = input(log.sprint('Password: '******'&pwd={}'.format(self.password) api_url1 += '&pwd={}'.format(self.password) meta1 = json.loads(get_content(api_url1)) meta = json.loads(get_content(api_url)) data1 = meta1['data'] data = meta['data'] else: raise AssertionError('[Failed] ' + data1['error']['note']) else: raise AssertionError('[Failed] Video not found.') info.title = data['video']['title'] self.ep = data['security']['encrypt_string'] self.ip = data['security']['ip'] try: self.stream_data = data1['stream'] except: if self.password_protected: raise AssertionError('incorrect password!!') else: raise AssertionError('No Stream found!!')
def print_subtitle_info(self, subtitle, show_all=False): print(' - language: %s' % log.sprint(subtitle['lang'], log.NEGATIVE)) if 'name' in subtitle: print(' name: %s' % subtitle['name']) print(' format: %s' % subtitle['format']) size = subtitle.get('size') if size and size != float('inf'): print(' size: %s KiB (%s bytes)' % (round(size / 1024, 1), size)) if show_all: print('Real url:') print(subtitle['src'])