Merge pull request #28 from Type-Delta/psflag-fix

Fix(downloader): corrupted Parametric Stereo (PS) flag in downloaded .m3u8 videos
This commit is contained in:
Benexl
2024-11-23 14:15:30 +03:00
committed by GitHub
3 changed files with 55 additions and 1 deletions

View File

@@ -43,6 +43,8 @@ class YtDLPDownloader:
merge=False,
clean=False,
prompt=True,
force_ffmpeg=False,
hls_use_mpegts=False,
):
"""Helper function that downloads anime given url and path details
@@ -91,7 +93,23 @@ class YtDLPDownloader:
vid_path = ""
sub_path = ""
for i, url in enumerate(urls):
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
options = ydl_opts
if i == 0:
if force_ffmpeg:
options = options | {
"external_downloader": {
'default': 'ffmpeg'
},
"external_downloader_args": {
"ffmpeg_i1": ["-v", "error", "-stats"],
},
}
if hls_use_mpegts:
options = options | {
"hls_use_mpegts": hls_use_mpegts,
}
with yt_dlp.YoutubeDL(options) as ydl:
info = ydl.extract_info(url, download=True)
if not info:
continue

View File

@@ -109,6 +109,16 @@ from .data import (
help="Whether to prompt for anything instead just do the best thing",
default=True,
)
@click.option(
"--force-ffmpeg",
is_flag=True,
help="Force the use of FFmpeg for downloading (supports large variety of streams but slower)",
)
@click.option(
"--hls-use-mpegts",
is_flag=True,
help="Use mpegts for hls streams (useful for some streams: see Docs) (this option forces --force-ffmpeg to be True)",
)
@click.option(
"--max-results", "-M", type=int, help="The maximum number of results to show"
)
@@ -132,11 +142,15 @@ def download(
clean,
wait_time,
prompt,
force_ffmpeg,
hls_use_mpegts,
max_results,
):
from ....anilist import AniList
from rich import print
force_ffmpeg |= hls_use_mpegts
success, anilist_search_results = AniList.search(
query=title,
sort=sort,
@@ -367,6 +381,8 @@ def download(
merge=merge,
clean=clean,
prompt=prompt,
force_ffmpeg=force_ffmpeg,
hls_use_mpegts=hls_use_mpegts,
)
except Exception as e:
print(e)

View File

@@ -114,6 +114,16 @@ if TYPE_CHECKING:
help="Whether to prompt for anything instead just do the best thing",
default=True,
)
@click.option(
"--force-ffmpeg",
is_flag=True,
help="Force the use of FFmpeg for downloading (supports large variety of streams but slower)",
)
@click.option(
"--hls-use-mpegts",
is_flag=True,
help="Use mpegts for hls streams (useful for some streams: see Docs) (this option forces --force-ffmpeg to be True)",
)
@click.pass_obj
def download(
config: "Config",
@@ -127,6 +137,8 @@ def download(
clean,
wait_time,
prompt,
force_ffmpeg,
hls_use_mpegts,
):
import time
@@ -146,6 +158,8 @@ def download(
move_preferred_subtitle_lang_to_top,
)
force_ffmpeg |= hls_use_mpegts
anime_provider = AnimeProvider(config.provider)
anilist_anime_info = None
@@ -185,6 +199,8 @@ def download(
clean,
wait_time,
prompt,
force_ffmpeg,
hls_use_mpegts,
)
return
search_results = search_results["results"]
@@ -236,6 +252,8 @@ def download(
clean,
wait_time,
prompt,
force_ffmpeg,
hls_use_mpegts,
)
return
@@ -369,6 +387,8 @@ def download(
merge=merge,
clean=clean,
prompt=prompt,
force_ffmpeg=force_ffmpeg,
hls_use_mpegts=hls_use_mpegts,
)
except Exception as e:
print(e)