diff --git a/README.md b/README.md index 66cfa21615..c3b1ce625a 100644 --- a/README.md +++ b/README.md @@ -83,12 +83,16 @@ - [✅ 特点](#特点) - [🔗 最新结果](#最新结果) -- [⚙️ 配置参数](./docs/config.md) +- [⚙️ 配置参数](#配置) - [🚀 快速上手](#快速上手) + - [工作流](#工作流) + - [命令行](#命令行) + - [GUI软件](#GUI-软件) + - [Docker](#Docker) - [📖 详细教程](./docs/tutorial.md) - [🗓️ 更新日志](./CHANGELOG.md) - [❤️ 赞赏](#赞赏) -- [👀 关注](#关注) +- [👀 关注(更新订阅+答疑交流)](#关注) - [📣 免责声明](#免责声明) - [⚖️ 许可证](#许可证) @@ -100,7 +104,7 @@ - ✅ 偏好设置:IPv6、接口来源排序优先级与数量配置、接口白名单 - ✅ 定时执行,北京时间每日 6:00 与 18:00 执行更新 - ✅ 支持多种运行方式:工作流、命令行、GUI 软件、Docker(amd64/arm64/arm v7) -- ✨ 更多功能请见[配置参数](./docs/config.md) +- ✨ 更多功能请见[配置参数](#配置) ## 最新结果 @@ -114,23 +118,90 @@ https://ghp.ci/raw.githubusercontent.com/Guovin/iptv-api/gd/output/result.m3u https://ghp.ci/raw.githubusercontent.com/Guovin/iptv-api/gd/output/result.txt ``` +或 + +```bash +https://cdn.jsdelivr.net/gh/Guovin/iptv-api@gd/output/result.m3u +``` + +```bash +https://cdn.jsdelivr.net/gh/Guovin/iptv-api@gd/output/result.txt +``` + - 数据源: ```bash https://ghp.ci/raw.githubusercontent.com/Guovin/iptv-api/gd/source.json ``` +或 + +```bash +https://cdn.jsdelivr.net/gh/Guovin/iptv-api@gd/source.json +``` + ## 配置 -[配置参数](./docs/config.md) +| 配置项 | 描述 | 默认值 | +|:-----------------------|:------------------------------------------------------------------------------------------|:----------------------------------------| +| open_driver | 开启浏览器运行,若更新无数据可开启此模式,较消耗性能 | True | +| open_empty_category | 开启无结果频道分类,自动归类至底部 | False | +| open_ffmpeg | 开启使用 FFmpeg 进行测速,获取更准确的速度与分辨率信息,需要提前手动安装 | True | +| open_filter_resolution | 开启分辨率过滤,低于最小分辨率(min_resolution)的接口将会被过滤 | True | +| open_filter_speed | 开启速率过滤,低于最小速率(min_speed)的接口将会被过滤 | True | +| open_hotel | 开启酒店源功能,关闭后所有酒店源工作模式都将关闭 | True | +| open_hotel_foodie | 开启 Foodie 酒店源工作模式 | True | +| open_hotel_fofa | 开启 FOFA、ZoomEye 酒店源工作模式 | True | +| open_keep_all | 开启保留所有检索结果,会保留非模板频道名称的结果,推荐手动维护时开启 | False | +| open_m3u_result | 开启转换生成 m3u 文件类型结果链接,支持显示频道图标 | True | +| open_multicast | 开启组播源功能,关闭后所有组播源工作模式都将关闭 | True | +| open_multicast_foodie | 开启 Foodie 组播源工作模式 | True | +| open_multicast_fofa | 开启 FOFA 组播源工作模式 | True | +| open_online_search | 开启关键字搜索源功能 | False | +| open_proxy | 开启代理,自动获取免费可用代理,若更新无数据可开启此模式 | False | +| open_request | 开启查询请求,数据来源于网络 | False | +| open_service | 开启页面服务,用于控制是否启动结果页面服务;如果使用青龙等平台部署,有专门设定的定时任务,需要更新完成后停止运行,可以关闭该功能 | True | +| open_sort | 开启排序功能(响应速度、日期、分辨率) | True | +| open_subscribe | 开启订阅源功能 | False | +| open_update | 开启更新,用于控制是否更新接口,若关闭则所有工作模式(获取接口和测速)均停止 | True | +| open_update_time | 开启显示更新时间 | True | +| open_url_info | 开启显示接口说明信息,用于控制是否显示分辨率、接口协议类型等信息,为$符号后的内容,播放软件使用该信息对接口进行描述 | True | +| open_use_cache | 开启使用本地缓存数据,适用于查询请求失败场景 | True | +| open_use_old_result | 开启使用历史更新结果(包含模板与结果文件的接口),合并至本次更新中 | True | +| delay_weight | 响应时间权重值(所有权重值总和应为 1) | 0.25 | +| final_file | 生成结果文件路径 | output/result.txt | +| hotel_num | 结果中偏好的酒店源接口数量 | 4 | +| hotel_page_num | 酒店地区获取分页数量 | 1 | +| hotel_region_list | 酒店源地区列表,"全部"表示所有地区 | 全部 | +| ipv4_num | 结果中偏好的 IPv4 接口数量 | 5 | +| ipv6_num | 结果中偏好的 IPv6 接口数量 | 5 | +| ipv_type | 生成结果中接口的协议类型,可选值:ipv4、ipv6、全部、all | 全部 | +| ipv_type_prefer | 接口协议类型偏好,优先将该类型的接口排在结果前面,可选值:IPv4、IPv6、自动、auto | 自动 | +| min_resolution | 接口最小分辨率,需要开启 open_filter_resolution 才能生效 | 1920x1080 | +| min_speed | 接口最小速率(单位M/s),需要开启 open_filter_speed 才能生效 | 0.2 | +| multicast_num | 结果中偏好的组播源接口数量 | 3 | +| multicast_page_num | 组播地区获取分页数量 | 1 | +| multicast_region_list | 组播源地区列表,"全部"表示所有地区 | 全部 | +| online_search_num | 结果中偏好的关键字搜索接口数量 | 0 | +| online_search_page_num | 关键字搜索频道获取分页数量 | 1 | +| origin_type_prefer | 结果偏好的接口来源,结果优先按该顺序进行排序,hotel:酒店源,multicast:组播源,subscribe:订阅源,online_search:关键字搜索 | hotel,multicast,subscribe,online_search | +| recent_days | 获取最近时间范围内更新的接口(单位天),适当减小可避免出现匹配问题 | 30 | +| request_timeout | 查询请求超时时长,单位秒(s),用于控制查询接口文本链接的超时时长以及重试时长,调整此值能优化更新时间 | 10 | +| resolution_weight | 分辨率权重值 (所有权重值总和应为 1) | 0.25 | +| sort_timeout | 单个接口测速超时时长,单位秒(s);数值越大测速所属时间越长,能提高获取接口数量,但质量会有所下降;数值越小测速所需时间越短,能获取低延时的接口,质量较好;调整此值能优化更新时间 | 10 | +| source_file | 模板文件路径 | config/demo.txt | +| speed_weight | 速率权重值(所有权重值总和应为 1) | 0.5 | +| subscribe_num | 结果中偏好的订阅源接口数量 | 3 | +| url_keywords_blacklist | 接口关键字黑名单,用于过滤含特定字符的接口 | | +| urls_limit | 单个频道接口数量 | 10 | ## 快速上手 -### 方式一:工作流 +### 工作流 Fork 本项目并开启工作流更新,具体步骤请见[详细教程](./docs/tutorial.md) -### 方式二:命令行 +### 命令行 ```shell pip install pipenv @@ -152,7 +223,7 @@ pipenv run dev pipenv run service ``` -### 方式三:GUI 软件 +### GUI 软件 1. 下载[IPTV-API 更新软件](https://github.com/Guovin/iptv-api/releases),打开软件,点击更新,即可完成更新 @@ -164,7 +235,7 @@ pipenv run ui IPTV-API更新软件 -### 方式四:Docker +### Docker - iptv-api(完整版本):性能要求较高,更新速度较慢,稳定性、成功率高;修改配置 open_driver = False 可切换到 Lite 版本运行模式(推荐酒店源、组播源、关键字搜索使用此版本) diff --git a/README_en.md b/README_en.md index f4897dd75b..8cc38408d8 100644 --- a/README_en.md +++ b/README_en.md @@ -83,12 +83,16 @@ - [✅ Features](#features) - [🔗 Latest results](#latest-results) -- [⚙️ Config parameter](./docs/config_en.md) +- [⚙️ Config parameter](#Config) - [🚀 Quick Start](#quick-start) + - [Workflow](#workflow) + - [Command Line](#command-line) + - [GUI Software](#gui-software) + - [Docker](#docker) - [📖 Detailed Tutorial](./docs/tutorial_en.md) - [🗓️ Changelog](./CHANGELOG.md) - [❤️ Appreciate](#appreciate) -- [👀 Follow](#follow) +- [👀 Follow(Update Subscription + Q&A)](#follow) - [📣 Disclaimer](#disclaimer) - [⚖️ License](#license) @@ -100,7 +104,7 @@ - ✅ Preferences: IPv6, priority and quantity of interface source sorting, and interface whitelist - ✅ Scheduled execution at 6:00 AM and 18:00 PM Beijing time daily - ✅ Supports various execution methods: workflows, command line, GUI software, Docker(amd64/arm64/arm v7) -- ✨ For more features, see [Config parameter](./docs/config_en.md) +- ✨ For more features, see [Config parameter](#Config) ## Latest results @@ -114,24 +118,91 @@ https://ghp.ci/raw.githubusercontent.com/Guovin/iptv-api/gd/output/result.m3u https://ghp.ci/raw.githubusercontent.com/Guovin/iptv-api/gd/output/result.txt ``` +or + +```bash +https://cdn.jsdelivr.net/gh/Guovin/iptv-api@gd/output/result.m3u +``` + +```bash +https://cdn.jsdelivr.net/gh/Guovin/iptv-api@gd/output/result.txt +``` + - Data source: ```bash https://ghp.ci/raw.githubusercontent.com/Guovin/iptv-api/gd/source.json ``` +or + +```bash +https://cdn.jsdelivr.net/gh/Guovin/iptv-api@gd/source.json +``` + ## Config -[Config parameter](./docs/config_en.md) +| Configuration Item | Description | Default Value | +|:-----------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-------------------------------------------| +| open_driver | Enable browser execution, If there are no updates, this mode can be enabled, which consumes more performance | True | +| open_empty_category | Enable the No Results Channel Category, which will automatically categorize channels without results to the bottom | False | +| open_ffmpeg | Enable speed testing using FFmpeg to obtain more accurate speed and resolution information. Manual installation is required in advance. | True | +| open_filter_resolution | Enable resolution filtering, interfaces with resolution lower than the minimum resolution (min_resolution) will be filtered | True | +| open_filter_speed | Enable speed filtering, interfaces with speed lower than the minimum speed (min_speed) will be filtered | True | +| open_hotel | Enable the hotel source function, after closing it all hotel source working modes will be disabled | True | +| open_hotel_foodie | Enable Foodie hotel source work mode | True | +| open_hotel_fofa | Enable FOFA、ZoomEye hotel source work mode | True | +| open_keep_all | Enable retain all search results, retain results with non-template channel names, recommended to be turned on when manually maintaining | False | +| open_m3u_result | Enable the conversion to generate m3u file type result links, supporting the display of channel icons | True | +| open_multicast | Enable the multicast source function, after disabling it all multicast sources will stop working | True | +| open_multicast_foodie | Enable Foodie multicast source work mode | True | +| open_multicast_fofa | Enable FOFA multicast source work mode | True | +| open_online_search | Enable keyword search source feature | False | +| open_proxy | Enable proxy, automatically obtains free available proxies, If there are no updates, this mode can be enabled | False | +| open_request | Enable query request, the data is obtained from the network | False | +| open_service | Enable page service, used to control whether to start the result page service; if deployed on platforms like Qinglong with dedicated scheduled tasks, the function can be turned off after updates are completed and the task is stopped | True | +| open_sort | Enable the sorting function (response speed, date, resolution) | True | +| open_subscribe | Enable subscription source feature | True | +| open_update | Enable updates, if disabled then only the result page service is run | True | +| open_update_time | Enable show update time | True | +| open_url_info | Enable display of API description information, used to control whether to show resolution, API protocol type, etc., the content after the $ symbol, playback software uses this information to describe the API | True | +| open_use_cache | Enable the use of local cache data, applicable to the query request failure scenario | True | +| open_use_old_result | Enable the use of historical update results (including the interface for template and result files) and merge them into the current update | True | +| delay_weight | Response time weight value (the sum of all weight values should be 1) | 0.25 | +| final_file | Generated result file path | output/result.txt | +| hotel_num | The number of preferred hotel source interfaces in the results | 4 | +| hotel_page_num | Number of pages to retrieve for hotel regions | 1 | +| hotel_region_list | List of hotel source regions, 'all' indicates all regions | all | +| ipv4_num | The preferred number of IPv4 interfaces in the result | 5 | +| ipv6_num | The preferred number of IPv6 interfaces in the result | 5 | +| ipv_type | The protocol type of interface in the generated result, optional values: ipv4, ipv6, all | all | +| ipv_type_prefer | Interface protocol type preference, prioritize interfaces of this type in the results, optional values: IPv4, IPv6, auto | auto | +| min_resolution | Minimum interface resolution, requires enabling open_filter_resolution to take effect | 1920x1080 | +| min_speed | Minimum interface speed (M/s), requires enabling open_filter_speed to take effect | 0.2 | +| multicast_num | The number of preferred multicast source interfaces in the results | 3 | +| multicast_page_num | Number of pages to retrieve for multicast regions | 1 | +| multicast_region_list | Multicast source region list, 'all' indicates all regions | all | +| online_search_num | The number of preferred keyword search interfaces in the results | 0 | +| online_search_page_num | Page retrieval quantity for keyword search channels | 1 | +| origin_type_prefer | Result preference for the source of the interface, results are prioritized in this order: hotel: hotel source, multicast: multicast source, subscribe: subscription source, online_search: keyword search | hotel, multicast, subscribe, online_search | +| recent_days | Retrieve interfaces updated within a recent time range (in days), reducing appropriately can avoid matching issues | 30 | +| request_timeout | Query request timeout duration, in seconds (s), used to control the timeout and retry duration for querying interface text links. Adjusting this value can optimize update time. | 10 | +| resolution_weight | Resolution weight value (the sum of all weight values should be 1) | 0.25 | +| sort_timeout | The timeout duration for speed testing of a single interface, in seconds (s). A larger value means a longer testing period, which can increase the number of interfaces obtained but may decrease their quality. A smaller value means a shorter testing time, which can obtain low-latency interfaces with better quality. Adjusting this value can optimize the update time. | 10 | +| source_file | Template file path | config/demo.txt | +| speed_weight | Speed weight value (the sum of all weight values should be 1) | 0.5 | +| subscribe_num | The number of preferred subscribe source interfaces in the results | 3 | +| url_keywords_blacklist | Interface keyword blacklist, used to filter out interfaces containing specific characters | | +| urls_limit | Number of interfaces per channel | 10 | ## Quick Start -### Method 1: Workflow +### Workflow Fork this project and initiate workflow updates, detailed steps are available at [Detailed Tutorial](./docs/tutorial_en.md) -### Method 2: Command Line +### Command Line ```shell pip install pipenv @@ -153,7 +224,7 @@ Start service: pipenv run service ``` -### Method 3: GUI Software +### GUI Software 1. Download [IPTV-API update software](https://github.com/Guovin/iptv-api/releases), open the software, click update to complete the update @@ -166,7 +237,7 @@ pipenv run ui IPTV-API update software -### Method 4: Docker +### Docker - iptv-api (Full version): Higher performance requirements, slower update speed, high stability and success rate. Set open_driver = False to switch to the lite running mode (recommended for hotel sources, multicast sources, and online diff --git a/config/config.ini b/config/config.ini index 2c8b5b64e9..6be19b1807 100644 --- a/config/config.ini +++ b/config/config.ini @@ -14,7 +14,7 @@ open_sort = True sort_timeout = 10 open_ffmpeg = True open_filter_speed = True -min_speed = 0.5 +min_speed = 0.2 open_filter_resolution = True min_resolution = 1920x1080 delay_weight = 0.25 @@ -28,7 +28,6 @@ ipv6_num = 5 open_m3u_result = True url_keywords_blacklist = epg.pw,skype.serv00.net,iptv.yjxfz.com,live-hls-web-ajb.getaj.net,live.goodiptv.club,hc73k3dhwo5gfkt.wcetv.com,stream1.freetv.fun,zw9999.cnstream.top,zsntlqj.xicp.net open_subscribe = True -subscribe_urls = https://iptv.b2og.com/txt/fmml_ipv6.txt,https://ghp.ci/raw.githubusercontent.com/suxuang/myIPTV/main/ipv6.m3u,https://live.zbds.top/tv/iptv6.txt,https://live.zbds.top/tv/iptv4.txt,https://live.fanmingming.com/tv/m3u/ipv6.m3u,https://ghp.ci/https://raw.githubusercontent.com/joevess/IPTV/main/home.m3u8,https://aktv.top/live.txt,http://175.178.251.183:6689/live.txt,https://ghp.ci/https://raw.githubusercontent.com/kimwang1978/collect-tv-txt/main/merged_output.txt,https://m3u.ibert.me/txt/fmml_dv6.txt,https://m3u.ibert.me/txt/o_cn.txt,https://m3u.ibert.me/txt/j_iptv.txt,https://ghp.ci/https://raw.githubusercontent.com/xzw832/cmys/main/S_CCTV.txt,https://ghp.ci/https://raw.githubusercontent.com/xzw832/cmys/main/S_weishi.txt,https://ghp.ci//https://raw.githubusercontent.com/asdjkl6/tv/tv/.m3u/整套直播源/测试/整套直播源/l.txt,https://ghp.ci//https://raw.githubusercontent.com/asdjkl6/tv/tv/.m3u/整套直播源/测试/整套直播源/kk.txt open_multicast = True open_multicast_foodie = True open_multicast_fofa = True diff --git a/config/subscribe.txt b/config/subscribe.txt new file mode 100644 index 0000000000..81ddce1127 --- /dev/null +++ b/config/subscribe.txt @@ -0,0 +1,19 @@ +# 这是订阅源列表,每行一个订阅地址 +# This is a list of subscription sources, with one subscription address per line + +https://iptv.b2og.com/txt/fmml_ipv6.txt +https://ghp.ci/raw.githubusercontent.com/suxuang/myIPTV/main/ipv6.m3u +https://live.zbds.top/tv/iptv6.txt +https://live.zbds.top/tv/iptv4.txt +https://live.fanmingming.com/tv/m3u/ipv6.m3u +https://ghp.ci/https://raw.githubusercontent.com/joevess/IPTV/main/home.m3u8 +https://aktv.top/live.txt +http://175.178.251.183:6689/live.txt +https://ghp.ci/https://raw.githubusercontent.com/kimwang1978/collect-tv-txt/main/merged_output.txt +https://m3u.ibert.me/txt/fmml_dv6.txt +https://m3u.ibert.me/txt/o_cn.txt +https://m3u.ibert.me/txt/j_iptv.txt +https://ghp.ci/https://raw.githubusercontent.com/xzw832/cmys/main/S_CCTV.txt +https://ghp.ci/https://raw.githubusercontent.com/xzw832/cmys/main/S_weishi.txt +https://ghp.ci//https://raw.githubusercontent.com/asdjkl6/tv/tv/.m3u/整套直播源/测试/整套直播源/l.txt +https://ghp.ci//https://raw.githubusercontent.com/asdjkl6/tv/tv/.m3u/整套直播源/测试/整套直播源/kk.txt diff --git a/docs/config.md b/docs/config.md index b8aa56df22..7a38a5b6f7 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1,53 +1,52 @@ -| 配置项 | 默认值 | 描述 | -|------------------------|-----------------------------------------|-------------------------------------------------------------------------------------------| -| open_service | True | 开启页面服务,用于控制是否启动结果页面服务;如果使用青龙等平台部署,有专门设定的定时任务,需要更新完成后停止运行,可以关闭该功能 | -| open_update | True | 开启更新,用于控制是否更新接口,若关闭则所有工作模式(获取接口和测速)均停止 | -| open_use_old_result | True | 开启使用历史更新结果(包含模板与结果文件的接口),合并至本次更新中 | -| open_use_cache | True | 开启使用本地缓存数据,适用于查询请求失败场景 | -| open_request | False | 开启查询请求,数据来源于网络 | -| open_driver | True | 开启浏览器运行,若更新无数据可开启此模式,较消耗性能 | -| open_proxy | False | 开启代理,自动获取免费可用代理,若更新无数据可开启此模式 | -| source_file | config/demo.txt | 模板文件路径 | -| final_file | output/result.txt | 生成结果文件路径 | -| open_online_search | False | 开启关键字搜索源功能 | -| online_search_page_num | 1 | 关键字搜索频道获取分页数量 | -| urls_limit | 10 | 单个频道接口数量 | -| open_keep_all | False | 保留所有检索结果,会保留非模板频道名称的结果,推荐手动维护时开启 | -| open_sort | True | 开启排序功能(响应速度、日期、分辨率) | -| sort_timeout | 5 | 单个接口测速超时时长,单位秒(s);数值越大测速所属时间越长,能提高获取接口数量,但质量会有所下降;数值越小测速所需时间越短,能获取低延时的接口,质量较好;调整此值能优化更新时间 | -| open_ffmpeg | True | 开启使用 FFmpeg 进行测速,获取更准确的速度与分辨率信息,需要提前手动安装 | -| open_m3u_result | True | 开启转换生成 m3u 文件类型结果链接,支持显示频道图标 | -| open_filter_speed | True | 开启速率过滤,低于最小速率(min_speed)的接口将会被过滤 | -| min_speed | 0.5 | 接口最小速率(单位M/s),需要开启 open_filter_speed 才能生效 | -| open_filter_resolution | True | 开启分辨率过滤,低于最小分辨率(min_resolution)的接口将会被过滤 | -| min_resolution | 1920x1080 | 接口最小分辨率,需要开启 open_filter_resolution 才能生效 | -| speed_weight | 0.5 | 速率权重值(所有权重值总和应为 1) | -| delay_weight | 0.25 | 响应时间权重值(所有权重值总和应为 1) | -| resolution_weight | 0.25 | 分辨率权重值 (所有权重值总和应为 1) | -| recent_days | 30 | 获取最近时间范围内更新的接口(单位天),适当减小可避免出现匹配问题 | -| ipv_type | 全部 | 生成结果中接口的协议类型,可选值:ipv4、ipv6、全部、all | -| ipv_type_prefer | 自动 | 接口协议类型偏好,优先将该类型的接口排在结果前面,可选值:IPv4、IPv6、自动、auto | -| ipv4_num | 5 | 结果中偏好的 IPv4 接口数量 | -| ipv6_num | 5 | 结果中偏好的 IPv6 接口数量 | -| url_keywords_blacklist | | 接口关键字黑名单,用于过滤含特定字符的接口 | -| open_subscribe | False | 开启订阅源功能 | -| subscribe_urls | | 订阅源,请输入订阅链接(支持 txt 与 m3u 链接),多个链接以逗号分隔 | -| open_multicast | True | 开启组播源功能,关闭后所有组播源工作模式都将关闭 | -| open_multicast_foodie | True | 开启 Foodie 组播源工作模式 | -| open_multicast_fofa | True | 开启 FOFA 组播源工作模式 | -| multicast_region_list | 全部 | 组播源地区列表,[更多地区](../updates/multicast/multicast_map.json),"全部"表示所有地区 | -| multicast_page_num | 1 | 组播地区获取分页数量 | -| open_hotel | True | 开启酒店源功能,关闭后所有酒店源工作模式都将关闭 | -| open_hotel_foodie | True | 开启 Foodie 酒店源工作模式 | -| open_hotel_fofa | True | 开启 FOFA、ZoomEye 酒店源工作模式 | -| hotel_region_list | 全部 | 酒店源地区列表,[更多地区](../updates/fofa/fofa_map.py),"全部"表示所有地区 | -| hotel_page_num | 1 | 酒店地区获取分页数量 | -| request_timeout | 10 | 查询请求超时时长,单位秒(s),用于控制查询接口文本链接的超时时长以及重试时长,调整此值能优化更新时间 | -| origin_type_prefer | hotel,multicast,subscribe,online_search | 结果偏好的接口来源,结果优先按该顺序进行排序,hotel:酒店源,multicast:组播源,subscribe:订阅源,online_search:关键字搜索 | -| hotel_num | 4 | 结果中偏好的酒店源接口数量 | -| multicast_num | 3 | 结果中偏好的组播源接口数量 | -| subscribe_num | 3 | 结果中偏好的订阅源接口数量 | -| online_search_num | 0 | 结果中偏好的关键字搜索接口数量 | -| open_url_info | True | 开启显示接口说明信息,用于控制是否显示分辨率、接口协议类型等信息,为$符号后的内容,播放软件使用该信息对接口进行描述 | -| open_empty_category | False | 开启无结果频道分类,自动归类至底部 | -| open_update_time | True | 开启显示更新时间 | \ No newline at end of file +| 配置项 | 描述 | 默认值 | +|:-----------------------|:------------------------------------------------------------------------------------------|:----------------------------------------| +| open_driver | 开启浏览器运行,若更新无数据可开启此模式,较消耗性能 | True | +| open_empty_category | 开启无结果频道分类,自动归类至底部 | False | +| open_ffmpeg | 开启使用 FFmpeg 进行测速,获取更准确的速度与分辨率信息,需要提前手动安装 | True | +| open_filter_resolution | 开启分辨率过滤,低于最小分辨率(min_resolution)的接口将会被过滤 | True | +| open_filter_speed | 开启速率过滤,低于最小速率(min_speed)的接口将会被过滤 | True | +| open_hotel | 开启酒店源功能,关闭后所有酒店源工作模式都将关闭 | True | +| open_hotel_foodie | 开启 Foodie 酒店源工作模式 | True | +| open_hotel_fofa | 开启 FOFA、ZoomEye 酒店源工作模式 | True | +| open_keep_all | 开启保留所有检索结果,会保留非模板频道名称的结果,推荐手动维护时开启 | False | +| open_m3u_result | 开启转换生成 m3u 文件类型结果链接,支持显示频道图标 | True | +| open_multicast | 开启组播源功能,关闭后所有组播源工作模式都将关闭 | True | +| open_multicast_foodie | 开启 Foodie 组播源工作模式 | True | +| open_multicast_fofa | 开启 FOFA 组播源工作模式 | True | +| open_online_search | 开启关键字搜索源功能 | False | +| open_proxy | 开启代理,自动获取免费可用代理,若更新无数据可开启此模式 | False | +| open_request | 开启查询请求,数据来源于网络 | False | +| open_service | 开启页面服务,用于控制是否启动结果页面服务;如果使用青龙等平台部署,有专门设定的定时任务,需要更新完成后停止运行,可以关闭该功能 | True | +| open_sort | 开启排序功能(响应速度、日期、分辨率) | True | +| open_subscribe | 开启订阅源功能 | False | +| open_update | 开启更新,用于控制是否更新接口,若关闭则所有工作模式(获取接口和测速)均停止 | True | +| open_update_time | 开启显示更新时间 | True | +| open_url_info | 开启显示接口说明信息,用于控制是否显示分辨率、接口协议类型等信息,为$符号后的内容,播放软件使用该信息对接口进行描述 | True | +| open_use_cache | 开启使用本地缓存数据,适用于查询请求失败场景 | True | +| open_use_old_result | 开启使用历史更新结果(包含模板与结果文件的接口),合并至本次更新中 | True | +| delay_weight | 响应时间权重值(所有权重值总和应为 1) | 0.25 | +| final_file | 生成结果文件路径 | output/result.txt | +| hotel_num | 结果中偏好的酒店源接口数量 | 4 | +| hotel_page_num | 酒店地区获取分页数量 | 1 | +| hotel_region_list | 酒店源地区列表,"全部"表示所有地区 | 全部 | +| ipv4_num | 结果中偏好的 IPv4 接口数量 | 5 | +| ipv6_num | 结果中偏好的 IPv6 接口数量 | 5 | +| ipv_type | 生成结果中接口的协议类型,可选值:ipv4、ipv6、全部、all | 全部 | +| ipv_type_prefer | 接口协议类型偏好,优先将该类型的接口排在结果前面,可选值:IPv4、IPv6、自动、auto | 自动 | +| min_resolution | 接口最小分辨率,需要开启 open_filter_resolution 才能生效 | 1920x1080 | +| min_speed | 接口最小速率(单位M/s),需要开启 open_filter_speed 才能生效 | 0.2 | +| multicast_num | 结果中偏好的组播源接口数量 | 3 | +| multicast_page_num | 组播地区获取分页数量 | 1 | +| multicast_region_list | 组播源地区列表,"全部"表示所有地区 | 全部 | +| online_search_num | 结果中偏好的关键字搜索接口数量 | 0 | +| online_search_page_num | 关键字搜索频道获取分页数量 | 1 | +| origin_type_prefer | 结果偏好的接口来源,结果优先按该顺序进行排序,hotel:酒店源,multicast:组播源,subscribe:订阅源,online_search:关键字搜索 | hotel,multicast,subscribe,online_search | +| recent_days | 获取最近时间范围内更新的接口(单位天),适当减小可避免出现匹配问题 | 30 | +| request_timeout | 查询请求超时时长,单位秒(s),用于控制查询接口文本链接的超时时长以及重试时长,调整此值能优化更新时间 | 10 | +| resolution_weight | 分辨率权重值 (所有权重值总和应为 1) | 0.25 | +| sort_timeout | 单个接口测速超时时长,单位秒(s);数值越大测速所属时间越长,能提高获取接口数量,但质量会有所下降;数值越小测速所需时间越短,能获取低延时的接口,质量较好;调整此值能优化更新时间 | 10 | +| source_file | 模板文件路径 | config/demo.txt | +| speed_weight | 速率权重值(所有权重值总和应为 1) | 0.5 | +| subscribe_num | 结果中偏好的订阅源接口数量 | 3 | +| url_keywords_blacklist | 接口关键字黑名单,用于过滤含特定字符的接口 | | +| urls_limit | 单个频道接口数量 | 10 | \ No newline at end of file diff --git a/docs/config_en.md b/docs/config_en.md index fa6ddf99e9..dca62473f4 100644 --- a/docs/config_en.md +++ b/docs/config_en.md @@ -1,53 +1,52 @@ -| Configuration Item | Default Value | Description | -|------------------------|--------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| open_service | True | Enable page service, used to control whether to start the result page service; if deployed on platforms like Qinglong with dedicated scheduled tasks, the function can be turned off after updates are completed and the task is stopped | -| open_update | True | Enable updates, if disabled then only the result page service is run | -| open_use_old_result | True | Enable the use of historical update results (including the interface for template and result files) and merge them into the current update | -| open_use_cache | True | Enable the use of local cache data, applicable to the query request failure scenario | -| open_request | False | Enable query request, the data is obtained from the network | -| open_driver | True | Enable browser execution, If there are no updates, this mode can be enabled, which consumes more performance | -| open_proxy | False | Enable proxy, automatically obtains free available proxies, If there are no updates, this mode can be enabled | -| source_file | config/demo.txt | Template file path | -| final_file | output/result.txt | Generated result file path | -| open_online_search | False | Enable keyword search source feature | -| online_search_page_num | 1 | Page retrieval quantity for keyword search channels | -| urls_limit | 10 | Number of interfaces per channel | -| open_keep_all | False | Retain all search results, retain results with non-template channel names, recommended to be turned on when manually maintaining | -| open_sort | True | Enable the sorting function (response speed, date, resolution) | -| sort_timeout | 5 | The timeout duration for speed testing of a single interface, in seconds (s). A larger value means a longer testing period, which can increase the number of interfaces obtained but may decrease their quality. A smaller value means a shorter testing time, which can obtain low-latency interfaces with better quality. Adjusting this value can optimize the update time. | -| open_ffmpeg | True | Enable speed testing using FFmpeg to obtain more accurate speed and resolution information. Manual installation is required in advance. | -| open_m3u_result | True | Enable the conversion to generate m3u file type result links, supporting the display of channel icons | -| open_filter_speed | True | Enable speed filtering, interfaces with speed lower than the minimum speed (min_speed) will be filtered | -| min_speed | 0.5 | Minimum interface speed (M/s), requires enabling open_filter_speed to take effect | -| open_filter_resolution | True | Enable resolution filtering, interfaces with resolution lower than the minimum resolution (min_resolution) will be filtered | -| min_resolution | 1920x1080 | Minimum interface resolution, requires enabling open_filter_resolution to take effect | -| speed_weight | 0.5 | Speed weight value (the sum of all weight values should be 1) | -| delay_weight | 0.25 | Response time weight value (the sum of all weight values should be 1) | -| resolution_weight | 0.25 | Resolution weight value (the sum of all weight values should be 1) | -| recent_days | 30 | Retrieve interfaces updated within a recent time range (in days), reducing appropriately can avoid matching issues | -| ipv_type | all | The protocol type of interface in the generated result, optional values: ipv4, ipv6, all | -| ipv_type_prefer | auto | Interface protocol type preference, prioritize interfaces of this type in the results, optional values: IPv4, IPv6, auto | -| ipv4_num | 5 | The preferred number of IPv4 interfaces in the result | -| ipv6_num | 5 | The preferred number of IPv6 interfaces in the result | -| url_keywords_blacklist | | Interface keyword blacklist, used to filter out interfaces containing specific characters | -| open_subscribe | True | Enable subscription source feature | -| subscribe_urls | | Subscription source, please enter the subscription link (supports txt and m3u links), multiple links should be separated by commas | -| open_multicast | True | Enable the multicast source function, after disabling it all multicast sources will stop working | -| open_multicast_foodie | True | Enable Foodie multicast source work mode | -| open_multicast_fofa | True | Enable FOFA multicast source work mode | -| multicast_region_list | all | Multicast source region list, [more regions](../updates/multicast/multicast_map.json, all means all regions) | -| multicast_page_num | 1 | Number of pages to retrieve for multicast regions | -| open_hotel | True | Enable the hotel source function, after closing it all hotel source working modes will be disabled | -| open_hotel_foodie | True | Enable Foodie hotel source work mode | -| open_hotel_fofa | True | Enable FOFA、ZoomEye hotel source work mode | -| hotel_region_list | all | List of hotel source regions, [more regions](../updates/fofa/fofa_map.py), 'all' indicates all regions | -| hotel_page_num | 1 | Number of pages to retrieve for hotel regions | -| request_timeout | 10 | Query request timeout duration, in seconds (s), used to control the timeout and retry duration for querying interface text links. Adjusting this value can optimize update time. | -| origin_type_prefer | hotel, multicast, subscribe, online_search | Result preference for the source of the interface, results are prioritized in this order: hotel: hotel source, multicast: multicast source, subscribe: subscription source, online_search: keyword search | -| hotel_num | 4 | The number of preferred hotel source interfaces in the results | -| multicast_num | 3 | The number of preferred multicast source interfaces in the results | -| subscribe_num | 3 | The number of preferred subscribe source interfaces in the results | -| online_search_num | 0 | The number of preferred keyword search interfaces in the results | -| open_url_info | True | Enable display of API description information, used to control whether to show resolution, API protocol type, etc., the content after the $ symbol, playback software uses this information to describe the API | -| open_empty_category | False | Enable the No Results Channel Category, which will automatically categorize channels without results to the bottom | -| open_update_time | True | Enable show update time | \ No newline at end of file +| Configuration Item | Description | Default Value | +|:-----------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-------------------------------------------| +| open_driver | Enable browser execution, If there are no updates, this mode can be enabled, which consumes more performance | True | +| open_empty_category | Enable the No Results Channel Category, which will automatically categorize channels without results to the bottom | False | +| open_ffmpeg | Enable speed testing using FFmpeg to obtain more accurate speed and resolution information. Manual installation is required in advance. | True | +| open_filter_resolution | Enable resolution filtering, interfaces with resolution lower than the minimum resolution (min_resolution) will be filtered | True | +| open_filter_speed | Enable speed filtering, interfaces with speed lower than the minimum speed (min_speed) will be filtered | True | +| open_hotel | Enable the hotel source function, after closing it all hotel source working modes will be disabled | True | +| open_hotel_foodie | Enable Foodie hotel source work mode | True | +| open_hotel_fofa | Enable FOFA、ZoomEye hotel source work mode | True | +| open_keep_all | Enable retain all search results, retain results with non-template channel names, recommended to be turned on when manually maintaining | False | +| open_m3u_result | Enable the conversion to generate m3u file type result links, supporting the display of channel icons | True | +| open_multicast | Enable the multicast source function, after disabling it all multicast sources will stop working | True | +| open_multicast_foodie | Enable Foodie multicast source work mode | True | +| open_multicast_fofa | Enable FOFA multicast source work mode | True | +| open_online_search | Enable keyword search source feature | False | +| open_proxy | Enable proxy, automatically obtains free available proxies, If there are no updates, this mode can be enabled | False | +| open_request | Enable query request, the data is obtained from the network | False | +| open_service | Enable page service, used to control whether to start the result page service; if deployed on platforms like Qinglong with dedicated scheduled tasks, the function can be turned off after updates are completed and the task is stopped | True | +| open_sort | Enable the sorting function (response speed, date, resolution) | True | +| open_subscribe | Enable subscription source feature | True | +| open_update | Enable updates, if disabled then only the result page service is run | True | +| open_update_time | Enable show update time | True | +| open_url_info | Enable display of API description information, used to control whether to show resolution, API protocol type, etc., the content after the $ symbol, playback software uses this information to describe the API | True | +| open_use_cache | Enable the use of local cache data, applicable to the query request failure scenario | True | +| open_use_old_result | Enable the use of historical update results (including the interface for template and result files) and merge them into the current update | True | +| delay_weight | Response time weight value (the sum of all weight values should be 1) | 0.25 | +| final_file | Generated result file path | output/result.txt | +| hotel_num | The number of preferred hotel source interfaces in the results | 4 | +| hotel_page_num | Number of pages to retrieve for hotel regions | 1 | +| hotel_region_list | List of hotel source regions, 'all' indicates all regions | all | +| ipv4_num | The preferred number of IPv4 interfaces in the result | 5 | +| ipv6_num | The preferred number of IPv6 interfaces in the result | 5 | +| ipv_type | The protocol type of interface in the generated result, optional values: ipv4, ipv6, all | all | +| ipv_type_prefer | Interface protocol type preference, prioritize interfaces of this type in the results, optional values: IPv4, IPv6, auto | auto | +| min_resolution | Minimum interface resolution, requires enabling open_filter_resolution to take effect | 1920x1080 | +| min_speed | Minimum interface speed (M/s), requires enabling open_filter_speed to take effect | 0.2 | +| multicast_num | The number of preferred multicast source interfaces in the results | 3 | +| multicast_page_num | Number of pages to retrieve for multicast regions | 1 | +| multicast_region_list | Multicast source region list, 'all' indicates all regions | all | +| online_search_num | The number of preferred keyword search interfaces in the results | 0 | +| online_search_page_num | Page retrieval quantity for keyword search channels | 1 | +| origin_type_prefer | Result preference for the source of the interface, results are prioritized in this order: hotel: hotel source, multicast: multicast source, subscribe: subscription source, online_search: keyword search | hotel, multicast, subscribe, online_search | +| recent_days | Retrieve interfaces updated within a recent time range (in days), reducing appropriately can avoid matching issues | 30 | +| request_timeout | Query request timeout duration, in seconds (s), used to control the timeout and retry duration for querying interface text links. Adjusting this value can optimize update time. | 10 | +| resolution_weight | Resolution weight value (the sum of all weight values should be 1) | 0.25 | +| sort_timeout | The timeout duration for speed testing of a single interface, in seconds (s). A larger value means a longer testing period, which can increase the number of interfaces obtained but may decrease their quality. A smaller value means a shorter testing time, which can obtain low-latency interfaces with better quality. Adjusting this value can optimize the update time. | 10 | +| source_file | Template file path | config/demo.txt | +| speed_weight | Speed weight value (the sum of all weight values should be 1) | 0.5 | +| subscribe_num | The number of preferred subscribe source interfaces in the results | 3 | +| url_keywords_blacklist | Interface keyword blacklist, used to filter out interfaces containing specific characters | | +| urls_limit | Number of interfaces per channel | 10 | \ No newline at end of file diff --git a/docs/tutorial.md b/docs/tutorial.md index 540c0f7eb3..e8106b96ea 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -92,7 +92,7 @@ ![创建user_config.ini](./images/edit-user-config.png '创建user_config.ini') 按照您的需要适当调整配置,以下是默认配置说明: -[配置参数](./docs/config.md) +[配置参数](./config.md) ## 步骤五:运行更新 diff --git a/docs/tutorial_en.md b/docs/tutorial_en.md index 162691471d..e96d296d8f 100644 --- a/docs/tutorial_en.md +++ b/docs/tutorial_en.md @@ -94,7 +94,7 @@ Similar to editing the template, modify the running configuration ![Create user_config.ini](./images/edit-user-config.png 'Create user_config.ini') Adjust the configuration as needed. Below is the default configuration explanation: -[Config parameter](./docs/config_en.md) +[Config parameter](./config_en.md) ## Step 5: Run Updates diff --git a/main.py b/main.py index d3ba78fcac..477a63a127 100644 --- a/main.py +++ b/main.py @@ -30,7 +30,7 @@ format_interval, check_ipv6_support, resource_path, - get_whitelist_urls + get_urls_from_file ) @@ -71,8 +71,8 @@ async def visit_page(self, channel_names=None): continue if config.open_method[setting]: if setting == "subscribe": - subscribe_urls = config.subscribe_urls - whitelist_urls = get_whitelist_urls() + subscribe_urls = get_urls_from_file(constants.subscribe_path) + whitelist_urls = get_urls_from_file(constants.whitelist_path) task = asyncio.create_task( task_func(subscribe_urls, whitelist=whitelist_urls, callback=self.update_progress) ) @@ -107,8 +107,9 @@ def get_urls_len(self, filter=False): async def main(self): try: + user_final_file = config.final_file + main_start_time = time() if config.open_update: - main_start_time = time() self.channel_items = get_channel_items() channel_names = [ name @@ -157,7 +158,6 @@ async def main(self): callback=lambda: self.pbar_update(name="写入结果"), ) self.pbar.close() - user_final_file = config.final_file update_file(user_final_file, constants.result_path) if config.open_use_old_result: if open_sort: @@ -170,9 +170,8 @@ async def main(self): ) as file: pickle.dump(channel_data_cache, file) convert_to_m3u() - total_time = format_interval(time() - main_start_time) print( - f"🥳 Update completed! Total time spent: {total_time}. Please check the {user_final_file} file!" + f"🥳 Update completed! Total time spent: {format_interval(time() - main_start_time)}. Please check the {user_final_file} file!" ) if self.run_ui: open_service = config.open_service @@ -180,7 +179,7 @@ async def main(self): tip = ( f"✅ 服务启动成功{service_tip}" if open_service and config.open_update == False - else f"🥳 更新完成, 耗时: {total_time}, 请检查{user_final_file}文件{service_tip}" + else f"🥳 更新完成, 耗时: {format_interval(time() - main_start_time)}, 请检查{user_final_file}文件{service_tip}" ) self.update_progress( tip, diff --git a/tkinter_ui/subscribe.py b/tkinter_ui/subscribe.py index b79305579b..323c857a91 100644 --- a/tkinter_ui/subscribe.py +++ b/tkinter_ui/subscribe.py @@ -1,7 +1,10 @@ import tkinter as tk +from tkinter import scrolledtext from tkinter import ttk + +import utils.constants as constants from utils.config import config -from tkinter import scrolledtext +from utils.tools import get_urls_from_file class SubscribeUI: @@ -39,7 +42,7 @@ def init_ui(self, root): self.subscribe_urls_text.pack( side=tk.LEFT, padx=4, pady=8, expand=True, fill=tk.BOTH ) - self.subscribe_urls_text.insert(tk.END, ",".join(config.subscribe_urls)) + self.subscribe_urls_text.insert(tk.END, ",".join(get_urls_from_file(constants.subscribe_path))) self.subscribe_urls_text.bind("", self.update_subscribe_urls) def update_open_subscribe(self): diff --git a/updates/subscribe/request.py b/updates/subscribe/request.py index 9c12a3dfc2..c6a9620ea7 100644 --- a/updates/subscribe/request.py +++ b/updates/subscribe/request.py @@ -31,7 +31,7 @@ async def get_channels_by_subscribe_urls( Get the channels by subscribe urls """ subscribe_results = {} - subscribe_urls_len = len(urls if urls else config.subscribe_urls) + subscribe_urls_len = len(urls) pbar = tqdm_asyncio( total=subscribe_urls_len, desc=f"Processing subscribe {'for multicast' if multicast else ''}", @@ -134,7 +134,7 @@ def process_subscribe_channels(subscribe_info): with ThreadPoolExecutor(max_workers=100) as executor: futures = [ executor.submit(process_subscribe_channels, subscribe_url) - for subscribe_url in (urls if urls else config.subscribe_urls) + for subscribe_url in urls ] for future in futures: subscribe_results = merge_objects(subscribe_results, future.result()) diff --git a/utils/channel.py b/utils/channel.py index 1ff5e7f4c5..5178fc4caa 100644 --- a/utils/channel.py +++ b/utils/channel.py @@ -6,6 +6,7 @@ import pickle import re from collections import defaultdict +from logging import INFO from bs4 import NavigableString from opencc import OpenCC @@ -25,8 +26,9 @@ remove_cache_info, resource_path, write_content_into_txt, - get_whitelist_urls, - get_whitelist_name_urls + get_urls_from_file, + get_name_urls_from_file, + get_logger, ) @@ -70,7 +72,7 @@ def get_channel_items(): """ user_source_file = resource_path(config.source_file) channels = defaultdict(lambda: defaultdict(list)) - whitelist = get_whitelist_name_urls() + whitelist = get_name_urls_from_file(constants.whitelist_path) whitelist_len = len(list(whitelist.keys())) if whitelist_len: print(f"Found {whitelist_len} channel in whitelist") @@ -547,12 +549,12 @@ async def process_sort_channel_list(data, ipv6=False, callback=None): """ ipv6_proxy = None if (not config.open_ipv6 or ipv6) else constants.ipv6_proxy need_sort_data = copy.deepcopy(data) - whitelist_urls = get_whitelist_urls() + whitelist_urls = get_urls_from_file(constants.whitelist_path) if whitelist_urls: print(f"Found {len(whitelist_urls)} whitelist urls") process_nested_dict(need_sort_data, seen=set(whitelist_urls), flag=r"cache:(.*)", force_str="!") result = {} - semaphore = asyncio.Semaphore(10) + semaphore = asyncio.Semaphore(5) async def limited_get_speed(info, ipv6_proxy, callback): async with semaphore: @@ -571,9 +573,10 @@ async def limited_get_speed(info, ipv6_proxy, callback): for info in info_list ] await asyncio.gather(*tasks) + logger = get_logger(constants.sort_log_path, level=INFO, init=True) for cate, obj in data.items(): for name, info_list in obj.items(): - info_list = sort_urls(name, info_list, whitelist=whitelist_urls) + info_list = sort_urls(name, info_list, logger=logger, whitelist=whitelist_urls) append_data_to_info_data( result, cate, @@ -581,6 +584,7 @@ async def limited_get_speed(info, ipv6_proxy, callback): info_list, check=False, ) + logger.handlers.clear() return result diff --git a/utils/config.py b/utils/config.py index 416c42a794..93c22202b1 100644 --- a/utils/config.py +++ b/utils/config.py @@ -305,16 +305,6 @@ def multicast_page_num(self): def online_search_page_num(self): return config.getint("Settings", "online_search_page_num", fallback=1) - @property - def subscribe_urls(self): - return [ - url.strip() - for url in self.config.get("Settings", "subscribe_urls", fallback="").split( - "," - ) - if url.strip() - ] - @property def delay_weight(self): return self.config.getfloat("Settings", "delay_weight", fallback=0.5) diff --git a/utils/constants.py b/utils/constants.py index 2ca97d4477..bf6463dde6 100644 --- a/utils/constants.py +++ b/utils/constants.py @@ -6,6 +6,8 @@ whitelist_path = os.path.join(config_path, "whitelist.txt") +subscribe_path = os.path.join(config_path, "subscribe.txt") + result_path = os.path.join(output_path, "result_new.txt") cache_path = os.path.join(output_path, "cache.pkl") diff --git a/utils/speed.py b/utils/speed.py index 3d1d8192c1..91a8550bdd 100644 --- a/utils/speed.py +++ b/utils/speed.py @@ -1,16 +1,14 @@ import asyncio import re import subprocess -from logging import INFO from time import time from urllib.parse import quote import m3u8 from aiohttp import ClientSession, TCPConnector -import utils.constants as constants from utils.config import config -from utils.tools import is_ipv6, remove_cache_info, get_resolution_value, get_logger +from utils.tools import is_ipv6, remove_cache_info, get_resolution_value async def get_speed_with_download(url: str, timeout: int = config.sort_timeout) -> dict[str, float | None]: @@ -47,19 +45,24 @@ async def get_speed_m3u8(url: str, timeout: int = config.sort_timeout) -> dict[s """ info = {'speed': None, 'delay': None} try: - url = quote(url, safe=':/?$&=@') - m3u8_obj = m3u8.load(url, timeout=2) - speed_list = [] - start_time = time() - for segment in m3u8_obj.segments: - if time() - start_time > timeout: - break - ts_url = segment.absolute_uri - download_info = await get_speed_with_download(ts_url, timeout) - speed_list.append(download_info['speed']) - if info['delay'] is None and download_info['delay'] is not None: - info['delay'] = download_info['delay'] - info['speed'] = sum(speed_list) / len(speed_list) if speed_list else 0 + url = quote(url, safe=':/?$&=@').partition('$')[0] + async with ClientSession(connector=TCPConnector(ssl=False), trust_env=True) as session: + async with session.head(url, timeout=2) as response: + if response.headers.get('Content-Length'): + m3u8_obj = m3u8.load(url, timeout=2) + speed_list = [] + start_time = time() + for segment in m3u8_obj.segments: + if time() - start_time > timeout: + break + ts_url = segment.absolute_uri + download_info = await get_speed_with_download(ts_url, timeout) + speed_list.append(download_info['speed']) + if info['delay'] is None and download_info['delay'] is not None: + info['delay'] = download_info['delay'] + info['speed'] = sum(speed_list) / len(speed_list) if speed_list else 0 + else: + return info except: pass finally: @@ -209,8 +212,6 @@ def sort_urls(name, data, logger=None, whitelist=None): Sort the urls with info """ filter_data = [] - if logger is None: - logger = get_logger(constants.sort_log_path, level=INFO, init=True) for url, date, resolution, origin in data: if whitelist and url in whitelist: origin = "important" @@ -246,8 +247,6 @@ def sort_urls(name, data, logger=None, whitelist=None): result["speed"] = speed result["resolution"] = resolution filter_data.append(result) - if logger: - logger.handlers.clear() def combined_key(item): speed, delay, resolution, origin = item["speed"], item["delay"], item["resolution"], item["origin"] diff --git a/utils/tools.py b/utils/tools.py index 260c84b781..8b38b4fedc 100644 --- a/utils/tools.py +++ b/utils/tools.py @@ -542,15 +542,25 @@ def get_name_url(content, pattern, multiline=False, check_url=True): return channels -def get_whitelist_urls(): +def get_real_path(path) -> str: """ - Get the whitelist urls + Get the real path """ - whitelist_file = resource_path(constants.whitelist_path) + dir_path, file = os.path.split(path) + user_real_path = os.path.join(dir_path, 'user_' + file) + real_path = user_real_path if os.path.exists(user_real_path) else path + return real_path + + +def get_urls_from_file(path: str) -> list: + """ + Get the urls from file + """ + real_path = get_real_path(resource_path(path)) urls = [] url_pattern = constants.url_pattern - if os.path.exists(whitelist_file): - with open(whitelist_file, "r", encoding="utf-8") as f: + if os.path.exists(real_path): + with open(real_path, "r", encoding="utf-8") as f: for line in f: match = re.search(url_pattern, line) if match: @@ -558,15 +568,15 @@ def get_whitelist_urls(): return urls -def get_whitelist_name_urls(): +def get_name_urls_from_file(path: str) -> dict[str, list]: """ - Get the whitelist name urls + Get the name and urls from file """ - whitelist_file = resource_path(constants.whitelist_path) + real_path = get_real_path(resource_path(path)) name_urls = defaultdict(list) txt_pattern = constants.txt_pattern - if os.path.exists(whitelist_file): - with open(whitelist_file, "r", encoding="utf-8") as f: + if os.path.exists(real_path): + with open(real_path, "r", encoding="utf-8") as f: for line in f: name_url = get_name_url(line, pattern=txt_pattern) if name_url and name_url[0]: