python写的m3u8-downloader

脚本只负责对hls流地址进行解析,下载通过aria2c,合并通过ffmpeg,aria2c和ffmpeg需要单独下载,并与该脚本放于同一个目录下,支持代理和非代理下载,本人菜鸟一只,代码写得不是很规范,但代码可以有效工作,支持m3u8加密和非加密的解析,个别特殊加密的流暂时无法解析。脚本每次只能解析和下载一个视频,但单个视频下载是多线程的

福利:支持解析和下载P站和X站的视频

下面是完整代码

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
用于流视频下载器
先下载m3u8文件
逐行读取文件
解析
'''

import requests
import os
import tkinter as tk
import random
import string
import sys

os.system("mode con cols=35 lines=11")
root=tk.Tk()
root.withdraw()
root.wm_attributes('-topmost',1)
proxies = {}
pxy = ''
fname = ''
cur_path = ''




def vname_str():
    ran_str = ''.join(random.sample(string.ascii_letters, 8))
    return ran_str

def GetDesktopPath():
    return os.path.join(os.path.expanduser("~"), 'Desktop')


def select_proxy():
    global proxies
    while True:
        id = input("是否启用代理(默认不启用)?Y/N")
        if id == "Y" or id == "y":
            check()
            os.system("title 【代理模式】")
            return
        elif id == "N" or id == "n":
            proxies = {}
            os.system("title 【直连模式】")
            return
        else:
            proxies = {}
            os.system("title 【直链模式】")
            return
        


def check():
    global proxies,pxy
    if not os.path.exists("proxy.ini"):
        f=open("proxy.ini","w",encoding="utf-8")
        f.close()
        
    f = open("proxy.ini","r",encoding="utf-8")
    line = f.readline()
    f.close()
    if line:
        proxies = {"http":line,"https":line}
        pxy = "--all-proxy=\"http://"+line+"\""
    else:
        print("代理格式:\"127.0.0.1:7890\"")
        os.system("notepad.exe proxy.ini")
        os.system("pause")
        check()
          
        
        
def m3u8_download(url):
    try:
        r = requests.get(url)
        with open("0.m3u8",'wb') as code:
            code.write(r.content)
        d = GetDesktopPath()
        premain_ = "&#
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值