吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 22477|回复: 225
上一主题 下一主题
收起左侧

[Python 原创] TVBox本地直播源高效检测

    [复制链接]
跳转到指定楼层
楼主
caliph21 发表于 2023-10-31 09:30 回帖奖励
本帖最后由 caliph21 于 2024-3-12 18:30 编辑

更新
[Python] 纯文本查看 复制代码
#TVBox本地直播源高效检测

#更新更新更新>>>
#૧(●´৺`●)૭

#✔原文件还是可以用的
#新文件为改写方式45行
#get_parse_href_result中2种情况X
#1.不通报错:exept
#2.直播源响应时间<=500毫秒(建议)
#当然也可设置成1000ms
#增加了移动/电信/联通信号测试,结果是不一样的,文件后缀也不一样
#128.131行添加status_codw是非200不显示问题
#更新时间:20240312

import os,requests,time
from urllib.parse import urlparse

def local_live_check(filename):       
        print('''#1.中国移动通信-----chinamobile CMCC
#2.中国联通通讯-----chinaunicom CUCC
#3.中国电信 ------chinatelecom CTCC''')       
        select=int(input('\nY select:'))
        if select==1:suffix='yd'
        elif select==2:suffix='lt'
        elif select==3:suffix='dx'
        path = os.path.abspath(filename)
        print(path)
        dir, file = os.path.split(path)
        # dir,file = os.path.split(file_path)
        # print(dir,file)“
        # basename=os.path.basename(filename)
        files = os.path.splitext(file)
        newfile = os.path.join(dir, files[0] + f'_{suffix}' + files[1])
        print(newfile)
        #if not os.path.isfile(newfile):
                #f = open(newfile, 'w')
                #f.close()
        # print(os.path.isfile(newfile))
        lives_data = get_lives_data(filename)
        # print(lives_data)
        test_url(newfile, lives_data)

def get_lives_data(filename):
        f=open(filename,'r+')
        r = f.readlines()
        lives_data = [x.strip() for x in r if x.strip() != '']
        # lives_data= list(map(lambda x: x.strip(), r))
        # lives_data=lives_data.remove('')
        f.close()
        return lives_data
               
def test_url(newfile,lives_data):
        # ll是电视直播源的链接列表
        # ll=['http://........','https://.......']
        invalids, valids = [], []
        # 用于检测失败或成功的net,不再检测,提高效率
        #l=lives_data.index('&#127795;电影直播,#genre#')
        with open(newfile, 'w+') as f:
                #for line in lives_data[:]:
                for line in lives_data:
                        if line.find(',http') != -1:
                                name = line.split(',http')[0]
                                urls = 'http' + line.split(',http')[-1]
                                if urls.find('#') != -1:
                                        hrefs = urls.split('#')
                                else:
                                        hrefs = [urls]

                                if len(hrefs) == 1:
                                        url_parse = urlparse(hrefs[0]).netloc
                                        # print(url_parse,invalids,valids)
                                        if url_parse not in invalids:
                                                # print('url_parse not in invalids')
                                                result = get_parse_href_result(name, hrefs[0], valids, f)
                                                invalids = list(set(invalids + result[0]))
                                                valids = list(set(valids + result[1]))
                                        else:
                                                print(f'[无效] {name} -')
                                # print(f'{hrefs[0]}')
                                else:  # 包含#
                                        content = name + ','
                                        for i in range(len(hrefs)):
                                                url_parse = urlparse(hrefs[i]).netloc
                                                if url_parse not in invalids:
                                                        result2 = \
                                                                get_parse_href_result2(name, hrefs[i], valids, f)
                                                        nvalids = list(set(invalids + result2[0]))
                                                        valids = list(set(valids + result2[1]))
                                                        content += result2[2]
                                        else:
                                                print(f'[无效] {name} -')
                                        # print(f'{hrefs[i]}')
                                        if content[:-1] != name:
                                                f.write(content[:-1] + '\n')
                        else:
                                if line[-7:] == '#genre#':f.write('\n' + line + '\n')
                                else:f.write(line + '\n')
                f.close()
                print(f'\n&#127514;效集合√:\n{invalids}')
                print(f'\n&#127542;效集合X:\n{valids}')

