import time import subprocess import argparse def command (cmd, timeout = 60 ): '' ' : param cmd: execute the command cmd and return the content of the command output. : param timeout: maximum waiting time, unit: second : return: '' ' p = subprocess.Popen (cmd, stderr = subprocess.STDOUT, stdout = subprocess.PIPE, shell = True) t_beginning = time.time () while True: if p.poll () is not None: break seconds_passed = time.time () -t_beginning if timeoutand seconds_passed > timeout: p.terminate() time.sleep(0.1) return p.stdout.read().decode('utf-8') def run(): ''' :param cmd: :param timeout: 默认20秒 :return: 结束 you-get: Skipping /Users/yy/Movies/斗罗大陆_06.mp4: file already exists ''' params = argparse.ArgumentParser() params.add_argument('-u', '--url') params.add_argument('-o', '--output', default='/Users/yy/Movies/') params.add_argument('-t', '--timeout', default=20, type=int) args = params.parse_args() cmd = 'you-get {0} -o {1}'.format(args.url, args.output) timeout = args.timeout if args.url is None: print('请输入下载地址') else: while True: result = command(cmd, timeout) print(result) res = result.find('exists') if res == -1: print('继续下载') else: break if __name__ == "__main__": run()
To use python3.7, you need to install you-get
pip3 install you-get
Solve the problem of Tencent download interruption, this method can download the full video