欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python基于tkinter制作m3u8視頻下載工具

 更新時(shí)間:2021年04月24日 15:57:17   作者:raxar81  
這篇文章主要介紹了python如何基于tkinter制作m3u8視頻下載工具,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下

這是我為了學(xué)習(xí)tkinter用python 寫的一個(gè)下載m3u8視頻的小程序,程序使用了多線程下載,下載后自動(dòng)合并成一個(gè)視頻文件,方便播放。

目前的眾多視頻都是m3u8的播放類型,只要知道視頻的m3u8地址,就可以完美下載整個(gè)視頻。

m3u8地址獲取

打開瀏覽器,點(diǎn)開你要獲取地址的視頻

 

重要的來(lái)了,右鍵>>審查元素或者按F12也可以

根據(jù)開發(fā)或測(cè)試的實(shí)際環(huán)境選擇相應(yīng)的設(shè)備,選擇iphone6 plus

選擇好了以后,刷新頁(yè)面,點(diǎn)擊漏斗,選擇media,一定刷新之后再點(diǎn)擊,沒出來(lái)的話切換幾下選項(xiàng)卡,就能出來(lái)了

點(diǎn)擊播放視頻,在下邊就可以看到地址了

程序代碼

# -*- coding: UTF-8 -*-
import sys

sys.path.append("C:\\Python36-32\\Lib\\site-packages")
import tkinter
import re
import urllib3
import threadpool
import threading
import os
import shutil
import time
import glob
from tkinter.ttk import *
from PIL import Image, ImageTk
import pyperclip
from tkinter.filedialog import askdirectory

def get_image(filename,width,height):
    im = Image.open(filename).resize((width,height))
    return ImageTk.PhotoImage(im)


def get_resource_path(relative_path):
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS, relative_path)
    return os.path.join(os.path.abspath("."), relative_path)


def getrealtask(link):
    global key
    rooturl1 = ''
    rooturl2 = ''
    pattern3 = re.compile(r'^.*[\/]', re.M)
    result11 = pattern3.findall(link)
    if result11:
        rooturl1 = result11[0]
    pattern4 = re.compile(r'^http[s]?:\/\/[^\/]*', re.M)
    result114 = pattern4.findall(link)
    if result114:
        rooturl2 = result114[0]
    res = http.request('GET', link)
    content = str(res.data, 'utf8')
    list = content.split('\n')
    reallist = []
    for one in list:
        if one.endswith('"key.key"'):
            keyurl = rooturl1 + "key.key"
            res = http.request('GET', keyurl)
            key = str(res.data, 'utf8')
        if one.endswith('.ts') or one.endswith('.image'):
            if re.match(r'http', one, re.M | re.I):
                reallist.append(one)
            elif re.match(r'\/', one, re.M | re.I):
                reallist.append(rooturl2 + one)
            else:
                reallist.append(rooturl1 + one)
        if one.endswith('.m3u8'):
            if re.match(r'\/', one, re.M | re.I):
                reallist = getrealtask(rooturl2 + one)
            else:
                reallist = getrealtask(rooturl1 + one)
            break
    return reallist

def download_ts(result):
    url = result['url']
    name = result['name']
    num = result['num']
    rootpath = result['root']
    m3u8Name = result['m3u8name']
    t= str(result['total'])
    if num % 10000 == 0:
        print(str(num)+' / '+t)
    basepath = os.path.join(rootpath,m3u8Name)
    fullpath = os.path.join(basepath,name)
    isExist = os.path.exists(fullpath)
    if not isExist:
        http = urllib3.PoolManager(timeout=10.0)
        while(1):
            try:
                f = http.request('GET', url)
                break
            except:
                print("URL ERRO: " + url)
                time.sleep(2)
        d = f.data
        with open(fullpath, "wb") as code:
            code.write(d)
        print("SAVE: " + url)
