Skip to content

Commit

Permalink
Merge pull request #84 from Guovin/dev
Browse files Browse the repository at this point in the history
Release: v1.0.7
  • Loading branch information
Guovin authored Apr 19, 2024
2 parents c5d103c + 64daf05 commit 08d381b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 36 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 更新日志(Changelog)

## v1.0.7

### 2024/4/19

- 增加双节点接口来源获取(Added dual-node interface source acquisition)
- 优化频道更新结果为空的情况(#81)(Optimized the situation where the channel update result is empty (#81))

## v1.0.6

### 2024/4/12
Expand Down
4 changes: 2 additions & 2 deletions README-EN.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TVBox Custom Channel Menu and Live Source Interface Auto-update
# Customization of TVBox TV Channel Menu and Automatic Verification and Update of Live Source Interfaces

Customize channel menus, automatically fetch and update the latest live source interfaces based on the template file, and generate usable channel interface files.
Customize channel menus and automatically obtain and update the latest live source interfaces based on template files, verify, and generate usable channel interface files.

[中文](./README.md) | English

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TVBox 电视频道菜单自定义与直播源接口自动更新
# TVBox 电视频道菜单自定义与直播源接口自动校验与更新

自定义频道菜单,根据模板文件的直播源接口,自动获取并更新最新的直播源接口,生成可用的频道接口文件
自定义频道菜单,根据模板文件的直播源接口,自动获取并更新最新的直播源接口,校验并生成可用的频道接口文件

[English](./README-EN.md) | 中文

Expand Down
29 changes: 15 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
checkByDomainBlacklist,
checkByURLKeywordsBlacklist,
filterUrlsByPatterns,
checkUrlAccessible,
useAccessibleUrl,
)
import logging
from logging.handlers import RotatingFileHandler
Expand Down Expand Up @@ -63,6 +63,9 @@ def __init__(self):
async def visitPage(self, channelItems):
total_channels = sum(len(channelObj) for _, channelObj in channelItems.items())
pbar = tqdm(total=total_channels)
pageObj = await useAccessibleUrl()
pageUrl = pageObj["url"]
pageName = pageObj["name"]
for cate, channelObj in channelItems.items():
channelUrls = {}
channelObjKeys = channelObj.keys()
Expand All @@ -74,25 +77,20 @@ async def visitPage(self, channelItems):
pageNum = (
config.favorite_page_num if isFavorite else config.default_page_num
)
baseUrl = "https://www.foodieguide.com/iptvsearch/"
infoList = []
urlAccessible = await checkUrlAccessible(baseUrl)
if urlAccessible:
if pageUrl:
for page in range(1, pageNum + 1):
try:
page_url = f"{baseUrl}?page={page}&s={name}"
page_url = f"{pageUrl}?page={page}&{pageName}={name}"
self.driver.get(page_url)
WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located(
(By.CSS_SELECTOR, "div.tables")
(By.CSS_SELECTOR, "div.result")
)
)
soup = BeautifulSoup(self.driver.page_source, "html.parser")
tables_div = soup.find("div", class_="tables")
results = (
tables_div.find_all("div", class_="result")
if tables_div
else []
soup.find_all("div", class_="result") if soup else []
)
for result in results:
try:
Expand All @@ -111,16 +109,19 @@ async def visitPage(self, channelItems):
print(f"Error on page {page}: {e}")
continue
try:
if infoList:
github_actions = os.environ.get("GITHUB_ACTIONS")
if not github_actions or (
total_channels <= 150 and github_actions == "true"
):
sorted_data = await compareSpeedAndResolution(infoList)
if sorted_data:
channelUrls[name] = (
getTotalUrls(sorted_data) or channelObj[name]
)
channelUrls[name] = getTotalUrls(sorted_data)
for (url, date, resolution), response_time in sorted_data:
logging.info(
f"Name: {name}, URL: {url}, Date: {date}, Resolution: {resolution}, Response Time: {response_time}ms"
)
else:
channelUrls[name] = filterUrlsByPatterns(channelObj[name])
else:
channelUrls[name] = filterUrlsByPatterns(channelObj[name])
except Exception as e:
Expand Down
30 changes: 13 additions & 17 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,8 @@ def getChannelItems():
channels = {}
current_category = ""
pattern = r"^(.*?),(?!#genre#)(.*?)$"
total_channels = 0
max_channels = 150

for line in lines:
if (
total_channels >= max_channels
and os.environ.get("GITHUB_ACTIONS") == "true"
):
break
line = line.strip()
if "#genre#" in line:
# This is a new channel, create a new key in the dictionary.
Expand All @@ -51,7 +44,6 @@ def getChannelItems():
if match:
if match.group(1) not in channels[current_category]:
channels[current_category][match.group(1)] = [match.group(2)]
total_channels += 1
else:
channels[current_category][match.group(1)].append(
match.group(2)
Expand Down Expand Up @@ -112,14 +104,14 @@ def getUrlInfo(result):
return url, date, resolution


async def getSpeed(url):
async def getSpeed(url, urlTimeout=5):
"""
Get the speed of the url
"""
async with aiohttp.ClientSession() as session:
start = time.time()
try:
async with session.get(url, timeout=5) as response:
async with session.get(url, timeout=urlTimeout) as response:
resStatus = response.status
except:
return float("inf")
Expand Down Expand Up @@ -267,13 +259,17 @@ def filterUrlsByPatterns(urls):
return urls


async def checkUrlAccessible(url):
async def useAccessibleUrl():
"""
Check if the url is accessible
"""
async with aiohttp.ClientSession() as session:
try:
async with session.get(url, timeout=30) as response:
return response.status == 200
except:
return False
baseUrl1 = "https://www.foodieguide.com/iptvsearch/"
baseUrl2 = "http://tonkiang.us/"
speed1 = await getSpeed(baseUrl1, 30)
speed2 = await getSpeed(baseUrl2, 30)
if speed1 == float("inf") and speed2 == float("inf"):
return {"url": None, "name": None}
if speed1 < speed2:
return {"url": baseUrl1, "name": "s"}
else:
return {"url": baseUrl2, "name": "tx"}
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "1.0.6"
"version": "1.0.7"
}

0 comments on commit 08d381b

Please sign in to comment.