Skip to content

Commit

Permalink
Merge pull request #204 from Guovin/master
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Guovin authored Jul 10, 2024
2 parents 3a89420 + 8d1dce1 commit 13efd11
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 56 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# 更新日志(Changelog)

## v1.3.2

### 2024/7/10

- 新增支持频道名称简体繁体匹配(Added support for channel name Simplified and Traditional Chinese match)
- 新增 Docker 修改模板与配置教程(Added Docker modification template and configuration tutorial)
- 修复频道更新结果为空问题(Fixed the issue where channel update result is empty)

## v1.3.1

### 2024/7/9
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pyinstaller = "*"
aiohttp = "*"
flask = "*"
gunicorn = "*"
opencc-python-reimplemented = "*"

[requires]
python_version = "3.8"
48 changes: 28 additions & 20 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ pipenv run ui

### 方式三:Docker 更新

- requests:轻量级,性能要求低,更新速度快,稳定性不确定(只使用订阅源推荐此版本)
- driver:性能要求较高,更新速度较慢,稳定性、成功率高(使用在线搜索、组播源使用此版本)
- requests:轻量级,性能要求低,更新速度快,稳定性不确定(推荐订阅源使用此版本)
- driver:性能要求较高,更新速度较慢,稳定性、成功率高(在线搜索、组播源使用此版本)

建议都试用一次,选择自己合适的版本,在线搜索和组播源使用 requests 能拿到结果的话,优先选择 requests 版本。

