def launch_player(player, urls, ext, **args): if ' ' in player: cmd = shlex.split(player, posix=posix) if not posix: cmd = [ arg[1:-1] if arg[0] == arg[-1] == "'" else arg for arg in cmd ] else: cmd = [player] if 'mpv' in cmd[0]: if ext == 'm3u8' and any(os.path.isfile(url) for url in urls): cmd += [ '--demuxer-lavf-o', 'protocol_whitelist=[file,tcp,http,https,tls]' ] if args['ua']: cmd += ['--user-agent', args['ua']] if args['referer']: cmd += ['--referrer', args['referer']] if args['title']: cmd += [ '--force-media-title', encode_for_wrap(args['title'], 'ignore') ] if args['header']: cmd += ['--http-header-fields', args['header']] urls = [encode_for_wrap(url) for url in urls] if args['rangefetch']: urls = ['http://127.0.0.1:8806/' + url for url in urls] cmds = split_cmd_urls(cmd, urls) env = os.environ.copy() env.pop('HTTP_PROXY', None) env.pop('HTTPS_PROXY', None) from ykdl.util.rangefetch_server import start_new_server new_server = start_new_server(**args['rangefetch']) for cmd in cmds: subprocess.call(cmd, env=env) new_server.server_close() else: urls = list(urls) cmds = split_cmd_urls(cmd, urls) if args['proxy']: env = os.environ.copy() env['HTTP_PROXY'] = args['proxy'] env['HTTPS_PROXY'] = args['proxy'] else: env = None for cmd in cmds: subprocess.call(cmd, env=env)
def launch_player(player, urls, ext, play=True, **args): if ' ' in player: lex = shlex.shlex(player, posix=nt or posix) lex.whitespace_split = True if nt: lex.quotes = '"' lex.escape = '' cmd = list(lex) else: cmd = [player] if 'mpv' in cmd[0]: if ext == 'm3u8' and any(os.path.isfile(url) for url in urls): cmd += [ '--demuxer-lavf-o=protocol_whitelist=[file,http,https,tls,rtp,tcp,udp,crypto,httpproxy]' ] if args['ua']: cmd += ['--user-agent=' + args['ua']] if args['referer']: cmd += ['--referrer=' + args['referer']] if args['title']: cmd += ['--force-media-title=' + args['title']] if args['header']: cmd += ['--http-header-fields=' + args['header']] if args['subs']: for sub in args['subs']: cmd += ['--sub-file', sub] if args['rangefetch']: urls = ['http://127.0.0.1:8806/' + url for url in urls] cmds = split_cmd_urls(cmd, urls) env = os.environ.copy() env.pop('HTTP_PROXY', None) env.pop('HTTPS_PROXY', None) from ykdl.util.rangefetch_server import start_new_server cleanup = start_new_server(**args['rangefetch']).server_close phandle = PlayerHandle(cmds, env, cleanup=cleanup) else: urls = list(urls) cmds = split_cmd_urls(cmd, urls) if args['proxy'].lower().startswith('http'): env = os.environ.copy() env['HTTP_PROXY'] = args['proxy'] env['HTTPS_PROXY'] = args['proxy'] else: env = None phandle = PlayerHandle(cmds, env) if play: phandle.play() return phandle
def launch_player(player, urls, ext, play=True, **args): if ' ' in player: cmd = shlex.split(player, posix=posix) if not posix: cmd = [ arg[1:-1] if arg[0] == arg[-1] == "'" else arg for arg in cmd ] else: cmd = [player] if 'mpv' in cmd[0]: if ext == 'm3u8' and any(os.path.isfile(url) for url in urls): cmd += [ '--demuxer-lavf-o=protocol_whitelist=[file,http,https,tls,rtp,tcp,udp,crypto,httpproxy]' ] if args['ua']: cmd += ['--user-agent=' + args['ua']] if args['referer']: cmd += ['--referrer=' + args['referer']] if args['title']: cmd += [ '--force-media-title=' + encode_for_wrap(args['title'], 'ignore') ] if args['header']: cmd += ['--http-header-fields=' + args['header']] urls = [encode_for_wrap(url) for url in urls] if args['rangefetch']: urls = ['http://127.0.0.1:8806/' + url for url in urls] cmds = split_cmd_urls(cmd, urls) env = os.environ.copy() env.pop('HTTP_PROXY', None) env.pop('HTTPS_PROXY', None) from ykdl.util.rangefetch_server import start_new_server cleanup = start_new_server(**args['rangefetch']).server_close phandle = PlayerHandle(cmds, env, cleanup=cleanup) else: urls = list(urls) cmds = split_cmd_urls(cmd, urls) if args['proxy'].lower().startswith('http'): env = os.environ.copy() env['HTTP_PROXY'] = args['proxy'] env['HTTPS_PROXY'] = args['proxy'] else: env = None phandle = PlayerHandle(cmds, env) if play: phandle.play() return phandle
def launch_player(player, urls, ext, **args): if ' ' in player: cmd = shlex.split(player, posix=posix) if not posix: cmd = [arg[1:-1] if arg[0] == arg[-1] == "'" else arg for arg in cmd] else: cmd = [player] if 'mpv' in cmd[0]: if ext == 'm3u8' and any(os.path.isfile(url) for url in urls): cmd += ['--demuxer-lavf-o', 'protocol_whitelist=[file,tcp,http,https,tls]'] if args['ua']: cmd += ['--user-agent', args['ua']] if args['referer']: cmd += ['--referrer', args['referer']] if args['title']: cmd += ['--force-media-title', encode_for_wrap(args['title'], 'ignore')] if args['header']: cmd += ['--http-header-fields', args['header']] urls = [encode_for_wrap(url) for url in urls] if args['rangefetch']: urls = ['http://127.0.0.1:8806/' + url for url in urls] cmds = split_cmd_urls(cmd, urls) env = os.environ.copy() env.pop('HTTP_PROXY', None) env.pop('HTTPS_PROXY', None) from ykdl.util.rangefetch_server import start_new_server new_server = start_new_server(**args['rangefetch']) for cmd in cmds: subprocess.call(cmd, env=env) new_server.server_close() else: urls = list(urls) cmds = split_cmd_urls(cmd, urls) if args['proxy']: env = os.environ.copy() env['HTTP_PROXY'] = args['proxy'] env['HTTPS_PROXY'] = args['proxy'] else: env = None for cmd in cmds: subprocess.call(cmd, env=env)
def launch_player(player, urls, **args): if ' ' in player: cmd = shlex.split(player, posix=posix) if not posix: cmd = [ arg[1:-1] if arg[0] == arg[-1] == "'" else arg for arg in cmd ] else: cmd = [player] if 'mpv' in cmd[0]: cmd += ['--demuxer-lavf-o', 'protocol_whitelist=[file,tcp,http]'] if args['ua']: cmd += ['--user-agent', args['ua']] if args['referer']: cmd += ['--referrer', args['referer']] if args['title']: cmd += ['--force-media-title', args['title']] if args['header']: cmd += ['--http-header-fields', args['header']] if args['rangefetch']: cmd += ['http://127.0.0.1:8806/' + url for url in urls] env = os.environ.copy() env.pop('HTTP_PROXY', None) env.pop('HTTPS_PROXY', None) from ykdl.util.rangefetch_server import start_new_server new_server = start_new_server(**args['rangefetch']) subprocess.call(cmd, env=env) new_server.server_close() else: cmd += list(urls) if args['proxy']: env = os.environ.copy() env['HTTP_PROXY'] = args['proxy'] env['HTTPS_PROXY'] = args['proxy'] subprocess.call(cmd, env=env) else: subprocess.call(cmd)
def launch_player(player, urls, ext, play=True, **args): if ' ' in player: lex = shlex.shlex(player, posix=nt or posix) lex.whitespace_split = True if nt: lex.quotes = '"' lex.escape = '' cmd = list(lex) else: cmd = [player] if 'mpv' in cmd[0]: if ext == 'm3u8' and any(os.path.isfile(url) for url in urls): cmd += [ '--demuxer-lavf-o=protocol_whitelist=[file,http,https,tls,rtp,tcp,udp,crypto,httpproxy]' ] if args['ua']: cmd += ['--user-agent=' + args['ua']] if args['referer']: cmd += ['--referrer=' + args['referer']] if args['title']: cmd += ['--force-media-title=' + args['title']] if args['header']: header = args['header'] if not isinstance(header, str): header = ','.join("'{}: {}'".format(k, v) for k, v in header.items()) cmd += ['--http-header-fields=' + header] if args['subs']: for sub in args['subs']: cmd += ['--sub-file=' + sub] start_new_server = None if args['rangefetch']: try: from ykdl.util.rangefetch_server import start_new_server except ImportError: logger.warning( 'start rangefetch failed, please install urllib3 to use it') else: args['rangefetch']['header'] = header = args['header'] or {} if isinstance(header, str): header = { k.strip(): v.strip() for k, v in [ kv.split(':', 1) for kv in header.strip("'").split("','") ] } if args['ua']: header['User-Agent'] = args['ua'] if args['referer']: header['Referrer'] = header['Referer'] = args['referer'] new_server = start_new_server(**args['rangefetch']) urls = [new_server.url_prefix + url for url in urls] cmds = split_cmd_urls(cmd, urls) env = os.environ.copy() env.pop('HTTP_PROXY', None) env.pop('HTTPS_PROXY', None) phandle = PlayerHandle(cmds, env, cleanup=new_server.server_close) if start_new_server is None: urls = list(urls) cmds = split_cmd_urls(cmd, urls) if args['proxy'].lower().startswith('http:'): env = os.environ.copy() env['HTTP_PROXY'] = args['proxy'] env['HTTPS_PROXY'] = args['proxy'] else: env = None phandle = PlayerHandle(cmds, env) if play: phandle.play() return phandle