Skip to content

Commit

Permalink
feat:config and LICENSE
Browse files Browse the repository at this point in the history
  • Loading branch information
Guovin committed Feb 28, 2024
1 parent 7ae50a4 commit 7ddefd5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TVbox 电视直播源接口自动爬取更新
# TVBox 电视直播源接口自动更新

根据基础配置直播源文件获取最新直播源接口链接
根据基础模板直播源接口文件自动获取并更新最新直播源接口链接

## 特点

Expand All @@ -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 &copy; 2024-PRESENT [Govin](https://github.com/guovin)
24 changes: 13 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

class GetSource:
source_file = "demo.txt"
finalFile = "result.txt"
importantList = [
final_file = "result.txt"
important_list = [
"珠江",
"开平综合",
"开平生活",
Expand All @@ -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):
Expand Down Expand Up @@ -119,12 +119,12 @@ async def compareSpeed(self, infoList):
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:
Expand All @@ -137,8 +137,10 @@ async def visitPage(self, channelItems):
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:
Expand Down Expand Up @@ -211,7 +213,7 @@ def extract_resolution(resolution_str):
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
Expand Down

0 comments on commit 7ddefd5

Please sign in to comment.