```bash
1. 拉取镜像:
Expand Down
6 changes: 4 additions & 2 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ pipenv run ui

### Method 3: Docker Update

- requests: Lightweight, low performance requirements, fast update speed, stability uncertain (recommend this version only for subscription sources)
- driver: Higher performance requirements, slower update speed, high stability, high success rate (use this version for online search, multicast sources)
- 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, high success rate (Online search, multicast source use this version)

It's recommended to try each one and choose the version that suits you. If you can get results with requests for online searches and multicast sources, prioritize choosing the version that uses requests.

```bash
1. Pull the image:
Expand Down
2 changes: 1 addition & 1 deletion tkinter_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TkinterUI:
def __init__(self, root):
self.root = root
self.root.title("直播源接口更新工具")
self.version = "v1.3.1"
self.version = "v1.3.2"
self.update_source = UpdateSource()
self.update_running = False
self.config_entrys = [
Expand Down
101 changes: 74 additions & 27 deletions utils/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from bs4 import NavigableString
import logging
from logging.handlers import RotatingFileHandler
from opencc import OpenCC

config = get_config()

Expand Down Expand Up @@ -94,25 +95,65 @@ def format_channel_name(name):
return name.lower()


def channel_name_is_equal(name1, name2):
"""
Check if the channel name is equal
"""
cc = OpenCC("t2s")
name1_converted = cc.convert(format_channel_name(name1))
name2_converted = cc.convert(format_channel_name(name2))
return name1_converted == name2_converted


def get_channel_results_by_name(name, data):
"""
Get channel results from data by name
"""
format_name = format_channel_name(name)
cc1 = OpenCC("s2t")
converted1 = cc1.convert(format_name)
cc2 = OpenCC("t2s")
converted2 = cc2.convert(format_name)
result1 = data.get(converted1, [])
result2 = data.get(converted2, [])
results = list(dict.fromkeys(result1 + result2))
return results


def get_element_child_text_list(element, child_name):
"""
Get the child text of the element
"""
text_list = []
children = element.find_all(child_name)
if children:
for child in children:
text = child.get_text(strip=True)
if text:
text_list.append(text)
return text_list


def get_results_from_soup(soup, name):
"""
Get the results from the soup
"""
results = []
for element in soup.descendants:
if isinstance(element, NavigableString):
url = get_channel_url(element)
text = element.get_text(strip=True)
url = get_channel_url(text)
if url and not any(item[0] == url for item in results):
url_element = soup.find(lambda tag: tag.get_text(strip=True) == url)
if url_element:
name_element = url_element.find_previous_sibling()
if name_element:
channel_name = name_element.get_text(strip=True)
if format_channel_name(name) == format_channel_name(
channel_name
):
if channel_name_is_equal(name, channel_name):
info_element = url_element.find_next_sibling()
date, resolution = get_channel_info(info_element)
date, resolution = get_channel_info(
info_element.get_text(strip=True)
)
results.append((url, date, resolution))
return results

Expand All @@ -127,10 +168,18 @@ def get_results_from_soup_requests(soup, name):
name_element = element.find("div", class_="channel")
if name_element:
channel_name = name_element.get_text(strip=True)
if format_channel_name(name) == format_channel_name(channel_name):
url = get_channel_url(element)
date, resolution = get_channel_info(element)
results.append((url, date, resolution))
if channel_name_is_equal(name, channel_name):
text_list = get_element_child_text_list(element, "div")
url = date = resolution = None
for text in text_list:
text_url = get_channel_url(text)
if text_url:
url = text_url
if " " in text:
text_info = get_channel_info(text)
date, resolution = text_info
if url:
results.append((url, date, resolution))
return results


Expand All @@ -155,33 +204,32 @@ def update_channel_urls_txt(cate, name, urls):
f.write(name + "," + url + "\n")


def get_channel_url(element):
def get_channel_url(text):
"""
Get the url, date and resolution
Get the url from text
"""
url = None
urlRegex = r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+"
url_search = re.search(
urlRegex,
element.get_text(strip=True),
text,
)
if url_search:
url = url_search.group()
return url


def get_channel_info(element):
def get_channel_info(text):
"""
Get the channel info
Get the channel info from text
"""
date, resolution = None, None
info_text = element.get_text(strip=True)
if info_text:
if text:
date, resolution = (
(info_text.partition(" ")[0] if info_text.partition(" ")[0] else None),
(text.partition(" ")[0] if text.partition(" ")[0] else None),
(
info_text.partition(" ")[2].partition("•")[2]
if info_text.partition(" ")[2].partition("•")[2]
text.partition(" ")[2].partition("•")[2]
if text.partition(" ")[2].partition("•")[2]
else None
),
)
Expand Down Expand Up @@ -218,42 +266,41 @@ def append_all_method_data(
"""
for cate, channel_obj in items:
for name, old_urls in channel_obj.items():
formatName = format_channel_name(name)
if config.open_subscribe:
data = append_data_to_info_data(
data,
cate,
name,
subscribe_result.get(formatName, []),
get_channel_results_by_name(name, subscribe_result),
)
print(
name,
"subscribe num:",
len(subscribe_result.get(formatName, [])),
len(get_channel_results_by_name(name, subscribe_result)),
)
if config.open_multicast:
data = append_data_to_info_data(
data,
cate,
name,
multicast_result.get(formatName, []),
get_channel_results_by_name(name, multicast_result),
)
print(
name,
"multicast num:",
len(multicast_result.get(formatName, [])),
len(get_channel_results_by_name(name, multicast_result)),
)
if config.open_online_search:
data = append_data_to_info_data(
data,
cate,
name,
online_search_result.get(formatName, []),
get_channel_results_by_name(name, online_search_result),
)
print(
name,
"online search num:",
len(online_search_result.get(formatName, [])),
len(get_channel_results_by_name(name, online_search_result)),
)
total_channel_data_len = len(data.get(cate, {}).get(name, []))
if total_channel_data_len == 0:
Expand Down Expand Up @@ -287,7 +334,7 @@ async def sort_channel_list(semaphore, cate, name, info_list, callback):
resolution,
), response_time in sorted_data:
logging.info(
f"Name: {name}, URL: {url}, Date: {date}, Resolution: {resolution}, Response Time: {response_time}ms"
f"Name: {name}, URL: {url}, Date: {date}, Resolution: {resolution}, Response Time: {response_time} ms"
)
data = [
(url, date, resolution)
Expand Down
4 changes: 1 addition & 3 deletions utils/speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ async def sort_urls_by_speed_and_resolution(infoList):
Sort by speed and resolution
"""
response_times = await gather(*(get_speed(url) for url, _, _ in infoList))
valid_responses = [
(info, rt) for info, rt in zip(infoList, response_times) if rt != float("inf")
]
valid_responses = [(info, rt) for info, rt in zip(infoList, response_times)]

def extract_resolution(resolution_str):
numbers = re.findall(r"\d+x\d+", resolution_str)
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "1.3.1"
"version": "1.3.2"
}

0 comments on commit 13efd11

Please sign in to comment.