feat:config and LICENSE

This commit is contained in:
guorong.zheng 2024-02-28 10:16:22 +08:00
parent 7ae50a4c0a
commit 7ddefd5bdd
3 changed files with 48 additions and 19 deletions

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024-PRESENT Govin <https://github.com/guovin>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,6 +1,6 @@
# TVbox 电视直播源接口自动爬取更新 # TVBox 电视直播源接口自动更新
根据基础配置直播源文件获取最新直播源接口链接 根据基础模板直播源接口文件自动获取并更新最新直播源接口链接
## 特点 ## 特点
@ -12,13 +12,19 @@
## 使用方法 ## 使用方法
1. Fork 此项目,开启 Action 工作流可读写权限 1. Fork 此项目,开启 Action 工作流可读写权限
2. 修改 demo.txt 文件,后续更新根据此文件内容进行更新 2. 修改 demo.txt 模板文件,后续更新根据此文件内容进行更新
3. 修改 main.py(可选) 3. 修改 main.py(可选)
- importantList关注频道名称列表 - source_file模板文件默认值demo.txt
- importantPageNum关注频道获取分页数量默认值5 - final_file生成文件默认值result.txt
- defaultPageNum常规频道获取分页数量默认值3 - important_list关注频道名称列表
- urlsLimit接口数量默认值15 - important_page_num关注频道获取分页数量默认值5
- default_page_num常规频道获取分页数量默认值3
- urls_limit接口数量默认值15
- filter_invalid_url是否过滤无效接口默认开启 - filter_invalid_url是否过滤无效接口默认开启
4. result.txt 为更新后的直播源文件source.json 为数据源文件 4. result.txt 为更新后的直播源接口文件source.json 为数据源文件
## License
[MIT](./LICENSE) License &copy; 2024-PRESENT [Govin](https://github.com/guovin)

24
main.py
View file

@ -15,8 +15,8 @@ import re
class GetSource: class GetSource:
source_file = "demo.txt" source_file = "demo.txt"
finalFile = "result.txt" final_file = "result.txt"
importantList = [ important_list = [
"珠江", "珠江",
"开平综合", "开平综合",
"开平生活", "开平生活",
@ -31,9 +31,9 @@ class GetSource:
"湖南卫视", "湖南卫视",
"翡翠台", "翡翠台",
] ]
importantPageNum = 5 important_page_num = 5
defaultPageNum = 3 default_page_num = 3
urlsLimit = 15 urls_limit = 15
filter_invalid_url = True filter_invalid_url = True
def __init__(self): def __init__(self):
@ -119,12 +119,12 @@ class GetSource:
return infoList_new return infoList_new
def removeFile(self): def removeFile(self):
if os.path.exists(self.finalFile): if os.path.exists(self.final_file):
os.remove(self.finalFile) os.remove(self.final_file)
def outputTxt(self, cate, channelUrls): def outputTxt(self, cate, channelUrls):
# Update the final file. # Update the final file.
with open(self.finalFile, "a") as f: with open(self.final_file, "a") as f:
f.write(cate + ",#genre#\n") f.write(cate + ",#genre#\n")
for name, urls in channelUrls.items(): for name, urls in channelUrls.items():
for url in urls: for url in urls:
@ -137,8 +137,10 @@ class GetSource:
for cate, channelObj in channelItems.items(): for cate, channelObj in channelItems.items():
channelUrls = {} channelUrls = {}
for name in channelObj.keys(): for name in channelObj.keys():
isImportant = name in self.importantList isImportant = name in self.important_list
pageNum = self.importantPageNum if isImportant else self.defaultPageNum pageNum = (
self.important_page_num if isImportant else self.default_page_num
)
infoList = [] infoList = []
for page in range(1, pageNum): for page in range(1, pageNum):
try: try:
@ -211,7 +213,7 @@ class GetSource:
reverse=True, reverse=True,
) # Sort by resolution ) # Sort by resolution
urls = list(dict.fromkeys(url for url, _, _ in infoList)) urls = list(dict.fromkeys(url for url, _, _ in infoList))
channelUrls[name] = (urls or channelObj[name])[: self.urlsLimit] channelUrls[name] = (urls or channelObj[name])[: self.urls_limit]
except Exception as e: except Exception as e:
print(f"Error on sorting: {e}") print(f"Error on sorting: {e}")
continue continue