Skip to content

Commit

Permalink
feat:speed and delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Guovin committed Dec 10, 2024
1 parent 822e47b commit b55fcb8
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 81 deletions.
7 changes: 4 additions & 3 deletions config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ online_search_page_num = 1
urls_limit = 10
open_keep_all = False
open_sort = True
sort_timeout = 5
sort_timeout = 10
open_ffmpeg = True
open_filter_resolution = True
min_resolution = 1920x1080
response_time_weight = 0.5
resolution_weight = 0.5
delay_weight = 0.25
speed_weight = 0.5
resolution_weight = 0.25
recent_days = 30
ipv_type = 全部
ipv_type_prefer = 自动
Expand Down
5 changes: 3 additions & 2 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
| open_m3u_result | True | 开启转换生成 m3u 文件类型结果链接,支持显示频道图标 |
| open_filter_resolution | True | 开启分辨率过滤,低于最小分辨率(min_resolution)的接口将会被过滤 |
| min_resolution | 1920x1080 | 接口最小分辨率,需要开启 open_filter_resolution 才能生效 |
| response_time_weight | 0.5 | 响应时间权重值(所有权重值总和应为 1) |
| resolution_weight | 0.5 | 分辨率权重值 (所有权重值总和应为 1) |
| speed_weight | 0.5 | 速率权重值(所有权重值总和应为 1) |
| delay_weight | 0.25 | 响应时间权重值(所有权重值总和应为 1) |
| resolution_weight | 0.25 | 分辨率权重值 (所有权重值总和应为 1) |
| recent_days | 30 | 获取最近时间范围内更新的接口(单位天),适当减小可避免出现匹配问题 |
| ipv_type | 全部 | 生成结果中接口的协议类型,可选值:ipv4、ipv6、全部、all |
| ipv_type_prefer | 自动 | 接口协议类型偏好,优先将该类型的接口排在结果前面,可选值:IPv4、IPv6、自动、auto |
Expand Down
5 changes: 3 additions & 2 deletions docs/config_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
| open_m3u_result | True | Enable the conversion to generate m3u file type result links, supporting the display of channel icons |
| open_filter_resolution | True | Enable resolution filtering, interfaces with resolution lower than the minimum resolution (min_resolution) will be filtered |
| min_resolution | 1920x1080 | Minimum interface resolution, requires enabling open_filter_resolution to take effect |
| response_time_weight | 0.5 | Response time weight value (the sum of all weight values should be 1) |
| resolution_weight | 0.5 | Resolution weight value (the sum of all weight values should be 1) |
| speed_weight | 0.5 | Speed weight value (the sum of all weight values should be 1) |
| delay_weight | 0.25 | Response time weight value (the sum of all weight values should be 1) |
| resolution_weight | 0.25 | Resolution weight value (the sum of all weight values should be 1) |
| recent_days | 30 | Retrieve interfaces updated within a recent time range (in days), reducing appropriately can avoid matching issues |
| ipv_type | all | The protocol type of interface in the generated result, optional values: ipv4, ipv6, all |
| ipv_type_prefer | auto | Interface protocol type preference, prioritize interfaces of this type in the results, optional values: IPv4, IPv6, auto |
Expand Down
33 changes: 17 additions & 16 deletions tkinter_ui/default.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import tkinter as tk
from utils.config import config
from tkinter import ttk
from tkinter import scrolledtext
from tkinter import filedialog
import os
from tkinter import scrolledtext
from tkinter import ttk

from utils.config import config


class DefaultUI:
Expand Down Expand Up @@ -292,20 +293,20 @@ def init_ui(self, root):
frame_default_sort_params_column2 = tk.Frame(frame_default_sort_params)
frame_default_sort_params_column2.pack(side=tk.RIGHT, fill=tk.Y)

