5 Star 12 Fork 2

不知天高地厚的颜某人/TvSources

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
self.py 2.77 KB
一键复制 编辑 原始数据 按行查看 历史
不知天高地厚的颜某人 提交于 2024-09-30 15:48 . Update self.py
import requests
import difflib
urls = ["https://m3u.ibert.me/txt/fmml_ipv6.txt"]
final = []
def txt_decode(file_content):
result = []
for line in file_content.split("\n"):
line = line.strip()
if "#genre#" not in line and line != "":
r = line.split(",")
result.append({
"name": r[0],
"url": r[1]
})
return result
def m3u8_decode(file_content):
tv_name = ""
result = []
for file_line in file_content.split("\n"):
file_line = file_line.strip()
if file_line.startswith("#EXTINF"):
tv_name = file_line.split(",")[-1]
elif file_line and not file_line.startswith("#"):
result.append({
"name": tv_name,
"url": file_line
})
# tv_name = ""
return result
def isSimilar(str1, str2, threshold=0.8):
ratio = difflib.SequenceMatcher(None, str1, str2).ratio()
return ratio >= threshold
tvData = {
"央视频道": [
"CCTV-1综合",
"CCTV-2财经",
"CCTV-3综艺",
"CCTV-4中文国际",
"CCTV-5体育",
"CCTV-5+体育赛事",
"CCTV-6电影",
"CCTV-7国防军事",
"CCTV-8电视剧",
"CCTV-9纪录",
"CCTV-10科教",
"CCTV-11戏曲",
"CCTV-12社会与法",
"CCTV-13新闻",
"CCTV-14少儿",
"CCTV-15音乐"
],
"地方频道" : [
"安徽卫视",
"东方卫视",
"江苏卫视",
"天津卫视",
"重庆卫视",
"黑龙江卫视",
"吉林卫视",
"辽宁卫视",
"内蒙古卫视",
"宁夏卫视",
"甘肃卫视",
"青海卫视",
"陕西卫视",
"河北卫视",
"山西卫视",
"山东卫视",
"北京卫视",
"河南卫视",
"湖北卫视",
"湖南卫视",
"江西卫视",
"浙江卫视",
"东南卫视",
"厦门卫视",
"广东卫视",
"深圳卫视",
"广西卫视",
"云南卫视",
"贵州卫视",
"四川卫视",
"新疆卫视",
"海南卫视"
]
}
allTvs = []
for url in urls:
# global allTVs
r = requests.get(url)
r.encoding = "utf-8"
allTvs.extend(txt_decode(r.text))
for key,value in tvData.items():
final.append(f"{key},#genre#")
for name in value:
haveOne = False
for tv in allTvs:
if isSimilar(name, tv["name"]):
final.append(f"{name},{tv['url']}")
haveOne = True
if not haveOne:
final.append(f"{name},none")
with open("./self.txt","w",encoding="utf-8") as f:
f.write("\n".join(final))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/e06yanm/TvSources.git
git@gitee.com:e06yanm/TvSources.git
e06yanm
TvSources
TvSources
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385