Skip to content

Commit

Permalink
Merge pull request #154 from Guovin/dev
Browse files Browse the repository at this point in the history
Release:v1.2.3
  • Loading branch information
Guovin authored Jun 17, 2024
2 parents 1d8b9a6 + 091a454 commit 8b827be
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
build
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 更新日志(Changelog)

## v1.2.3

### 2024/6/17

- 新增请求重连重试功能(Added request reconnection retry function)
- 修复个别系统环境文件路径报错问题(Fixed some system environment file path errors)

## v1.2.2

### 2024/6/16
Expand Down
6 changes: 3 additions & 3 deletions tkinter_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TkinterUI:
def __init__(self, root):
self.root = root
self.root.title("直播源接口更新工具")
self.version = "v1.0.2"
self.version = "v1.2.3"
self.update_source = UpdateSource()
self.update_running = False
self.config_entrys = [
Expand Down Expand Up @@ -59,7 +59,7 @@ def select_source_file(self):
if filepath:
self.source_file_entry.delete(0, tk.END)
self.source_file_entry.insert(0, filepath)
config.source_file = f'"{filepath}"'
config.source_file = filepath

def select_final_file(self):
filepath = filedialog.askopenfilename(
Expand All @@ -68,7 +68,7 @@ def select_final_file(self):
if filepath:
self.final_file_entry.delete(0, tk.END)
self.final_file_entry.insert(0, filepath)
config.final_file = f'"{filepath}"'
config.final_file = filepath

def update_open_subscribe(self):
config.open_subscribe = self.open_subscribe_var.get()
Expand Down
78 changes: 60 additions & 18 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,31 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium_stealth import stealth
import concurrent.futures
import sys
import importlib.util

timeout = 15
max_retries = 3


def retry_func(func, retries=max_retries + 1, name=""):
"""
Retry the function
"""
for i in range(retries):
try:
return func()
except Exception as e:
count = retries - 1
if name and i < count:
print(f"Failed to connect to the {name}. Retrying {i+1}...")
if i == count:
break
else:
continue


def resource_path(relative_path, persistent=False):
"""
Expand Down Expand Up @@ -83,6 +104,15 @@ def setup_driver():
options.add_argument("--allow-running-insecure-content")
options.add_argument("blink-settings=imagesEnabled=false")
driver = webdriver.Chrome(options=options)
stealth(
driver,
languages=["en-US", "en"],
vendor="Google Inc.",
platform="Win32",
webgl_vendor="Intel Inc.",
renderer="Intel Iris OpenGL Engine",
fix_hairline=True,
)
return driver


Expand Down Expand Up @@ -192,12 +222,16 @@ async def get_channels_by_subscribe_urls(callback):

def process_subscribe_channels(subscribe_url):
try:
response = None
try:
response = requests.get(subscribe_url, timeout=30)
response = retry_func(
lambda: requests.get(subscribe_url, timeout=timeout),
name=subscribe_url,
)
except requests.exceptions.Timeout:
print(f"Timeout on {subscribe_url}")
content = response.text
if content:
if response:
content = response.text
lines = content.split("\n")
for line in lines:
if re.match(pattern, line) is not None:
Expand Down Expand Up @@ -255,17 +289,21 @@ async def get_channels_by_online_search(names, callback):

def process_channel_by_online_search(name):
driver = setup_driver()
wait = WebDriverWait(driver, 10)
wait = WebDriverWait(driver, timeout)
info_list = []
try:
driver.get(pageUrl)
search_box = wait.until(
EC.presence_of_element_located((By.XPATH, '//input[@type="text"]'))
retry_func(lambda: driver.get(pageUrl), name="online search")
search_box = retry_func(
lambda: wait.until(
EC.presence_of_element_located((By.XPATH, '//input[@type="text"]'))
)
)
search_box.clear()
search_box.send_keys(name)
submit_button = wait.until(
EC.element_to_be_clickable((By.XPATH, '//input[@type="submit"]'))
submit_button = retry_func(
lambda: wait.until(
EC.element_to_be_clickable((By.XPATH, '//input[@type="submit"]'))
)
)
driver.execute_script("arguments[0].click();", submit_button)
isFavorite = name in config.favorite_list
Expand All @@ -275,11 +313,13 @@ def process_channel_by_online_search(name):
for page in range(1, pageNum + 1):
try:
if page > 1:
page_link = wait.until(
EC.element_to_be_clickable(
(
By.XPATH,
f'//a[contains(@href, "={page}") and contains(@href, "{name}")]',
page_link = retry_func(
lambda: wait.until(
EC.element_to_be_clickable(
(
By.XPATH,
f'//a[contains(@href, "={page}") and contains(@href, "{name}")]',
)
)
)
)
Expand Down Expand Up @@ -418,7 +458,7 @@ def get_results_from_soup(soup, name):
return results


async def get_speed(url, urlTimeout=5):
async def get_speed(url, urlTimeout=10):
"""
Get the speed of the url
"""
Expand Down Expand Up @@ -642,14 +682,16 @@ async def get_channels_by_fofa(callback):
def process_fofa_channels(fofa_url, pbar, fofa_urls_len, callback):
driver = setup_driver()
try:
driver.get(fofa_url)
retry_func(lambda: driver.get(fofa_url), name=fofa_url)
fofa_source = re.sub(r"<!--.*?-->", "", driver.page_source, flags=re.DOTALL)
urls = set(re.findall(r"https?://[\w\.-]+:\d+", fofa_source))
channels = {}
for url in urls:
try:
response = requests.get(
url + "/iptv/live/1000.json?key=txiptv", timeout=2
final_url = url + "/iptv/live/1000.json?key=txiptv"
response = retry_func(
lambda: requests.get(final_url, timeout=timeout),
name=final_url,
)
try:
json_data = response.json()
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.2.2"
"version": "1.2.3"
}

0 comments on commit 8b827be

Please sign in to comment.