def clock2(num,path):
    global window
    global key
    v3 = tkinter.StringVar();
    v4 = tkinter.StringVar();
    l3 = tkinter.Label(window, text='', textvariable=v3, font=('Arial', 10))
    l4 = tkinter.Label(window, text='', textvariable=v4, font=('Arial', 10))
    l3.place(x=10, y=130, anchor='nw')
    l4.place(x=10, y=160, anchor='nw')
    v3.set("下載中。。。")
    while(1):
        path_file_number = len(glob.glob(path+'/*.ts'))
        mp4_file_number = len(glob.glob(path + '/*.mp4'))
        numberstr = str(path_file_number) + '/'+str(num)
        v4.set(numberstr)
        if mp4_file_number==1:
            v3.set("下載完成!")
            key = ''
            break

def clock1():
    global v
    global v2
    global rootpath
    m3u8Name = v2.get()
    url = v.get()
    print(url)
    urls = getrealtask(url)
    total = len(urls)
    i = 0
    tasks = []
    tsNames = []
    for one in urls:
        task = {}
        task['root'] = rootpath
        task['m3u8name'] = m3u8Name
        task['url'] = one
        task['num'] = i
        task['total'] = total
        task['name'] = str(i) + '.ts'
        tsNames.append(str(i) + '.ts')
        i = i + 1
        tasks.append(task)
    print('tasks: ' + str(len(tasks)))
    targetpath = os.path.join(rootpath, m3u8Name)
    if not os.path.exists(targetpath):
        os.makedirs(targetpath)
    timer2 = threading.Thread(target=clock2,args=(len(tasks),targetpath))
    timer2.daemon = True
    timer2.start()
    requests = threadpool.makeRequests(download_ts, tasks)
    [task_pool.putRequest(req) for req in requests]
    task_pool.wait()
    mp4targetfile = os.path.join(targetpath, m3u8Name + '.mp4')
    with open(mp4targetfile, 'wb') as f:
        for ts in tsNames:
            tstargetfile = os.path.join(targetpath, ts)
            with open(tstargetfile, 'rb') as mergefile:
                shutil.copyfileobj(mergefile, f)
            print(tstargetfile + ' merged.')
        for tts in tsNames:
            tstargetfile = os.path.join(targetpath, tts)
            os.remove(tstargetfile)
    print(total)

def hit_me():
    global on_hit
    timer = threading.Thread(target=clock1)
    timer.daemon = True
    timer.start()
    return

def choose_dir():
    global v5
    global rootpath
    rootpath = askdirectory()
    v5.set('文件夾: '+rootpath+'/')
    return

def about():
    window = tkinter.Toplevel()
    window.geometry('600x100')# Note Toplevel, NOT Tk.
    msg = 'Rax m3u8下載器 v1.4\n寫這個(gè)程序主要是為了學(xué)習(xí)Tk,順便滿足下自己看視頻的需求。\n家里的移動(dòng)網(wǎng)絡(luò)看在線視頻還是有些卡頓的。 '
    label = tkinter.Label(window, text=msg,font=('Arial', 15))
    label.grid()
def update():
    window = tkinter.Toplevel()
    window.geometry('250x200')
    msg = 'Rax m3u8下載器 v1.5\n可以選擇保存的目錄了\nRax m3u8下載器 v1.4\n增加了菜單欄'
    label = tkinter.Label(window, text=msg,font=('Arial', 13))
    label.place(x=30, y=30, anchor='nw')
def donate():
    window = tkinter.Toplevel()
    window.geometry('500x400')
    msg = '軟件免費(fèi)使用\n歡迎喜歡此軟件的各位大佬打賞,謝謝。'
    label = tkinter.Label(window, text=msg, font=('Arial', 20))


    i1 = tkinter.PhotoImage(file=get_resource_path("images\\wx.png"))
    i2 = tkinter.PhotoImage(file=get_resource_path("images\\zfb.png"))
    imagelabel = tkinter.Label(window, text='aaa', image=i1, font=('Arial', 10))
    imagelabel2 = tkinter.Label(window, text='vvv', image=i2, font=('Arial', 10))
    imagelabel.place(x=10, y=145, anchor='nw')
    imagelabel2.place(x=230, y=145, anchor='nw')
    label.place(x=40, y=50, anchor='nw')
    window.mainloop()
