diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..14b7038 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024-PRESENT Govin + +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. \ No newline at end of file diff --git a/README.md b/README.md index f447816..06e608e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# TVbox 电视直播源接口自动爬取更新 +# TVBox 电视直播源接口自动更新 -根据基础配置直播源文件获取最新直播源接口链接 +根据基础模板直播源接口文件自动获取并更新最新直播源接口链接 ## 特点 @@ -12,13 +12,19 @@ ## 使用方法 1. Fork 此项目,开启 Action 工作流可读写权限 -2. 修改 demo.txt 文件,后续更新根据此文件内容进行更新 +2. 修改 demo.txt 模板文件,后续更新根据此文件内容进行更新 3. 修改 main.py(可选): -- importantList:关注频道名称列表 -- importantPageNum:关注频道获取分页数量,默认值:5 -- defaultPageNum:常规频道获取分页数量,默认值:3 -- urlsLimit:接口数量,默认值:15 +- source_file:模板文件,默认值:demo.txt +- final_file:生成文件,默认值:result.txt +- important_list:关注频道名称列表 +- important_page_num:关注频道获取分页数量,默认值:5 +- default_page_num:常规频道获取分页数量,默认值:3 +- urls_limit:接口数量,默认值:15 - filter_invalid_url:是否过滤无效接口,默认开启 -4. result.txt 为更新后的直播源文件,source.json 为数据源文件 +4. result.txt 为更新后的直播源接口文件,source.json 为数据源文件 + +## License + +[MIT](./LICENSE) License © 2024-PRESENT [Govin](https://github.com/guovin) diff --git a/main.py b/main.py index 036c58c..e405642 100644 --- a/main.py +++ b/main.py @@ -15,8 +15,8 @@ import re class GetSource: source_file = "demo.txt" - finalFile = "result.txt" - importantList = [ + final_file = "result.txt" + important_list = [ "珠江", "开平综合", "开平生活", @@ -31,9 +31,9 @@ class GetSource: "湖南卫视", "翡翠台", ] - importantPageNum = 5 - defaultPageNum = 3 - urlsLimit = 15 + important_page_num = 5 + default_page_num = 3 + urls_limit = 15 filter_invalid_url = True def __init__(self): @@ -119,12 +119,12 @@ class GetSource: return infoList_new def removeFile(self): - if os.path.exists(self.finalFile): - os.remove(self.finalFile) + if os.path.exists(self.final_file): + os.remove(self.final_file) def outputTxt(self, cate, channelUrls): # Update the final file. - with open(self.finalFile, "a") as f: + with open(self.final_file, "a") as f: f.write(cate + ",#genre#\n") for name, urls in channelUrls.items(): for url in urls: @@ -137,8 +137,10 @@ class GetSource: for cate, channelObj in channelItems.items(): channelUrls = {} for name in channelObj.keys(): - isImportant = name in self.importantList - pageNum = self.importantPageNum if isImportant else self.defaultPageNum + isImportant = name in self.important_list + pageNum = ( + self.important_page_num if isImportant else self.default_page_num + ) infoList = [] for page in range(1, pageNum): try: @@ -211,7 +213,7 @@ class GetSource: reverse=True, ) # Sort by resolution 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: print(f"Error on sorting: {e}") continue