仅仅76行代码就能下载b站所有视频

先上效果图
在这里插入图片描述
再上代码

# ---------------------------------------------------------------------------------------------
import os
import tkinter as tk
from tkinter import *
from threading import *
import threading
import tkinter.messagebox

import sys
from you_get import common as you_get  # 导入you-get库
import time

nMaxThread = 4
ThreadLock = BoundedSemaphore(nMaxThread)


def Download():
    url = en1.get()
    directory = en2.get()

    if re.match(r'^https?:/{2}\w.+$', url) and directory != '':
        try:
            sys.argv = ['you-get', '-o', directory, url]

            for i in range(4):
                ThreadLock.acquire()
                t = threading.Thread(target=you_get.main(), args=())
                t = setDaemon(True)
                t.start()

            tk.messagebox.showinfo(message="下载完成")
        except:
            time.sleep(0.01)
            tk.messagebox.showerror(message="下载失败")
        finally:
            ThreadLock.release()

    else:
        tk.messagebox.showerror(message="下载失败")


def CreateSaveFile():
    filedir = "E:\\b站视频\\"
    if not os.path.exists(filedir):
        os.mkdir(filedir)


# ---------------一、窗口---------------------
root = tk.Tk()
root.title('bilibili的视频下载器')
root["height"] = 150
root["width"] = 380
root.resizable(0, 0)

lal = tk.Label(root, text="欢迎使用bilibili的视频下载器")
lal.place(x=90, y=15, width=200, height=50)

lal = tk.Label(root, text="视频链接")
lal.place(x=10, y=70, height=15)
en1 = tk.Entry(root, justify=LEFT, state=NORMAL)
en1.place(x=75, y=70, width=230, height=15)

lal = tk.Label(root, text="存放路径")
lal.place(x=10, y=100, height=15)

entry_var1 = tk.StringVar()
entry_var1.set('E:\\b站视频\\')

en2 = tk.Entry(root, textvariable=entry_var1, justify=LEFT, state=NORMAL)
en2.place(x=75, y=100, width=230, height=15)

b3 = tk.Button(root, text="下载", command=Download)
b3.place(x=320, y=70, width=45, height=45)

CreateSaveFile()
root.mainloop()

注意:光理论是不够的,在此免费送大家一套2020最新Python全栈实战视频教程,点击此处 获取一起进步哦!

创作不易,点个赞吧!!

版权声明:如无特殊说明,文章均为本站原创,转载请注明出处
本文链接:https://blog.csdn.net/wsad861512140

猜你喜欢

转载自blog.csdn.net/wsad861512140/article/details/106454086