StreamingCommunity 1.9.5__py3-none-any.whl → 1.9.90__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/Api/Player/Helper/Vixcloud/js_parser.py +143 -0
  2. StreamingCommunity/Api/Player/Helper/Vixcloud/util.py +145 -0
  3. StreamingCommunity/Api/Player/ddl.py +89 -0
  4. StreamingCommunity/Api/Player/maxstream.py +151 -0
  5. StreamingCommunity/Api/Player/supervideo.py +194 -0
  6. StreamingCommunity/Api/Player/vixcloud.py +273 -0
  7. StreamingCommunity/Api/Site/1337xx/__init__.py +51 -0
  8. StreamingCommunity/Api/Site/1337xx/costant.py +15 -0
  9. StreamingCommunity/Api/Site/1337xx/site.py +86 -0
  10. StreamingCommunity/Api/Site/1337xx/title.py +66 -0
  11. StreamingCommunity/Api/Site/altadefinizione/__init__.py +51 -0
  12. StreamingCommunity/Api/Site/altadefinizione/costant.py +15 -0
  13. StreamingCommunity/Api/Site/altadefinizione/film.py +74 -0
  14. StreamingCommunity/Api/Site/altadefinizione/site.py +89 -0
  15. StreamingCommunity/Api/Site/animeunity/__init__.py +51 -0
  16. StreamingCommunity/Api/Site/animeunity/costant.py +15 -0
  17. StreamingCommunity/Api/Site/animeunity/film_serie.py +135 -0
  18. StreamingCommunity/Api/Site/animeunity/site.py +167 -0
  19. StreamingCommunity/Api/Site/animeunity/util/ScrapeSerie.py +97 -0
  20. StreamingCommunity/Api/Site/cb01new/__init__.py +52 -0
  21. StreamingCommunity/Api/Site/cb01new/costant.py +15 -0
  22. StreamingCommunity/Api/Site/cb01new/film.py +73 -0
  23. StreamingCommunity/Api/Site/cb01new/site.py +76 -0
  24. StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py +58 -0
  25. StreamingCommunity/Api/Site/ddlstreamitaly/costant.py +16 -0
  26. StreamingCommunity/Api/Site/ddlstreamitaly/series.py +146 -0
  27. StreamingCommunity/Api/Site/ddlstreamitaly/site.py +95 -0
  28. StreamingCommunity/Api/Site/ddlstreamitaly/util/ScrapeSerie.py +85 -0
  29. StreamingCommunity/Api/Site/guardaserie/__init__.py +53 -0
  30. StreamingCommunity/Api/Site/guardaserie/costant.py +15 -0
  31. StreamingCommunity/Api/Site/guardaserie/series.py +199 -0
  32. StreamingCommunity/Api/Site/guardaserie/site.py +86 -0
  33. StreamingCommunity/Api/Site/guardaserie/util/ScrapeSerie.py +110 -0
  34. StreamingCommunity/Api/Site/ilcorsaronero/__init__.py +52 -0
  35. StreamingCommunity/Api/Site/ilcorsaronero/costant.py +15 -0
  36. StreamingCommunity/Api/Site/ilcorsaronero/site.py +63 -0
  37. StreamingCommunity/Api/Site/ilcorsaronero/title.py +46 -0
  38. StreamingCommunity/Api/Site/ilcorsaronero/util/ilCorsarScraper.py +141 -0
  39. StreamingCommunity/Api/Site/mostraguarda/__init__.py +49 -0
  40. StreamingCommunity/Api/Site/mostraguarda/costant.py +15 -0
  41. StreamingCommunity/Api/Site/mostraguarda/film.py +99 -0
  42. StreamingCommunity/Api/Site/streamingcommunity/__init__.py +56 -0
  43. StreamingCommunity/Api/Site/streamingcommunity/costant.py +15 -0
  44. StreamingCommunity/Api/Site/streamingcommunity/film.py +75 -0
  45. StreamingCommunity/Api/Site/streamingcommunity/series.py +206 -0
  46. StreamingCommunity/Api/Site/streamingcommunity/site.py +137 -0
  47. StreamingCommunity/Api/Site/streamingcommunity/util/ScrapeSerie.py +123 -0
  48. StreamingCommunity/Api/Template/Class/SearchType.py +101 -0
  49. StreamingCommunity/Api/Template/Util/__init__.py +5 -0
  50. StreamingCommunity/Api/Template/Util/get_domain.py +173 -0
  51. StreamingCommunity/Api/Template/Util/manage_ep.py +179 -0
  52. StreamingCommunity/Api/Template/Util/recall_search.py +37 -0
  53. StreamingCommunity/Api/Template/__init__.py +3 -0
  54. StreamingCommunity/Api/Template/site.py +87 -0
  55. StreamingCommunity/Lib/Downloader/HLS/downloader.py +946 -0
  56. StreamingCommunity/Lib/Downloader/HLS/proxyes.py +110 -0
  57. StreamingCommunity/Lib/Downloader/HLS/segments.py +561 -0
  58. StreamingCommunity/Lib/Downloader/MP4/downloader.py +155 -0
  59. StreamingCommunity/Lib/Downloader/TOR/downloader.py +296 -0
  60. StreamingCommunity/Lib/Downloader/__init__.py +5 -0
  61. StreamingCommunity/Lib/FFmpeg/__init__.py +4 -0
  62. StreamingCommunity/Lib/FFmpeg/capture.py +170 -0
  63. StreamingCommunity/Lib/FFmpeg/command.py +296 -0
  64. StreamingCommunity/Lib/FFmpeg/util.py +249 -0
  65. StreamingCommunity/Lib/M3U8/__init__.py +6 -0
  66. StreamingCommunity/Lib/M3U8/decryptor.py +164 -0
  67. StreamingCommunity/Lib/M3U8/estimator.py +176 -0
  68. StreamingCommunity/Lib/M3U8/parser.py +666 -0
  69. StreamingCommunity/Lib/M3U8/url_fixer.py +52 -0
  70. StreamingCommunity/Lib/TMBD/__init__.py +2 -0
  71. StreamingCommunity/Lib/TMBD/obj_tmbd.py +39 -0
  72. StreamingCommunity/Lib/TMBD/tmdb.py +346 -0
  73. StreamingCommunity/Upload/update.py +68 -0
  74. StreamingCommunity/Upload/version.py +5 -0
  75. StreamingCommunity/Util/_jsonConfig.py +204 -0
  76. StreamingCommunity/Util/call_stack.py +42 -0
  77. StreamingCommunity/Util/color.py +20 -0
  78. StreamingCommunity/Util/console.py +12 -0
  79. StreamingCommunity/Util/ffmpeg_installer.py +311 -0
  80. StreamingCommunity/Util/headers.py +147 -0
  81. StreamingCommunity/Util/logger.py +53 -0
  82. StreamingCommunity/Util/message.py +64 -0
  83. StreamingCommunity/Util/os.py +554 -0
  84. StreamingCommunity/Util/table.py +229 -0
  85. StreamingCommunity/__init__.py +0 -0
  86. StreamingCommunity/run.py +2 -11
  87. {StreamingCommunity-1.9.5.dist-info → StreamingCommunity-1.9.90.dist-info}/METADATA +10 -27
  88. StreamingCommunity-1.9.90.dist-info/RECORD +92 -0
  89. {StreamingCommunity-1.9.5.dist-info → StreamingCommunity-1.9.90.dist-info}/WHEEL +1 -1
  90. {StreamingCommunity-1.9.5.dist-info → StreamingCommunity-1.9.90.dist-info}/entry_points.txt +0 -1
  91. StreamingCommunity-1.9.5.dist-info/RECORD +0 -7
  92. {StreamingCommunity-1.9.5.dist-info → StreamingCommunity-1.9.90.dist-info}/LICENSE +0 -0
  93. {StreamingCommunity-1.9.5.dist-info → StreamingCommunity-1.9.90.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,204 @@
1
+ # 29.01.24
2
+
3
+ import os
4
+ import json
5
+ import httpx
6
+ import logging
7
+ from typing import Any, List
8
+
9
+
10
+ class ConfigManager:
11
+ def __init__(self, file_path: str = 'config.json') -> None:
12
+ """Initialize the ConfigManager.
13
+
14
+ Parameters:
15
+ - file_path (str, optional): The path to the configuration file. Default is 'config.json'.
16
+ """
17
+ self.file_path = file_path
18
+ self.config = {}
19
+ self.cache = {}
20
+
21
+ def read_config(self) -> None:
22
+ """Read the configuration file."""
23
+ try:
24
+ logging.info(f"Reading file: {self.file_path}")
25
+
26
+ # Check if file exist
27
+ if os.path.exists(self.file_path):
28
+ with open(self.file_path, 'r') as f:
29
+ self.config = json.load(f)
30
+ logging.info("Configuration file loaded successfully.")
31
+
32
+ # Download config.json
33
+ else:
34
+ logging.info("Configuration file does not exist. Downloading...")
35
+ url = "https://raw.githubusercontent.com/Lovi-0/StreamingCommunity/refs/heads/main/config.json"
36
+
37
+ with httpx.Client() as client:
38
+ response = client.get(url)
39
+
40
+ if response.status_code == 200:
41
+ with open(self.file_path, 'w') as f:
42
+ f.write(response.text)
43
+
44
+ self.config = json.loads(response.text)
45
+ logging.info("Configuration file downloaded and saved.")
46
+
47
+ else:
48
+ logging.error(f"Failed to download configuration file. Status code: {response.status_code}")
49
+
50
+ except Exception as e:
51
+ logging.error(f"Error reading configuration file: {e}")
52
+
53
+ def read_key(self, section: str, key: str, data_type: type = str) -> Any:
54
+ """Read a key from the configuration file.
55
+
56
+ Parameters:
57
+ - section (str): The section in the configuration file.
58
+ - key (str): The key to be read.
59
+ - data_type (type, optional): The expected data type of the key's value. Default is str.
60
+
61
+ Returns:
62
+ The value of the key converted to the specified data type.
63
+ """
64
+ cache_key = f"{section}.{key}"
65
+ logging.info(f"Read key: {cache_key}")
66
+
67
+ if cache_key in self.cache:
68
+ return self.cache[cache_key]
69
+
70
+ if section in self.config and key in self.config[section]:
71
+ value = self.config[section][key]
72
+ else:
73
+ raise ValueError(f"Key '{key}' not found in section '{section}'")
74
+
75
+ value = self._convert_to_data_type(value, data_type)
76
+ self.cache[cache_key] = value
77
+
78
+ return value
79
+
80
+ def _convert_to_data_type(self, value: str, data_type: type) -> Any:
81
+ """Convert the value to the specified data type.
82
+
83
+ Parameters:
84
+ - value (str): The value to be converted.
85
+ - data_type (type): The expected data type.
86
+
87
+ Returns:
88
+ The value converted to the specified data type.
89
+ """
90
+ if data_type == int:
91
+ return int(value)
92
+ elif data_type == bool:
93
+ return bool(value)
94
+ elif data_type == list:
95
+ return value if isinstance(value, list) else [item.strip() for item in value.split(',')]
96
+ elif data_type == type(None):
97
+ return None
98
+ else:
99
+ return value
100
+
101
+ def get(self, section: str, key: str) -> Any:
102
+ """Read a value from the configuration file.
103
+
104
+ Parameters:
105
+ - section (str): The section in the configuration file.
106
+ - key (str): The key to be read.
107
+
108
+ Returns:
109
+ The value associated with the key.
110
+ """
111
+ return self.read_key(section, key)
112
+
113
+ def get_int(self, section: str, key: str) -> int:
114
+ """Read an integer value from the configuration file.
115
+
116
+ Parameters:
117
+ - section (str): The section in the configuration file.
118
+ - key (str): The key to be read.
119
+
120
+ Returns:
121
+ int: The integer value.
122
+ """
123
+ return self.read_key(section, key, int)
124
+
125
+ def get_float(self, section: str, key: str) -> int:
126
+ """Read an float value from the configuration file.
127
+
128
+ Parameters:
129
+ - section (str): The section in the configuration file.
130
+ - key (str): The key to be read.
131
+
132
+ Returns:
133
+ float: The float value.
134
+ """
135
+ return self.read_key(section, key, float)
136
+
137
+ def get_bool(self, section: str, key: str) -> bool:
138
+ """Read a boolean value from the configuration file.
139
+
140
+ Parameters:
141
+ - section (str): The section in the configuration file.
142
+ - key (str): The key to be read.
143
+
144
+ Returns:
145
+ bool: The boolean value.
146
+ """
147
+ return self.read_key(section, key, bool)
148
+
149
+ def get_list(self, section: str, key: str) -> List[str]:
150
+ """Read a list value from the configuration file.
151
+
152
+ Parameters:
153
+ - section (str): The section in the configuration file.
154
+ - key (str): The key to be read.
155
+
156
+ Returns:
157
+ list: The list value.
158
+ """
159
+ return self.read_key(section, key, list)
160
+
161
+ def get_dict(self, section: str, key: str) -> dict:
162
+ """Read a dictionary value from the configuration file.
163
+
164
+ Parameters:
165
+ - section (str): The section in the configuration file.
166
+ - key (str): The key to be read.
167
+
168
+ Returns:
169
+ dict: The dictionary value.
170
+ """
171
+ return self.read_key(section, key, dict)
172
+
173
+ def set_key(self, section: str, key: str, value: Any) -> None:
174
+ """Set a key in the configuration file.
175
+
176
+ Parameters:
177
+ - section (str): The section in the configuration file.
178
+ - key (str): The key to be set.
179
+ - value (Any): The value to be associated with the key.
180
+ """
181
+ try:
182
+ if section not in self.config:
183
+ self.config[section] = {}
184
+
185
+ self.config[section][key] = value
186
+ cache_key = f"{section}.{key}"
187
+ self.cache[cache_key] = value
188
+ self.write_config()
189
+
190
+ except Exception as e:
191
+ print(f"Error setting key '{key}' in section '{section}': {e}")
192
+
193
+ def write_config(self) -> None:
194
+ """Write the configuration to the file."""
195
+ try:
196
+ with open(self.file_path, 'w') as f:
197
+ json.dump(self.config, f, indent=4)
198
+ except Exception as e:
199
+ print(f"Error writing configuration file: {e}")
200
+
201
+
202
+ # Initialize
203
+ config_manager = ConfigManager()
204
+ config_manager.read_config()
@@ -0,0 +1,42 @@
1
+ # 21.06.24
2
+
3
+ import os
4
+ import inspect
5
+
6
+
7
+ def get_call_stack():
8
+ """
9
+ Retrieves the current call stack with details about each call.
10
+
11
+ This function inspects the current call stack and returns a list of dictionaries,
12
+ where each dictionary contains details about a function call in the stack.
13
+
14
+ Returns:
15
+ list: A list of dictionaries, each containing the following keys:
16
+ - function (str): The name of the function.
17
+ - folder (str): The directory path of the script containing the function.
18
+ - folder_base (str): The base name of the directory path.
19
+ - script (str): The name of the script file containing the function.
20
+ - line (int): The line number in the script where the function is defined.
21
+ """
22
+
23
+ stack = inspect.stack()
24
+ call_stack = []
25
+
26
+ for frame_info in stack:
27
+ function_name = frame_info.function
28
+ filename = frame_info.filename
29
+ lineno = frame_info.lineno
30
+ folder_name = os.path.dirname(filename)
31
+ folder_base = os.path.basename(folder_name)
32
+ script_name = os.path.basename(filename)
33
+
34
+ call_stack.append({
35
+ "function": function_name,
36
+ "folder": folder_name,
37
+ "folder_base": folder_base,
38
+ "script": script_name,
39
+ "line": lineno
40
+ })
41
+
42
+ return call_stack
@@ -0,0 +1,20 @@
1
+ # 24.05.24
2
+
3
+ class Colors:
4
+ BLACK = "\033[30m"
5
+ RED = "\033[31m"
6
+ GREEN = "\033[32m"
7
+ YELLOW = "\033[33m"
8
+ BLUE = "\033[34m"
9
+ MAGENTA = "\033[35m"
10
+ CYAN = "\033[36m"
11
+ LIGHT_GRAY = "\033[37m"
12
+ DARK_GRAY = "\033[90m"
13
+ LIGHT_RED = "\033[91m"
14
+ LIGHT_GREEN = "\033[92m"
15
+ LIGHT_YELLOW = "\033[93m"
16
+ LIGHT_BLUE = "\033[94m"
17
+ LIGHT_MAGENTA = "\033[95m"
18
+ LIGHT_CYAN = "\033[96m"
19
+ WHITE = "\033[97m"
20
+ RESET = "\033[0m"
@@ -0,0 +1,12 @@
1
+ # 24.02.24
2
+
3
+ from rich.console import Console
4
+ from rich.prompt import Prompt, Confirm
5
+ from rich.panel import Panel
6
+ from rich.table import Table
7
+ from rich.text import Text
8
+
9
+
10
+ # Variable
11
+ msg = Prompt()
12
+ console = Console()
@@ -0,0 +1,311 @@
1
+ # 24.01.2024
2
+
3
+ import os
4
+ import platform
5
+ import subprocess
6
+ import zipfile
7
+ import tarfile
8
+ import logging
9
+ import requests
10
+ import shutil
11
+ import glob
12
+ from typing import Optional, Tuple
13
+
14
+
15
+ # External library
16
+ from rich.console import Console
17
+ from rich.progress import Progress, SpinnerColumn, BarColumn, TextColumn, TimeRemainingColumn
18
+
19
+
20
+ # Variable
21
+ console = Console()
22
+ FFMPEG_CONFIGURATION = {
23
+ 'windows': {
24
+ 'base_dir': lambda home: os.path.join(os.path.splitdrive(home)[0] + os.path.sep, 'binary'),
25
+ 'download_url': 'https://github.com/GyanD/codexffmpeg/releases/download/{version}/ffmpeg-{version}-full_build.zip',
26
+ 'file_extension': '.zip',
27
+ 'executables': ['ffmpeg.exe', 'ffprobe.exe', 'ffplay.exe']
28
+ },
29
+ 'darwin': {
30
+ 'base_dir': lambda home: os.path.join(home, 'Applications', 'binary'),
31
+ 'download_url': 'https://evermeet.cx/ffmpeg/ffmpeg-{version}.zip',
32
+ 'file_extension': '.zip',
33
+ 'executables': ['ffmpeg', 'ffprobe', 'ffplay']
34
+ },
35
+ 'linux': {
36
+ 'base_dir': lambda home: os.path.join(home, '.local', 'bin', 'binary'),
37
+ 'download_url': 'https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-{arch}-static.tar.xz',
38
+ 'file_extension': '.tar.xz',
39
+ 'executables': ['ffmpeg', 'ffprobe', 'ffplay']
40
+ }
41
+ }
42
+
43
+
44
+ class FFMPEGDownloader:
45
+ """
46
+ A class for downloading and managing FFmpeg executables.
47
+
48
+ This class handles the detection of the operating system, downloading of FFmpeg binaries,
49
+ and management of the FFmpeg executables (ffmpeg, ffprobe, and ffplay).
50
+
51
+ Attributes:
52
+ os_name (str): The detected operating system name
53
+ arch (str): The system architecture (e.g., x86_64, arm64)
54
+ home_dir (str): User's home directory path
55
+ base_dir (str): Base directory for storing FFmpeg binaries
56
+ """
57
+
58
+ def __init__(self):
59
+ self.os_name = self._detect_system()
60
+ self.arch = self._detect_arch()
61
+ self.home_dir = os.path.expanduser('~')
62
+ self.base_dir = self._get_base_directory()
63
+
64
+ def _detect_system(self) -> str:
65
+ """
66
+ Detect and normalize the operating system name.
67
+
68
+ Returns:
69
+ str: Normalized operating system name ('windows', 'darwin', or 'linux')
70
+
71
+ Raises:
72
+ ValueError: If the operating system is not supported
73
+ """
74
+ system = platform.system().lower()
75
+ if system in FFMPEG_CONFIGURATION:
76
+ return system
77
+ raise ValueError(f"Unsupported operating system: {system}")
78
+
79
+ def _detect_arch(self) -> str:
80
+ """
81
+ Detect and normalize the system architecture.
82
+
83
+ Returns:
84
+ str: Normalized architecture name (e.g., 'x86_64', 'arm64')
85
+
86
+ The method normalizes various architecture names to consistent values:
87
+ - amd64/x86_64/x64 -> x86_64
88
+ - arm64/aarch64 -> arm64
89
+ """
90
+ machine = platform.machine().lower()
91
+ arch_map = {
92
+ 'amd64': 'x86_64',
93
+ 'x86_64': 'x86_64',
94
+ 'x64': 'x86_64',
95
+ 'arm64': 'arm64',
96
+ 'aarch64': 'arm64'
97
+ }
98
+ return arch_map.get(machine, machine)
99
+
100
+ def _get_base_directory(self) -> str:
101
+ """
102
+ Get and create the base directory for storing FFmpeg binaries.
103
+
104
+ Returns:
105
+ str: Path to the base directory
106
+
107
+ The directory location varies by operating system:
108
+ - Windows: C:\\binary
109
+ - macOS: ~/Applications/binary
110
+ - Linux: ~/.local/bin/binary
111
+ """
112
+ base_dir = FFMPEG_CONFIGURATION[self.os_name]['base_dir'](self.home_dir)
113
+ os.makedirs(base_dir, exist_ok=True)
114
+ return base_dir
115
+
116
+ def _check_existing_binaries(self) -> Tuple[Optional[str], Optional[str], Optional[str]]:
117
+ """
118
+ Check if FFmpeg binaries already exist in the base directory.
119
+
120
+ Returns:
121
+ Tuple[Optional[str], Optional[str], Optional[str]]: Paths to ffmpeg, ffprobe, and ffplay executables.
122
+ Returns None for each executable that is not found.
123
+ """
124
+ config = FFMPEG_CONFIGURATION[self.os_name]
125
+ executables = config['executables']
126
+ found_executables = []
127
+
128
+ for executable in executables:
129
+ exe_paths = glob.glob(os.path.join(self.base_dir, executable))
130
+ if exe_paths:
131
+ found_executables.append(exe_paths[0])
132
+ else:
133
+ found_executables.append(None)
134
+
135
+ return tuple(found_executables) if len(found_executables) == 3 else (None, None, None)
136
+
137
+ def _get_latest_version(self) -> Optional[str]:
138
+ """
139
+ Get the latest FFmpeg version from the official website.
140
+
141
+ Returns:
142
+ Optional[str]: The latest version string, or None if retrieval fails
143
+
144
+ Raises:
145
+ requests.exceptions.RequestException: If there are network-related errors
146
+ """
147
+ try:
148
+ version_url = 'https://www.gyan.dev/ffmpeg/builds/release-version'
149
+ return requests.get(version_url).text.strip()
150
+ except Exception as e:
151
+ logging.error(f"Unable to get version: {e}")
152
+ return None
153
+
154
+ def _download_file(self, url: str, destination: str) -> bool:
155
+ """
156
+ Download a file from URL with a Rich progress bar display.
157
+
158
+ Parameters:
159
+ url (str): The URL to download the file from. Should be a direct download link.
160
+ destination (str): Local file path where the downloaded file will be saved.
161
+
162
+ Returns:
163
+ bool: True if download was successful, False otherwise.
164
+
165
+ Raises:
166
+ requests.exceptions.RequestException: If there are network-related errors
167
+ IOError: If there are issues writing to the destination file
168
+ """
169
+ try:
170
+ response = requests.get(url, stream=True)
171
+ response.raise_for_status()
172
+ total_size = int(response.headers.get('content-length', 0))
173
+
174
+ with open(destination, 'wb') as file, \
175
+ Progress(
176
+ SpinnerColumn(),
177
+ TextColumn("[progress.description]{task.description}"),
178
+ BarColumn(),
179
+ TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
180
+ TimeRemainingColumn()
181
+ ) as progress:
182
+
183
+ download_task = progress.add_task("[green]Downloading FFmpeg", total=total_size)
184
+ for chunk in response.iter_content(chunk_size=8192):
185
+ size = file.write(chunk)
186
+ progress.update(download_task, advance=size)
187
+ return True
188
+ except Exception as e:
189
+ logging.error(f"Download error: {e}")
190
+ return False
191
+
192
+ def _extract_and_copy_binaries(self, archive_path: str) -> Tuple[Optional[str], Optional[str], Optional[str]]:
193
+ """
194
+ Extract FFmpeg binaries from the downloaded archive and copy them to the base directory.
195
+
196
+ Parameters:
197
+ archive_path (str): Path to the downloaded archive file
198
+
199
+ Returns:
200
+ Tuple[Optional[str], Optional[str], Optional[str]]: Paths to the extracted ffmpeg,
201
+ ffprobe, and ffplay executables. Returns None for each executable that couldn't be extracted.
202
+ """
203
+ try:
204
+ extraction_path = os.path.join(self.base_dir, 'temp_extract')
205
+ os.makedirs(extraction_path, exist_ok=True)
206
+
207
+ if archive_path.endswith('.zip'):
208
+ with zipfile.ZipFile(archive_path, 'r') as zip_ref:
209
+ zip_ref.extractall(extraction_path)
210
+ elif archive_path.endswith('.tar.xz'):
211
+ with tarfile.open(archive_path) as tar_ref:
212
+ tar_ref.extractall(extraction_path)
213
+
214
+ config = FFMPEG_CONFIGURATION[self.os_name]
215
+ executables = config['executables']
216
+ found_paths = []
217
+
218
+ for executable in executables:
219
+ exe_paths = glob.glob(os.path.join(extraction_path, '**', executable), recursive=True)
220
+
221
+ if exe_paths:
222
+ dest_path = os.path.join(self.base_dir, executable)
223
+ shutil.copy2(exe_paths[0], dest_path)
224
+
225
+ if self.os_name != 'windows':
226
+ os.chmod(dest_path, 0o755)
227
+
228
+ found_paths.append(dest_path)
229
+ else:
230
+ found_paths.append(None)
231
+
232
+ shutil.rmtree(extraction_path, ignore_errors=True)
233
+ os.remove(archive_path)
234
+
235
+ return tuple(found_paths) if len(found_paths) == 3 else (None, None, None)
236
+
237
+ except Exception as e:
238
+ logging.error(f"Extraction/copy error: {e}")
239
+ return None, None, None
240
+
241
+ def download(self) -> Tuple[Optional[str], Optional[str], Optional[str]]:
242
+ """
243
+ Main method to download and set up FFmpeg executables.
244
+
245
+ Returns:
246
+ Tuple[Optional[str], Optional[str], Optional[str]]: Paths to ffmpeg, ffprobe, and ffplay executables.
247
+ Returns None for each executable that couldn't be downloaded or set up.
248
+ """
249
+ existing_ffmpeg, existing_ffprobe, existing_ffplay = self._check_existing_binaries()
250
+ if all([existing_ffmpeg, existing_ffprobe, existing_ffplay]):
251
+ return existing_ffmpeg, existing_ffprobe, existing_ffplay
252
+
253
+ version = self._get_latest_version()
254
+ if not version:
255
+ logging.error("Cannot proceed: version not found")
256
+ return None, None, None
257
+
258
+ config = FFMPEG_CONFIGURATION[self.os_name]
259
+ download_url = config['download_url'].format(
260
+ version=version,
261
+ arch=self.arch
262
+ )
263
+
264
+ download_path = os.path.join(
265
+ self.base_dir,
266
+ f'ffmpeg-{version}{config["file_extension"]}'
267
+ )
268
+
269
+ console.print(f"[bold blue]Downloading FFmpeg from:[/] {download_url}")
270
+ if not self._download_file(download_url, download_path):
271
+ return None, None, None
272
+
273
+ return self._extract_and_copy_binaries(download_path)
274
+
275
+ def check_ffmpeg() -> Tuple[Optional[str], Optional[str], Optional[str]]:
276
+ """
277
+ Check for FFmpeg executables in the system and download them if not found.
278
+
279
+ Returns:
280
+ Tuple[Optional[str], Optional[str], Optional[str]]: Paths to ffmpeg, ffprobe, and ffplay executables.
281
+ Returns None for each executable that couldn't be found or downloaded.
282
+
283
+ The function first checks if FFmpeg executables are available in the system PATH:
284
+ - On Windows, uses the 'where' command
285
+ - On Unix-like systems, uses 'which'
286
+
287
+ If the executables are not found in PATH, it attempts to download and install them
288
+ using the FFMPEGDownloader class.
289
+ """
290
+ try:
291
+ if platform.system().lower() == 'windows':
292
+ ffmpeg_path = subprocess.check_output(['where', 'ffmpeg'], text=True).strip().split('\n')[0] if subprocess.call(['where', 'ffmpeg'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0 else None
293
+ ffprobe_path = subprocess.check_output(['where', 'ffprobe'], text=True).strip().split('\n')[0] if subprocess.call(['where', 'ffprobe'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0 else None
294
+ ffplay_path = subprocess.check_output(['where', 'ffplay'], text=True).strip().split('\n')[0] if subprocess.call(['where', 'ffplay'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0 else None
295
+
296
+ if all([ffmpeg_path, ffprobe_path, ffplay_path]):
297
+ return ffmpeg_path, ffprobe_path, ffplay_path
298
+ else:
299
+ ffmpeg_path = shutil.which('ffmpeg')
300
+ ffprobe_path = shutil.which('ffprobe')
301
+ ffplay_path = shutil.which('ffplay')
302
+
303
+ if all([ffmpeg_path, ffprobe_path, ffplay_path]):
304
+ return ffmpeg_path, ffprobe_path, ffplay_path
305
+
306
+ downloader = FFMPEGDownloader()
307
+ return downloader.download()
308
+
309
+ except Exception as e:
310
+ logging.error(f"Error checking FFmpeg: {e}")
311
+ return None, None, None