#!/usr/bin/python3
import threading import time exitFlag = 0 import subprocess class myThread (threading.Thread): def __init__(self, threadID, name): threading.Thread.__init__(self) self.threadID = threadID self.name = name self.counter = threadID self.i= threadID def run(self): print ("开始线程:" + self.name) print_time(self.name, self.counter, 5) url = " https://www.bilibili.com/video/BV1WJ411k7L3?p={}".format(self.i) command = 'you-get -o F:\\Tcai ' + url print(command) subprocess.call(command, shell=True) print ("退出线程:" + self.name) def print_time(threadName, delay, counter): while counter: if exitFlag: threadName.exit() time.sleep(delay) print ("%s: %s" % (threadName, time.ctime(time.time()))) counter -= 1 threads = [] for i in range(1,259): thread = myThread(i, "Thread-{}".format(i)) thread.start() threads.append(thread) for th in threads: th.jion() print ("退出主线程")
注意:多线程下载 容易被封IP
可以单线程下载。有点慢哦
#!/usr/bin/python3 import subprocess for i in range(300,400): url = "https://www.bilibili.com/video/BV1Kb411W75N?p={}".format(i) command = 'you-get -o G:\\guigu ' + url print(command) subprocess.call(command, shell=True)