def clear():
    global v
    v.set("")
def paste():
    global v
    v.set(pyperclip.paste())

key = ''
on_hit = False
rootpath = "d:\\"
#最高50線程
task_pool = threadpool.ThreadPool(50)
http = urllib3.PoolManager(timeout=5.0)
urllib3.disable_warnings()

#主窗口初始化
window = tkinter.Tk()
window.style = Style()
window.style.theme_use("clam")
window.title("Rax m3u8視頻下載器")
window.geometry('500x300')
window.resizable(0,0)


#飛機(jī)背景圖
canvas_root = tkinter.Canvas(window,width=500,height=300)
im_root = get_image(get_resource_path('images\\feiji.jpeg'),500,300)
canvas_root.create_image(250,240,image=im_root)
canvas_root.pack()

#各控件初始狀態(tài)
l1 = tkinter.Label(window, text='m3u8地址:', font=('Arial', 10))
l1.place(x=10, y=0, anchor='nw')

#   地址欄
v = tkinter.StringVar();
e2 = tkinter.Entry(window, show=None, textvariable = v,font=('Arial', 10),width=40)
v.set('')
e2.place(x=10, y=30, anchor='nw')

#   視頻名稱
l6 = tkinter.Label(window, text = ' 視頻文件名稱:', font=('Arial', 10))
l6.place(x=0, y=90, anchor='nw')

#   視頻名稱欄
v2 = tkinter.StringVar();
e3 = tkinter.Entry(window, show=None, textvariable = v2,font=('Arial', 10),width=15)
v2.set('')
e3.place(x=105, y=90, anchor='nw')

#   保存位置
v5 = tkinter.StringVar();
l2 = tkinter.Label(window, textvariable = v5, font=('Arial', 10))
v5.set('文件夾: D:/')
l2.place(x=10, y=60, anchor='nw')

#   下載按鈕
b = tkinter.Button(window, text='下載', font=('Arial', 10), width=10, command=hit_me)
b.place(x=400, y=100, anchor='nw')

#   選擇路徑按鈕
pathselectButton = tkinter.Button(window, text='選擇路徑', font=('Arial', 10), width=10, command=choose_dir)
pathselectButton.place(x=400, y=60, anchor='nw')

#   清空按鈕
b2 = tkinter.Button(window, text='清空', font=('Arial', 10), width=10, command=clear)
b2.place(x=300, y=25, anchor='nw')

#   粘貼地址按鈕
b3 = tkinter.Button(window, text='粘貼地址', font=('Arial', 10), width=10, command=paste)
b3.place(x=400, y=25, anchor='nw')

#   求捐贈(zèng)按鈕
l5 = tkinter.Label(window, text='軟件免費(fèi)使用,歡迎各位喜歡此軟件的大佬打賞,謝謝。\nQQ討論群:519565890', font=('Arial', 10))
l5.place(x=100, y=160, anchor='nw')

window.option_add('*tearOff', False)

#菜單欄
menubar = tkinter.Menu(window)
window['menu'] = menubar
help_menu = tkinter.Menu(menubar)
menubar.add_command(label='捐助作者',command=lambda: donate())
menubar.add_cascade(menu=help_menu, label='幫助')

#幫助 下拉菜單
help_menu.add_command(label='更新內(nèi)容',command=lambda: update())
help_menu.add_command(label='關(guān)于',command=lambda: about())

# 進(jìn)入消息循環(huán)
window.mainloop()

項(xiàng)目地址

https://github.com/raxar81/rax_m3u8_downloader

