you-get是github上python的一個(gè)開源庫(https://github.com/soimort/you-get)封拧,使用you-get你只需要取得視頻所在網(wǎng)頁鏈接地址就可以很輕松的下載下來误趴,目前you-get所支持的網(wǎng)站包含國內(nèi)外幾十個(gè)網(wǎng)站(youtube、twitter、騰訊成福、愛奇藝、優(yōu)酷困食、bilibili等),基本上可以滿足你的需求翎承。
1.you-get可以直接通過命令行使用(前提是你要先安裝you-get:pip install you-get)
下載命令:you-get ?your-url
l例如:you-get? https://www.bilibili.com/bangumi/play/ep118488?from=search&seid=5050973611974373611
效果如下:(我直接在pycharm的終端命令行執(zhí)行)
2.通過python 簡單調(diào)用you-get庫
# 硕盹!/usr/bin/env python
# -*-coding:utf-8-*-
import sys
import you_get
def download(url, path):
? ? sys.argv = ['you-get', '-o', path, url]
? ? you_get.main()
if __name__ == '__main__':
? ? # 視頻網(wǎng)站的地址
? ? url = 'https://www.bilibili.com/bangumi/play/ep118488?from=search&seid=5050973611974373611'
? ? # 視頻輸出的位置
? ? path = 'G:/test'
? ? download(url, path)
3.python 簡單集成 tkinter,通過GUI的形式展現(xiàn)(單線程叨咖,未做優(yōu)化瘩例,后續(xù)做優(yōu)化處理)
import re,sys甸各,you_get垛贤,webbrowser
import tkinter as tk
import tkinter.messagebox as msgbox
"""
視頻下載類
"""
class DownloadApp:
? ? # construct
? ? def __init__(self, width=800, height=200):
? ? ? ? self.w = width
? ? ? ? self.h = height
? ? ? ? self.title = '視頻下載助手'
? ? ? ? self.root = tk.Tk(className=self.title)
? ? ? ? self.url = tk.StringVar()
? ? ? ? self.start = tk.IntVar()
? ? ? ? self.end = tk.IntVar()
? ? ? ? self.path = tk.StringVar()
? ? ? ? self.path.set('D:/DownloadApp')
? ? ? ? # define frame
? ? ? ? frame_1 = tk.Frame(self.root)
? ? ? ? frame_2 = tk.Frame(self.root)
? ? ? ? frame_3 = tk.Frame(self.root)
? ? ? ? frame_4 = tk.Frame(self.root)
? ? ? ? # menu
? ? ? ? menu = tk.Menu(self.root)
? ? ? ? self.root.config(menu=menu)
? ? ? ? menu1 = tk.Menu(menu, tearoff=0)
? ? ? ? menu.add_cascade(label='Menu', menu=menu1)
? ? ? ? menu1.add_command(label='about me', command=lambda: webbrowser.open('https://blog.csdn.net/zwx19921215'))
? ? ? ? menu1.add_command(label='exit', command=lambda: self.root.quit())
? ? ? ? # set frame_1
? ? ? ? label1 = tk.Label(frame_1, text='請(qǐng)輸入視頻鏈接:')
? ? ? ? entry_url = tk.Entry(frame_1, textvariable=self.url, highlightcolor='Fuchsia', highlightthickness=1, width=35)
? ? ? ? # set frame_2
? ? ? ? s_lable = tk.Label(frame_2, text='起始值:')
? ? ? ? e_lable = tk.Label(frame_2, text='結(jié)束值:')
? ? ? ? start = tk.Entry(frame_2, textvariable=self.start, highlightcolor='Fuchsia', highlightthickness=1, width=10)
? ? ? ? end = tk.Entry(frame_2, textvariable=self.end, highlightcolor='Fuchsia', highlightthickness=1, width=10)
? ? ? ? # set frame_3
? ? ? ? label2 = tk.Label(frame_3, text='請(qǐng)輸入視頻輸出地址:')
? ? ? ? entry_path = tk.Entry(frame_3, textvariable=self.path, highlightcolor='Fuchsia', highlightthickness=1, width=35)
? ? ? ? down = tk.Button(frame_3, text='下載', font=('楷體', 12), fg='green', width=3, height=-1,
? ? ? ? ? ? ? ? ? ? ? ? command=self.video_download)
? ? ? ? # set frame_4
? ? ? ? label_desc = tk.Label(frame_4, fg='black', font=('楷體', 12),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? text='\n注意:支持youtube、twitter痴晦、騰訊南吮、愛奇藝、優(yōu)酷誊酌、bilibili等大部分主流網(wǎng)站視頻下載部凑、圖片下載!')
? ? ? ? label_warning = tk.Label(frame_4, fg='blue', font=('楷體', 12), text='\nauthor:xiaofeng')
? ? ? ? # layout
? ? ? ? frame_1.pack()
? ? ? ? frame_2.pack()
? ? ? ? frame_3.pack()
? ? ? ? frame_4.pack()
? ? ? ? label1.grid(row=0, column=0)
? ? ? ? entry_url.grid(row=0, column=1)
? ? ? ? s_lable.grid(row=1, column=0)
? ? ? ? start.grid(row=1, column=1)
? ? ? ? e_lable.grid(row=1, column=2)
? ? ? ? end.grid(row=1, column=3)
? ? ? ? label2.grid(row=2, column=0)
? ? ? ? entry_path.grid(row=2, column=1)
? ? ? ? down.grid(row=2, column=2, ipadx=20)
? ? ? ? label_desc.grid(row=3, column=0)
? ? ? ? label_warning.grid(row=4, column=0)
? ? """
? ? 視頻下載
? ? """
? ? def video_download(self):
? ? ? ? # 正則表達(dá)是判定是否為合法鏈接
? ? ? ? url = self.url.get()
? ? ? ? path = self.path.get()
? ? ? ? if re.match(r'^https?:/{2}\w.+$', url):
? ? ? ? ? ? if path != '':
? ? ? ? ? ? ? ? msgbox.showwarning(title='警告', message='下載過程中窗口如果出現(xiàn)短暫卡頓說明文件正在下載中碧浊!')
? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? sys.argv = ['you-get', '-o', path, url]
? ? ? ? ? ? ? ? ? ? you_get.main()
? ? ? ? ? ? ? ? except Exception as e:
? ? ? ? ? ? ? ? ? ? print(e)
? ? ? ? ? ? ? ? ? ? msgbox.showerror(title='error', message=e)
? ? ? ? ? ? ? ? msgbox.showinfo(title='info', message='下載完成涂邀!')
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? msgbox.showerror(title='error', message='輸出地址錯(cuò)誤!')
? ? ? ? else:
? ? ? ? ? ? msgbox.showerror(title='error', message='視頻地址錯(cuò)誤箱锐!')
? ? def center(self):
? ? ? ? ws = self.root.winfo_screenwidth()
? ? ? ? hs = self.root.winfo_screenheight()
? ? ? ? x = int((ws / 2) - (self.w / 2))
? ? ? ? y = int((hs / 2) - (self.h / 2))
? ? ? ? self.root.geometry('{}x{}+{}+{}'.format(self.w, self.h, x, y))
? ? def event(self):
? ? ? ? self.root.resizable(False, False)
? ? ? ? self.center()
? ? ? ? self.root.mainloop()
if __name__ == '__main__':
? ? app = DownloadApp()
? ? app.event()