StreamingCommunity 2.3.0__py3-none-any.whl → 2.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of StreamingCommunity might be problematic. Click here for more details.
- StreamingCommunity/run.py +61 -7
- {StreamingCommunity-2.3.0.dist-info → StreamingCommunity-2.5.0.dist-info}/METADATA +88 -18
- StreamingCommunity-2.5.0.dist-info/RECORD +8 -0
- StreamingCommunity/Api/Player/Helper/Vixcloud/js_parser.py +0 -143
- StreamingCommunity/Api/Player/Helper/Vixcloud/util.py +0 -136
- StreamingCommunity/Api/Player/ddl.py +0 -89
- StreamingCommunity/Api/Player/maxstream.py +0 -151
- StreamingCommunity/Api/Player/supervideo.py +0 -194
- StreamingCommunity/Api/Player/vixcloud.py +0 -273
- StreamingCommunity/Api/Site/1337xx/__init__.py +0 -51
- StreamingCommunity/Api/Site/1337xx/costant.py +0 -15
- StreamingCommunity/Api/Site/1337xx/site.py +0 -89
- StreamingCommunity/Api/Site/1337xx/title.py +0 -66
- StreamingCommunity/Api/Site/altadefinizione/__init__.py +0 -51
- StreamingCommunity/Api/Site/altadefinizione/costant.py +0 -19
- StreamingCommunity/Api/Site/altadefinizione/film.py +0 -74
- StreamingCommunity/Api/Site/altadefinizione/site.py +0 -95
- StreamingCommunity/Api/Site/animeunity/__init__.py +0 -51
- StreamingCommunity/Api/Site/animeunity/costant.py +0 -19
- StreamingCommunity/Api/Site/animeunity/film_serie.py +0 -135
- StreamingCommunity/Api/Site/animeunity/site.py +0 -175
- StreamingCommunity/Api/Site/animeunity/util/ScrapeSerie.py +0 -97
- StreamingCommunity/Api/Site/cb01new/__init__.py +0 -52
- StreamingCommunity/Api/Site/cb01new/costant.py +0 -19
- StreamingCommunity/Api/Site/cb01new/film.py +0 -73
- StreamingCommunity/Api/Site/cb01new/site.py +0 -83
- StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py +0 -56
- StreamingCommunity/Api/Site/ddlstreamitaly/costant.py +0 -20
- StreamingCommunity/Api/Site/ddlstreamitaly/series.py +0 -146
- StreamingCommunity/Api/Site/ddlstreamitaly/site.py +0 -99
- StreamingCommunity/Api/Site/ddlstreamitaly/util/ScrapeSerie.py +0 -85
- StreamingCommunity/Api/Site/guardaserie/__init__.py +0 -51
- StreamingCommunity/Api/Site/guardaserie/costant.py +0 -19
- StreamingCommunity/Api/Site/guardaserie/series.py +0 -198
- StreamingCommunity/Api/Site/guardaserie/site.py +0 -90
- StreamingCommunity/Api/Site/guardaserie/util/ScrapeSerie.py +0 -110
- StreamingCommunity/Api/Site/ilcorsaronero/__init__.py +0 -52
- StreamingCommunity/Api/Site/ilcorsaronero/costant.py +0 -19
- StreamingCommunity/Api/Site/ilcorsaronero/site.py +0 -72
- StreamingCommunity/Api/Site/ilcorsaronero/title.py +0 -46
- StreamingCommunity/Api/Site/ilcorsaronero/util/ilCorsarScraper.py +0 -149
- StreamingCommunity/Api/Site/mostraguarda/__init__.py +0 -49
- StreamingCommunity/Api/Site/mostraguarda/costant.py +0 -19
- StreamingCommunity/Api/Site/mostraguarda/film.py +0 -101
- StreamingCommunity/Api/Site/streamingcommunity/__init__.py +0 -56
- StreamingCommunity/Api/Site/streamingcommunity/costant.py +0 -19
- StreamingCommunity/Api/Site/streamingcommunity/film.py +0 -75
- StreamingCommunity/Api/Site/streamingcommunity/series.py +0 -206
- StreamingCommunity/Api/Site/streamingcommunity/site.py +0 -139
- StreamingCommunity/Api/Site/streamingcommunity/util/ScrapeSerie.py +0 -123
- StreamingCommunity/Api/Template/Class/SearchType.py +0 -101
- StreamingCommunity/Api/Template/Util/__init__.py +0 -5
- StreamingCommunity/Api/Template/Util/get_domain.py +0 -137
- StreamingCommunity/Api/Template/Util/manage_ep.py +0 -179
- StreamingCommunity/Api/Template/Util/recall_search.py +0 -37
- StreamingCommunity/Api/Template/__init__.py +0 -3
- StreamingCommunity/Api/Template/site.py +0 -87
- StreamingCommunity/Lib/Downloader/HLS/downloader.py +0 -955
- StreamingCommunity/Lib/Downloader/HLS/proxyes.py +0 -110
- StreamingCommunity/Lib/Downloader/HLS/segments.py +0 -564
- StreamingCommunity/Lib/Downloader/MP4/downloader.py +0 -155
- StreamingCommunity/Lib/Downloader/TOR/downloader.py +0 -296
- StreamingCommunity/Lib/Downloader/__init__.py +0 -5
- StreamingCommunity/Lib/FFmpeg/__init__.py +0 -4
- StreamingCommunity/Lib/FFmpeg/capture.py +0 -170
- StreamingCommunity/Lib/FFmpeg/command.py +0 -296
- StreamingCommunity/Lib/FFmpeg/util.py +0 -249
- StreamingCommunity/Lib/M3U8/__init__.py +0 -6
- StreamingCommunity/Lib/M3U8/decryptor.py +0 -164
- StreamingCommunity/Lib/M3U8/estimator.py +0 -229
- StreamingCommunity/Lib/M3U8/parser.py +0 -666
- StreamingCommunity/Lib/M3U8/url_fixer.py +0 -52
- StreamingCommunity/Lib/TMBD/__init__.py +0 -2
- StreamingCommunity/Lib/TMBD/obj_tmbd.py +0 -39
- StreamingCommunity/Lib/TMBD/tmdb.py +0 -346
- StreamingCommunity/Upload/update.py +0 -67
- StreamingCommunity/Upload/version.py +0 -5
- StreamingCommunity/Util/_jsonConfig.py +0 -204
- StreamingCommunity/Util/call_stack.py +0 -42
- StreamingCommunity/Util/color.py +0 -20
- StreamingCommunity/Util/console.py +0 -12
- StreamingCommunity/Util/ffmpeg_installer.py +0 -351
- StreamingCommunity/Util/headers.py +0 -147
- StreamingCommunity/Util/logger.py +0 -53
- StreamingCommunity/Util/message.py +0 -64
- StreamingCommunity/Util/os.py +0 -545
- StreamingCommunity/Util/table.py +0 -229
- StreamingCommunity-2.3.0.dist-info/RECORD +0 -92
- {StreamingCommunity-2.3.0.dist-info → StreamingCommunity-2.5.0.dist-info}/LICENSE +0 -0
- {StreamingCommunity-2.3.0.dist-info → StreamingCommunity-2.5.0.dist-info}/WHEEL +0 -0
- {StreamingCommunity-2.3.0.dist-info → StreamingCommunity-2.5.0.dist-info}/entry_points.txt +0 -0
- {StreamingCommunity-2.3.0.dist-info → StreamingCommunity-2.5.0.dist-info}/top_level.txt +0 -0
StreamingCommunity/Util/os.py
DELETED
|
@@ -1,545 +0,0 @@
|
|
|
1
|
-
# 24.01.24
|
|
2
|
-
|
|
3
|
-
import io
|
|
4
|
-
import os
|
|
5
|
-
import sys
|
|
6
|
-
import time
|
|
7
|
-
import shutil
|
|
8
|
-
import hashlib
|
|
9
|
-
import logging
|
|
10
|
-
import platform
|
|
11
|
-
import unidecode
|
|
12
|
-
import subprocess
|
|
13
|
-
import contextlib
|
|
14
|
-
import pathvalidate
|
|
15
|
-
import urllib.request
|
|
16
|
-
import importlib.metadata
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# External library
|
|
20
|
-
import httpx
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
# Internal utilities
|
|
24
|
-
from .ffmpeg_installer import check_ffmpeg
|
|
25
|
-
from StreamingCommunity.Util.console import console, msg
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
# Variable
|
|
29
|
-
OS_CONFIGURATIONS = {
|
|
30
|
-
'windows': {
|
|
31
|
-
'max_length': 255,
|
|
32
|
-
'invalid_chars': '<>:"/\\|?*',
|
|
33
|
-
'reserved_names': [
|
|
34
|
-
"CON", "PRN", "AUX", "NUL",
|
|
35
|
-
"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
|
|
36
|
-
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"
|
|
37
|
-
],
|
|
38
|
-
'max_path': 255
|
|
39
|
-
},
|
|
40
|
-
'darwin': {
|
|
41
|
-
'max_length': 4096,
|
|
42
|
-
'invalid_chars': '/:',
|
|
43
|
-
'reserved_names': [],
|
|
44
|
-
'hidden_file_restriction': True
|
|
45
|
-
},
|
|
46
|
-
'linux': {
|
|
47
|
-
'max_length': 4096,
|
|
48
|
-
'invalid_chars': '/\0',
|
|
49
|
-
'reserved_names': []
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
class OsManager:
|
|
56
|
-
def __init__(self):
|
|
57
|
-
self.system = self._detect_system()
|
|
58
|
-
self.config = OS_CONFIGURATIONS.get(self.system, {})
|
|
59
|
-
|
|
60
|
-
def _detect_system(self) -> str:
|
|
61
|
-
"""Detect and normalize operating system name."""
|
|
62
|
-
system = platform.system().lower()
|
|
63
|
-
|
|
64
|
-
if system in OS_CONFIGURATIONS:
|
|
65
|
-
return system
|
|
66
|
-
|
|
67
|
-
raise ValueError(f"Unsupported operating system: {system}")
|
|
68
|
-
|
|
69
|
-
def _normalize_windows_path(self, path: str) -> str:
|
|
70
|
-
"""
|
|
71
|
-
Normalize Windows paths to handle drive letters correctly.
|
|
72
|
-
|
|
73
|
-
Args:
|
|
74
|
-
path (str): Original path that might contain a drive letter.
|
|
75
|
-
|
|
76
|
-
Returns:
|
|
77
|
-
str: Properly normalized absolute path.
|
|
78
|
-
"""
|
|
79
|
-
if self.system != 'windows':
|
|
80
|
-
return path
|
|
81
|
-
|
|
82
|
-
# Check if path starts with a drive letter
|
|
83
|
-
if len(path) >= 2 and path[1] == ':':
|
|
84
|
-
drive = path[0:2]
|
|
85
|
-
rest = path[2:].lstrip(os.sep)
|
|
86
|
-
# Ensure proper absolute path format
|
|
87
|
-
return os.path.join(drive + os.sep, rest)
|
|
88
|
-
return path
|
|
89
|
-
|
|
90
|
-
def _process_filename(self, filename: str) -> str:
|
|
91
|
-
"""
|
|
92
|
-
Comprehensively process filename with cross-platform considerations.
|
|
93
|
-
|
|
94
|
-
Args:
|
|
95
|
-
filename (str): Original filename.
|
|
96
|
-
|
|
97
|
-
Returns:
|
|
98
|
-
str: Processed filename.
|
|
99
|
-
"""
|
|
100
|
-
name, ext = os.path.splitext(filename)
|
|
101
|
-
|
|
102
|
-
# Handle length restrictions
|
|
103
|
-
if len(name) > self.config['max_length']:
|
|
104
|
-
name = self._truncate_filename(name)
|
|
105
|
-
|
|
106
|
-
# Reconstruct filename
|
|
107
|
-
processed_filename = name + ext
|
|
108
|
-
|
|
109
|
-
return processed_filename
|
|
110
|
-
|
|
111
|
-
def _truncate_filename(self, name: str) -> str:
|
|
112
|
-
"""
|
|
113
|
-
Truncate filename based on OS-specific rules.
|
|
114
|
-
|
|
115
|
-
Args:
|
|
116
|
-
name (str): Original filename.
|
|
117
|
-
|
|
118
|
-
Returns:
|
|
119
|
-
str: Truncated filename.
|
|
120
|
-
"""
|
|
121
|
-
logging.info("_truncate_filename: ", name)
|
|
122
|
-
|
|
123
|
-
if self.system == 'windows':
|
|
124
|
-
return name[:self.config['max_length'] - 3] + '___'
|
|
125
|
-
elif self.system == 'darwin':
|
|
126
|
-
return name[:self.config['max_length']]
|
|
127
|
-
elif self.system == 'linux':
|
|
128
|
-
return name[:self.config['max_length'] - 2] + '___'
|
|
129
|
-
|
|
130
|
-
def get_sanitize_file(self, filename: str) -> str:
|
|
131
|
-
"""
|
|
132
|
-
Sanitize filename using pathvalidate with unidecode.
|
|
133
|
-
|
|
134
|
-
Args:
|
|
135
|
-
filename (str): Original filename.
|
|
136
|
-
|
|
137
|
-
Returns:
|
|
138
|
-
str: Sanitized filename.
|
|
139
|
-
"""
|
|
140
|
-
|
|
141
|
-
# Decode unicode characters and sanitize
|
|
142
|
-
decoded_filename = unidecode.unidecode(filename)
|
|
143
|
-
sanitized_filename = pathvalidate.sanitize_filename(decoded_filename)
|
|
144
|
-
|
|
145
|
-
# Truncate if necessary based on OS configuration
|
|
146
|
-
name, ext = os.path.splitext(sanitized_filename)
|
|
147
|
-
if len(name) > self.config['max_length']:
|
|
148
|
-
name = self._truncate_filename(name)
|
|
149
|
-
|
|
150
|
-
result = name + ext
|
|
151
|
-
return result
|
|
152
|
-
|
|
153
|
-
def get_sanitize_path(self, path: str) -> str:
|
|
154
|
-
"""
|
|
155
|
-
Sanitize folder path using pathvalidate with unidecode.
|
|
156
|
-
|
|
157
|
-
Args:
|
|
158
|
-
path (str): Original folder path.
|
|
159
|
-
|
|
160
|
-
Returns:
|
|
161
|
-
str: Sanitized folder path.
|
|
162
|
-
"""
|
|
163
|
-
|
|
164
|
-
# Normalize path for Windows drive letters first
|
|
165
|
-
path = self._normalize_windows_path(path)
|
|
166
|
-
|
|
167
|
-
# Decode unicode characters and sanitize
|
|
168
|
-
decoded_path = unidecode.unidecode(path)
|
|
169
|
-
sanitized_path = pathvalidate.sanitize_filepath(decoded_path)
|
|
170
|
-
|
|
171
|
-
# Split path and process each component
|
|
172
|
-
path_components = os.path.normpath(sanitized_path).split(os.sep)
|
|
173
|
-
|
|
174
|
-
# Handle Windows drive letter specially
|
|
175
|
-
if self.system == 'windows' and len(path_components[0]) == 2 and path_components[0][1] == ':':
|
|
176
|
-
drive = path_components.pop(0)
|
|
177
|
-
processed_components = [drive + os.sep]
|
|
178
|
-
|
|
179
|
-
else:
|
|
180
|
-
processed_components = []
|
|
181
|
-
|
|
182
|
-
# Process remaining components
|
|
183
|
-
for component in path_components:
|
|
184
|
-
if component: # Skip empty components
|
|
185
|
-
if len(component) > self.config['max_length']:
|
|
186
|
-
component = self._truncate_filename(component)
|
|
187
|
-
|
|
188
|
-
processed_components.append(component)
|
|
189
|
-
|
|
190
|
-
# Join with proper separator and normalize
|
|
191
|
-
result = os.path.normpath(os.path.join(*processed_components))
|
|
192
|
-
return result
|
|
193
|
-
|
|
194
|
-
def create_path(self, path: str, mode: int = 0o755) -> bool:
|
|
195
|
-
"""
|
|
196
|
-
Create directory path with specified permissions.
|
|
197
|
-
|
|
198
|
-
Args:
|
|
199
|
-
path (str): Path to create.
|
|
200
|
-
mode (int, optional): Directory permissions. Defaults to 0o755.
|
|
201
|
-
|
|
202
|
-
Returns:
|
|
203
|
-
bool: True if path created successfully, False otherwise.
|
|
204
|
-
"""
|
|
205
|
-
try:
|
|
206
|
-
sanitized_path = self.get_sanitize_path(path)
|
|
207
|
-
os.makedirs(sanitized_path, mode=mode, exist_ok=True)
|
|
208
|
-
return True
|
|
209
|
-
|
|
210
|
-
except Exception as e:
|
|
211
|
-
logging.error(f"Path creation error: {e}")
|
|
212
|
-
return False
|
|
213
|
-
|
|
214
|
-
def remove_folder(self, folder_path: str) -> bool:
|
|
215
|
-
"""
|
|
216
|
-
Safely remove a folder.
|
|
217
|
-
|
|
218
|
-
Args:
|
|
219
|
-
folder_path (str): Path of directory to remove.
|
|
220
|
-
|
|
221
|
-
Returns:
|
|
222
|
-
bool: Removal status.
|
|
223
|
-
"""
|
|
224
|
-
try:
|
|
225
|
-
shutil.rmtree(folder_path)
|
|
226
|
-
return True
|
|
227
|
-
|
|
228
|
-
except OSError as e:
|
|
229
|
-
logging.error(f"Folder removal error: {e}")
|
|
230
|
-
return False
|
|
231
|
-
|
|
232
|
-
def remove_files_except_one(self, folder_path: str, keep_file: str) -> None:
|
|
233
|
-
"""
|
|
234
|
-
Delete all files in a folder except for one specified file.
|
|
235
|
-
|
|
236
|
-
Parameters:
|
|
237
|
-
- folder_path (str): The path to the folder containing the files.
|
|
238
|
-
- keep_file (str): The filename to keep in the folder.
|
|
239
|
-
"""
|
|
240
|
-
|
|
241
|
-
try:
|
|
242
|
-
# List all files in the folder
|
|
243
|
-
files_in_folder = os.listdir(folder_path)
|
|
244
|
-
|
|
245
|
-
# Iterate over each file in the folder
|
|
246
|
-
for file_name in files_in_folder:
|
|
247
|
-
file_path = os.path.join(folder_path, file_name)
|
|
248
|
-
|
|
249
|
-
# Check if the file is not the one to keep and is a regular file
|
|
250
|
-
if file_name != keep_file and os.path.isfile(file_path):
|
|
251
|
-
os.remove(file_path) # Delete the file
|
|
252
|
-
|
|
253
|
-
except Exception as e:
|
|
254
|
-
logging.error(f"An error occurred: {e}")
|
|
255
|
-
raise
|
|
256
|
-
|
|
257
|
-
def check_file(self, file_path: str) -> bool:
|
|
258
|
-
"""
|
|
259
|
-
Check if a file exists at the given file path.
|
|
260
|
-
|
|
261
|
-
Parameters:
|
|
262
|
-
file_path (str): The path to the file.
|
|
263
|
-
|
|
264
|
-
Returns:
|
|
265
|
-
bool: True if the file exists, False otherwise.
|
|
266
|
-
"""
|
|
267
|
-
try:
|
|
268
|
-
logging.info(f"Check if file exists: {file_path}")
|
|
269
|
-
return os.path.exists(file_path)
|
|
270
|
-
|
|
271
|
-
except Exception as e:
|
|
272
|
-
logging.error(f"An error occurred while checking file existence: {e}")
|
|
273
|
-
return False
|
|
274
|
-
|
|
275
|
-
class InternManager():
|
|
276
|
-
|
|
277
|
-
def format_file_size(self, size_bytes: float) -> str:
|
|
278
|
-
"""
|
|
279
|
-
Formats a file size from bytes into a human-readable string representation.
|
|
280
|
-
|
|
281
|
-
Parameters:
|
|
282
|
-
size_bytes (float): Size in bytes to be formatted.
|
|
283
|
-
|
|
284
|
-
Returns:
|
|
285
|
-
str: Formatted string representing the file size with appropriate unit (B, KB, MB, GB, TB).
|
|
286
|
-
"""
|
|
287
|
-
if size_bytes <= 0:
|
|
288
|
-
return "0B"
|
|
289
|
-
|
|
290
|
-
units = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
291
|
-
unit_index = 0
|
|
292
|
-
|
|
293
|
-
while size_bytes >= 1024 and unit_index < len(units) - 1:
|
|
294
|
-
size_bytes /= 1024
|
|
295
|
-
unit_index += 1
|
|
296
|
-
|
|
297
|
-
return f"{size_bytes:.2f} {units[unit_index]}"
|
|
298
|
-
|
|
299
|
-
def format_transfer_speed(self, bytes: float) -> str:
|
|
300
|
-
"""
|
|
301
|
-
Formats a transfer speed from bytes per second into a human-readable string representation.
|
|
302
|
-
|
|
303
|
-
Parameters:
|
|
304
|
-
bytes (float): Speed in bytes per second to be formatted.
|
|
305
|
-
|
|
306
|
-
Returns:
|
|
307
|
-
str: Formatted string representing the transfer speed with appropriate unit (Bytes/s, KB/s, MB/s).
|
|
308
|
-
"""
|
|
309
|
-
if bytes < 1024:
|
|
310
|
-
return f"{bytes:.2f} Bytes/s"
|
|
311
|
-
elif bytes < 1024 * 1024:
|
|
312
|
-
return f"{bytes / 1024:.2f} KB/s"
|
|
313
|
-
else:
|
|
314
|
-
return f"{bytes / (1024 * 1024):.2f} MB/s"
|
|
315
|
-
|
|
316
|
-
@staticmethod
|
|
317
|
-
def check_internet():
|
|
318
|
-
while True:
|
|
319
|
-
try:
|
|
320
|
-
httpx.get("https://www.google.com", timeout=15)
|
|
321
|
-
break
|
|
322
|
-
|
|
323
|
-
except urllib.error.URLError:
|
|
324
|
-
console.log("[bold red]Internet is not available. Waiting...[/bold red]")
|
|
325
|
-
time.sleep(5)
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
class OsSummary:
|
|
329
|
-
|
|
330
|
-
def __init__(self):
|
|
331
|
-
self.ffmpeg_path = None
|
|
332
|
-
self.ffprobe_path = None
|
|
333
|
-
self.ffplay_path = None
|
|
334
|
-
|
|
335
|
-
def get_executable_version(self, command: list):
|
|
336
|
-
"""
|
|
337
|
-
Get the version of a given command-line executable.
|
|
338
|
-
|
|
339
|
-
Args:
|
|
340
|
-
command (list): The command to run, e.g., `['ffmpeg', '-version']`.
|
|
341
|
-
|
|
342
|
-
Returns:
|
|
343
|
-
str: The version string of the executable.
|
|
344
|
-
"""
|
|
345
|
-
try:
|
|
346
|
-
version_output = subprocess.check_output(command, stderr=subprocess.STDOUT).decode().split('\n')[0]
|
|
347
|
-
return version_output.split(" ")[2]
|
|
348
|
-
|
|
349
|
-
except (FileNotFoundError, subprocess.CalledProcessError):
|
|
350
|
-
console.print(f"{command[0]} not found", style="bold red")
|
|
351
|
-
sys.exit(0)
|
|
352
|
-
|
|
353
|
-
def check_ffmpeg_location(self, command: list) -> str:
|
|
354
|
-
"""
|
|
355
|
-
Check if a specific executable (ffmpeg or ffprobe) is located using the given command.
|
|
356
|
-
Returns the path of the executable or None if not found.
|
|
357
|
-
"""
|
|
358
|
-
try:
|
|
359
|
-
result = subprocess.check_output(command, text=True).strip()
|
|
360
|
-
return result.split('\n')[0] if result else None
|
|
361
|
-
|
|
362
|
-
except subprocess.CalledProcessError:
|
|
363
|
-
return None
|
|
364
|
-
|
|
365
|
-
def get_library_version(self, lib_name: str):
|
|
366
|
-
"""
|
|
367
|
-
Retrieve the version of a Python library.
|
|
368
|
-
|
|
369
|
-
Args:
|
|
370
|
-
lib_name (str): The name of the Python library.
|
|
371
|
-
|
|
372
|
-
Returns:
|
|
373
|
-
str: The library name followed by its version, or `-not installed` if not found.
|
|
374
|
-
"""
|
|
375
|
-
try:
|
|
376
|
-
version = importlib.metadata.version(lib_name)
|
|
377
|
-
return f"{lib_name}-{version}"
|
|
378
|
-
|
|
379
|
-
except importlib.metadata.PackageNotFoundError:
|
|
380
|
-
return f"{lib_name}-not installed"
|
|
381
|
-
|
|
382
|
-
def download_requirements(self, url: str, filename: str):
|
|
383
|
-
"""
|
|
384
|
-
Download the requirements.txt file from the specified URL if not found locally using requests.
|
|
385
|
-
|
|
386
|
-
Args:
|
|
387
|
-
url (str): The URL to download the requirements file from.
|
|
388
|
-
filename (str): The local filename to save the requirements file as.
|
|
389
|
-
"""
|
|
390
|
-
try:
|
|
391
|
-
import requests
|
|
392
|
-
|
|
393
|
-
logging.info(f"{filename} not found locally. Downloading from {url}...")
|
|
394
|
-
response = requests.get(url)
|
|
395
|
-
|
|
396
|
-
if response.status_code == 200:
|
|
397
|
-
with open(filename, 'wb') as f:
|
|
398
|
-
f.write(response.content)
|
|
399
|
-
|
|
400
|
-
else:
|
|
401
|
-
logging.error(f"Failed to download {filename}. HTTP Status code: {response.status_code}")
|
|
402
|
-
sys.exit(0)
|
|
403
|
-
|
|
404
|
-
except Exception as e:
|
|
405
|
-
logging.error(f"Failed to download {filename}: {e}")
|
|
406
|
-
sys.exit(0)
|
|
407
|
-
|
|
408
|
-
def install_library(self, lib_name: str):
|
|
409
|
-
"""
|
|
410
|
-
Install a Python library using pip.
|
|
411
|
-
|
|
412
|
-
Args:
|
|
413
|
-
lib_name (str): The name of the library to install.
|
|
414
|
-
"""
|
|
415
|
-
try:
|
|
416
|
-
console.print(f"Installing {lib_name}...", style="bold yellow")
|
|
417
|
-
subprocess.check_call([sys.executable, "-m", "pip", "install", lib_name])
|
|
418
|
-
console.print(f"{lib_name} installed successfully!", style="bold green")
|
|
419
|
-
|
|
420
|
-
except subprocess.CalledProcessError as e:
|
|
421
|
-
console.print(f"Failed to install {lib_name}: {e}", style="bold red")
|
|
422
|
-
sys.exit(1)
|
|
423
|
-
|
|
424
|
-
def check_python_version(self):
|
|
425
|
-
"""
|
|
426
|
-
Check if the installed Python is the official CPython distribution.
|
|
427
|
-
Exits with a message if not the official version.
|
|
428
|
-
"""
|
|
429
|
-
python_implementation = platform.python_implementation()
|
|
430
|
-
|
|
431
|
-
if python_implementation != "CPython":
|
|
432
|
-
console.print(f"[bold red]Warning: You are using a non-official Python distribution: {python_implementation}.[/bold red]")
|
|
433
|
-
console.print("Please install the official Python from [bold blue]https://www.python.org[/bold blue] and try again.", style="bold yellow")
|
|
434
|
-
sys.exit(0)
|
|
435
|
-
|
|
436
|
-
def get_system_summary(self):
|
|
437
|
-
"""
|
|
438
|
-
Generate a summary of the system environment.
|
|
439
|
-
|
|
440
|
-
Includes:
|
|
441
|
-
- Python version and implementation details.
|
|
442
|
-
- Operating system and architecture.
|
|
443
|
-
- Versions of `ffmpeg` and `ffprobe` executables.
|
|
444
|
-
- Installed Python libraries as listed in `requirements.txt`.
|
|
445
|
-
"""
|
|
446
|
-
|
|
447
|
-
# Check if Python is the official CPython
|
|
448
|
-
self.check_python_version()
|
|
449
|
-
|
|
450
|
-
# Check internet connectivity
|
|
451
|
-
InternManager().check_internet()
|
|
452
|
-
console.print("[bold blue]System Summary[/bold blue][white]:")
|
|
453
|
-
|
|
454
|
-
# Python version and platform
|
|
455
|
-
python_version = sys.version.split()[0]
|
|
456
|
-
python_implementation = platform.python_implementation()
|
|
457
|
-
arch = platform.machine()
|
|
458
|
-
os_info = platform.platform()
|
|
459
|
-
glibc_version = 'glibc ' + '.'.join(map(str, platform.libc_ver()[1]))
|
|
460
|
-
|
|
461
|
-
console.print(f"[cyan]Python[white]: [bold red]{python_version} ({python_implementation} {arch}) - {os_info} ({glibc_version})[/bold red]")
|
|
462
|
-
logging.info(f"Python: {python_version} ({python_implementation} {arch}) - {os_info} ({glibc_version})")
|
|
463
|
-
|
|
464
|
-
# Use the 'where' command on Windows and 'which' command on Unix-like systems
|
|
465
|
-
system_platform = platform.system().lower()
|
|
466
|
-
command = 'where' if system_platform == 'windows' else 'which'
|
|
467
|
-
|
|
468
|
-
# Locate ffmpeg and ffprobe from the PATH environment
|
|
469
|
-
if self.ffmpeg_path is not None and "binary" not in self.ffmpeg_path:
|
|
470
|
-
self.ffmpeg_path = self.check_ffmpeg_location([command, 'ffmpeg'])
|
|
471
|
-
|
|
472
|
-
if self.ffprobe_path is not None and "binary" not in self.ffprobe_path:
|
|
473
|
-
self.ffprobe_path = self.check_ffmpeg_location([command, 'ffprobe'])
|
|
474
|
-
|
|
475
|
-
# If ffmpeg or ffprobe is not located, fall back to using the check_ffmpeg function
|
|
476
|
-
if self.ffmpeg_path is None or self.ffprobe_path is None:
|
|
477
|
-
self.ffmpeg_path, self.ffprobe_path, self.ffplay_path = check_ffmpeg()
|
|
478
|
-
|
|
479
|
-
# If still not found, print error and exit
|
|
480
|
-
if self.ffmpeg_path is None or self.ffprobe_path is None:
|
|
481
|
-
console.log("[red]Can't locate ffmpeg or ffprobe")
|
|
482
|
-
sys.exit(0)
|
|
483
|
-
|
|
484
|
-
ffmpeg_version = self.get_executable_version([self.ffprobe_path, '-version'])
|
|
485
|
-
ffprobe_version = self.get_executable_version([self.ffprobe_path, '-version'])
|
|
486
|
-
|
|
487
|
-
console.print(f"[cyan]Path[white]: [red]ffmpeg [bold yellow]'{self.ffmpeg_path}'[/bold yellow][white], [red]ffprobe '[bold yellow]{self.ffprobe_path}'[/bold yellow]")
|
|
488
|
-
console.print(f"[cyan]Exe versions[white]: [bold red]ffmpeg {ffmpeg_version}, ffprobe {ffprobe_version}[/bold red]")
|
|
489
|
-
|
|
490
|
-
# Check if requirements.txt exists, if not on pyinstaller
|
|
491
|
-
if not getattr(sys, 'frozen', False):
|
|
492
|
-
requirements_file = 'requirements.txt'
|
|
493
|
-
|
|
494
|
-
if not os.path.exists(requirements_file):
|
|
495
|
-
self.download_requirements(
|
|
496
|
-
'https://raw.githubusercontent.com/Lovi-0/StreamingCommunity/refs/heads/main/requirements.txt',
|
|
497
|
-
requirements_file
|
|
498
|
-
)
|
|
499
|
-
|
|
500
|
-
# Read the optional libraries from the requirements file, get only name without version if "library==1.0.0"
|
|
501
|
-
optional_libraries = [line.strip().split("=")[0] for line in open(requirements_file, 'r', encoding='utf-8-sig')]
|
|
502
|
-
|
|
503
|
-
# Check if libraries are installed and prompt to install missing ones
|
|
504
|
-
for lib in optional_libraries:
|
|
505
|
-
installed_version = self.get_library_version(lib)
|
|
506
|
-
|
|
507
|
-
if 'not installed' in installed_version:
|
|
508
|
-
user_response = msg.ask(f"{lib} is not installed. Do you want to install it? (yes/no)", default="y")
|
|
509
|
-
|
|
510
|
-
if user_response.lower().strip() in ["yes", "y"]:
|
|
511
|
-
self.install_library(lib)
|
|
512
|
-
|
|
513
|
-
else:
|
|
514
|
-
logging.info(f"Library: {installed_version}")
|
|
515
|
-
|
|
516
|
-
console.print(f"[cyan]Libraries[white]: [bold red]{', '.join([self.get_library_version(lib) for lib in optional_libraries])}[/bold red]\n")
|
|
517
|
-
logging.info(f"Libraries: {', '.join([self.get_library_version(lib) for lib in optional_libraries])}")
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
# OTHER
|
|
521
|
-
os_manager = OsManager()
|
|
522
|
-
internet_manager = InternManager()
|
|
523
|
-
os_summary = OsSummary()
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
@contextlib.contextmanager
|
|
527
|
-
def suppress_output():
|
|
528
|
-
with contextlib.redirect_stdout(io.StringIO()):
|
|
529
|
-
yield
|
|
530
|
-
|
|
531
|
-
def compute_sha1_hash(input_string: str) -> str:
|
|
532
|
-
"""
|
|
533
|
-
Computes the SHA-1 hash of the input string.
|
|
534
|
-
|
|
535
|
-
Parameters:
|
|
536
|
-
- input_string (str): The string to be hashed.
|
|
537
|
-
|
|
538
|
-
Returns:
|
|
539
|
-
str: The SHA-1 hash of the input string.
|
|
540
|
-
"""
|
|
541
|
-
# Compute the SHA-1 hash
|
|
542
|
-
hashed_string = hashlib.sha1(input_string.encode()).hexdigest()
|
|
543
|
-
|
|
544
|
-
# Return the hashed string
|
|
545
|
-
return hashed_string
|