self.response_time_weight_label = tk.Label(
self.delay_weight_label = tk.Label(
frame_default_sort_params_column1, text="响应时间权重:", width=12
)
self.response_time_weight_label.pack(side=tk.LEFT, padx=4, pady=8)
self.response_time_weight_scale = tk.Scale(
self.delay_weight_label.pack(side=tk.LEFT, padx=4, pady=8)
self.delay_weight_scale = tk.Scale(
frame_default_sort_params_column1,
from_=0,
to=1,
orient=tk.HORIZONTAL,
resolution=0.1,
command=self.update_response_time_weight,
command=self.update_delay_weight,
)
self.response_time_weight_scale.pack(side=tk.LEFT, padx=4, pady=8)
self.response_time_weight_scale.set(config.response_time_weight)
self.delay_weight_scale.pack(side=tk.LEFT, padx=4, pady=8)
self.delay_weight_scale.set(config.delay_weight)

self.resolution_weight_label = tk.Label(
frame_default_sort_params_column2, text="分辨率权重:", width=12
Expand Down Expand Up @@ -458,19 +459,19 @@ def update_min_resolution(self, event):
def update_urls_limit(self, event):
config.set("Settings", "urls_limit", self.urls_limit_entry.get())

def update_response_time_weight(self, event):
weight1 = self.response_time_weight_scale.get()
def update_delay_weight(self, event):
weight1 = self.delay_weight_scale.get()
weight2 = 1 - weight1
self.resolution_weight_scale.set(weight2)
config.set("Settings", "response_time_weight", str(weight1))
config.set("Settings", "delay_weight", str(weight1))
config.set("Settings", "resolution_weight", str(weight2))

def update_resolution_weight(self, event):
weight1 = self.resolution_weight_scale.get()
weight2 = 1 - weight1
self.response_time_weight_scale.set(weight2)
self.delay_weight_scale.set(weight2)
config.set("Settings", "resolution_weight", str(weight1))
config.set("Settings", "response_time_weight", str(weight2))
config.set("Settings", "delay_weight", str(weight2))

def update_open_update_time(self):
config.set("Settings", "open_update_time", str(self.open_update_time_var.get()))
Expand Down Expand Up @@ -518,7 +519,7 @@ def change_entry_state(self, state):
"open_filter_resolution_checkbutton",
"min_resolution_entry",
"urls_limit_entry",
"response_time_weight_scale",
"delay_weight_scale",
"resolution_weight_scale",
"open_update_time_checkbutton",
"open_url_info_checkbutton",
Expand Down
4 changes: 2 additions & 2 deletions tkinter_ui/tkinter_ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
import os
import sys

sys.path.append(os.path.dirname(sys.path[0]))
import tkinter as tk
Expand Down Expand Up @@ -55,7 +55,7 @@ def save_config(self):
"open_sort": self.default_ui.open_sort_var.get(),
"open_filter_resolution": self.default_ui.open_filter_resolution_var.get(),
"min_resolution": self.default_ui.min_resolution_entry.get(),
"response_time_weight": self.default_ui.response_time_weight_scale.get(),
"delay_weight": self.default_ui.delay_weight_scale.get(),
"resolution_weight": self.default_ui.resolution_weight_scale.get(),
"ipv_type": self.default_ui.ipv_type_combo.get(),
"url_keywords_blacklist": self.default_ui.url_keywords_blacklist_text.get(
Expand Down
10 changes: 6 additions & 4 deletions updates/proxy/request.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from asyncio import Semaphore
from concurrent.futures import ThreadPoolExecutor

from tqdm import tqdm
from tqdm.asyncio import tqdm_asyncio
from utils.config import config
from utils.speed import get_speed_requests
from concurrent.futures import ThreadPoolExecutor

from driver.utils import get_soup_driver
from requests_custom.utils import get_soup_requests, close_session
from utils.config import config
from utils.retry import retry_func
from utils.speed import get_delay_requests


def get_proxy_list(page_count=1):
Expand Down Expand Up @@ -71,7 +73,7 @@ async def get_proxy_list_with_test(base_url, proxy_list):

async def get_speed_task(url, timeout, proxy):
async with semaphore:
return await get_speed_requests(url, timeout=timeout, proxy=proxy)
return await get_delay_requests(url, timeout=timeout, proxy=proxy)

response_times = await tqdm_asyncio.gather(
*(get_speed_task(base_url, timeout=30, proxy=url) for url in proxy_list),
Expand Down
16 changes: 10 additions & 6 deletions utils/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import configparser
import os
import re
import shutil
import sys
import re


def resource_path(relative_path, persistent=False):
Expand Down Expand Up @@ -63,7 +63,7 @@ def ipv_type(self):
@property
def open_ipv6(self):
return (
"ipv6" in self.ipv_type or "all" in self.ipv_type or "全部" in self.ipv_type
"ipv6" in self.ipv_type or "all" in self.ipv_type or "全部" in self.ipv_type
)

@property
Expand Down Expand Up @@ -297,8 +297,12 @@ def subscribe_urls(self):
]

@property
def response_time_weight(self):
return self.config.getfloat("Settings", "response_time_weight", fallback=0.5)
def delay_weight(self):
return self.config.getfloat("Settings", "delay_weight", fallback=0.5)

@property
def speed_weight(self):
return self.config.getfloat("Settings", "speed_weight", fallback=0.5)

@property
def resolution_weight(self):
Expand Down Expand Up @@ -370,7 +374,7 @@ def copy(self):
for src_file in files_to_copy:
dest_path = os.path.join(dest_folder, os.path.basename(src_file))
if os.path.abspath(src_file) == os.path.abspath(
dest_path
dest_path
) or os.path.exists(dest_path):
continue
shutil.copy(src_file, dest_folder)
Expand Down
Loading

0 comments on commit b55fcb8

Please sign in to comment.