1. 程式人生 > 實用技巧 >you-get 多執行緒下載網站視訊

you-get 多執行緒下載網站視訊

#!/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 ("退出主執行緒")