feat:config
This commit is contained in:
parent
1bb44c6d71
commit
34748eca46
@ -13,15 +13,15 @@ Automatically obtain and update the latest live broadcast interface link accordi
|
||||
|
||||
1. Fork this project, turn on Action workflow read and write permissions, Settings → Actions → General → Workflow permissions → Read and write permissions → Save
|
||||
2. Modify the demo.txt template file, subsequent updates will be based on the content of this file
|
||||
3. Modify main.py (optional):
|
||||
3. Modify config.py (optional):
|
||||
|
||||
- source_file: Template file, default value: demo.txt
|
||||
- final_file: Generated file, default value: result.txt
|
||||
- important_list: List of focus channel names
|
||||
- important_page_num: Number of pages to get for focus channels, default value: 5
|
||||
- favorite_list: List of focus channel names
|
||||
- favorite_page_num: Number of pages to get for focus channels, default value: 5
|
||||
- default_page_num: Number of pages to get for regular channels, default value: 3
|
||||
- urls_limit: Number of interfaces, default value: 15
|
||||
- filter_invalid_url: Whether to filter invalid interfaces, default is true
|
||||
- filter_invalid_url: Whether to filter invalid interfaces, default: True
|
||||
|
||||
4. result.txt is the updated live broadcast interface file, source.json is the data source file
|
||||
|
||||
|
@ -15,15 +15,15 @@
|
||||
|
||||
1. Fork 此项目,开启 Action 工作流可读写权限,Settings → Actions → General → Workflow permissions → Read and write permissions → Save
|
||||
2. 修改 demo.txt 模板文件,后续更新根据此文件内容进行更新
|
||||
3. 修改 main.py(可选):
|
||||
3. 修改配置 config.py(可选):
|
||||
|
||||
- source_file:模板文件,默认值:demo.txt
|
||||
- final_file:生成文件,默认值:result.txt
|
||||
- important_list:关注频道名称列表
|
||||
- important_page_num:关注频道获取分页数量,默认值:5
|
||||
- favorite_list:关注频道名称列表
|
||||
- favorite_page_num:关注频道获取分页数量,默认值:5
|
||||
- default_page_num:常规频道获取分页数量,默认值:3
|
||||
- urls_limit:接口数量,默认值:15
|
||||
- filter_invalid_url:是否过滤无效接口,默认开启
|
||||
- filter_invalid_url:是否过滤无效接口,默认值:True
|
||||
|
||||
4. result.txt 为更新后的直播源接口文件,source.json 为数据源文件
|
||||
|
||||
|
21
config.py
Normal file
21
config.py
Normal file
@ -0,0 +1,21 @@
|
||||
source_file = "demo.txt"
|
||||
final_file = "result.txt"
|
||||
favorite_list = [
|
||||
"珠江",
|
||||
"开平综合",
|
||||
"开平生活",
|
||||
"CCTV1",
|
||||
"CCTV5",
|
||||
"CCTV5+",
|
||||
"CCTV13",
|
||||
"广东体育",
|
||||
"广东卫视",
|
||||
"大湾区卫视",
|
||||
"浙江卫视",
|
||||
"湖南卫视",
|
||||
"翡翠台",
|
||||
]
|
||||
favorite_page_num = 5
|
||||
default_page_num = 3
|
||||
urls_limit = 15
|
||||
filter_invalid_url = True
|
38
main.py
38
main.py
@ -1,3 +1,4 @@
|
||||
import config
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
@ -14,27 +15,6 @@ import re
|
||||
|
||||
|
||||
class GetSource:
|
||||
source_file = "demo.txt"
|
||||
final_file = "result.txt"
|
||||
important_list = [
|
||||
"珠江",
|
||||
"开平综合",
|
||||
"开平生活",
|
||||
"CCTV1",
|
||||
"CCTV5",
|
||||
"CCTV5+",
|
||||
"CCTV13",
|
||||
"广东体育",
|
||||
"广东卫视",
|
||||
"大湾区卫视",
|
||||
"浙江卫视",
|
||||
"湖南卫视",
|
||||
"翡翠台",
|
||||
]
|
||||
important_page_num = 5
|
||||
default_page_num = 3
|
||||
urls_limit = 15
|
||||
filter_invalid_url = True
|
||||
|
||||
def __init__(self):
|
||||
self.driver = self.setup_driver()
|
||||
@ -61,7 +41,7 @@ class GetSource:
|
||||
|
||||
def getChannelItems(self):
|
||||
# Open the source file and read all lines.
|
||||
with open(self.source_file, "r") as f:
|
||||
with open(config.source_file, "r") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
# Create a dictionary to store the channels.
|
||||
@ -104,7 +84,7 @@ class GetSource:
|
||||
*(self.getSpeed(url) for url, _, _ in infoList)
|
||||
)
|
||||
# Filter out invalid links if filter_invalid_url is True
|
||||
if self.filter_invalid_url:
|
||||
if config.filter_invalid_url:
|
||||
valid_responses = [
|
||||
(info, rt)
|
||||
for info, rt in zip(infoList, response_times)
|
||||
@ -119,12 +99,12 @@ class GetSource:
|
||||
return infoList_new
|
||||
|
||||
def removeFile(self):
|
||||
if os.path.exists(self.final_file):
|
||||
os.remove(self.final_file)
|
||||
if os.path.exists(config.final_file):
|
||||
os.remove(config.final_file)
|
||||
|
||||
def outputTxt(self, cate, channelUrls):
|
||||
# Update the final file.
|
||||
with open(self.final_file, "a") as f:
|
||||
with open(config.final_file, "a") as f:
|
||||
f.write(cate + ",#genre#\n")
|
||||
for name, urls in channelUrls.items():
|
||||
for url in urls:
|
||||
@ -137,9 +117,9 @@ class GetSource:
|
||||
for cate, channelObj in channelItems.items():
|
||||
channelUrls = {}
|
||||
for name in channelObj.keys():
|
||||
isImportant = name in self.important_list
|
||||
isFavorite = name in config.favorite_list
|
||||
pageNum = (
|
||||
self.important_page_num if isImportant else self.default_page_num
|
||||
config.favorite_page_num if isFavorite else config.default_page_num
|
||||
)
|
||||
infoList = []
|
||||
for page in range(1, pageNum):
|
||||
@ -213,7 +193,7 @@ class GetSource:
|
||||
reverse=True,
|
||||
) # Sort by resolution
|
||||
urls = list(dict.fromkeys(url for url, _, _ in infoList))
|
||||
channelUrls[name] = (urls or channelObj[name])[: self.urls_limit]
|
||||
channelUrls[name] = (urls or channelObj[name])[: config.urls_limit]
|
||||
except Exception as e:
|
||||
print(f"Error on sorting: {e}")
|
||||
continue
|
||||
|
Loading…
x
Reference in New Issue
Block a user