Skip to content

Commit

Permalink
Merge pull request #95 from Guovin/dev
Browse files Browse the repository at this point in the history
Release: v1.0.9
  • Loading branch information
Guovin authored Apr 25, 2024
2 parents 2cbb073 + 485a1ab commit d52b8a4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志(Changelog)

## v1.0.9

### 2024/4/25

- 改进接口获取方法,增强处理多种失效场景(Improve the method of obtaining the interface, enhance the handling of various failure scenarios)

## v1.0.8

### 2024/4/24
Expand Down
23 changes: 14 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,22 @@ 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"]
pageUrl = await useAccessibleUrl()
for cate, channelObj in channelItems.items():
channelUrls = {}
channelObjKeys = channelObj.keys()
for name in channelObjKeys:
pbar.set_description(
f"Processing {name}, {total_channels - pbar.n} channels remaining"
)
self.driver.get(pageUrl)
search_box = self.driver.find_element(By.XPATH, '//input[@type="text"]')
search_box.clear()
search_box.send_keys(name)
submit_button = self.driver.find_element(
By.XPATH, '//input[@type="submit"]'
)
submit_button.click()
isFavorite = name in config.favorite_list
pageNum = (
config.favorite_page_num if isFavorite else config.default_page_num
Expand All @@ -81,13 +87,12 @@ async def visitPage(self, channelItems):
if pageUrl:
for page in range(1, pageNum + 1):
try:
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.result")
if page > 1:
page_link = self.driver.find_element(
By.XPATH,
f'//a[contains(@href, "={page}") and contains(@href, "{name}")]',
)
)
page_link.click()
soup = BeautifulSoup(self.driver.page_source, "html.parser")
results = (
soup.find_all("div", class_="result") if soup else []
Expand Down
6 changes: 3 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ async def useAccessibleUrl():
speed1 = await getSpeed(baseUrl1, 30)
speed2 = await getSpeed(baseUrl2, 30)
if speed1 == float("inf") and speed2 == float("inf"):
return {"url": None, "name": None}
return None
if speed1 < speed2:
return {"url": baseUrl1, "name": "s"}
return baseUrl1
else:
return {"url": baseUrl2, "name": "tv"}
return baseUrl2
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.8"
"version": "1.0.9"
}

0 comments on commit d52b8a4

Please sign in to comment.