python制作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:\\bilibili视频\\"
    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:\\bilibili视频\\')

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()
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值