StreamingCommunity 1.9.8__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 -2
  87. {StreamingCommunity-1.9.8.dist-info → StreamingCommunity-1.9.90.dist-info}/METADATA +7 -10
  88. StreamingCommunity-1.9.90.dist-info/RECORD +92 -0
  89. {StreamingCommunity-1.9.8.dist-info → StreamingCommunity-1.9.90.dist-info}/WHEEL +1 -1
  90. {StreamingCommunity-1.9.8.dist-info → StreamingCommunity-1.9.90.dist-info}/entry_points.txt +0 -1
  91. StreamingCommunity-1.9.8.dist-info/RECORD +0 -7
  92. {StreamingCommunity-1.9.8.dist-info → StreamingCommunity-1.9.90.dist-info}/LICENSE +0 -0
  93. {StreamingCommunity-1.9.8.dist-info → StreamingCommunity-1.9.90.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,296 @@
1
+ # 31.01.24
2
+
3
+ import sys
4
+ import time
5
+ import logging
6
+ import subprocess
7
+ from typing import List, Dict
8
+
9
+
10
+ # Internal utilities
11
+ from StreamingCommunity.Util._jsonConfig import config_manager
12
+ from StreamingCommunity.Util.os import os_manager, os_summary, suppress_output
13
+ from StreamingCommunity.Util.console import console
14
+
15
+
16
+ # Logic class
17
+ from .util import need_to_force_to_ts, check_duration_v_a
18
+ from .capture import capture_ffmpeg_real_time
19
+ from ..M3U8 import M3U8_Codec
20
+
21
+
22
+ # Config
23
+ DEBUG_MODE = config_manager.get_bool("DEFAULT", "debug")
24
+ DEBUG_FFMPEG = "debug" if DEBUG_MODE else "error"
25
+ USE_CODEC = config_manager.get_bool("M3U8_CONVERSION", "use_codec")
26
+ USE_VCODEC = config_manager.get_bool("M3U8_CONVERSION", "use_vcodec")
27
+ USE_ACODEC = config_manager.get_bool("M3U8_CONVERSION", "use_acodec")
28
+ USE_BITRATE = config_manager.get_bool("M3U8_CONVERSION", "use_bitrate")
29
+ USE_GPU = config_manager.get_bool("M3U8_CONVERSION", "use_gpu")
30
+ FFMPEG_DEFAULT_PRESET = config_manager.get("M3U8_CONVERSION", "default_preset")
31
+
32
+
33
+ # Variable
34
+ TQDM_USE_LARGE_BAR = config_manager.get_int('M3U8_DOWNLOAD', 'tqdm_use_large_bar')
35
+ FFMPEG_PATH = os_summary.ffmpeg_path
36
+
37
+
38
+ def join_video(video_path: str, out_path: str, codec: M3U8_Codec = None):
39
+
40
+ """
41
+ Joins single ts video file to mp4
42
+
43
+ Parameters:
44
+ - video_path (str): The path to the video file.
45
+ - out_path (str): The path to save the output file.
46
+ - vcodec (str): The video codec to use. Defaults to 'copy'.
47
+ - acodec (str): The audio codec to use. Defaults to 'aac'.
48
+ - bitrate (str): The bitrate for the audio stream. Defaults to '192k'.
49
+ - force_ts (bool): Force video path to be mpegts as input.
50
+ """
51
+
52
+ if not os_manager.check_file(video_path):
53
+ logging.error("Missing input video for ffmpeg conversion.")
54
+ sys.exit(0)
55
+
56
+ # Start command with locate ffmpeg
57
+ ffmpeg_cmd = [FFMPEG_PATH]
58
+
59
+ # Enabled the use of gpu
60
+ if USE_GPU:
61
+ ffmpeg_cmd.extend(['-hwaccel', 'cuda'])
62
+
63
+ # Add mpegts to force to detect input file as ts file
64
+ if need_to_force_to_ts(video_path):
65
+ #console.log("[red]Force input file to 'mpegts'.")
66
+ ffmpeg_cmd.extend(['-f', 'mpegts'])
67
+ vcodec = "libx264"
68
+
69
+ # Insert input video path
70
+ ffmpeg_cmd.extend(['-i', video_path])
71
+
72
+ # Add output Parameters
73
+ if USE_CODEC and codec != None:
74
+ if USE_VCODEC:
75
+ if codec.video_codec_name:
76
+ if not USE_GPU:
77
+ ffmpeg_cmd.extend(['-c:v', codec.video_codec_name])
78
+ else:
79
+ ffmpeg_cmd.extend(['-c:v', 'h264_nvenc'])
80
+ else:
81
+ console.log("[red]Cant find vcodec for 'join_audios'")
82
+ else:
83
+ if USE_GPU:
84
+ ffmpeg_cmd.extend(['-c:v', 'h264_nvenc'])
85
+
86
+
87
+ if USE_ACODEC:
88
+ if codec.audio_codec_name:
89
+ ffmpeg_cmd.extend(['-c:a', codec.audio_codec_name])
90
+ else:
91
+ console.log("[red]Cant find acodec for 'join_audios'")
92
+
93
+ if USE_BITRATE:
94
+ ffmpeg_cmd.extend(['-b:v', f'{codec.video_bitrate // 1000}k'])
95
+ ffmpeg_cmd.extend(['-b:a', f'{codec.audio_bitrate // 1000}k'])
96
+
97
+ else:
98
+ ffmpeg_cmd.extend(['-c', 'copy'])
99
+
100
+ # Ultrafast preset always or fast for gpu
101
+ if not USE_GPU:
102
+ ffmpeg_cmd.extend(['-preset', FFMPEG_DEFAULT_PRESET])
103
+ else:
104
+ ffmpeg_cmd.extend(['-preset', 'fast'])
105
+
106
+ # Overwrite
107
+ ffmpeg_cmd += [out_path, "-y"]
108
+
109
+ # Run join
110
+ if DEBUG_MODE:
111
+ subprocess.run(ffmpeg_cmd, check=True)
112
+ else:
113
+
114
+ if TQDM_USE_LARGE_BAR:
115
+ capture_ffmpeg_real_time(ffmpeg_cmd, "[cyan]Join video")
116
+ print()
117
+
118
+ else:
119
+ console.log(f"[purple]FFmpeg [white][[cyan]Join video[white]] ...")
120
+ with suppress_output():
121
+ capture_ffmpeg_real_time(ffmpeg_cmd, "[cyan]Join video")
122
+ print()
123
+
124
+ time.sleep(0.5)
125
+ if not os_manager.check_file(out_path):
126
+ logging.error("Missing output video for ffmpeg conversion video.")
127
+ sys.exit(0)
128
+
129
+
130
+ def join_audios(video_path: str, audio_tracks: List[Dict[str, str]], out_path: str, codec: M3U8_Codec = None):
131
+ """
132
+ Joins audio tracks with a video file using FFmpeg.
133
+
134
+ Parameters:
135
+ - video_path (str): The path to the video file.
136
+ - audio_tracks (list[dict[str, str]]): A list of dictionaries containing information about audio tracks.
137
+ Each dictionary should contain the 'path' key with the path to the audio file.
138
+ - out_path (str): The path to save the output file.
139
+ """
140
+
141
+ if not os_manager.check_file(video_path):
142
+ logging.error("Missing input video for ffmpeg conversion.")
143
+ sys.exit(0)
144
+
145
+ video_audio_same_duration = check_duration_v_a(video_path, audio_tracks[0].get('path'))
146
+
147
+ # Start command with locate ffmpeg
148
+ ffmpeg_cmd = [FFMPEG_PATH]
149
+
150
+ # Enabled the use of gpu
151
+ if USE_GPU:
152
+ ffmpeg_cmd.extend(['-hwaccel', 'cuda'])
153
+
154
+ # Insert input video path
155
+ ffmpeg_cmd.extend(['-i', video_path])
156
+
157
+ # Add audio tracks as input
158
+ for i, audio_track in enumerate(audio_tracks):
159
+ if os_manager.check_file(audio_track.get('path')):
160
+ ffmpeg_cmd.extend(['-i', audio_track.get('path')])
161
+ else:
162
+ logging.error(f"Skip audio join: {audio_track.get('path')} dont exist")
163
+
164
+ # Map the video and audio streams
165
+ ffmpeg_cmd.append('-map')
166
+ ffmpeg_cmd.append('0:v') # Map video stream from the first input (video_path)
167
+
168
+ for i in range(1, len(audio_tracks) + 1):
169
+ ffmpeg_cmd.append('-map')
170
+ ffmpeg_cmd.append(f'{i}:a') # Map audio streams from subsequent inputs
171
+
172
+ # Add output Parameters
173
+ if USE_CODEC:
174
+ if USE_VCODEC:
175
+ if codec.video_codec_name:
176
+ if not USE_GPU:
177
+ ffmpeg_cmd.extend(['-c:v', codec.video_codec_name])
178
+ else:
179
+ ffmpeg_cmd.extend(['-c:v', 'h264_nvenc'])
180
+ else:
181
+ console.log("[red]Cant find vcodec for 'join_audios'")
182
+ else:
183
+ if USE_GPU:
184
+ ffmpeg_cmd.extend(['-c:v', 'h264_nvenc'])
185
+
186
+ if USE_ACODEC:
187
+ if codec.audio_codec_name:
188
+ ffmpeg_cmd.extend(['-c:a', codec.audio_codec_name])
189
+ else:
190
+ console.log("[red]Cant find acodec for 'join_audios'")
191
+
192
+ if USE_BITRATE:
193
+ ffmpeg_cmd.extend(['-b:v', f'{codec.video_bitrate // 1000}k'])
194
+ ffmpeg_cmd.extend(['-b:a', f'{codec.audio_bitrate // 1000}k'])
195
+
196
+ else:
197
+ ffmpeg_cmd.extend(['-c', 'copy'])
198
+
199
+ # Ultrafast preset always or fast for gpu
200
+ if not USE_GPU:
201
+ ffmpeg_cmd.extend(['-preset', FFMPEG_DEFAULT_PRESET])
202
+ else:
203
+ ffmpeg_cmd.extend(['-preset', 'fast'])
204
+
205
+ # Use shortest input path for video and audios
206
+ if not video_audio_same_duration:
207
+ logging.info("[red]Use shortest input.")
208
+ ffmpeg_cmd.extend(['-shortest', '-strict', 'experimental'])
209
+
210
+ # Overwrite
211
+ ffmpeg_cmd += [out_path, "-y"]
212
+
213
+ # Run join
214
+ if DEBUG_MODE:
215
+ subprocess.run(ffmpeg_cmd, check=True)
216
+ else:
217
+
218
+ if TQDM_USE_LARGE_BAR:
219
+ capture_ffmpeg_real_time(ffmpeg_cmd, "[cyan]Join audio")
220
+ print()
221
+
222
+ else:
223
+ console.log(f"[purple]FFmpeg [white][[cyan]Join audio[white]] ...")
224
+ with suppress_output():
225
+ capture_ffmpeg_real_time(ffmpeg_cmd, "[cyan]Join audio")
226
+ print()
227
+
228
+ time.sleep(0.5)
229
+ if not os_manager.check_file(out_path):
230
+ logging.error("Missing output video for ffmpeg conversion audio.")
231
+ sys.exit(0)
232
+
233
+
234
+ def join_subtitle(video_path: str, subtitles_list: List[Dict[str, str]], out_path: str):
235
+ """
236
+ Joins subtitles with a video file using FFmpeg.
237
+
238
+ Parameters:
239
+ - video (str): The path to the video file.
240
+ - subtitles_list (list[dict[str, str]]): A list of dictionaries containing information about subtitles.
241
+ Each dictionary should contain the 'path' key with the path to the subtitle file and the 'name' key with the name of the subtitle.
242
+ - out_path (str): The path to save the output file.
243
+ """
244
+
245
+ if not os_manager.check_file(video_path):
246
+ logging.error("Missing input video for ffmpeg conversion.")
247
+ sys.exit(0)
248
+
249
+ # Start command with locate ffmpeg
250
+ ffmpeg_cmd = [FFMPEG_PATH, "-i", video_path]
251
+
252
+ # Add subtitle input files first
253
+ for subtitle in subtitles_list:
254
+ if os_manager.check_file(subtitle.get('path')):
255
+ ffmpeg_cmd += ["-i", subtitle['path']]
256
+ else:
257
+ logging.error(f"Skip subtitle join: {subtitle.get('path')} doesn't exist")
258
+
259
+ # Add maps for video and audio streams
260
+ ffmpeg_cmd += ["-map", "0:v", "-map", "0:a"]
261
+
262
+ # Add subtitle maps and metadata
263
+ for idx, subtitle in enumerate(subtitles_list):
264
+ ffmpeg_cmd += ["-map", f"{idx + 1}:s"]
265
+ ffmpeg_cmd += ["-metadata:s:s:{}".format(idx), "title={}".format(subtitle['language'])]
266
+
267
+ # Add output Parameters
268
+ if USE_CODEC:
269
+ ffmpeg_cmd.extend(['-c:v', 'copy', '-c:a', 'copy', '-c:s', 'mov_text'])
270
+ else:
271
+ ffmpeg_cmd.extend(['-c', 'copy', '-c:s', 'mov_text'])
272
+
273
+ # Overwrite
274
+ ffmpeg_cmd += [out_path, "-y"]
275
+ logging.info(f"FFmpeg command: {ffmpeg_cmd}")
276
+
277
+
278
+ # Run join
279
+ if DEBUG_MODE:
280
+ subprocess.run(ffmpeg_cmd, check=True)
281
+ else:
282
+
283
+ if TQDM_USE_LARGE_BAR:
284
+ capture_ffmpeg_real_time(ffmpeg_cmd, "[cyan]Join subtitle")
285
+ print()
286
+
287
+ else:
288
+ console.log(f"[purple]FFmpeg [white][[cyan]Join subtitle[white]] ...")
289
+ with suppress_output():
290
+ capture_ffmpeg_real_time(ffmpeg_cmd, "[cyan]Join subtitle")
291
+ print()
292
+
293
+ time.sleep(0.5)
294
+ if not os_manager.check_file(out_path):
295
+ logging.error("Missing output video for ffmpeg conversion subtitle.")
296
+ sys.exit(0)
@@ -0,0 +1,249 @@
1
+ # 16.04.24
2
+
3
+ import os
4
+ import sys
5
+ import json
6
+ import subprocess
7
+ import logging
8
+ from typing import Tuple
9
+
10
+
11
+ # Internal utilities
12
+ from StreamingCommunity.Util.console import console
13
+ from StreamingCommunity.Util.os import os_summary
14
+
15
+
16
+ # Variable
17
+ FFPROB_PATH = os_summary.ffprobe_path
18
+
19
+
20
+
21
+ def has_audio_stream(video_path: str) -> bool:
22
+ """
23
+ Check if the input video has an audio stream.
24
+
25
+ Parameters:
26
+ - video_path (str): Path to the input video file.
27
+
28
+ Returns:
29
+ has_audio (bool): True if the input video has an audio stream, False otherwise.
30
+ """
31
+ try:
32
+ ffprobe_cmd = [FFPROB_PATH, '-v', 'error', '-print_format', 'json', '-select_streams', 'a', '-show_streams', video_path]
33
+ logging.info(f"FFmpeg command: {ffprobe_cmd}")
34
+
35
+ with subprocess.Popen(ffprobe_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) as proc:
36
+ stdout, stderr = proc.communicate()
37
+ if stderr:
38
+ logging.error(f"Error: {stderr}")
39
+ else:
40
+ probe_result = json.loads(stdout)
41
+ return bool(probe_result.get('streams', []))
42
+
43
+ except Exception as e:
44
+ logging.error(f"Error: {e}")
45
+ return False
46
+
47
+
48
+ def get_video_duration(file_path: str) -> float:
49
+ """
50
+ Get the duration of a video file.
51
+
52
+ Parameters:
53
+ - file_path (str): The path to the video file.
54
+
55
+ Returns:
56
+ (float): The duration of the video in seconds if successful, None if there's an error.
57
+ """
58
+
59
+ try:
60
+ ffprobe_cmd = [FFPROB_PATH, '-v', 'error', '-show_format', '-print_format', 'json', file_path]
61
+ logging.info(f"FFmpeg command: {ffprobe_cmd}")
62
+
63
+ # Use a with statement to ensure the subprocess is cleaned up properly
64
+ with subprocess.Popen(ffprobe_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) as proc:
65
+ stdout, stderr = proc.communicate()
66
+
67
+ if proc.returncode != 0:
68
+ logging.error(f"Error: {stderr}")
69
+ return None
70
+
71
+ # Parse JSON output
72
+ probe_result = json.loads(stdout)
73
+
74
+ # Extract duration from the video information
75
+ try:
76
+ return float(probe_result['format']['duration'])
77
+
78
+ except:
79
+ return 1
80
+
81
+ except Exception as e:
82
+ logging.error(f"Get video duration error: {e}")
83
+ sys.exit(0)
84
+
85
+
86
+ def get_video_duration_s(filename):
87
+ """
88
+ Get the duration of a video file using ffprobe.
89
+
90
+ Parameters:
91
+ - filename (str): Path to the video file (e.g., 'sim.mp4')
92
+
93
+ Returns:
94
+ - duration (float): Duration of the video in seconds, or None if an error occurs.
95
+ """
96
+ ffprobe_cmd = ['ffprobe', '-v', 'error', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', filename]
97
+
98
+ try:
99
+
100
+ # Run ffprobe command and capture output
101
+ result = subprocess.run(ffprobe_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True)
102
+
103
+ # Extract duration from the output
104
+ duration_str = result.stdout.strip()
105
+ duration = float(duration_str) # Convert duration to float
106
+
107
+ return int(duration)
108
+
109
+ except subprocess.CalledProcessError as e:
110
+ print(f"Error running ffprobe: {e}")
111
+ return None
112
+ except ValueError as e:
113
+ print(f"Error converting duration to float: {e}")
114
+ return None
115
+
116
+
117
+ def format_duration(seconds: float) -> Tuple[int, int, int]:
118
+ """
119
+ Format duration in seconds into hours, minutes, and seconds.
120
+
121
+ Parameters:
122
+ - seconds (float): Duration in seconds.
123
+
124
+ Returns:
125
+ list[int, int, int]: List containing hours, minutes, and seconds.
126
+ """
127
+
128
+ hours, remainder = divmod(seconds, 3600)
129
+ minutes, seconds = divmod(remainder, 60)
130
+
131
+ return int(hours), int(minutes), int(seconds)
132
+
133
+
134
+ def print_duration_table(file_path: str, description: str = "Duration", return_string: bool = False):
135
+ """
136
+ Print the duration of a video file in hours, minutes, and seconds, or return it as a formatted string.
137
+
138
+ Parameters:
139
+ - file_path (str): The path to the video file.
140
+ - description (str): Optional description to be included in the output. Defaults to "Duration". If not provided, the duration will not be printed.
141
+ - return_string (bool): If True, returns the formatted duration string. If False, returns a dictionary with hours, minutes, and seconds.
142
+
143
+ Returns:
144
+ - str: The formatted duration string if return_string is True.
145
+ - dict: A dictionary with keys 'h', 'm', 's' representing hours, minutes, and seconds if return_string is False.
146
+ """
147
+ video_duration = get_video_duration(file_path)
148
+
149
+ if video_duration is not None:
150
+ hours, minutes, seconds = format_duration(video_duration)
151
+ formatted_duration = f"[yellow]{int(hours)}[red]h [yellow]{int(minutes)}[red]m [yellow]{int(seconds)}[red]s"
152
+ duration_dict = {'h': hours, 'm': minutes, 's': seconds}
153
+
154
+ if description:
155
+ console.print(f"[cyan]{description} for [white]([green]{os.path.basename(file_path)}[white]): {formatted_duration}")
156
+ else:
157
+ if return_string:
158
+ return formatted_duration
159
+ else:
160
+ return duration_dict
161
+
162
+
163
+ def get_ffprobe_info(file_path):
164
+ """
165
+ Get format and codec information for a media file using ffprobe.
166
+
167
+ Parameters:
168
+ - file_path (str): Path to the media file.
169
+
170
+ Returns:
171
+ dict: A dictionary containing the format name and a list of codec names.
172
+ """
173
+ try:
174
+ result = subprocess.run(
175
+ [FFPROB_PATH, '-v', 'error', '-show_format', '-show_streams', '-print_format', 'json', file_path],
176
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True
177
+ )
178
+ output = result.stdout
179
+ info = json.loads(output)
180
+
181
+ format_name = info['format']['format_name'] if 'format' in info else None
182
+ codec_names = [stream['codec_name'] for stream in info['streams']] if 'streams' in info else []
183
+
184
+ return {
185
+ 'format_name': format_name,
186
+ 'codec_names': codec_names
187
+ }
188
+
189
+ except subprocess.CalledProcessError as e:
190
+ logging.error(f"ffprobe failed for file {file_path}: {e}")
191
+ return None
192
+
193
+ except json.JSONDecodeError as e:
194
+ logging.error(f"Failed to parse JSON output from ffprobe for file {file_path}: {e}")
195
+ return None
196
+
197
+
198
+ def is_png_format_or_codec(file_info):
199
+ """
200
+ Check if the format is 'png_pipe' or if any codec is 'png'.
201
+
202
+ Parameters:
203
+ - file_info (dict): The dictionary containing file information.
204
+
205
+ Returns:
206
+ bool: True if the format is 'png_pipe' or any codec is 'png', otherwise False.
207
+ """
208
+ if not file_info:
209
+ return False
210
+
211
+ console.print(f"[yellow][FFmpeg] [cyan]Avaiable codec[white]: [red]{file_info['codec_names']}")
212
+ return file_info['format_name'] == 'png_pipe' or 'png' in file_info['codec_names']
213
+
214
+
215
+ def need_to_force_to_ts(file_path):
216
+ """
217
+ Get if a file to TS format if it is in PNG format or contains a PNG codec.
218
+
219
+ Parameters:
220
+ - file_path (str): Path to the input media file.
221
+ """
222
+ logging.info(f"Processing file: {file_path}")
223
+ file_info = get_ffprobe_info(file_path)
224
+
225
+ if is_png_format_or_codec(file_info):
226
+ return True
227
+ return False
228
+
229
+
230
+ def check_duration_v_a(video_path, audio_path):
231
+ """
232
+ Check if the duration of the video and audio matches.
233
+
234
+ Parameters:
235
+ - video_path (str): Path to the video file.
236
+ - audio_path (str): Path to the audio file.
237
+
238
+ Returns:
239
+ - bool: True if the duration of the video and audio matches, False otherwise.
240
+ """
241
+
242
+ # Ottieni la durata del video
243
+ video_duration = get_video_duration(video_path)
244
+
245
+ # Ottieni la durata dell'audio
246
+ audio_duration = get_video_duration(audio_path)
247
+
248
+ # Verifica se le durate corrispondono
249
+ return video_duration == audio_duration
@@ -0,0 +1,6 @@
1
+ # 02.04.24
2
+
3
+ from .decryptor import M3U8_Decryption
4
+ from .estimator import M3U8_Ts_Estimator
5
+ from .parser import M3U8_Parser, M3U8_Codec
6
+ from .url_fixer import M3U8_UrlFix