Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev #499

Merged
merged 6 commits into from
Nov 1, 2024
Merged

dev #499

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,19 @@ https://ghproxy.net/raw.githubusercontent.com/Guovin/TV/gd/source.json

## 快速上手

### 方式一:工作流更新
### 方式一:工作流

Fork 本项目并开启工作流更新,具体步骤请见[详细教程](./docs/tutorial.md)

### 方式二:命令行更新
### 方式二:命令行

```python
pip3 install pipenv
pipenv install
pipenv run build
```

### 方式三:GUI 软件更新
### 方式三:GUI 软件

1. 下载[更新工具软件](https://github.com/Guovin/TV/releases),打开软件,点击更新,即可完成更新

Expand All @@ -130,7 +130,7 @@ pipenv run ui

<img src="./docs/images/ui.png" alt="更新工具软件" title="更新工具软件" style="height:600px" />

### 方式四:Docker 更新
### 方式四:Docker

- requests:轻量级,性能要求低,更新速度快,稳定性不确定(推荐订阅源使用此版本)
- driver:性能要求较高,更新速度较慢,稳定性、成功率高;修改配置 open_driver = False 可切换到 request 版本(推荐酒店源、组播源、关键字搜索使用此版本)
Expand Down
8 changes: 4 additions & 4 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,19 @@ https://ghproxy.net/raw.githubusercontent.com/Guovin/TV/gd/source.json

## Quick Start

### Method 1: Workflow Update
### Method 1: Workflow

Fork this project and initiate workflow updates, detailed steps are available at [Detailed Tutorial](./docs/tutorial_en.md)

### Method 2: Command Line Update
### Method 2: Command Line

```python
pip3 install pipenv
pipenv install
pipenv run build
```

### Method 3: GUI Software Update
### Method 3: GUI Software

1. Download [Update tool software](https://github.com/Guovin/TV/releases), open the software, click update to complete the update

Expand All @@ -130,7 +130,7 @@ pipenv run ui

<img src="./docs/images/ui.png" alt="Update tool software" title="Update tool software" style="height:600px" />

### Method 4: Docker Update
### Method 4: Docker

- requests: Lightweight, low performance requirements, fast update speed, stability uncertain (recommend using this version for the subscription source)
- driver: Higher performance requirements, slower update speed, high stability and success rate. Set open_driver = False to switch to the request version (recommended for hotel sources, multicast sources, and online searches)
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

1. 创建文件
2. 模板文件命名为 user_demo.txt
3. 模板文件需要按照(频道分类,#genre#),(频道名称,频道接口)进行编写,注意是英文逗号。
3. 模板文件需要按照(频道分类,#genre#),(频道名称,频道接口)进行编写,注意是英文逗号。如果需要将该接口设为白名单(不测速、保留在结果最前),可在地址后添加$!即可,例如http://xxx$!。后面也可以添加额外说明信息,如:http://xxx$!白名单接口
4. 点击 Commit changes...进行保存

![创建user_demo.txt](./images/edit-user-demo.png '创建user_demo.txt')
Expand Down Expand Up @@ -92,7 +92,7 @@

## 步骤五:运行更新

### 方式一:工作流更新
### 方式一:工作流

#### 注意: 请谨慎使用工作流更新,如果您有大量的频道需要更新,请使用本地更新,勿使用自动更新,配置不当可能导致账户或工作流封禁!

Expand Down Expand Up @@ -166,7 +166,7 @@ https://mirror.ghproxy.com/raw.githubusercontent.com/您的github用户名/仓

#### 2. 请留意您的工作流运行时长,若发现执行时间过长,需要适当删减模板中频道数量、修改配置中的分页数量和接口数量,以达到合规的运行要求。

### 方式二:命令行更新
### 方式二:命令行

```python
1. 安装 Python
Expand All @@ -179,7 +179,7 @@ pipenv install
pipenv run build
```

### 方式三:GUI 软件更新
### 方式三:GUI 软件

1. 下载[更新工具软件](https://github.com/Guovin/TV/releases),打开软件,点击更新,即可完成更新

Expand All @@ -191,7 +191,7 @@ pipenv run ui

![更新工具软件](./images/ui.png '更新工具软件')

### 方式四:Docker 更新
### 方式四:Docker

- requests:轻量级,性能要求低,更新速度快,稳定性不确定(推荐订阅源使用此版本)
- driver:性能要求较高,更新速度较慢,稳定性、成功率高;修改配置 open_driver = False 可切换到 request 版本(推荐酒店源、组播源、关键字搜索使用此版本)
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorial_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ When you click to confirm and create in step one, you will be automatically redi

1. Create file
2. Name the template file user_demo.txt
3. The template file needs to be written in the format of (channel category, #genre#), (channel name, channel interface), note that it is an English comma.
3. The template file needs to be written in the format of (channel category, #genre#), (channel name, channel interface), note that it is an English comma. If you need to set this interface as a whitelist (no speed testing, kept at the front of the results), simply add $! after the address. For example: http://xxx$!. Additional information can also be appended afterward, such as: http://xxx$! Whitelist interface.
4. Click Commit changes... to save

![Create user_demo.txt](./images/edit-user-demo.png 'Create user_demo.txt')
Expand Down Expand Up @@ -89,7 +89,7 @@ Adjust the configuration as needed. Below is the default configuration explanati

## Step 5: Run Updates

## Method 1: Workflow update
## Method 1: Workflow

#### Warning: Please use the following content with caution. If you have a large number of channels that need to be updated, please use local updates instead of automatic updates. Improper configuration may lead to your account or workflow being banned!

Expand Down Expand Up @@ -163,7 +163,7 @@ If you want to perform updates every 2 days, you can modify it like this:

#### 2. Please pay attention to the runtime of your workflow. If you find that the execution time is too long, you need to appropriately reduce the number of channels in the template, modify the number of pages and interfaces in the configuration, in order to meet the compliant operation requirements.

### Method 2: Command Line Update
### Method 2: Command Line

```python
1. Install Python
Expand All @@ -176,7 +176,7 @@ pipenv install
pipenv run build
```

### Method 3: GUI Software Update
### Method 3: GUI Software

1. Download the update tool software, open the software, click update to complete the update.

Expand All @@ -188,7 +188,7 @@ pipenv run ui

![Update tool software](./images/ui.png 'Update tool software')

### Method 4: Docker Update
### Method 4: Docker

- requests: Lightweight, low performance requirements, fast update speed, stability uncertain (recommend this version for subscription sources)
- driver: Higher performance requirements, slower update speed, high stability and success rate. Set open_driver = False to switch to the request version (recommended for hotel sources, multicast sources, and keyword search)
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def pbar_update(self, name=""):
def get_urls_len(self, filter=False):
data = copy.deepcopy(self.channel_data)
if filter:
process_nested_dict(data, seen=set(), flag=r"cache:(.*)")
process_nested_dict(data, seen=set(), flag=r"cache:(.*)", force_str="!")
processed_urls = set(
url_info[0]
for channel_obj in data.values()
Expand Down
94 changes: 70 additions & 24 deletions utils/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ def get_channel_data_from_file(channels, file, use_old):
if name not in category_dict:
category_dict[name] = []
if use_old and url:
info = (url, None, None, None)
if info[0] and info not in category_dict[name]:
category_dict[name].append(info)
info = url.partition("$")[2]
origin = None
if info and info.startswith("!"):
origin = "important"
data = (url, None, None, origin)
if data not in category_dict[name]:
category_dict[name].append(data)
return channels


Expand All @@ -119,10 +123,17 @@ def get_channel_items():
for cate, data in channels.items():
if cate in old_result:
for name, info_list in data.items():
urls = [
item[0].partition("$")[0]
for item in info_list
if item[0]
]
if name in old_result[cate]:
for info in old_result[cate][name]:
if info not in info_list:
channels[cate][name].append(info)
if info:
pure_url = info[0].partition("$")[0]
if pure_url not in urls:
channels[cate][name].append(info)
return channels


Expand Down Expand Up @@ -473,17 +484,36 @@ def init_info_data(data, cate, name):
data[cate][name] = []


def append_data_to_info_data(info_data, cate, name, data, origin=None, check=True):
def append_data_to_info_data(
info_data, cate, name, data, origin=None, check=True, insert=False
):
"""
Append channel data to total info data
"""
init_info_data(info_data, cate, name)
urls = [x[0].partition("$")[0] for x in info_data[cate][name] if x[0]]
for item in data:
try:
url, date, resolution, *rest = item
origin = origin or (rest[0] if rest else None)
if (url and not check) or (url and check and check_url_by_patterns(url)):
info_data[cate][name].append((url, date, resolution, origin))
url_origin = origin or (rest[0] if rest else None)
if url:
pure_url = url.partition("$")[0]
if pure_url in urls:
continue
if (
url_origin == "important"
or (not check)
or (check and check_url_by_patterns(pure_url))
):
if insert:
info_data[cate][name].insert(
0, (url, date, resolution, url_origin)
)
else:
info_data[cate][name].append(
(url, date, resolution, url_origin)
)
urls.append(pure_url)
except:
continue

Expand All @@ -499,19 +529,15 @@ def get_origin_method_name(method):

def append_old_data_to_info_data(info_data, cate, name, data):
"""
Append old channel data to total info data
Append history channel data to total info data
"""
append_data_to_info_data(
info_data,
cate,
name,
data,
)
print(name, "old:", len(data), end=", ")
print(
"total:",
len(info_data.get(cate, {}).get(name, [])),
)
print("History:", len(data), end=", ")


def append_total_data(
Expand All @@ -537,6 +563,8 @@ def append_total_data(
for cate, channel_obj in items:
for name, old_info_list in channel_obj.items():
print(f"{name}:", end=" ")
if constants.open_use_old_result and old_info_list:
append_old_data_to_info_data(data, cate, name, old_info_list)
for method, result in total_result:
if constants.open_method[method]:
origin_method = get_origin_method_name(method)
Expand All @@ -547,8 +575,10 @@ def append_total_data(
data, cate, name, name_results, origin=origin_method
)
print(f"{method.capitalize()}:", len(name_results), end=", ")
if constants.open_use_old_result:
append_old_data_to_info_data(data, cate, name, old_info_list)
print(
"total:",
len(data.get(cate, {}).get(name, [])),
)
if constants.open_keep_all:
extra_cate = "📥其它频道"
for method, result in total_result:
Expand All @@ -560,15 +590,20 @@ def append_total_data(
if name in names:
continue
print(f"{name}:", end=" ")
if constants.open_use_old_result:
old_info_list = channel_obj.get(name, [])
if old_info_list:
append_old_data_to_info_data(
data, extra_cate, name, old_info_list
)
append_data_to_info_data(
data, extra_cate, name, urls, origin=origin_method
)
print(name, f"{method.capitalize()}:", len(urls), end=", ")
if constants.open_use_old_result:
old_info_list = channel_obj.get(name, [])
append_old_data_to_info_data(
data, extra_cate, name, old_info_list
)
print(
"total:",
len(data.get(cate, {}).get(name, [])),
)


async def sort_channel_list(
Expand Down Expand Up @@ -624,7 +659,7 @@ async def process_sort_channel_list(data, ipv6=False, callback=None):
is_ffmpeg = constants.open_ffmpeg and ffmpeg_installed
semaphore = asyncio.Semaphore(5)
need_sort_data = copy.deepcopy(data)
process_nested_dict(need_sort_data, seen=set(), flag=r"cache:(.*)")
process_nested_dict(need_sort_data, seen=set(), flag=r"cache:(.*)", force_str="!")
tasks = [
asyncio.create_task(
sort_channel_list(
Expand Down Expand Up @@ -658,7 +693,18 @@ async def process_sort_channel_list(data, ipv6=False, callback=None):
}
for url, date, resolution, origin in info_list:
if "$" in url:
matcher = re.search(r"cache:(.*)", url)
info = url.partition("$")[2]
if info and info.startswith("!"):
append_data_to_info_data(
sort_data,
cate,
name,
[(url, date, resolution, origin)],
check=False,
insert=True,
)
continue
matcher = re.search(r"cache:(.*)", info)
if matcher:
cache_key = matcher.group(1)
if not cache_key:
Expand Down
2 changes: 1 addition & 1 deletion utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def get_resolution_value(resolution_str):

log_path = os.path.join(log_dir, log_file)

url_pattern = r"\b((https?):\/\/)?(\[[0-9a-fA-F:]+\]|([\w-]+\.)+[\w-]+)(:[0-9]{1,5})?(\/[^\s]*)?\b"
url_pattern = r"((https?):\/\/)?(\[[0-9a-fA-F:]+\]|([\w-]+\.)+[\w-]+)(:[0-9]{1,5})?(\/[^\s]*)?(\$[^\s]+)?"

rtp_pattern = r"^([^,,]+)(?:[,,])?(rtp://.*)$"

Expand Down
Loading
Loading