StreamingCommunity 1.7.6__py3-none-any.whl → 1.8.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.

Files changed (93) hide show
  1. StreamingCommunity/Src/Api/Player/Helper/Vixcloud/js_parser.py +4 -1
  2. StreamingCommunity/Src/Api/Player/Helper/Vixcloud/util.py +166 -166
  3. StreamingCommunity/Src/Api/Player/ddl.py +89 -89
  4. StreamingCommunity/Src/Api/Player/maxstream.py +151 -151
  5. StreamingCommunity/Src/Api/Player/supervideo.py +193 -193
  6. StreamingCommunity/Src/Api/Player/vixcloud.py +224 -212
  7. StreamingCommunity/Src/Api/Site/1337xx/__init__.py +50 -50
  8. StreamingCommunity/Src/Api/Site/1337xx/costant.py +14 -14
  9. StreamingCommunity/Src/Api/Site/1337xx/site.py +83 -83
  10. StreamingCommunity/Src/Api/Site/1337xx/title.py +66 -66
  11. StreamingCommunity/Src/Api/Site/altadefinizione/__init__.py +50 -50
  12. StreamingCommunity/Src/Api/Site/altadefinizione/costant.py +14 -14
  13. StreamingCommunity/Src/Api/Site/altadefinizione/film.py +69 -69
  14. StreamingCommunity/Src/Api/Site/altadefinizione/site.py +86 -86
  15. StreamingCommunity/Src/Api/Site/animeunity/__init__.py +50 -50
  16. StreamingCommunity/Src/Api/Site/animeunity/costant.py +15 -15
  17. StreamingCommunity/Src/Api/Site/animeunity/film_serie.py +131 -131
  18. StreamingCommunity/Src/Api/Site/animeunity/site.py +164 -164
  19. StreamingCommunity/Src/Api/Site/bitsearch/__init__.py +51 -51
  20. StreamingCommunity/Src/Api/Site/bitsearch/costant.py +15 -15
  21. StreamingCommunity/Src/Api/Site/bitsearch/site.py +84 -84
  22. StreamingCommunity/Src/Api/Site/bitsearch/title.py +47 -47
  23. StreamingCommunity/Src/Api/Site/cb01new/__init__.py +51 -51
  24. StreamingCommunity/Src/Api/Site/cb01new/costant.py +15 -15
  25. StreamingCommunity/Src/Api/Site/cb01new/film.py +69 -69
  26. StreamingCommunity/Src/Api/Site/cb01new/site.py +74 -74
  27. StreamingCommunity/Src/Api/Site/ddlstreamitaly/__init__.py +57 -57
  28. StreamingCommunity/Src/Api/Site/ddlstreamitaly/costant.py +16 -16
  29. StreamingCommunity/Src/Api/Site/ddlstreamitaly/series.py +142 -142
  30. StreamingCommunity/Src/Api/Site/ddlstreamitaly/site.py +92 -92
  31. StreamingCommunity/Src/Api/Site/ddlstreamitaly/util/ScrapeSerie.py +82 -82
  32. StreamingCommunity/Src/Api/Site/guardaserie/__init__.py +52 -52
  33. StreamingCommunity/Src/Api/Site/guardaserie/costant.py +15 -15
  34. StreamingCommunity/Src/Api/Site/guardaserie/series.py +195 -195
  35. StreamingCommunity/Src/Api/Site/guardaserie/site.py +84 -84
  36. StreamingCommunity/Src/Api/Site/guardaserie/util/ScrapeSerie.py +110 -110
  37. StreamingCommunity/Src/Api/Site/mostraguarda/__init__.py +48 -48
  38. StreamingCommunity/Src/Api/Site/mostraguarda/costant.py +14 -14
  39. StreamingCommunity/Src/Api/Site/mostraguarda/film.py +94 -94
  40. StreamingCommunity/Src/Api/Site/piratebays/__init__.py +50 -50
  41. StreamingCommunity/Src/Api/Site/piratebays/costant.py +14 -14
  42. StreamingCommunity/Src/Api/Site/piratebays/site.py +88 -88
  43. StreamingCommunity/Src/Api/Site/piratebays/title.py +45 -45
  44. StreamingCommunity/Src/Api/Site/streamingcommunity/__init__.py +55 -55
  45. StreamingCommunity/Src/Api/Site/streamingcommunity/costant.py +14 -14
  46. StreamingCommunity/Src/Api/Site/streamingcommunity/film.py +70 -70
  47. StreamingCommunity/Src/Api/Site/streamingcommunity/series.py +203 -203
  48. StreamingCommunity/Src/Api/Site/streamingcommunity/site.py +125 -125
  49. StreamingCommunity/Src/Api/Template/Class/SearchType.py +101 -101
  50. StreamingCommunity/Src/Api/Template/Util/__init__.py +4 -4
  51. StreamingCommunity/Src/Api/Template/Util/get_domain.py +137 -137
  52. StreamingCommunity/Src/Api/Template/Util/manage_ep.py +153 -153
  53. StreamingCommunity/Src/Api/Template/Util/recall_search.py +37 -37
  54. StreamingCommunity/Src/Api/Template/__init__.py +2 -2
  55. StreamingCommunity/Src/Api/Template/site.py +87 -87
  56. StreamingCommunity/Src/Lib/Downloader/HLS/downloader.py +968 -968
  57. StreamingCommunity/Src/Lib/Downloader/HLS/proxyes.py +110 -110
  58. StreamingCommunity/Src/Lib/Downloader/HLS/segments.py +540 -540
  59. StreamingCommunity/Src/Lib/Downloader/MP4/downloader.py +156 -156
  60. StreamingCommunity/Src/Lib/Downloader/TOR/downloader.py +222 -222
  61. StreamingCommunity/Src/Lib/Downloader/__init__.py +4 -4
  62. StreamingCommunity/Src/Lib/Driver/driver_1.py +76 -76
  63. StreamingCommunity/Src/Lib/FFmpeg/__init__.py +4 -4
  64. StreamingCommunity/Src/Lib/FFmpeg/capture.py +170 -170
  65. StreamingCommunity/Src/Lib/FFmpeg/command.py +292 -292
  66. StreamingCommunity/Src/Lib/FFmpeg/util.py +241 -241
  67. StreamingCommunity/Src/Lib/M3U8/__init__.py +5 -5
  68. StreamingCommunity/Src/Lib/M3U8/decryptor.py +128 -128
  69. StreamingCommunity/Src/Lib/M3U8/estimator.py +172 -172
  70. StreamingCommunity/Src/Lib/M3U8/parser.py +666 -666
  71. StreamingCommunity/Src/Lib/M3U8/url_fixer.py +51 -51
  72. StreamingCommunity/Src/Lib/TMBD/__init__.py +1 -1
  73. StreamingCommunity/Src/Lib/TMBD/obj_tmbd.py +39 -39
  74. StreamingCommunity/Src/Lib/TMBD/tmdb.py +345 -345
  75. StreamingCommunity/Src/Upload/update.py +64 -64
  76. StreamingCommunity/Src/Upload/version.py +5 -5
  77. StreamingCommunity/Src/Util/_jsonConfig.py +204 -204
  78. StreamingCommunity/Src/Util/call_stack.py +42 -42
  79. StreamingCommunity/Src/Util/color.py +20 -20
  80. StreamingCommunity/Src/Util/console.py +12 -12
  81. StreamingCommunity/Src/Util/headers.py +147 -147
  82. StreamingCommunity/Src/Util/logger.py +53 -53
  83. StreamingCommunity/Src/Util/message.py +46 -46
  84. StreamingCommunity/Src/Util/os.py +417 -417
  85. StreamingCommunity/Src/Util/table.py +163 -163
  86. StreamingCommunity/run.py +196 -196
  87. {StreamingCommunity-1.7.6.dist-info → StreamingCommunity-1.8.0.dist-info}/METADATA +1 -1
  88. StreamingCommunity-1.8.0.dist-info/RECORD +97 -0
  89. StreamingCommunity-1.7.6.dist-info/RECORD +0 -97
  90. {StreamingCommunity-1.7.6.dist-info → StreamingCommunity-1.8.0.dist-info}/LICENSE +0 -0
  91. {StreamingCommunity-1.7.6.dist-info → StreamingCommunity-1.8.0.dist-info}/WHEEL +0 -0
  92. {StreamingCommunity-1.7.6.dist-info → StreamingCommunity-1.8.0.dist-info}/entry_points.txt +0 -0
  93. {StreamingCommunity-1.7.6.dist-info → StreamingCommunity-1.8.0.dist-info}/top_level.txt +0 -0