def get_parse_href_result(name, href, valids, f):
        headers = {
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'}
        invalid, valid = [], []
        now = time.time()

        try:
                # print(hrefs[0])
                netloc = urlparse(href).netloc
                # print(netloc not in valids)
                if netloc not in valids:
                        # print('get:url_parse not in valids')
                        res = requests.get(href, headers=headers, timeout=5, stream=True)
                        ms_=res.elapsed.total_seconds()*1000
                        res_time=round(ms_)#ms
                        #print(res_time,type(res_time))
                        #print(res.status_code)
                        if res.status_code == 200:
                                for chunk in res.iter_content(chunk_size=1024):
                                        if chunk:                                               
                                                #print(f'{time.time() - now:.2f}\t{name}') 1m=1000ms
                                                if int(res_time)>500:#
                                                        print(f'[X][{res_time}ms] {name}')
                                                else:
                                                        print(f'[&#10004;][{res_time}ms] {name}')
                                                        valid += [netloc]
                                                        content = name + ',' + href + '\n'
                                                        # print(content)
                                                        f.write(content)
                                                        break
                        else:
                                print(f'[X] {name}, status_code: [{res.status_code}]')
                                invalid += [urlparse(href).netloc]
                else:
                        print(f'{time.time() - now:.2f}\t{name} +')
                        content = name + ',' + href + '\n'
                        f.write(content)
        except Exception:
                invalid += [urlparse(href).netloc]
                # 无法连接并超时的情况下输出“X”
                print(f'无法连接或超时 [X] {name}')
        # print(f'{href}')
        return invalid, valid

def get_parse_href_result2(name,href,valids,f):
        #带#
        headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'}
        invalid,valid,content=[],[],''
        now=time.time()
        try:
                netloc=urlparse(href).netloc
                if netloc not in valids:
                        res=requests.get(href,headers=headers,timeout=5,stream=True)
                        print(res.elapsed.total_seconds)
                        if res.status_code==200:
                                for chunk in res.iter_content(chunk_size=1024):
                                #for k in res.iter_content(chunk_size=1048576):
                                        if chunk:
                                                valid+=[urlparse(href).netloc]
                                                print(f'{time.time()-now:.2f}\t{name}')
                                                content+=href+'#'
                                                break
        except Exception:
                invalid+=[urlparse(href).netloc]
                # 无法连接并超时的情况下输出“X”
                print(f'[无效] {name}')
                #print(f'{href}')
        return invalid,valid,content
                       
if __name__ == '__main__':
        filename = '/storage/emulated/0/TVBoxx/lives/migu.txt'
        local_live_check(filename)





##市面上,度娘,公众号对TvBox直播源都是胡乱的嗮在一起,检测工具也就检测连通性,而且检测较慢,自己搞了下脚本,用的还行,分享

检测过程及结果说明:
[文件越大,相同host越多,越到后面速度越快]


#待检测的tvbox直播源本地文件
/storage/emulated/0/TVBoxx/lives/agit_live.txt
#待保存的新文件
/storage/emulated/0/TVBoxx/lives/agit_live_ttd.txt
#无效地址 直播名称
[无效] CCTV1
#连接速度数据越小,速度越快
0.12    CCTV1
# -号无效集合里的host,已检测无需再次检测,以提高速度
[无效] CCTV3 -
# 0.00 有效集合里数据,host已检测无需再次检测,可用
0.00    伤感DJ串烧为爱流泪 +


[无效] 津南一套
[无效] 湖南张家界宝峰湖
[无效] 四川峨眉山云海日出 -


#已检测的无效有效host集合:
无效集合√:
['117.169.121.162:6610', '115.231.128.81', '115.231.128.80', 'yixing-tv-ori-hls.jstv.com', 'stream.ysbtv.net', '117.169.124.149:8080']


有效集合X:
['112.45.133.129:90', 'pluslive.wrbtv.cn', '118.122.78.172:89', 'tv.drs.hhtv.cc:8100', 'm3u8.channel.wsrtv.com.cn', 'stream10.jlntv.cn', 'live.cms.anhuinews.com', 'stream.hrbtv.net','pili-live-hls.hfmt.net']


请同我追寻高天的境地,送给天下愉悦欢欣。
            ——水对天的述说
[Python] 纯文本查看 复制代码
#import 自己看不需要的可以#批注掉
#invalids, valids  list用于收集检测失败或成功的直播源,已检测的同样的host,不再检测,提高效率!
#filename,newfile路径设置,win和linux肯定不一样
#newfile将是检测后可用的直播源,后缀_ttd,如需自行修改
import time,re,json,requests,random
import os.path
from urllib.parse import urlparse
from pprint import pprint
from lxml import etree
import pandas as pd


def get_lives_data(filename):
        f=open(filename,'r+')
        r = f.readlines()
        lives_data = [x.strip() for x in r if x.strip() != '']
        # lives_data= list(map(lambda x: x.strip(), r))
        # lives_data=lives_data.remove('')
        f.close()
        return lives_data

def test_url(newfile,lives_data):
        # ll是电视直播源的链接列表
        # ll=['http://........','https://.......']
        invalids, valids = [], []
        # 用于检测失败或成功的net,不再检测,提高效率
        #l=lives_data.index('&#127795;电影直播,#genre#')
        with open(newfile, 'a+') as f:
                #for line in lives_data[:]:
                for line in lives_data:
                        if line.find(',http') != -1:
                                name = line.split(',http')[0]
                                urls = 'http' + line.split(',http')[-1]
                                if urls.find('#') != -1:
                                        hrefs = urls.split('#')
                                else:
                                        hrefs = [urls]


                                if len(hrefs) == 1:
                                        url_parse = urlparse(hrefs[0]).netloc
                                        # print(url_parse,invalids,valids)
                                        if url_parse not in invalids:
                                                # print('url_parse not in invalids')
                                                result = get_parse_href_result(name, hrefs[0], valids, f)
                                                invalids = list(set(invalids + result[0]))
                                                valids = list(set(valids + result[1]))
                                        else:
                                                print(f'[无效] {name} -')
                                # print(f'{hrefs[0]}')
                                else:  # 包含#
                                        content = name + ','
                                        for i in range(len(hrefs)):
                                                url_parse = urlparse(hrefs[i]).netloc
                                                if url_parse not in invalids:
                                                        result2 = \
                                                                get_parse_href_result2(name, hrefs[i], valids, f)
                                                        nvalids = list(set(invalids + result2[0]))
                                                        valids = list(set(valids + result2[1]))
                                                        content += result2[2]
                                        else:
                                                print(f'[无效] {name} -')
                                        # print(f'{hrefs[i]}')
                                        if content[:-1] != name:
                                                f.write(content[:-1] + '\n')
                        else:
                                if line[-7:] == '#genre#':f.write('\n' + line + '\n')
                                else:f.write(line + '\n')
                f.close()
                print(f'\n&#127514;效集合√:\n{invalids}')
                print(f'\n&#127542;效集合X:\n{valids}')
def local_live_check():
        filename = '/storage/emulated/0/TVBoxx//公测版/live_local.txt'
        path = os.path.abspath(filename)
        print(path)
        dir, file = os.path.split(path)
        # dir,file = os.path.split(file_path)
        # print(dir,file)“
        # basename=os.path.basename(filename)
        files = os.path.splitext(file)
        newfile = os.path.join(dir, files[0] + '_ttd' + files[1])
        print(newfile)
        if not os.path.isfile(newfile):
                f = open(newfile, 'w')
                f.close()
        # print(os.path.isfile(newfile))
        lives_data = get_lives_data(filename)
        # print(lives_data)
        test_url(newfile, lives_data)
if __name__ == '__main__':
    local_live_check()

免费评分

参与人数 27吾爱币 +28 热心值 +25 收起 理由
yawn1030 + 1 + 1 热心回复!
chenlugen + 1 谢谢@Thanks!
fs000x + 1 + 1 用心讨论,共获提升!
可曾 + 1 + 1 谢谢@Thanks!
seasouling + 1 + 1 我很赞同!
nydal + 1 + 1 谢谢@Thanks!
wqra1 + 1 我很赞同!
zzdzxx + 1 + 1 谢谢@Thanks!
多幸运遇见baby + 1 + 1 用心讨论,共获提升!
yxwudi + 1 谢谢@Thanks!
lynahlq + 1 + 1 我很赞同!
billsmiless + 1 + 1 我很赞同!
duanbaosen + 1 + 1 谢谢@Thanks!
laobj + 1 谢谢@Thanks!
Peanutegg + 1 热心回复!
wusger + 1 谢谢@Thanks!
李霸霸 + 1 + 1 谢谢@Thanks!
gaving + 1 + 1 我很赞同!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
MLxxoo + 1 + 1 谢谢@Thanks!
sd1190047 + 1 + 1 谢谢@Thanks!
timeni + 1 + 1 用心讨论,共获提升!
TheSSS + 1 + 1 谢谢@Thanks!
taishou7658 + 1 + 1 我很赞同!
44018723 + 1 + 1 谢谢@Thanks!
shengruqing + 1 热心回复!
15235109295 + 1 + 1 热心回复!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
 楼主| caliph21 发表于 2023-10-31 10:19 |楼主
本帖最后由 caliph21 于 2023-10-31 10:50 编辑

有的同志没数据源,给


[{'name': '应用多多家庭版', 'url': 'http://yydsys.top/duo'},
{'name': '应用多多备用', 'url': 'https://cloud.lxweb.cn/f/MoJNuG/xm.json'},
{'name': '阿里精品专线', 'url': 'http://yydsys.top/duo/ali'},
{'name': '饭太硬线路', 'url': 'http://饭太硬.top/tv'},
{'name': '肥猫线路', 'url': 'http://肥猫.love'},
{'name': '蜂蜜线路',
  'url': 'https://ghproxy.com/https://raw.githubusercontent.com/FongMi/CatVodSpider/main/json/config.json'},
{'name': '道长线路', 'url': 'https://pastebin.com/raw/5NHaxyGR'}, {'name': '香雅情线路',
  'url': 'https://raw.gitmirror.com/gaotianliuyun/gao/master/XYQ.json'},
{'name': '小米线路', 'url': 'http://xhww.fun:63/小米/DEMO.json'}, {'name': '菜妮丝线路', 'url': 'https://tvbox.cainisi.cf'},
{'name': '俊佬线路', 'url': 'http://home.jundie.top:81/top98.json'},
{'name': '小雅线路', 'url': 'http://101.34.67.237/config/1'},
{'name': '霜辉月明',
  'url': 'https://ghproxy.com/https://raw.githubusercontent.com/lm317379829/PyramidStore/pyramid/py.json'},
{'name': 'dxawi0线路', 'url': 'https://xhdwc.tk/0'},
{'name': '老刘备线路', 'url': 'https://raw.liucn.cc/box/m.json'}, {'name': '运输车(有跑马灯)', 'url': 'https://weixine.net/ysc.json'},
{'name': '潇洒线路', 'url': 'https://la.kstore.space/download/2863/01.txt'},
{'name': '南风线路',
  'url': 'https://agit.ai/Yoursmile7/TVBox/raw/branch/master/XC.json'},
{'name': '蚂蚁论坛线路', 'url': 'https://la.kstore.space/download/2883/0110.txt'},
{'name': '月光宝盒',
  'url': 'https://raw.gitmirror.com/guot55/YGBH/main/ygbox.json'},
{'name': '欧歌线路',
  'url': 'http://tv.nxog.top/m/111.php?ou=%E6%AC%A7%E6%AD%8C&mz=index2&xl=&jar=index2'},
{'name': '吾爱线路', 'url': 'http://52bsj.vip:98/wuai'},
{'name': '云星日记', 'url': 'http://itvbox.cc/tvbox/云星日记/1.m3u8'},
{'name': '星辰线路', 'url': 'http://8.210.232.168/xc.json'},
{'name': '分享者线路',
  'url': 'https://agit.ai/66666/mao/raw/branch/master/00/000.m3u8'},
{'name': '冰河线路', 'url': 'https://ju.binghe.ga/4.txt'},
{'name': '不良帅线路',
  'url': 'https://notabug.org/qizhen15800/My9394/raw/master/ProfessionalEdition.m3u8'},
{'name': '乱世线路', 'url': 'http://www.dmtv.ml/mao/single.json'},
{'name': '一影视线路',
  'url': 'https://ghproxy.com/https://raw.githubusercontent.com/tv-player/tvbox-line/main/tv/fj.json'},
{'name': '佰欣园线路',
  'url': 'https://ghproxy.com/https://raw.githubusercontent.com/chengxueli818913/maoTV/main/44.txt'},
{'name': '甜蜜线路',
  'url': 'https://ghproxy.com/https://raw.githubusercontent.com/kebedd69/TVbox-interface/main/%E7%94%9C%E8%9C%9C.json'},
{'name': '一木线路',
  'url': 'https://ghproxy.com/https://raw.githubusercontent.com/xianyuyimu/TVBOX-/main/TVBox/%E4%B8%80%E6%9C%A8%E8%87%AA%E7%94%A8.json'},
{'name': 'kvymin线路',
  'url': 'https://agit.ai/kvymin/TV/raw/branch/master/Box.json'},
{'name': 'agit/abc线路', 'url': 'https://agit.ai/n/b/raw/branch/a/b/c.json'},
{'name': 'zzz1线路',
  'url': 'https://agit.ai/mmmgit/tvbox/raw/branch/main/zzz1.json'}, {'name': '&#128142;小马线路', 'url': 'https://szyyds.cn/tv/x.json'},
{'name': '业余线路',
  'url': 'https://raw.gitmirror.com/yydfys/yydf/main/yydf/yydf.json'},
{'name': '荷城茶秀', 'url': 'http://rihou.cc:88/荷城茶秀'},
{'name': '高天流云',
  'url': 'https://raw.gitmirror.com/gaotianliuyun/gao/master/js.json'},
{'name': '胖鸭线路',
  'url': 'https://agit.ai/cyl518/yl/raw/branch/master/ml.json'},
{'name': '元兴线路', 'url': 'https://freed.yuanhsing.cf/TVBox/meowcf.json'},
{'name': '猫爪线路',
  'url': 'https://codeberg.org/AK47/drpy-js/raw/branch/main/js.json'},
{'name': '应用多多',
  'url': 'https://jihulab.com/duomv/apps/-/raw/main/fast.json'},
{'name': '欧歌', 'url': 'http://tv.nxog.top/api.php?mz=xb&id=1&b=欧歌'},
{'name': '云星日记', 'url': 'http://jk.itvbox.cc:66/可视TV/云星日记/仓库/api.json'},
{'name': '吾爱多仓', 'url': 'http://52bsj.vip:98/wuaihouse'}]

免费评分

参与人数 14吾爱币 +14 热心值 +12 收起 理由
yxmlop + 1 谢谢@Thanks!
mcz170 + 1 + 1 谢谢@Thanks!
qyccq156 + 1 + 1 谢谢@Thanks!
dong824 + 1 + 1 谢谢@Thanks!
billsmiless + 1 + 1 我很赞同!
bb89 + 1 + 1 我很赞同!
laobj + 1 谢谢@Thanks!
yunshuiwanxiang + 1 + 1 我很赞同!
lb12718 + 1 + 1 热心回复!
bluewatercom + 1 + 1 谢谢@Thanks!
youai + 1 + 1 鼓励转贴优秀软件安全工具和文档!
茶城兄弟 + 1 + 1 谢谢@Thanks!
damnedvi + 1 + 1 虽有但谢!!!!
10jr4 + 1 + 1 谢谢@Thanks!

查看全部评分

推荐
 楼主| caliph21 发表于 2023-12-17 09:58 |楼主
本帖最后由 caliph21 于 2023-12-17 10:14 编辑

萌29199 发表于 2023-12-17 08:37
有好的直播源没有



自定义空壳app


安卓:
https://lanzouw.com/icw9y1hvneob


直播源接口:
https://gitee.com/xiaohe-commune/tv/raw/master/12HD.txt


12.12直播源:
https://lanzouw.com/iXHE81hnu82h

免费评分

参与人数 2吾爱币 +2 热心值 +2 收起 理由
billkeyjian + 1 + 1 热心回复!
茶城兄弟 + 1 + 1 谢谢@Thanks!

查看全部评分

推荐
冂吉 发表于 2023-10-31 09:46
推荐
Vincent168 发表于 2023-10-31 09:56
感谢分享
推荐
15235109295 发表于 2023-10-31 09:37
感谢分享
推荐
xwcyg6 发表于 2023-10-31 09:44
感谢大佬分享
推荐
y2k1127 发表于 2023-10-31 10:13
感谢分享,有这个检查就方便多了
5#
cool1000 发表于 2023-10-31 09:36
感谢分享,
6#
ciker_li 发表于 2023-10-31 09:40
感谢分享,挺好用,就是代码前后缀没去掉
7#
skzhaixing 发表于 2023-10-31 09:40
这个能包成个执行文件不
8#
gccccc 发表于 2023-10-31 09:46
感谢分享
9#
端午后第四天 发表于 2023-10-31 09:49
好,感谢分享。
10#
shubiao 发表于 2023-10-31 09:51
谢谢分享
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 13:02

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表