Handle m3u8 and HttpFD downloads in ytdlp

This commit is contained in:
Rafael Moraes
2026-05-23 15:44:23 -03:00
parent 6d8ecf65b6
commit a8bf884d8f
+33 -15
View File
@@ -11,6 +11,7 @@ from mutagen.mp4 import MP4, MP4Cover
from yt_dlp import YoutubeDL from yt_dlp import YoutubeDL
from ..interface.enums import CoverFormat from ..interface.enums import CoverFormat
from yt_dlp.downloader.http import HttpFD
from ..interface.interface import AppleMusicInterface from ..interface.interface import AppleMusicInterface
from ..interface.types import MediaTags, PlaylistTags from ..interface.types import MediaTags, PlaylistTags
from ..utils import CustomStringFormatter, async_subprocess from ..utils import CustomStringFormatter, async_subprocess
@@ -27,19 +28,34 @@ def _download_ytdlp_process(
result_queue, result_queue,
) -> None: ) -> None:
try: try:
with YoutubeDL( common_args = {
{ "quiet": True,
"quiet": True, "no_warnings": True,
"no_warnings": True, "noprogress": silent,
"outtmpl": download_path, }
"allow_unplayable_formats": True,
"overwrites": True, if stream_url.split("?")[0].endswith(".m3u8"):
"fixup": "never", with YoutubeDL(
"noprogress": silent, {
"allowed_extractors": ["generic"], **common_args,
} "outtmpl": download_path,
) as ydl: "allow_unplayable_formats": True,
ydl.download(stream_url) "overwrites": True,
"fixup": "never",
"allowed_extractors": ["generic"],
}
) as ydl:
ydl.download(stream_url)
else:
Path(download_path).parent.mkdir(parents=True, exist_ok=True)
with YoutubeDL(common_args) as ydl:
http_downloader = HttpFD(ydl, ydl.params)
http_downloader.download(
download_path,
{
"url": stream_url,
},
)
except Exception as e: except Exception as e:
result_queue.put(("error", repr(e), traceback.format_exc())) result_queue.put(("error", repr(e), traceback.format_exc()))
@@ -222,10 +238,12 @@ class AppleMusicBaseDownloader:
action="download_stream", stream_url=stream_url, download_path=download_path action="download_stream", stream_url=stream_url, download_path=download_path
) )
if self.download_mode == DownloadMode.YTDLP: if self.download_mode == DownloadMode.YTDLP or not stream_url.split("?")[
0
].endswith(".m3u8"):
await self._download_ytdlp_async(stream_url, download_path) await self._download_ytdlp_async(stream_url, download_path)
if self.download_mode == DownloadMode.NM3U8DLRE: elif self.download_mode == DownloadMode.NM3U8DLRE:
await self._download_nm3u8dlre(stream_url, download_path) await self._download_nm3u8dlre(stream_url, download_path)
log.debug("success") log.debug("success")