mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-07 20:15:24 +00:00
refact(audio_extractor): improves code readability refactoring audio_extractor_m3u8 function
This commit is contained in:
parent
bee29b5d60
commit
3026a39e14
@ -4,7 +4,8 @@
|
|||||||
from Src.Util.console import console
|
from Src.Util.console import console
|
||||||
|
|
||||||
# Import
|
# Import
|
||||||
import ffmpeg
|
import ffmpeg
|
||||||
|
|
||||||
|
|
||||||
# Variable
|
# Variable
|
||||||
|
|
||||||
@ -19,14 +20,37 @@ def get_video_duration(file_path):
|
|||||||
print(f"Error: {e.stderr}")
|
print(f"Error: {e.stderr}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def format_duration(seconds):
|
def format_duration(seconds):
|
||||||
hours, remainder = divmod(seconds, 3600)
|
hours, remainder = divmod(seconds, 3600)
|
||||||
minutes, seconds = divmod(remainder, 60)
|
minutes, seconds = divmod(remainder, 60)
|
||||||
return int(hours), int(minutes), int(seconds)
|
return int(hours), int(minutes), int(seconds)
|
||||||
|
|
||||||
|
|
||||||
def print_duration_table(file_path):
|
def print_duration_table(file_path):
|
||||||
video_duration = get_video_duration(file_path)
|
video_duration = get_video_duration(file_path)
|
||||||
|
|
||||||
if video_duration is not None:
|
if video_duration is not None:
|
||||||
hours, minutes, seconds = format_duration(video_duration)
|
hours, minutes, seconds = format_duration(video_duration)
|
||||||
console.log(f"[cyan]Info [green]'{file_path}': [purple]{int(hours)}[red]h [purple]{int(minutes)}[red]m [purple]{int(seconds)}[red]s")
|
console.log(
|
||||||
|
f"[cyan]Info [green]'{file_path}': [purple]{int(hours)}[red]h [purple]{int(minutes)}[red]m [purple]{int(seconds)}[red]s")
|
||||||
|
|
||||||
|
|
||||||
|
def audio_extractor_m3u8(req):
|
||||||
|
m3u8_cont = req.text.split()
|
||||||
|
m3u8_cont_arr = []
|
||||||
|
for row in m3u8_cont:
|
||||||
|
if "audio" in str(row):
|
||||||
|
lang = None
|
||||||
|
default = False
|
||||||
|
for field in row.split(","):
|
||||||
|
if "NAME" in field:
|
||||||
|
lang = field.split('"')[-2]
|
||||||
|
if "DEFAULT" in field:
|
||||||
|
default_str = field.split('=')[1]
|
||||||
|
default = default_str.strip() == "YES"
|
||||||
|
audioobj = {"url": row.split(",")[-1].split('"')[-2], "lang": lang, "default": default}
|
||||||
|
if audioobj['lang'] is None:
|
||||||
|
continue
|
||||||
|
m3u8_cont_arr.append(audioobj)
|
||||||
|
return m3u8_cont_arr or None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user