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.

Files changed (92) hide show
  1. StreamingCommunity/run.py +61 -7
  2. {StreamingCommunity-2.3.0.dist-info → StreamingCommunity-2.5.0.dist-info}/METADATA +88 -18
  3. StreamingCommunity-2.5.0.dist-info/RECORD +8 -0
  4. StreamingCommunity/Api/Player/Helper/Vixcloud/js_parser.py +0 -143
  5. StreamingCommunity/Api/Player/Helper/Vixcloud/util.py +0 -136
  6. StreamingCommunity/Api/Player/ddl.py +0 -89
  7. StreamingCommunity/Api/Player/maxstream.py +0 -151
  8. StreamingCommunity/Api/Player/supervideo.py +0 -194
  9. StreamingCommunity/Api/Player/vixcloud.py +0 -273
  10. StreamingCommunity/Api/Site/1337xx/__init__.py +0 -51
  11. StreamingCommunity/Api/Site/1337xx/costant.py +0 -15
  12. StreamingCommunity/Api/Site/1337xx/site.py +0 -89
  13. StreamingCommunity/Api/Site/1337xx/title.py +0 -66
  14. StreamingCommunity/Api/Site/altadefinizione/__init__.py +0 -51
  15. StreamingCommunity/Api/Site/altadefinizione/costant.py +0 -19
  16. StreamingCommunity/Api/Site/altadefinizione/film.py +0 -74
  17. StreamingCommunity/Api/Site/altadefinizione/site.py +0 -95
  18. StreamingCommunity/Api/Site/animeunity/__init__.py +0 -51
  19. StreamingCommunity/Api/Site/animeunity/costant.py +0 -19
  20. StreamingCommunity/Api/Site/animeunity/film_serie.py +0 -135
  21. StreamingCommunity/Api/Site/animeunity/site.py +0 -175
  22. StreamingCommunity/Api/Site/animeunity/util/ScrapeSerie.py +0 -97
  23. StreamingCommunity/Api/Site/cb01new/__init__.py +0 -52
  24. StreamingCommunity/Api/Site/cb01new/costant.py +0 -19
  25. StreamingCommunity/Api/Site/cb01new/film.py +0 -73
  26. StreamingCommunity/Api/Site/cb01new/site.py +0 -83
  27. StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py +0 -56
  28. StreamingCommunity/Api/Site/ddlstreamitaly/costant.py +0 -20
  29. StreamingCommunity/Api/Site/ddlstreamitaly/series.py +0 -146
  30. StreamingCommunity/Api/Site/ddlstreamitaly/site.py +0 -99
  31. StreamingCommunity/Api/Site/ddlstreamitaly/util/ScrapeSerie.py +0 -85
  32. StreamingCommunity/Api/Site/guardaserie/__init__.py +0 -51
  33. StreamingCommunity/Api/Site/guardaserie/costant.py +0 -19
  34. StreamingCommunity/Api/Site/guardaserie/series.py +0 -198
  35. StreamingCommunity/Api/Site/guardaserie/site.py +0 -90
  36. StreamingCommunity/Api/Site/guardaserie/util/ScrapeSerie.py +0 -110
  37. StreamingCommunity/Api/Site/ilcorsaronero/__init__.py +0 -52
  38. StreamingCommunity/Api/Site/ilcorsaronero/costant.py +0 -19
  39. StreamingCommunity/Api/Site/ilcorsaronero/site.py +0 -72
  40. StreamingCommunity/Api/Site/ilcorsaronero/title.py +0 -46
  41. StreamingCommunity/Api/Site/ilcorsaronero/util/ilCorsarScraper.py +0 -149
  42. StreamingCommunity/Api/Site/mostraguarda/__init__.py +0 -49
  43. StreamingCommunity/Api/Site/mostraguarda/costant.py +0 -19
  44. StreamingCommunity/Api/Site/mostraguarda/film.py +0 -101
  45. StreamingCommunity/Api/Site/streamingcommunity/__init__.py +0 -56
  46. StreamingCommunity/Api/Site/streamingcommunity/costant.py +0 -19
  47. StreamingCommunity/Api/Site/streamingcommunity/film.py +0 -75
  48. StreamingCommunity/Api/Site/streamingcommunity/series.py +0 -206
  49. StreamingCommunity/Api/Site/streamingcommunity/site.py +0 -139
  50. StreamingCommunity/Api/Site/streamingcommunity/util/ScrapeSerie.py +0 -123
  51. StreamingCommunity/Api/Template/Class/SearchType.py +0 -101
  52. StreamingCommunity/Api/Template/Util/__init__.py +0 -5
  53. StreamingCommunity/Api/Template/Util/get_domain.py +0 -137
  54. StreamingCommunity/Api/Template/Util/manage_ep.py +0 -179
  55. StreamingCommunity/Api/Template/Util/recall_search.py +0 -37
  56. StreamingCommunity/Api/Template/__init__.py +0 -3
  57. StreamingCommunity/Api/Template/site.py +0 -87
  58. StreamingCommunity/Lib/Downloader/HLS/downloader.py +0 -955
  59. StreamingCommunity/Lib/Downloader/HLS/proxyes.py +0 -110
  60. StreamingCommunity/Lib/Downloader/HLS/segments.py +0 -564
  61. StreamingCommunity/Lib/Downloader/MP4/downloader.py +0 -155
  62. StreamingCommunity/Lib/Downloader/TOR/downloader.py +0 -296
  63. StreamingCommunity/Lib/Downloader/__init__.py +0 -5
  64. StreamingCommunity/Lib/FFmpeg/__init__.py +0 -4
  65. StreamingCommunity/Lib/FFmpeg/capture.py +0 -170
  66. StreamingCommunity/Lib/FFmpeg/command.py +0 -296
  67. StreamingCommunity/Lib/FFmpeg/util.py +0 -249
  68. StreamingCommunity/Lib/M3U8/__init__.py +0 -6
  69. StreamingCommunity/Lib/M3U8/decryptor.py +0 -164
  70. StreamingCommunity/Lib/M3U8/estimator.py +0 -229
  71. StreamingCommunity/Lib/M3U8/parser.py +0 -666
  72. StreamingCommunity/Lib/M3U8/url_fixer.py +0 -52
  73. StreamingCommunity/Lib/TMBD/__init__.py +0 -2
  74. StreamingCommunity/Lib/TMBD/obj_tmbd.py +0 -39
  75. StreamingCommunity/Lib/TMBD/tmdb.py +0 -346
  76. StreamingCommunity/Upload/update.py +0 -67
  77. StreamingCommunity/Upload/version.py +0 -5
  78. StreamingCommunity/Util/_jsonConfig.py +0 -204
  79. StreamingCommunity/Util/call_stack.py +0 -42
  80. StreamingCommunity/Util/color.py +0 -20
  81. StreamingCommunity/Util/console.py +0 -12
  82. StreamingCommunity/Util/ffmpeg_installer.py +0 -351
  83. StreamingCommunity/Util/headers.py +0 -147
  84. StreamingCommunity/Util/logger.py +0 -53
  85. StreamingCommunity/Util/message.py +0 -64
  86. StreamingCommunity/Util/os.py +0 -545
  87. StreamingCommunity/Util/table.py +0 -229
  88. StreamingCommunity-2.3.0.dist-info/RECORD +0 -92
  89. {StreamingCommunity-2.3.0.dist-info → StreamingCommunity-2.5.0.dist-info}/LICENSE +0 -0
  90. {StreamingCommunity-2.3.0.dist-info → StreamingCommunity-2.5.0.dist-info}/WHEEL +0 -0
  91. {StreamingCommunity-2.3.0.dist-info → StreamingCommunity-2.5.0.dist-info}/entry_points.txt +0 -0
  92. {StreamingCommunity-2.3.0.dist-info → StreamingCommunity-2.5.0.dist-info}/top_level.txt +0 -0