以上就是python基于tkinter制作m3u8視頻下載工具的詳細(xì)內(nèi)容,更多關(guān)于python m3u8視頻下載的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Python繪制極坐標(biāo)基向量詳解

    Python繪制極坐標(biāo)基向量詳解

    這篇文章主要介紹了如何利用python繪制極坐標(biāo)的基向量,文中的示例代碼講解詳細(xì),具有一定的的參考價(jià)值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-08-08
  • Python實(shí)現(xiàn)甘特圖繪制的示例詳解

    Python實(shí)現(xiàn)甘特圖繪制的示例詳解

    相信在平常實(shí)際工作當(dāng)中,需要對(duì)整體的項(xiàng)目做一個(gè)梳理,這時(shí)如果有一個(gè)網(wǎng)頁(yè)應(yīng)用能夠?qū)φw項(xiàng)目有一個(gè)可視化頁(yè)面的展示,是不是會(huì)對(duì)你的實(shí)際工作有所幫助呢?今天小編就通過Python+Streamlit框架來(lái)繪制甘特圖并制作可視化大屏,需要的可以參考一下
    2023-04-04
  • python開發(fā)實(shí)例之python使用Websocket庫(kù)開發(fā)簡(jiǎn)單聊天工具實(shí)例詳解(python+Websocket+JS)

    python開發(fā)實(shí)例之python使用Websocket庫(kù)開發(fā)簡(jiǎn)單聊天工具實(shí)例詳解(python+Websocket+J

    這篇文章主要介紹了python開發(fā)實(shí)例之python使用Websocket庫(kù)開發(fā)簡(jiǎn)單聊天工具實(shí)例詳解(python+Websocket+JS),需要的朋友可以參考下
    2020-03-03
  • python定時(shí)任務(wù) sched模塊用法實(shí)例

    python定時(shí)任務(wù) sched模塊用法實(shí)例

    這篇文章主要介紹了python定時(shí)任務(wù) sched模塊用法實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • Python遍歷目錄并批量更換文件名和目錄名的方法

    Python遍歷目錄并批量更換文件名和目錄名的方法

    這篇文章主要介紹了Python遍歷目錄并批量更換文件名和目錄名的方法,涉及Python針對(duì)文件與目錄的遍歷、讀取及修改等操作技巧,需要的朋友可以參考下
    2016-09-09
  • pycharm打包python項(xiàng)目為exe執(zhí)行文件的實(shí)例代碼

    pycharm打包python項(xiàng)目為exe執(zhí)行文件的實(shí)例代碼

    這篇文章主要介紹了pycharm打包python項(xiàng)目為exe執(zhí)行文件,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-07-07
  • Python中的類與類型示例詳解

    Python中的類與類型示例詳解

    這篇文章主要給大家介紹了關(guān)于Python中類與類型的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Python具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • Python中關(guān)于字典的常規(guī)操作范例以及介紹

    Python中關(guān)于字典的常規(guī)操作范例以及介紹

    今天小編幫大家簡(jiǎn)單介紹下Python的一種數(shù)據(jù)結(jié)構(gòu): 字典,字典是 Python 提供的一種常用的數(shù)據(jù)結(jié)構(gòu),它用于存放具有映射關(guān)系的數(shù)據(jù),通讀本篇對(duì)大家的學(xué)習(xí)或工作具有一定的價(jià)值,需要的朋友可以參考下
    2021-09-09
  • Python selenium的基本使用方法分析

    Python selenium的基本使用方法分析

    這篇文章主要介紹了Python selenium的基本使用方法,結(jié)合實(shí)例形式分析了Python使用selenium模塊進(jìn)行web自動(dòng)化測(cè)試的基本模塊導(dǎo)入、操作技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2019-12-12
  • 在Apache服務(wù)器上同時(shí)運(yùn)行多個(gè)Django程序的方法

    在Apache服務(wù)器上同時(shí)運(yùn)行多個(gè)Django程序的方法

    這篇文章主要介紹了在Apache服務(wù)器上同時(shí)運(yùn)行多個(gè)Django程序的方法,Django是Python各色高人氣web框架中最為著名的一個(gè),需要的朋友可以參考下
    2015-07-07

最新評(píng)論