mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-07 12:05:35 +00:00
Fix psutil for termux
This commit is contained in:
parent
590533a141
commit
4d48f5fa92
@ -24,11 +24,11 @@ def search():
|
|||||||
# Select title from list
|
# Select title from list
|
||||||
select_title = run_get_select_title()
|
select_title = run_get_select_title()
|
||||||
|
|
||||||
if select_title.type == 'TV':
|
if select_title.type == 'Movie':
|
||||||
download_series(select_title)
|
download_film(select_title)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
download_film(select_title)
|
download_series(select_title)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
console.print(f"\n[red]Nothing matching was found for[white]: [purple]{string_to_search}")
|
console.print(f"\n[red]Nothing matching was found for[white]: [purple]{string_to_search}")
|
||||||
|
@ -277,12 +277,7 @@ class M3U8_Segments:
|
|||||||
if response_size == 0:
|
if response_size == 0:
|
||||||
response_size = int(len(response.content))
|
response_size = int(len(response.content))
|
||||||
|
|
||||||
# Check length segments
|
# Update progress bar with custom Class
|
||||||
"""
|
|
||||||
expected_length = int(response.headers.get('Content-Length', 0))
|
|
||||||
if not (expected_length != 0 and len(response.content) == expected_length):
|
|
||||||
console.print(f"Incomplete download for '{ts_url}' (received {len(response.content)} bytes, expected {expected_length}).")
|
|
||||||
"""
|
|
||||||
self.class_ts_estimator.update_progress_bar(response_size, duration, progress_bar)
|
self.class_ts_estimator.update_progress_bar(response_size, duration, progress_bar)
|
||||||
|
|
||||||
# Decrypt the segment content if decryption is needed
|
# Decrypt the segment content if decryption is needed
|
||||||
|
@ -25,16 +25,16 @@ 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.
|
Initialize the M3U8_Ts_Estimator object.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
- total_segments (int): Len of total segments to download
|
- total_segments (int): Length of total segments to download.
|
||||||
"""
|
"""
|
||||||
self.ts_file_sizes = []
|
self.ts_file_sizes = []
|
||||||
self.now_downloaded_size = 0
|
self.now_downloaded_size = 0
|
||||||
self.total_segments = total_segments
|
self.total_segments = total_segments
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
self.speed = 0
|
self.speed = {"upload": "N/A", "download": "N/A"} # Default to N/A
|
||||||
self.speed_thread = threading.Thread(target=self.capture_speed)
|
self.speed_thread = threading.Thread(target=self.capture_speed)
|
||||||
self.speed_thread.daemon = True
|
self.speed_thread.daemon = True
|
||||||
self.speed_thread.start()
|
self.speed_thread.start()
|
||||||
@ -58,37 +58,41 @@ class M3U8_Ts_Estimator:
|
|||||||
|
|
||||||
def capture_speed(self, interval: float = 1):
|
def capture_speed(self, interval: float = 1):
|
||||||
"""
|
"""
|
||||||
Capture the internet speed periodically and store the values in a deque.
|
Capture the internet speed periodically and store the values.
|
||||||
"""
|
"""
|
||||||
def get_network_io():
|
def get_network_io():
|
||||||
io_counters = psutil.net_io_counters()
|
"""Get network I/O counters, handle missing psutil gracefully."""
|
||||||
return io_counters
|
try:
|
||||||
|
io_counters = psutil.net_io_counters()
|
||||||
# Get proc id
|
return io_counters
|
||||||
pid = os.getpid()
|
except Exception as e:
|
||||||
|
logging.warning(f"Unable to access network I/O counters: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
# Get value
|
|
||||||
old_value = get_network_io()
|
old_value = get_network_io()
|
||||||
|
if old_value is None: # If psutil is not available, continue with default values
|
||||||
|
time.sleep(interval)
|
||||||
|
continue
|
||||||
|
|
||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
new_value = get_network_io()
|
new_value = get_network_io()
|
||||||
|
if new_value is None: # Handle again if psutil fails in the next call
|
||||||
|
time.sleep(interval)
|
||||||
|
continue
|
||||||
|
|
||||||
with self.lock:
|
with self.lock:
|
||||||
upload_speed = (new_value.bytes_sent - old_value.bytes_sent) / interval
|
upload_speed = (new_value.bytes_sent - old_value.bytes_sent) / interval
|
||||||
download_speed = (new_value.bytes_recv - old_value.bytes_recv) / interval
|
download_speed = (new_value.bytes_recv - old_value.bytes_recv) / interval
|
||||||
|
|
||||||
self.speed = ({
|
self.speed = {
|
||||||
"upload": format_transfer_speed(upload_speed),
|
"upload": format_transfer_speed(upload_speed),
|
||||||
"download": format_transfer_speed(download_speed)
|
"download": format_transfer_speed(download_speed)
|
||||||
})
|
}
|
||||||
|
|
||||||
old_value = new_value
|
|
||||||
|
|
||||||
|
|
||||||
def get_average_speed(self) -> float:
|
def get_average_speed(self) -> float:
|
||||||
"""
|
"""
|
||||||
Calculate the average internet speed from the values in the deque.
|
Calculate the average internet speed.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: The average internet speed in Mbps.
|
float: The average internet speed in Mbps.
|
||||||
@ -135,7 +139,7 @@ class M3U8_Ts_Estimator:
|
|||||||
Updates the progress bar with information about the TS segment download.
|
Updates the progress bar with information about the TS segment download.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
total_downloaded (int): The len of the content of the downloaded TS segment.
|
total_downloaded (int): The length of the content of the downloaded TS segment.
|
||||||
duration (float): The duration of the segment download in seconds.
|
duration (float): The duration of the segment download in seconds.
|
||||||
progress_counter (tqdm): The tqdm object representing the progress bar.
|
progress_counter (tqdm): The tqdm object representing the progress bar.
|
||||||
"""
|
"""
|
||||||
@ -166,3 +170,4 @@ class M3U8_Ts_Estimator:
|
|||||||
f"{Colors.WHITE}[ {Colors.GREEN}{number_file_downloaded}{Colors.RED} {units_file_downloaded} "
|
f"{Colors.WHITE}[ {Colors.GREEN}{number_file_downloaded}{Colors.RED} {units_file_downloaded} "
|
||||||
f"{Colors.WHITE}| {Colors.CYAN}{average_internet_speed} {Colors.RED}{average_internet_unit}"
|
f"{Colors.WHITE}| {Colors.CYAN}{average_internet_speed} {Colors.RED}{average_internet_unit}"
|
||||||
)
|
)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user