@@ -1,955 +0,0 @@
1
- # 17.10.24
2
-
3
- import os
4
- import sys
5
- import logging
6
-
7
-
8
- # External libraries
9
- import httpx
10
-
11
-
12
- # Internal utilities
13
- from StreamingCommunity.Util._jsonConfig import config_manager
14
- from StreamingCommunity.Util.console import console, Panel, Table
15
- from StreamingCommunity.Util.color import Colors
16
- from StreamingCommunity.Util.os import (
17
- compute_sha1_hash,
18
- os_manager,
19
- internet_manager
20
- )
21
-
22
- # Logic class
23
- from ...FFmpeg import (
24
- print_duration_table,
25
- join_video,
26
- join_audios,
27
- join_subtitle
28
- )
29
- from ...M3U8 import (
30
- M3U8_Parser,
31
- M3U8_Codec,
32
- M3U8_UrlFix
33
- )
34
- from .segments import M3U8_Segments
35
-
36
-
37
- # Config
38
- DOWNLOAD_SPECIFIC_AUDIO = config_manager.get_list('M3U8_DOWNLOAD', 'specific_list_audio')
39
- DOWNLOAD_SPECIFIC_SUBTITLE = config_manager.get_list('M3U8_DOWNLOAD', 'specific_list_subtitles')
40
- DOWNLOAD_VIDEO = config_manager.get_bool('M3U8_DOWNLOAD', 'download_video')
41
- DOWNLOAD_AUDIO = config_manager.get_bool('M3U8_DOWNLOAD', 'download_audio')
42
- MERGE_AUDIO = config_manager.get_bool('M3U8_DOWNLOAD', 'merge_audio')
43
- DOWNLOAD_SUBTITLE = config_manager.get_bool('M3U8_DOWNLOAD', 'download_sub')
44
- MERGE_SUBTITLE = config_manager.get_bool('M3U8_DOWNLOAD', 'merge_subs')
45
- REMOVE_SEGMENTS_FOLDER = config_manager.get_bool('M3U8_DOWNLOAD', 'cleanup_tmp_folder')
46
- FILTER_CUSTOM_REOLUTION = config_manager.get_int('M3U8_PARSER', 'force_resolution')
47
- GET_ONLY_LINK = config_manager.get_bool('M3U8_PARSER', 'get_only_link')
48
-
49
-
50
- # Variable
51
- max_timeout = config_manager.get_int("REQUESTS", "timeout")
52
- m3u8_url_fixer = M3U8_UrlFix()
53
- list_MissingTs = []
54
-
55
-
56
-
57
- class PathManager:
58
- def __init__(self, output_filename):
59
- """
60
- Initializes the PathManager with the output filename.
61
-
62
- Args:
63
- output_filename (str): The name of the output file (should end with .mp4).
64
- """
65
- self.output_filename = output_filename
66
-
67
- # Create the base path by removing the '.mp4' extension from the output filename
68
- self.base_path = str(output_filename).replace(".mp4", "")
69
- logging.info(f"class 'PathManager'; set base path: {self.base_path}")
70
-
71
- # Define the path for a temporary directory where segments will be stored
72
- self.base_temp = os.path.join(self.base_path, "tmp")
73
- self.video_segments_path = os.path.join(self.base_temp, "video")
74
- self.audio_segments_path = os.path.join(self.base_temp, "audio")
75
- self.subtitle_segments_path = os.path.join(self.base_temp, "subtitle")
76
-
77
- def create_directories(self):
78
- """
79
- Creates the necessary directories for storing video, audio, and subtitle segments.
80
- """
81
-
82
- os.makedirs(self.base_temp, exist_ok=True)
83
- os.makedirs(self.video_segments_path, exist_ok=True)
84
- os.makedirs(self.audio_segments_path, exist_ok=True)
85
- os.makedirs(self.subtitle_segments_path, exist_ok=True)
86
-
87
-
88
- class HttpClient:
89
- def __init__(self, headers: str = None):
90
- """
91
- Initializes the HttpClient with specified headers.
92
- """
93
- self.headers = headers
94
-
95
- def get(self, url: str):
96
- """
97
- Sends a GET request to the specified URL and returns the response as text.
98
-
99
- Returns:
100
- str: The response body as text if the request is successful, None otherwise.
101
- """
102
- logging.info(f"class 'HttpClient'; make request: {url}")
103
- try:
104
- response = httpx.get(
105
- url=url,
106
- headers=self.headers,
107
- timeout=max_timeout,
108
- follow_redirects=True
109
- )
110
-
111
- response.raise_for_status()
112
- return response.text
113
-
114
- except Exception as e:
115
- console.print(f"Request to {url} failed with error: {e}")
116
- return 404
117
-
118
- def get_content(self, url):
119
- """
120
- Sends a GET request to the specified URL and returns the raw response content.
121
-
122
- Returns:
123
- bytes: The response content as bytes if the request is successful, None otherwise.
124
- """
125
- logging.info(f"class 'HttpClient'; make request: {url}")
126
- try:
127
- response = httpx.get(
128
- url=url,
129
- headers=self.headers,
130
- timeout=max_timeout
131
- )
132
-
133
- response.raise_for_status()
134
- return response.content # Return the raw response content
135
-
136
- except Exception as e:
137
- logging.error(f"Request to {url} failed: {response.status_code} when get content.")
138
- return None
139
-
140
-
141
- class ContentExtractor:
142
- def __init__(self):
143
- """
144
- This class is responsible for extracting audio, subtitle, and video information from an M3U8 playlist.
145
- """
146
- pass
147
-
148
- def start(self, obj_parse: M3U8_Parser):
149
- """
150
- Starts the extraction process by parsing the M3U8 playlist and collecting audio, subtitle, and video data.
151
-
152
- Args:
153
- obj_parse (str): The M3U8_Parser obj of the M3U8 playlist.
154
- """
155
-
156
- self.obj_parse = obj_parse
157
-
158
- # Collect audio, subtitle, and video information
159
- self._collect_audio()
160
- self._collect_subtitle()
161
- self._collect_video()
162
-
163
- def _collect_audio(self):
164
- """
165
- It checks for available audio languages and the specific audio tracks to download.
166
- """
167
- logging.info(f"class 'ContentExtractor'; call _collect_audio()")
168
-
169
- # Collect available audio tracks and their corresponding URIs and names
170
- self.list_available_audio = self.obj_parse._audio.get_all_uris_and_names()
171
-
172
- # Check if there are any audio tracks available; if not, disable download
173
- if self.list_available_audio is not None:
174
-
175
- # Extract available languages from the audio tracks
176
- available_languages = [obj_audio.get('language') for obj_audio in self.list_available_audio]
177
- set_language = DOWNLOAD_SPECIFIC_AUDIO
178
- downloadable_languages = list(set(available_languages) & set(set_language))
179
-
180
- # Only show if there is something available
181
- if len(available_languages) > 0:
182
- console.print(f"[cyan bold]Audio →[/cyan bold] [green]Available:[/green] [purple]{', '.join(available_languages)}[/purple] | "
183
- f"[red]Set:[/red] [purple]{', '.join(set_language)}[/purple] | "
184
- f"[yellow]Downloadable:[/yellow] [purple]{', '.join(downloadable_languages)}[/purple]")
185
-
186
- else:
187
- console.log("[red]Can't find a list of audios")
188
-
189
- def _collect_subtitle(self):
190
- """
191
- It checks for available subtitle languages and the specific subtitles to download.
192
- """
193
- logging.info(f"class 'ContentExtractor'; call _collect_subtitle()")
194
-
195
- # Collect available subtitles and their corresponding URIs and names
196
- self.list_available_subtitles = self.obj_parse._subtitle.get_all_uris_and_names()
197
-
198
- # Check if there are any subtitles available; if not, disable download
199
- if self.list_available_subtitles is not None:
200
-
201
- # Extract available languages from the subtitles
202
- available_languages = [obj_subtitle.get('language') for obj_subtitle in self.list_available_subtitles]
203
- set_language = DOWNLOAD_SPECIFIC_SUBTITLE
204
- downloadable_languages = list(set(available_languages) & set(set_language))
205
-
206
- # Only show if there is something available
207
- if len(available_languages) > 0:
208
- console.print(f"[cyan bold]Subtitle →[/cyan bold] [green]Available:[/green] [purple]{', '.join(available_languages)}[/purple] | "
209
- f"[red]Set:[/red] [purple]{', '.join(set_language)}[/purple] | "
210
- f"[yellow]Downloadable:[/yellow] [purple]{', '.join(downloadable_languages)}[/purple]")
211
-
212
- else:
213
- console.log("[red]Can't find a list of subtitles")
214
-
215
- def _collect_video(self):
216
- """
217
- It identifies the best video quality and displays relevant information to the user.
218
- """
219
- logging.info(f"class 'ContentExtractor'; call _collect_video()")
220
- set_resolution = "Best"
221
-
222
- # Collect custom quality video if a specific resolution is set
223
- if FILTER_CUSTOM_REOLUTION != -1:
224
- self.m3u8_index, video_res = self.obj_parse._video.get_custom_uri(y_resolution=FILTER_CUSTOM_REOLUTION)
225
- set_resolution = f"{FILTER_CUSTOM_REOLUTION}p"
226
-
227
- else:
228
-
229
- # Otherwise, get the best available video quality
230
- self.m3u8_index, video_res = self.obj_parse._video.get_best_uri()
231
-
232
- self.codec: M3U8_Codec = self.obj_parse.codec
233
-
234
- # List all available resolutions
235
- tuple_available_resolution = self.obj_parse._video.get_list_resolution()
236
- list_available_resolution = [str(resolution[0]) + "x" + str(resolution[1]) for resolution in tuple_available_resolution]
237
- logging.info(f"M3U8 index selected: {self.m3u8_index}, with resolution: {video_res}")
238
-
239
- # Create a formatted table to display video info
240
- console.print(f"[cyan bold]Video →[/cyan bold] [green]Available:[/green] [purple]{', '.join(list_available_resolution)}[/purple] | "
241
- f"[red]Set:[/red] [purple]{set_resolution}[/purple] | "
242
- f"[yellow]Downloadable:[/yellow] [purple]{video_res[0]}x{video_res[1]}[/purple]")
243
-
244
- if self.codec is not None:
245
-
246
- # Generate the string for available codec information
247
- available_codec_info = (
248
- f"[green]v[/green]: [yellow]{self.codec.video_codec_name}[/yellow] "
249
- f"([green]b[/green]: [yellow]{self.codec.video_bitrate // 1000}k[/yellow]), "
250
- f"[green]a[/green]: [yellow]{self.codec.audio_codec_name}[/yellow] "
251
- f"([green]b[/green]: [yellow]{self.codec.audio_bitrate // 1000}k[/yellow])"
252
- )
253
-
254
- # Determine what to display for "Set"
255
- # If the codec usage is enabled in the configuration, use the detailed codec info
256
- # Otherwise, display "copy"
257
- if config_manager.get_bool("M3U8_CONVERSION", "use_codec"):
258
- set_codec_info = available_codec_info
259
- else:
260
- set_codec_info = "[purple]copy[/purple]"
261
-
262
- # Print the formatted result with "Available" and "Set" information
263
- console.print(
264
- f"[bold cyan]Codec →[/bold cyan] [green]Available:[/green] {available_codec_info} | "
265
- f"[red]Set:[/red] {set_codec_info}"
266
- )
267
-
268
-
269
- # Fix the URL if it does not include the full protocol
270
- if "http" not in self.m3u8_index:
271
-
272
- # Generate the full URL
273
- self.m3u8_index = m3u8_url_fixer.generate_full_url(self.m3u8_index)
274
- logging.info(f"Generated index URL: {self.m3u8_index}")
275
-
276
- # Check if a valid HTTPS URL is obtained
277
- if self.m3u8_index is not None and "https" in self.m3u8_index:
278
- #console.print(f"[cyan]Found m3u8 index [white]=> [red]{self.m3u8_index}")
279
- print()
280
-
281
- else:
282
- logging.error("[download_m3u8] Can't find a valid m3u8 index")
283
- raise ValueError("Invalid m3u8 index URL")
284
-
285
- print("")
286
-
287
- class DownloadTracker:
288
- def __init__(self, path_manager: PathManager):
289
- """
290
- Initializes the DownloadTracker with paths for audio, subtitle, and video segments.
291
-
292
- Args:
293
- path_manager (PathManager): An instance of the PathManager class to manage file paths.
294
- """
295
-
296
- # Initialize lists to track downloaded audio, subtitles, and video
297
- self.downloaded_audio = []
298
- self.downloaded_subtitle = []
299
- self.downloaded_video = []
300
-
301
- self.video_segment_path = path_manager.video_segments_path
302
- self.audio_segments_path = path_manager.audio_segments_path
303
- self.subtitle_segments_path = path_manager.subtitle_segments_path
304
-
305
- def add_video(self, available_video):
306
- """
307
- Adds a single video to the list of downloaded videos.
308
-
309
- Args:
310
- available_video (str): The URL of the video to be downloaded.
311
- """
312
- logging.info(f"class 'DownloadTracker'; call add_video() with parameter: {available_video}")
313
-
314
- self.downloaded_video.append({
315
- 'type': 'video',
316
- 'url': available_video,
317
- 'path': os.path.join(self.video_segment_path, "0.ts")
318
- })
319
-
320
- def add_audio(self, list_available_audio):
321
- """
322
- Adds available audio tracks to the list of downloaded audio.
323
-
324
- Args:
325
- list_available_audio (list): A list of available audio track objects.
326
- """
327
- logging.info(f"class 'DownloadTracker'; call add_audio() with parameter: {list_available_audio}")
328
-
329
- for obj_audio in list_available_audio:
330
-
331
- # Check if specific audio languages are set for download
332
- if len(DOWNLOAD_SPECIFIC_AUDIO) > 0:
333
-
334
- # Skip this audio track if its language is not in the specified list
335
- if obj_audio.get('language') not in DOWNLOAD_SPECIFIC_AUDIO:
336
- continue
337
-
338
- # Construct the full path for the audio segment directory
339
- full_path_audio = os.path.join(self.audio_segments_path, obj_audio.get('language'))
340
-
341
- # Append the audio information to the downloaded audio list
342
- self.downloaded_audio.append({
343
- 'type': 'audio',
344
- 'url': obj_audio.get('uri'),
345
- 'language': obj_audio.get('language'),
346
- 'path': os.path.join(full_path_audio, "0.ts")
347
- })
348
-
349
- def add_subtitle(self, list_available_subtitles):
350
- """
351
- Adds available subtitles to the list of downloaded subtitles.
352
-
353
- Args:
354
- list_available_subtitles (list): A list of available subtitle objects.
355
- """
356
- logging.info(f"class 'DownloadTracker'; call add_subtitle() with parameter: {list_available_subtitles}")
357
-
358
- for obj_subtitle in list_available_subtitles:
359
-
360
- # Check if specific subtitle languages are set for download
361
- if len(DOWNLOAD_SPECIFIC_SUBTITLE) > 0:
362
-
363
- # Skip this subtitle if its language is not in the specified list
364
- if obj_subtitle.get('language') not in DOWNLOAD_SPECIFIC_SUBTITLE:
365
- continue
366
-
367
- sub_language = obj_subtitle.get('language')
368
-
369
- # Construct the full path for the subtitle file
370
- sub_full_path = os.path.join(self.subtitle_segments_path, sub_language + ".vtt")
371
-
372
- self.downloaded_subtitle.append({
373
- 'type': 'sub',
374
- 'url': obj_subtitle.get('uri'),
375
- 'language': obj_subtitle.get('language'),
376
- 'path': sub_full_path
377
- })
378
-
379
-
380
- class ContentDownloader:
381
- def __init__(self):
382
- """
383
- Initializes the ContentDownloader class.
384
-
385
- Attributes:
386
- expected_real_time (float): Expected real-time duration of the video download.
387
- """
388
- self.expected_real_time = None
389
-
390
- def download_video(self, downloaded_video):
391
- """
392
- Downloads the video if it doesn't already exist.
393
-
394
- Args:
395
- downloaded_video (list): A list containing information about the video to download.
396
- """
397
- logging.info(f"class 'ContentDownloader'; call download_video() with parameter: {downloaded_video}")
398
-
399
- # Check if the video file already exists
400
- if not os.path.exists(downloaded_video[0].get('path')):
401
- folder_name = os.path.dirname(downloaded_video[0].get('path'))
402
-
403
- # Create an instance of M3U8_Segments to handle video segments download
404
- video_m3u8 = M3U8_Segments(downloaded_video[0].get('url'), folder_name)
405
-
406
- # Get information about the video segments (e.g., duration, ts files to download)
407
- video_m3u8.get_info()
408
-
409
- # Store the expected real-time duration of the video
410
- self.expected_real_time = video_m3u8.expected_real_time
411
-
412
- # Download the video streams and print status
413
- info_dw = video_m3u8.download_streams(f"{Colors.MAGENTA}video", "video")
414
- list_MissingTs.append(info_dw)
415
-
416
- # Print duration information of the downloaded video
417
- #print_duration_table(downloaded_video[0].get('path'))
418
-
419
- else:
420
- console.log("[cyan]Video [red]already exists.")
421
-
422
- def download_audio(self, downloaded_audio):
423
- """
424
- Downloads audio tracks if they don't already exist.
425
-
426
- Args:
427
- downloaded_audio (list): A list containing information about audio tracks to download.
428
- """
429
- logging.info(f"class 'ContentDownloader'; call download_audio() with parameter: {downloaded_audio}")
430
-
431
- for obj_audio in downloaded_audio:
432
- folder_name = os.path.dirname(obj_audio.get('path'))
433
-
434
- # Check if the audio file already exists
435
- if not os.path.exists(obj_audio.get('path')):
436
-
437
- # Create an instance of M3U8_Segments to handle audio segments download
438
- audio_m3u8 = M3U8_Segments(obj_audio.get('url'), folder_name)
439
-
440
- # Get information about the audio segments (e.g., duration, ts files to download)
441
- audio_m3u8.get_info()
442
-
443
- # Download the audio segments and print status
444
- info_dw = audio_m3u8.download_streams(f"{Colors.MAGENTA}audio {Colors.RED}{obj_audio.get('language')}", f"audio_{obj_audio.get('language')}")
445
- list_MissingTs.append(info_dw)
446
-
447
- # Print duration information of the downloaded audio
448
- #print_duration_table(obj_audio.get('path'))
449
-
450
- else:
451
- console.log(f"[cyan]Audio [white]([green]{obj_audio.get('language')}[white]) [red]already exists.")
452
-
453
- def download_subtitle(self, downloaded_subtitle):
454
- """
455
- Downloads subtitle files if they don't already exist.
456
-
457
- Args:
458
- downloaded_subtitle (list): A list containing information about subtitles to download.
459
- """
460
- logging.info(f"class 'ContentDownloader'; call download_subtitle() with parameter: {downloaded_subtitle}")
461
-
462
- for obj_subtitle in downloaded_subtitle:
463
- sub_language = obj_subtitle.get('language')
464
-
465
- # Check if the subtitle file already exists
466
- if os.path.exists(obj_subtitle.get("path")):
467
- console.log(f"[cyan]Subtitle [white]([green]{sub_language}[white]) [red]already exists.")
468
- continue # Skip to the next subtitle if it exists
469
-
470
- # Parse the M3U8 file to get the subtitle URI
471
- m3u8_sub_parser = M3U8_Parser()
472
- m3u8_sub_parser.parse_data(
473
- uri=obj_subtitle.get('uri'),
474
- raw_content=httpx.get(obj_subtitle.get('url')).text # Fetch subtitle content
475
- )
476
-
477
- # Print the status of the subtitle download
478
- #console.print(f"[cyan]Downloading subtitle: [red]{sub_language.lower()}")
479
-
480
- # Write the content to the specified file
481
- with open(obj_subtitle.get("path"), "wb") as f:
482
- f.write(HttpClient().get_content(m3u8_sub_parser.subtitle[-1]))
483
-
484
-
485
- class ContentJoiner:
486
- def __init__(self, path_manager):
487
- """
488
- Initializes the ContentJoiner class.
489
-
490
- Args:
491
- path_manager (PathManager): An instance of PathManager to manage output paths.
492
- """
493
- self.path_manager: PathManager = path_manager
494
-
495
- def setup(self, downloaded_video, downloaded_audio, downloaded_subtitle, codec = None):
496
- """
497
- Sets up the content joiner with downloaded media files.
498
-
499
- Args:
500
- downloaded_video (list): List of downloaded video information.
501
- downloaded_audio (list): List of downloaded audio information.
502
- downloaded_subtitle (list): List of downloaded subtitle information.
503
- """
504
- self.downloaded_video = downloaded_video
505
- self.downloaded_audio = downloaded_audio
506
- self.downloaded_subtitle = downloaded_subtitle
507
- self.codec = codec
508
-
509
- # Initialize flags to check if media is available
510
- self.converted_out_path = None
511
- self.there_is_video = len(downloaded_video) > 0
512
- self.there_is_audio = len(downloaded_audio) > 0
513
- self.there_is_subtitle = len(downloaded_subtitle) > 0
514
-
515
- # Start the joining process
516
- self.conversione()
517
-
518
- def conversione(self):
519
- """
520
- Handles the joining of video, audio, and subtitles based on availability.
521
- """
522
-
523
- # Join audio and video if audio is available
524
- if self.there_is_audio:
525
- if MERGE_AUDIO:
526
-
527
- # Join video with audio tracks
528
- self.converted_out_path = self._join_video_audio()
529
-
530
- else:
531
-
532
- # Process each available audio track
533
- for obj_audio in self.downloaded_audio:
534
- language = obj_audio.get('language')
535
- path = obj_audio.get('path')
536
-
537
- # Set the new path for regular audio
538
- new_path = self.path_manager.output_filename.replace(".mp4", f"_{language}.mp4")
539
-
540
- try:
541
-
542
- # Rename the audio file to the new path
543
- os.rename(path, new_path)
544
- logging.info(f"Audio moved to {new_path}")
545
-
546
- except Exception as e:
547
- logging.error(f"Failed to move audio {path} to {new_path}: {e}")
548
-
549
- # Convert video if available
550
- if self.there_is_video:
551
- self.converted_out_path = self._join_video()
552
-
553
- # If no audio but video is available, join video
554
- else:
555
- if self.there_is_video:
556
- self.converted_out_path = self._join_video()
557
-
558
- # Join subtitles if available
559
- if self.there_is_subtitle:
560
- if MERGE_SUBTITLE:
561
- if self.converted_out_path is not None:
562
- self.converted_out_path = self._join_video_subtitles(self.converted_out_path)
563
-
564
- else:
565
-
566
- # Process each available subtitle track
567
- for obj_sub in self.downloaded_subtitle:
568
- language = obj_sub.get('language')
569
- path = obj_sub.get('path')
570
- forced = 'forced' in language
571
-
572
- # Adjust the language name and set the new path based on forced status
573
- if forced:
574
- language = language.replace("forced-", "")
575
- new_path = self.path_manager.output_filename.replace(".mp4", f".{language}.forced.vtt")
576
- else:
577
- new_path = self.path_manager.output_filename.replace(".mp4", f".{language}.vtt")
578
-
579
- try:
580
- # Rename the subtitle file to the new path
581
- os.rename(path, new_path)
582
- logging.info(f"Subtitle moved to {new_path}")
583
-
584
- except Exception as e:
585
- logging.error(f"Failed to move subtitle {path} to {new_path}: {e}")
586
-
587
- def _join_video(self):
588
- """
589
- Joins video segments into a single video file.
590
-
591
- Returns:
592
- str: The path to the joined video file.
593
- """
594
- path_join_video = os.path.join(self.path_manager.base_path, "v_v.mp4")
595
- logging.info(f"JOIN video path: {path_join_video}")
596
-
597
- # Check if the joined video file already exists
598
- if not os.path.exists(path_join_video):
599
-
600
- # Join the video segments into a single video file
601
- join_video(
602
- video_path=self.downloaded_video[0].get('path'),
603
- out_path=path_join_video,
604
- codec=self.codec
605
- )
606
-
607
- else:
608
- console.log("[red]Output join video already exists.")
609
-
610
- return path_join_video
611
-
612
- def _join_video_audio(self):
613
- """
614
- Joins video segments with audio tracks into a single video with audio file.
615
-
616
- Returns:
617
- str: The path to the joined video with audio file.
618
- """
619
- path_join_video_audio = os.path.join(self.path_manager.base_path, "v_a.mp4")
620
- logging.info(f"JOIN audio path: {path_join_video_audio}")
621
-
622
- # Check if the joined video with audio file already exists
623
- if not os.path.exists(path_join_video_audio):
624
-
625
- # Set codec to None if not defined in class
626
- #if not hasattr(self, 'codec'):
627
- # self.codec = None
628
-
629
- # Join the video with audio segments
630
- join_audios(
631
- video_path=self.downloaded_video[0].get('path'),
632
- audio_tracks=self.downloaded_audio,
633
- out_path=path_join_video_audio,
634
- codec=self.codec
635
- )
636
-
637
- else:
638
- console.log("[red]Output join video and audio already exists.")
639
-
640
- return path_join_video_audio
641
-
642
- def _join_video_subtitles(self, input_path):
643
- """
644
- Joins subtitles with the video.
645
-
646
- Args:
647
- input_path (str): The path to the video file to which subtitles will be added.
648
-
649
- Returns:
650
- str: The path to the video with subtitles file.
651
- """
652
- path_join_video_subtitle = os.path.join(self.path_manager.base_path, "v_s.mp4")
653
- logging.info(f"JOIN subtitle path: {path_join_video_subtitle}")
654
-
655
- # Check if the video with subtitles file already exists
656
- if not os.path.exists(path_join_video_subtitle):
657
-
658
- # Join the video with subtitles
659
- join_subtitle(
660
- input_path,
661
- self.downloaded_subtitle,
662
- path_join_video_subtitle
663
- )
664
-
665
- return path_join_video_subtitle
666
-
667
-
668
- class HLS_Downloader:
669
- def __init__(self, output_filename: str=None, m3u8_playlist: str=None, m3u8_index: str=None, is_playlist_url: bool=True, is_index_url: bool=True):
670
- """
671
- Initializes the HLS_Downloader class.
672
-
673
- Args:
674
- output_filename (str): The desired output filename for the downloaded content.
675
- m3u8_playlist (str): The URL or content of the m3u8 playlist.
676
- m3u8_index (str): The index URL for m3u8 streams.
677
- is_playlist_url (bool): Flag indicating if the m3u8_playlist is a URL.
678
- is_index_url (bool): Flag indicating if the m3u8_index is a URL.
679
- """
680
- if ((m3u8_playlist == None or m3u8_playlist == "") and output_filename is None) or ((m3u8_index == None or m3u8_index == "") and output_filename is None):
681
- logging.info(f"class 'HLS_Downloader'; call __init__(); no parameter")
682
- sys.exit(0)
683
-
684
- self.output_filename = self._generate_output_filename(output_filename, m3u8_playlist, m3u8_index)
685
- self.path_manager = PathManager(self.output_filename)
686
- self.download_tracker = DownloadTracker(self.path_manager)
687
- self.content_extractor = ContentExtractor()
688
- self.content_downloader = ContentDownloader()
689
- self.content_joiner = ContentJoiner(self.path_manager)
690
-
691
- self.m3u8_playlist = m3u8_playlist
692
- self.m3u8_index = m3u8_index
693
- self.is_playlist_url = is_playlist_url
694
- self.is_index_url = is_index_url
695
- self.expected_real_time = None
696
- self.instace_parserClass = M3U8_Parser()
697
-
698
- self.request_m3u8_playlist = None
699
- self.request_m3u8_index = None
700
- if (m3u8_playlist == None or m3u8_playlist == ""):
701
- self.request_m3u8_index = HttpClient().get(self.m3u8_index)
702
- if (m3u8_index == None or m3u8_index == ""):
703
- self.request_m3u8_playlist = HttpClient().get(self.m3u8_playlist)
704
-
705
- def _generate_output_filename(self, output_filename, m3u8_playlist, m3u8_index):
706
- """
707
- Generates a valid output filename based on provided parameters.
708
-
709
- Args:
710
- output_filename (str): The desired output filename.
711
- m3u8_playlist (str): The m3u8 playlist URL or content.
712
- m3u8_index (str): The m3u8 index URL.
713
-
714
- Returns:
715
- str: The generated output filename.
716
- """
717
- root_path = config_manager.get('DEFAULT', 'root_path')
718
- new_filename = None
719
- new_folder = os.path.join(root_path, "undefined")
720
- logging.info(f"class 'HLS_Downloader'; call _generate_output_filename(); destination folder: {new_folder}")
721
-
722
- # Auto-generate output file name if not present
723
- if (output_filename is None) or ("mp4" not in output_filename):
724
- if m3u8_playlist is not None:
725
- new_filename = os.path.join(new_folder, compute_sha1_hash(m3u8_playlist) + ".mp4")
726
- else:
727
- new_filename = os.path.join(new_folder, compute_sha1_hash(m3u8_index) + ".mp4")
728
-
729
- else:
730
-
731
- # Check if output_filename contains a folder path
732
- folder, base_name = os.path.split(output_filename)
733
-
734
- # If no folder is specified, default to 'undefined'
735
- if not folder:
736
- folder = new_folder
737
-
738
- # Sanitize base name and folder
739
- folder = os_manager.get_sanitize_path(folder)
740
- base_name = os_manager.get_sanitize_file(base_name)
741
- os_manager.create_path(folder)
742
-
743
- # Parse to only ASCII for compatibility across platforms
744
- new_filename = os.path.join(folder, base_name)
745
-
746
- logging.info(f"class 'HLS_Downloader'; call _generate_output_filename(); return path: {new_filename}")
747
- return new_filename
748
-
749
- def start(self):
750
- """
751
- Initiates the downloading process. Checks if the output file already exists and proceeds with processing the playlist or index.
752
- """
753
- if os.path.exists(self.output_filename):
754
- console.log("[red]Output file already exists.")
755
- return 400
756
-
757
- self.path_manager.create_directories()
758
-
759
- # Determine whether to process a playlist or index
760
- if self.m3u8_playlist:
761
- if self.m3u8_playlist is not None:
762
- if self.request_m3u8_playlist != 404:
763
- logging.info(f"class 'HLS_Downloader'; call start(); parse m3u8 data")
764
-
765
- self.instace_parserClass.parse_data(uri=self.m3u8_playlist, raw_content=self.request_m3u8_playlist)
766
- is_masterPlaylist = self.instace_parserClass.is_master_playlist
767
-
768
- # Check if it's a real master playlist
769
- if is_masterPlaylist:
770
- if not GET_ONLY_LINK:
771
- r_proc = self._process_playlist()
772
-
773
- if r_proc == 404:
774
- return 404
775
- else:
776
- return None
777
-
778
- else:
779
- return {
780
- 'path': self.output_filename,
781
- 'url': self.m3u8_playlist
782
- }
783
-
784
- else:
785
- console.log("[red]Error: URL passed to M3U8_Parser is an index playlist; expected a master playlist. Crucimorfo strikes again!")
786
- else:
787
- console.log(f"[red]Error: m3u8_playlist failed request for: {self.m3u8_playlist}")
788
- else:
789
- console.log("[red]Error: m3u8_playlist is None")
790
-
791
- elif self.m3u8_index:
792
- if self.m3u8_index is not None:
793
- if self.request_m3u8_index != 404:
794
- logging.info(f"class 'HLS_Downloader'; call start(); parse m3u8 data")
795
-
796
- self.instace_parserClass.parse_data(uri=self.m3u8_index, raw_content=self.request_m3u8_index)
797
- is_masterPlaylist = self.instace_parserClass.is_master_playlist
798
-
799
- # Check if it's a real index playlist
800
- if not is_masterPlaylist:
801
- if not GET_ONLY_LINK:
802
- self._process_index()
803
- return None
804
-
805
- else:
806
- return {
807
- 'path': self.output_filename,
808
- 'url': self.m3u8_index
809
- }
810
-
811
- else:
812
- console.log("[red]Error: URL passed to M3U8_Parser is an master playlist; expected a index playlist. Crucimorfo strikes again!")
813
- else:
814
- console.log("[red]Error: m3u8_index failed request")
815
- else:
816
- console.log("[red]Error: m3u8_index is None")
817
-
818
- def _clean(self, out_path: str) -> None:
819
- """
820
- Cleans up temporary files and folders after downloading and processing.
821
-
822
- Args:
823
- out_path (str): The path of the output file to be cleaned up.
824
- """
825
-
826
- # Check if the final output file exists
827
- logging.info(f"Check if end file converted exists: {out_path}")
828
- if out_path is None or not os.path.isfile(out_path):
829
- logging.error("Video file converted does not exist.")
830
- sys.exit(0)
831
-
832
- # Rename the output file to the desired output filename if it does not already exist
833
- if not os.path.exists(self.output_filename):
834
- missing_ts = False
835
- missing_info = ""
836
-
837
- # Rename the converted file to the specified output filename
838
- os.rename(out_path, self.output_filename)
839
-
840
- # Calculate file size and duration for reporting
841
- formatted_size = internet_manager.format_file_size(os.path.getsize(self.output_filename))
842
- formatted_duration = print_duration_table(self.output_filename, description=False, return_string=True)
843
-
844
- # Collect info about type missing
845
- for item in list_MissingTs:
846
- if int(item['nFailed']) >= 1:
847
- missing_ts = True
848
- missing_info += f"[red]TS Failed: {item['nFailed']} {item['type']} tracks[/red]\n"
849
-
850
- # Prepare the report panel content
851
- print("")
852
- panel_content = (
853
- f"[bold green]Download completed![/bold green]\n"
854
- f"[cyan]File size: [bold red]{formatted_size}[/bold red]\n"
855
- f"[cyan]Duration: [bold]{formatted_duration}[/bold]\n"
856
- f"[cyan]Output: [bold]{os.path.abspath(self.output_filename)}[/bold]"
857
- )
858
-
859
- if missing_ts:
860
- panel_content += f"\n{missing_info}"
861
-
862
- # Display the download completion message
863
- console.print(Panel(
864
- panel_content,
865
- title=f"{os.path.basename(self.output_filename.replace('.mp4', ''))}",
866
- border_style="green"
867
- ))
868
-
869
- # Handle missing segments
870
- if missing_ts:
871
- os.rename(self.output_filename, self.output_filename.replace(".mp4", "_failed.mp4"))
872
-
873
- # Delete all temporary files except for the output file
874
- os_manager.remove_files_except_one(self.path_manager.base_path, os.path.basename(self.output_filename.replace(".mp4", "_failed.mp4")))
875
-
876
- # Remove the base folder if specified
877
- if REMOVE_SEGMENTS_FOLDER:
878
- os_manager.remove_folder(self.path_manager.base_path)
879
-
880
- else:
881
- logging.info("Video file converted already exists.")
882
-
883
- def _valida_playlist(self):
884
- """
885
- Validates the m3u8 playlist content, saves it to a temporary file, and collects playlist information.
886
- """
887
- logging.info("class 'HLS_Downloader'; call _valida_playlist()")
888
-
889
- # Retrieve the m3u8 playlist content
890
- if self.is_playlist_url:
891
- if self.request_m3u8_playlist != 404:
892
- m3u8_playlist_text = self.request_m3u8_playlist
893
- m3u8_url_fixer.set_playlist(self.m3u8_playlist)
894
-
895
- else:
896
- logging.info(f"class 'HLS_Downloader'; call _process_playlist(); return 404")
897
- return 404
898
-
899
- else:
900
- m3u8_playlist_text = self.m3u8_playlist
901
-
902
- # Check if the m3u8 content is valid
903
- if m3u8_playlist_text is None:
904
- console.log("[red]Playlist m3u8 to download is empty.")
905
- sys.exit(0)
906
-
907
- # Save the m3u8 playlist text to a temporary file
908
- open(os.path.join(self.path_manager.base_temp, "playlist.m3u8"), "w+", encoding="utf-8").write(m3u8_playlist_text)
909
-
910
- # Collect information about the playlist
911
- if self.is_playlist_url:
912
- self.content_extractor.start(self.instace_parserClass)
913
- else:
914
- self.content_extractor.start("https://fake.com", m3u8_playlist_text)
915
-
916
- def _process_playlist(self):
917
- """
918
- Processes the m3u8 playlist to download video, audio, and subtitles.
919
- """
920
- self._valida_playlist()
921
-
922
- # Add downloaded elements to the tracker
923
- self.download_tracker.add_video(self.content_extractor.m3u8_index)
924
- self.download_tracker.add_audio(self.content_extractor.list_available_audio)
925
- self.download_tracker.add_subtitle(self.content_extractor.list_available_subtitles)
926
-
927
- # Download each type of content
928
- if DOWNLOAD_VIDEO and len(self.download_tracker.downloaded_video) > 0:
929
- self.content_downloader.download_video(self.download_tracker.downloaded_video)
930
- if DOWNLOAD_AUDIO and len(self.download_tracker.downloaded_audio) > 0:
931
- self.content_downloader.download_audio(self.download_tracker.downloaded_audio)
932
- if DOWNLOAD_SUBTITLE and len(self.download_tracker.downloaded_subtitle) > 0:
933
- self.content_downloader.download_subtitle(self.download_tracker.downloaded_subtitle)
934
-
935
- # Join downloaded content
936
- self.content_joiner.setup(self.download_tracker.downloaded_video, self.download_tracker.downloaded_audio, self.download_tracker.downloaded_subtitle, self.content_extractor.codec)
937
-
938
- # Clean up temporary files and directories
939
- self._clean(self.content_joiner.converted_out_path)
940
-
941
- def _process_index(self):
942
- """
943
- Processes the m3u8 index to download only video.
944
- """
945
- m3u8_url_fixer.set_playlist(self.m3u8_index)
946
-
947
- # Download video
948
- self.download_tracker.add_video(self.m3u8_index)
949
- self.content_downloader.download_video(self.download_tracker.downloaded_video)
950
-
951
- # Join video
952
- self.content_joiner.setup(self.download_tracker.downloaded_video, [], [])
953
-
954
- # Clean up temporary files and directories
955
- self._clean(self.content_joiner.converted_out_path)