mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-07 20:15:24 +00:00
Fix speed download
This commit is contained in:
parent
86ecac7edd
commit
93a594beef
@ -15,6 +15,8 @@ from unidecode import unidecode
|
|||||||
from Src.Util.table import TVShowManager
|
from Src.Util.table import TVShowManager
|
||||||
from Src.Util.console import console
|
from Src.Util.console import console
|
||||||
from Src.Util._jsonConfig import config_manager
|
from Src.Util._jsonConfig import config_manager
|
||||||
|
from Src.Util.headers import get_headers
|
||||||
|
|
||||||
|
|
||||||
# Logic class
|
# Logic class
|
||||||
from .Core.Class.SearchType import MediaManager, MediaItem
|
from .Core.Class.SearchType import MediaManager, MediaItem
|
||||||
@ -44,7 +46,7 @@ def title_search(title_search: str) -> int:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Send request to search for titles
|
# Send request to search for titles
|
||||||
response = requests.get(f"https://{AD_SITE_NAME}.{AD_DOMAIN_NOW}/page/1/?story={unidecode(title_search.replace(' ', '+'))}&do=search&subaction=search&titleonly=3")
|
response = requests.get(f"https://{AD_SITE_NAME}.{AD_DOMAIN_NOW}/page/1/?story={unidecode(title_search.replace(' ', '+'))}&do=search&subaction=search&titleonly=3", headers={'user-agent': get_headers()})
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
# Create soup and find table
|
# Create soup and find table
|
||||||
|
@ -22,20 +22,13 @@ TQDM_USE_LARGE_BAR = config_manager.get_int('M3U8_DOWNLOAD', 'tqdm_use_large_bar
|
|||||||
|
|
||||||
class M3U8_Ts_Estimator:
|
class M3U8_Ts_Estimator:
|
||||||
def __init__(self, total_segments: int):
|
def __init__(self, total_segments: int):
|
||||||
"""
|
|
||||||
Initialize the TSFileSizeCalculator object.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
- workers (int): The number of workers using with ThreadPool.
|
|
||||||
- total_segments (int): Len of total segments to download
|
|
||||||
"""
|
|
||||||
self.ts_file_sizes = []
|
self.ts_file_sizes = []
|
||||||
self.now_downloaded_size = 0
|
self.now_downloaded_size = 0
|
||||||
self.average_over = 3
|
self.average_over = 5
|
||||||
self.list_speeds = deque(maxlen=self.average_over)
|
self.list_speeds = deque(maxlen=self.average_over)
|
||||||
self.smoothed_speeds = []
|
|
||||||
self.total_segments = total_segments
|
self.total_segments = total_segments
|
||||||
self.lock = threading.Lock()
|
self.last_segment_duration = 1
|
||||||
|
self.last_segment_size = 0
|
||||||
|
|
||||||
def add_ts_file(self, size: int, size_download: int, duration: float):
|
def add_ts_file(self, size: int, size_download: int, duration: float):
|
||||||
"""
|
"""
|
||||||
@ -50,26 +43,23 @@ class M3U8_Ts_Estimator:
|
|||||||
logging.error("Invalid input values: size=%d, size_download=%d, duration=%f", size, size_download, duration)
|
logging.error("Invalid input values: size=%d, size_download=%d, duration=%f", size, size_download, duration)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Calculate speed outside of the lock
|
# Calibrazione dinamica del tempo
|
||||||
|
self.last_segment_duration = duration
|
||||||
|
|
||||||
|
# Considerazione della variazione di dimensione del segmento
|
||||||
|
self.last_segment_size = size_download
|
||||||
|
|
||||||
|
# Calcolo velocità
|
||||||
try:
|
try:
|
||||||
speed_mbps = (size_download * 8) / (duration * 1_000_000)
|
speed_mbps = (size_download * 8) / (duration * 1024 * 1024)
|
||||||
|
|
||||||
except ZeroDivisionError as e:
|
except ZeroDivisionError as e:
|
||||||
logging.error("Division by zero error while calculating speed: %s", e)
|
logging.error("Division by zero error while calculating speed: %s", e)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Only update shared data within the lock
|
self.ts_file_sizes.append(size)
|
||||||
with self.lock:
|
self.now_downloaded_size += size_download
|
||||||
self.ts_file_sizes.append(size)
|
self.list_speeds.append(speed_mbps)
|
||||||
self.now_downloaded_size += size_download
|
|
||||||
self.list_speeds.append(speed_mbps)
|
|
||||||
|
|
||||||
# Calculate moving average
|
|
||||||
smoothed_speed = sum(self.list_speeds) / len(self.list_speeds)
|
|
||||||
self.smoothed_speeds.append(smoothed_speed)
|
|
||||||
|
|
||||||
# Update smooth speeds
|
|
||||||
if len(self.smoothed_speeds) > self.average_over:
|
|
||||||
self.smoothed_speeds.pop(0)
|
|
||||||
|
|
||||||
def calculate_total_size(self) -> str:
|
def calculate_total_size(self) -> str:
|
||||||
"""
|
"""
|
||||||
@ -103,7 +93,13 @@ class M3U8_Ts_Estimator:
|
|||||||
Returns:
|
Returns:
|
||||||
float: The average speed in megabytes per second (MB/s).
|
float: The average speed in megabytes per second (MB/s).
|
||||||
"""
|
"""
|
||||||
return ((sum(self.smoothed_speeds) / len(self.smoothed_speeds)) / 8 ) * 10 # MB/s
|
|
||||||
|
# Smooth the speeds for better accuracy using the window defined by average_over
|
||||||
|
smoothed_speed = sum(self.list_speeds) / min(len(self.list_speeds), self.average_over)
|
||||||
|
predicted_speed = smoothed_speed * (self.last_segment_size / (1024 * 1024)) / self.last_segment_duration
|
||||||
|
|
||||||
|
# Convert to mb/s
|
||||||
|
return predicted_speed / 8
|
||||||
|
|
||||||
def get_downloaded_size(self) -> str:
|
def get_downloaded_size(self) -> str:
|
||||||
"""
|
"""
|
||||||
|
@ -45,6 +45,6 @@
|
|||||||
"SITE": {
|
"SITE": {
|
||||||
"streamingcommunity": "foo",
|
"streamingcommunity": "foo",
|
||||||
"animeunity": "to",
|
"animeunity": "to",
|
||||||
"altadefinizione": "food"
|
"altadefinizione": "vodka"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user