Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
})
handlers.append(proxy_handler)
elif args.socks_proxy:
try:
import socks
addr, port = args.socks_proxy.split(':')
socks.set_default_proxy(socks.SOCKS5, addr, int(port))
socket.socket = socks.socksocket
except:
print('Failed to set socks5 proxy. Please install PySocks.', file=sys.stderr)
opener = build_opener(*handlers)
install_opener(opener)
m, u = url_to_module(args.video_url)
info = m.parser(u)
# Is a playlist?
if m.list_only():
video_list = m.prepare_list()
result = [ {'title': match1(get_content(url), r'<title>(.+?)</title>'), 'url': url} for url in video_list ]
else:
result = info.jsonlize()
print(json.dumps(result, indent=4, sort_keys=True, ensure_ascii=False))
def _parser(self, video_info):
if 'info' in video_info:
return video_info['info']
elif 'site' in video_info:
site = video_info['site']
vid = video_info['vid']
if site in alias.keys():
site = alias[site]
s = import_module('.'.join(['ykdl','extractors',site])).site
info = s.parser(vid)
elif 'url' in video_info:
url = video_info['url']
s, u = url_to_module(url)
info = s.parser(u)
if 'title' in video_info:
info.title = video_info['title']
if 'artist' in video_info:
info.artist = video_info['artist']
if 'extra' in video_info and video_info['extra']:
info.extra.update(video_info['extra'])
return info
def check_stream(self):
logger.debug(self.fname)
site, url = url_to_module(self.url)
try:
info = site.parser(url)
except AssertionError:
return
stream_id = info.stream_types[0]
urls = info.streams[stream_id]['src']
self.ydl_opts['absurl'] = urls[0]
# print(info.title)
return True