@@ -1,417 +1,417 @@
1
- # 24.01.24
2
-
3
- import io
4
- import os
5
- import sys
6
- import ssl
7
- import time
8
- import shutil
9
- import hashlib
10
- import logging
11
- import platform
12
- import unidecode
13
- import importlib
14
- import subprocess
15
- import contextlib
16
- import pathvalidate
17
- import urllib.request
18
- import importlib.metadata
19
-
20
-
21
- # External library
22
- import httpx
23
-
24
-
25
- # Internal utilities
26
- from StreamingCommunity.Src.Util.console import console
27
-
28
-
29
- # Variable
30
- OS_CONFIGURATIONS = {
31
- 'windows': {
32
- 'max_length': 255,
33
- 'invalid_chars': '<>:"/\\|?*',
34
- 'reserved_names': [
35
- "CON", "PRN", "AUX", "NUL",
36
- "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
37
- "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"
38
- ],
39
- 'max_path': 255
40
- },
41
- 'darwin': {
42
- 'max_length': 4096,
43
- 'invalid_chars': '/:',
44
- 'reserved_names': [],
45
- 'hidden_file_restriction': True
46
- },
47
- 'linux': {
48
- 'max_length': 4096,
49
- 'invalid_chars': '/\0',
50
- 'reserved_names': []
51
- }
52
- }
53
-
54
-
55
-
56
- class OsManager:
57
- def __init__(self):
58
- self.system = self._detect_system()
59
- self.config = OS_CONFIGURATIONS.get(self.system, {})
60
-
61
- def _detect_system(self) -> str:
62
- """Detect and normalize operating system name."""
63
- system = platform.system().lower()
64
-
65
- if system in OS_CONFIGURATIONS:
66
- return system
67
-
68
- raise ValueError(f"Unsupported operating system: {system}")
69
-
70
- def _process_filename(self, filename: str) -> str:
71
- """
72
- Comprehensively process filename with cross-platform considerations.
73
-
74
- Args:
75
- filename (str): Original filename.
76
-
77
- Returns:
78
- str: Processed filename.
79
- """
80
- # Preserve file extension
81
- logging.info("_process_filename: ", filename)
82
- name, ext = os.path.splitext(filename)
83
-
84
- # Handle length restrictions
85
- if len(name) > self.config['max_length']:
86
- name = self._truncate_filename(name)
87
-
88
- # Reconstruct filename
89
- processed_filename = name + ext
90
-
91
- return processed_filename
92
-
93
- def _truncate_filename(self, name: str) -> str:
94
- """
95
- Truncate filename based on OS-specific rules.
96
-
97
- Args:
98
- name (str): Original filename.
99
-
100
- Returns:
101
- str: Truncated filename.
102
- """
103
- logging.info("_truncate_filename: ", name)
104
-
105
- if self.system == 'windows':
106
- return name[:self.config['max_length'] - 3] + '___'
107
- elif self.system == 'darwin':
108
- return name[:self.config['max_length']]
109
- elif self.system == 'linux':
110
- return name[:self.config['max_length'] - 2] + '___'
111
-
112
- def get_sanitize_file(self, filename: str) -> str:
113
- """
114
- Sanitize filename using pathvalidate with unidecode.
115
-
116
- Args:
117
- filename (str): Original filename.
118
-
119
- Returns:
120
- str: Sanitized filename.
121
- """
122
- logging.info("get_sanitize_file: ", filename)
123
-
124
- # Decode unicode characters and sanitize
125
- decoded_filename = unidecode.unidecode(filename)
126
- sanitized_filename = pathvalidate.sanitize_filename(decoded_filename)
127
-
128
- # Truncate if necessary based on OS configuration
129
- name, ext = os.path.splitext(sanitized_filename)
130
- if len(name) > self.config['max_length']:
131
- name = self._truncate_filename(name)
132
-
133
- logging.info("return :", name + ext)
134
- return name + ext
135
-
136
- def get_sanitize_path(self, path: str) -> str:
137
- """
138
- Sanitize folder path using pathvalidate with unidecode.
139
-
140
- Args:
141
- path (str): Original folder path.
142
-
143
- Returns:
144
- str: Sanitized folder path.
145
- """
146
- logging.info("get_sanitize_file: ", path)
147
-
148
- # Decode unicode characters and sanitize
149
- decoded_path = unidecode.unidecode(path)
150
- sanitized_path = pathvalidate.sanitize_filepath(decoded_path)
151
-
152
- # Split path and process each component
153
- path_components = os.path.normpath(sanitized_path).split(os.sep)
154
- processed_components = []
155
-
156
- for component in path_components:
157
- # Truncate component if necessary
158
- if len(component) > self.config['max_length']:
159
- component = self._truncate_filename(component)
160
- processed_components.append(component)
161
-
162
- logging.info("return :", os.path.join(*processed_components))
163
- return os.path.join(*processed_components)
164
-
165
- def create_path(self, path: str, mode: int = 0o755) -> bool:
166
- """
167
- Create directory path with specified permissions.
168
-
169
- Args:
170
- path (str): Path to create.
171
- mode (int, optional): Directory permissions. Defaults to 0o755.
172
-
173
- Returns:
174
- bool: True if path created successfully, False otherwise.
175
- """
176
- try:
177
- # Sanitize path first
178
- sanitized_path = self.get_sanitize_path(path)
179
-
180
- # Create directory with recursive option
181
- os.makedirs(sanitized_path, mode=mode, exist_ok=True)
182
- return True
183
-
184
- except Exception as e:
185
- logging.error(f"Path creation error: {e}")
186
- return False
187
-
188
- def remove_folder(self, folder_path: str) -> bool:
189
- """
190
- Safely remove a folder.
191
-
192
- Args:
193
- folder_path (str): Path of directory to remove.
194
-
195
- Returns:
196
- bool: Removal status.
197
- """
198
- try:
199
- shutil.rmtree(folder_path)
200
- return True
201
- except OSError as e:
202
- logging.error(f"Folder removal error: {e}")
203
- return False
204
-
205
- def remove_files_except_one(self, folder_path: str, keep_file: str) -> None:
206
- """
207
- Delete all files in a folder except for one specified file.
208
-
209
- Parameters:
210
- - folder_path (str): The path to the folder containing the files.
211
- - keep_file (str): The filename to keep in the folder.
212
- """
213
-
214
- try:
215
- # List all files in the folder
216
- files_in_folder = os.listdir(folder_path)
217
-
218
- # Iterate over each file in the folder
219
- for file_name in files_in_folder:
220
- file_path = os.path.join(folder_path, file_name)
221
-
222
- # Check if the file is not the one to keep and is a regular file
223
- if file_name != keep_file and os.path.isfile(file_path):
224
- os.remove(file_path) # Delete the file
225
-
226
- except Exception as e:
227
- logging.error(f"An error occurred: {e}")
228
- raise
229
-
230
- def check_file(self, file_path: str) -> bool:
231
- """
232
- Check if a file exists at the given file path.
233
-
234
- Parameters:
235
- file_path (str): The path to the file.
236
-
237
- Returns:
238
- bool: True if the file exists, False otherwise.
239
- """
240
- try:
241
- logging.info(f"Check if file exists: {file_path}")
242
- if os.path.exists(file_path):
243
- logging.info(f"The file '{file_path}' exists.")
244
- return True
245
-
246
- else:
247
- return False
248
-
249
- except Exception as e:
250
- logging.error(f"An error occurred while checking file existence: {e}")
251
- return False
252
-
253
-
254
- class InternManager():
255
-
256
- def format_file_size(self, size_bytes: float) -> str:
257
- """
258
- Formats a file size from bytes into a human-readable string representation.
259
-
260
- Parameters:
261
- size_bytes (float): Size in bytes to be formatted.
262
-
263
- Returns:
264
- str: Formatted string representing the file size with appropriate unit (B, KB, MB, GB, TB).
265
- """
266
- if size_bytes <= 0:
267
- return "0B"
268
-
269
- units = ['B', 'KB', 'MB', 'GB', 'TB']
270
- unit_index = 0
271
-
272
- while size_bytes >= 1024 and unit_index < len(units) - 1:
273
- size_bytes /= 1024
274
- unit_index += 1
275
-
276
- return f"{size_bytes:.2f} {units[unit_index]}"
277
-
278
- def format_transfer_speed(self, bytes: float) -> str:
279
- """
280
- Formats a transfer speed from bytes per second into a human-readable string representation.
281
-
282
- Parameters:
283
- bytes (float): Speed in bytes per second to be formatted.
284
-
285
- Returns:
286
- str: Formatted string representing the transfer speed with appropriate unit (Bytes/s, KB/s, MB/s).
287
- """
288
- if bytes < 1024:
289
- return f"{bytes:.2f} Bytes/s"
290
- elif bytes < 1024 * 1024:
291
- return f"{bytes / 1024:.2f} KB/s"
292
- else:
293
- return f"{bytes / (1024 * 1024):.2f} MB/s"
294
-
295
- @staticmethod
296
- def check_internet():
297
- while True:
298
- try:
299
- httpx.get("https://www.google.com")
300
- console.log("[bold green]Internet is available![/bold green]")
301
- break
302
-
303
- except urllib.error.URLError:
304
- console.log("[bold red]Internet is not available. Waiting...[/bold red]")
305
- time.sleep(5)
306
-
307
- print()
308
-
309
-
310
- class OsSummary():
311
-
312
- def get_executable_version(self, command: list):
313
- """
314
- Get the version of a given command-line executable.
315
-
316
- Args:
317
- command (list): The command to run, e.g., `['ffmpeg', '-version']`.
318
-
319
- Returns:
320
- str: The version string of the executable.
321
-
322
- Raises:
323
- SystemExit: If the command is not found or fails to execute.
324
- """
325
-
326
- try:
327
- version_output = subprocess.check_output(command, stderr=subprocess.STDOUT).decode().split('\n')[0]
328
- return version_output.split(" ")[2]
329
-
330
- except (FileNotFoundError, subprocess.CalledProcessError):
331
- print(f"{command[0]} not found")
332
- sys.exit(0)
333
-
334
- def get_library_version(self, lib_name: str):
335
- """
336
- Retrieve the version of a Python library.
337
-
338
- Args:
339
- lib_name (str): The name of the Python library.
340
-
341
- Returns:
342
- str: The library name followed by its version, or `-not installed` if not found.
343
- """
344
-
345
- try:
346
- version = importlib.metadata.version(lib_name)
347
- return f"{lib_name}-{version}"
348
-
349
- except importlib.metadata.PackageNotFoundError:
350
- return f"{lib_name}-not installed"
351
-
352
- def get_system_summary(self):
353
- """
354
- Generate a summary of the system environment.
355
-
356
- Includes:
357
- - Python version and implementation details.
358
- - Operating system and architecture.
359
- - Versions of `ffmpeg` and `ffprobe` executables.
360
- - Installed Python libraries as listed in `requirements.txt`.
361
- """
362
-
363
- # Check internet connectivity
364
- InternManager().check_internet()
365
- console.print("[bold blue]System Summary[/bold blue][white]:")
366
-
367
- # Python version and platform
368
- python_version = sys.version.split()[0]
369
- python_implementation = platform.python_implementation()
370
- arch = platform.machine()
371
- os_info = platform.platform()
372
- glibc_version = 'glibc ' + '.'.join(map(str, platform.libc_ver()[1]))
373
-
374
- console.print(f"[cyan]Python[white]: [bold red]{python_version} ({python_implementation} {arch}) - {os_info} ({glibc_version})[/bold red]")
375
- logging.info(f"Python: {python_version} ({python_implementation} {arch}) - {os_info} ({glibc_version})")
376
-
377
- # ffmpeg and ffprobe versions
378
- ffmpeg_version = self.get_executable_version(['ffmpeg', '-version'])
379
- ffprobe_version = self.get_executable_version(['ffprobe', '-version'])
380
-
381
- console.print(f"[cyan]Exe versions[white]: [bold red]ffmpeg {ffmpeg_version}, ffprobe {ffprobe_version}[/bold red]")
382
- logging.info(f"Dependencies: ffmpeg {ffmpeg_version}, ffprobe {ffprobe_version}")
383
-
384
- # Optional libraries versions
385
- """optional_libraries = [line.strip() for line in open('requirements.txt', 'r', encoding='utf-8-sig')]
386
- optional_libs_versions = [self.get_library_version(lib) for lib in optional_libraries]
387
-
388
- console.print(f"[cyan]Libraries[white]: [bold red]{', '.join(optional_libs_versions)}[/bold red]\n")
389
- logging.info(f"Libraries: {', '.join(optional_libs_versions)}")"""
390
-
391
-
392
-
393
- # OTHER
394
- os_manager = OsManager()
395
- internet_manager = InternManager()
396
- os_summary = OsSummary()
397
-
398
- @contextlib.contextmanager
399
- def suppress_output():
400
- with contextlib.redirect_stdout(io.StringIO()):
401
- yield
402
-
403
- def compute_sha1_hash(input_string: str) -> str:
404
- """
405
- Computes the SHA-1 hash of the input string.
406
-
407
- Parameters:
408
- - input_string (str): The string to be hashed.
409
-
410
- Returns:
411
- str: The SHA-1 hash of the input string.
412
- """
413
- # Compute the SHA-1 hash
414
- hashed_string = hashlib.sha1(input_string.encode()).hexdigest()
415
-
416
- # Return the hashed string
417
- return hashed_string
1
+ # 24.01.24
2
+
3
+ import io
4
+ import os
5
+ import sys
6
+ import ssl
7
+ import time
8
+ import shutil
9
+ import hashlib
10
+ import logging
11
+ import platform
12
+ import unidecode
13
+ import importlib
14
+ import subprocess
15
+ import contextlib
16
+ import pathvalidate
17
+ import urllib.request
18
+ import importlib.metadata
19
+
20
+
21
+ # External library
22
+ import httpx
23
+
24
+
25
+ # Internal utilities
26
+ from StreamingCommunity.Src.Util.console import console
27
+
28
+
29
+ # Variable
30
+ OS_CONFIGURATIONS = {
31
+ 'windows': {
32
+ 'max_length': 255,
33
+ 'invalid_chars': '<>:"/\\|?*',
34
+ 'reserved_names': [
35
+ "CON", "PRN", "AUX", "NUL",
36
+ "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
37
+ "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"
38
+ ],
39
+ 'max_path': 255
40
+ },
41
+ 'darwin': {
42
+ 'max_length': 4096,
43
+ 'invalid_chars': '/:',
44
+ 'reserved_names': [],
45
+ 'hidden_file_restriction': True
46
+ },
47
+ 'linux': {
48
+ 'max_length': 4096,
49
+ 'invalid_chars': '/\0',
50
+ 'reserved_names': []
51
+ }
52
+ }
53
+
54
+
55
+
56
+ class OsManager:
57
+ def __init__(self):
58
+ self.system = self._detect_system()
59
+ self.config = OS_CONFIGURATIONS.get(self.system, {})
60
+
61
+ def _detect_system(self) -> str:
62
+ """Detect and normalize operating system name."""
63
+ system = platform.system().lower()
64
+
65
+ if system in OS_CONFIGURATIONS:
66
+ return system
67
+
68
+ raise ValueError(f"Unsupported operating system: {system}")
69
+
70
+ def _process_filename(self, filename: str) -> str:
71
+ """
72
+ Comprehensively process filename with cross-platform considerations.
73
+
74
+ Args:
75
+ filename (str): Original filename.
76
+
77
+ Returns:
78
+ str: Processed filename.
79
+ """
80
+ # Preserve file extension
81
+ logging.info("_process_filename: ", filename)
82
+ name, ext = os.path.splitext(filename)
83
+
84
+ # Handle length restrictions
85
+ if len(name) > self.config['max_length']:
86
+ name = self._truncate_filename(name)
87
+
88
+ # Reconstruct filename
89
+ processed_filename = name + ext
90
+
91
+ return processed_filename
92
+
93
+ def _truncate_filename(self, name: str) -> str:
94
+ """
95
+ Truncate filename based on OS-specific rules.
96
+
97
+ Args:
98
+ name (str): Original filename.
99
+
100
+ Returns:
101
+ str: Truncated filename.
102
+ """
103
+ logging.info("_truncate_filename: ", name)
104
+
105
+ if self.system == 'windows':
106
+ return name[:self.config['max_length'] - 3] + '___'
107
+ elif self.system == 'darwin':
108
+ return name[:self.config['max_length']]
109
+ elif self.system == 'linux':
110
+ return name[:self.config['max_length'] - 2] + '___'
111
+
112
+ def get_sanitize_file(self, filename: str) -> str:
113
+ """
114
+ Sanitize filename using pathvalidate with unidecode.
115
+
116
+ Args:
117
+ filename (str): Original filename.
118
+
119
+ Returns:
120
+ str: Sanitized filename.
121
+ """
122
+ logging.info("get_sanitize_file: ", filename)
123
+
124
+ # Decode unicode characters and sanitize
125
+ decoded_filename = unidecode.unidecode(filename)
126
+ sanitized_filename = pathvalidate.sanitize_filename(decoded_filename)
127
+
128
+ # Truncate if necessary based on OS configuration
129
+ name, ext = os.path.splitext(sanitized_filename)
130
+ if len(name) > self.config['max_length']:
131
+ name = self._truncate_filename(name)
132
+
133
+ logging.info("return :", name + ext)
134
+ return name + ext
135
+
136
+ def get_sanitize_path(self, path: str) -> str:
137
+ """
138
+ Sanitize folder path using pathvalidate with unidecode.
139
+
140
+ Args:
141
+ path (str): Original folder path.
142
+
143
+ Returns:
144
+ str: Sanitized folder path.
145
+ """
146
+ logging.info("get_sanitize_file: ", path)
147
+
148
+ # Decode unicode characters and sanitize
149
+ decoded_path = unidecode.unidecode(path)
150
+ sanitized_path = pathvalidate.sanitize_filepath(decoded_path)
151
+
152
+ # Split path and process each component
153
+ path_components = os.path.normpath(sanitized_path).split(os.sep)
154
+ processed_components = []
155
+
156
+ for component in path_components:
157
+ # Truncate component if necessary
158
+ if len(component) > self.config['max_length']:
159
+ component = self._truncate_filename(component)
160
+ processed_components.append(component)
161
+
162
+ logging.info("return :", os.path.join(*processed_components))
163
+ return os.path.join(*processed_components)
164
+
165
+ def create_path(self, path: str, mode: int = 0o755) -> bool:
166
+ """
167
+ Create directory path with specified permissions.
168
+
169
+ Args:
170
+ path (str): Path to create.
171
+ mode (int, optional): Directory permissions. Defaults to 0o755.
172
+
173
+ Returns:
174
+ bool: True if path created successfully, False otherwise.
175
+ """
176
+ try:
177
+ # Sanitize path first
178
+ sanitized_path = self.get_sanitize_path(path)
179
+
180
+ # Create directory with recursive option
181
+ os.makedirs(sanitized_path, mode=mode, exist_ok=True)
182
+ return True
183
+
184
+ except Exception as e:
185
+ logging.error(f"Path creation error: {e}")
186
+ return False
187
+
188
+ def remove_folder(self, folder_path: str) -> bool:
189
+ """
190
+ Safely remove a folder.
191
+
192
+ Args:
193
+ folder_path (str): Path of directory to remove.
194
+
195
+ Returns:
196
+ bool: Removal status.
197
+ """
198
+ try:
199
+ shutil.rmtree(folder_path)
200
+ return True
201
+ except OSError as e:
202
+ logging.error(f"Folder removal error: {e}")
203
+ return False
204
+
205
+ def remove_files_except_one(self, folder_path: str, keep_file: str) -> None:
206
+ """
207
+ Delete all files in a folder except for one specified file.
208
+
209
+ Parameters:
210
+ - folder_path (str): The path to the folder containing the files.
211
+ - keep_file (str): The filename to keep in the folder.
212
+ """
213
+
214
+ try:
215
+ # List all files in the folder
216
+ files_in_folder = os.listdir(folder_path)
217
+
218
+ # Iterate over each file in the folder
219
+ for file_name in files_in_folder:
220
+ file_path = os.path.join(folder_path, file_name)
221
+
222
+ # Check if the file is not the one to keep and is a regular file
223
+ if file_name != keep_file and os.path.isfile(file_path):
224
+ os.remove(file_path) # Delete the file
225
+
226
+ except Exception as e:
227
+ logging.error(f"An error occurred: {e}")
228
+ raise
229
+
230
+ def check_file(self, file_path: str) -> bool:
231
+ """
232
+ Check if a file exists at the given file path.
233
+
234
+ Parameters:
235
+ file_path (str): The path to the file.
236
+
237
+ Returns:
238
+ bool: True if the file exists, False otherwise.
239
+ """
240
+ try:
241
+ logging.info(f"Check if file exists: {file_path}")
242
+ if os.path.exists(file_path):
243
+ logging.info(f"The file '{file_path}' exists.")
244
+ return True
245
+
246
+ else:
247
+ return False
248
+
249
+ except Exception as e:
250
+ logging.error(f"An error occurred while checking file existence: {e}")
251
+ return False
252
+
253
+
254
+ class InternManager():
255
+
256
+ def format_file_size(self, size_bytes: float) -> str:
257
+ """
258
+ Formats a file size from bytes into a human-readable string representation.
259
+
260
+ Parameters:
261
+ size_bytes (float): Size in bytes to be formatted.
262
+
263
+ Returns:
264
+ str: Formatted string representing the file size with appropriate unit (B, KB, MB, GB, TB).
265
+ """
266
+ if size_bytes <= 0:
267
+ return "0B"
268
+
269
+ units = ['B', 'KB', 'MB', 'GB', 'TB']
270
+ unit_index = 0
271
+
272
+ while size_bytes >= 1024 and unit_index < len(units) - 1:
273
+ size_bytes /= 1024
274
+ unit_index += 1
275
+
276
+ return f"{size_bytes:.2f} {units[unit_index]}"
277
+
278
+ def format_transfer_speed(self, bytes: float) -> str:
279
+ """
280
+ Formats a transfer speed from bytes per second into a human-readable string representation.
281
+
282
+ Parameters:
283
+ bytes (float): Speed in bytes per second to be formatted.
284
+
285
+ Returns:
286
+ str: Formatted string representing the transfer speed with appropriate unit (Bytes/s, KB/s, MB/s).
287
+ """
288
+ if bytes < 1024:
289
+ return f"{bytes:.2f} Bytes/s"
290
+ elif bytes < 1024 * 1024:
291
+ return f"{bytes / 1024:.2f} KB/s"
292
+ else:
293
+ return f"{bytes / (1024 * 1024):.2f} MB/s"
294
+
295
+ @staticmethod
296
+ def check_internet():
297
+ while True:
298
+ try:
299
+ httpx.get("https://www.google.com")
300
+ console.log("[bold green]Internet is available![/bold green]")
301
+ break
302
+
303
+ except urllib.error.URLError:
304
+ console.log("[bold red]Internet is not available. Waiting...[/bold red]")
305
+ time.sleep(5)
306
+
307
+ print()
308
+
309
+
310
+ class OsSummary():
311
+
312
+ def get_executable_version(self, command: list):
313
+ """
314
+ Get the version of a given command-line executable.
315
+
316
+ Args:
317
+ command (list): The command to run, e.g., `['ffmpeg', '-version']`.
318
+
319
+ Returns:
320
+ str: The version string of the executable.
321
+
322
+ Raises:
323
+ SystemExit: If the command is not found or fails to execute.
324
+ """
325
+
326
+ try:
327
+ version_output = subprocess.check_output(command, stderr=subprocess.STDOUT).decode().split('\n')[0]
328
+ return version_output.split(" ")[2]
329
+
330
+ except (FileNotFoundError, subprocess.CalledProcessError):
331
+ print(f"{command[0]} not found")
332
+ sys.exit(0)
333
+
334
+ def get_library_version(self, lib_name: str):
335
+ """
336
+ Retrieve the version of a Python library.
337
+
338
+ Args:
339
+ lib_name (str): The name of the Python library.
340
+
341
+ Returns:
342
+ str: The library name followed by its version, or `-not installed` if not found.
343
+ """
344
+
345
+ try:
346
+ version = importlib.metadata.version(lib_name)
347
+ return f"{lib_name}-{version}"
348
+
349
+ except importlib.metadata.PackageNotFoundError:
350
+ return f"{lib_name}-not installed"
351
+
352
+ def get_system_summary(self):
353
+ """
354
+ Generate a summary of the system environment.
355
+
356
+ Includes:
357
+ - Python version and implementation details.
358
+ - Operating system and architecture.
359
+ - Versions of `ffmpeg` and `ffprobe` executables.
360
+ - Installed Python libraries as listed in `requirements.txt`.
361
+ """
362
+
363
+ # Check internet connectivity
364
+ InternManager().check_internet()
365
+ console.print("[bold blue]System Summary[/bold blue][white]:")
366
+
367
+ # Python version and platform
368
+ python_version = sys.version.split()[0]
369
+ python_implementation = platform.python_implementation()
370
+ arch = platform.machine()
371
+ os_info = platform.platform()
372
+ glibc_version = 'glibc ' + '.'.join(map(str, platform.libc_ver()[1]))
373
+
374
+ console.print(f"[cyan]Python[white]: [bold red]{python_version} ({python_implementation} {arch}) - {os_info} ({glibc_version})[/bold red]")
375
+ logging.info(f"Python: {python_version} ({python_implementation} {arch}) - {os_info} ({glibc_version})")
376
+
377
+ # ffmpeg and ffprobe versions
378
+ ffmpeg_version = self.get_executable_version(['ffmpeg', '-version'])
379
+ ffprobe_version = self.get_executable_version(['ffprobe', '-version'])
380
+
381
+ console.print(f"[cyan]Exe versions[white]: [bold red]ffmpeg {ffmpeg_version}, ffprobe {ffprobe_version}[/bold red]")
382
+ logging.info(f"Dependencies: ffmpeg {ffmpeg_version}, ffprobe {ffprobe_version}")
383
+
384
+ # Optional libraries versions
385
+ """optional_libraries = [line.strip() for line in open('requirements.txt', 'r', encoding='utf-8-sig')]
386
+ optional_libs_versions = [self.get_library_version(lib) for lib in optional_libraries]
387
+
388
+ console.print(f"[cyan]Libraries[white]: [bold red]{', '.join(optional_libs_versions)}[/bold red]\n")
389
+ logging.info(f"Libraries: {', '.join(optional_libs_versions)}")"""
390
+
391
+
392
+
393
+ # OTHER
394
+ os_manager = OsManager()
395
+ internet_manager = InternManager()
396
+ os_summary = OsSummary()
397
+
398
+ @contextlib.contextmanager
399
+ def suppress_output():
400
+ with contextlib.redirect_stdout(io.StringIO()):
401
+ yield
402
+
403
+ def compute_sha1_hash(input_string: str) -> str:
404
+ """
405
+ Computes the SHA-1 hash of the input string.
406
+
407
+ Parameters:
408
+ - input_string (str): The string to be hashed.
409
+
410
+ Returns:
411
+ str: The SHA-1 hash of the input string.
412
+ """
413
+ # Compute the SHA-1 hash
414
+ hashed_string = hashlib.sha1(input_string.encode()).hexdigest()
415
+
416
+ # Return the hashed string
417
+ return hashed_string