split download function

This commit is contained in:
R. M
2023-09-04 23:22:56 -03:00
parent 2d510a7703
commit fca7ee5c3b
2 changed files with 34 additions and 33 deletions
+8 -4
View File
@@ -395,8 +395,12 @@ def main(
stream_url, track_id
)
encrypted_location = dl.get_encrypted_location_audio(track_id)
logger.debug(f'Downloading to "{encrypted_location}"')
dl.download(encrypted_location, stream_url)
if download_mode == "yt-dlp":
logger.debug(f'Downloading with yt-dlp to "{encrypted_location}"')
dl.download_yt_dlp(encrypted_location, stream_url)
if download_mode == "nm3u8dlre":
logger.debug(f'Downloading with N_m3u8DL-RE to "{encrypted_location}"')
dl.download_nm3u8dlre(encrypted_location, stream_url)
decrypted_location = dl.get_decrypted_location_audio(track_id)
fixed_location = dl.get_fixed_location(track_id, ".m4a")
if remux_mode == "ffmpeg":
@@ -478,7 +482,7 @@ def main(
logger.debug(
f'Downloading video to "{encrypted_location_video}"'
)
dl.download(encrypted_location_video, stream_url_video)
dl.download_yt_dlp(encrypted_location_video, stream_url_video)
encrypted_location_audio = dl.get_encrypted_location_audio(
track_id
)
@@ -488,7 +492,7 @@ def main(
logger.debug(
f'Downloading audio to "{encrypted_location_audio}"'
)
dl.download(encrypted_location_audio, stream_url_audio)
dl.download_yt_dlp(encrypted_location_audio, stream_url_audio)
logger.debug(
f'Decrypting video to "{decrypted_location_video}"'
)
+26 -29
View File
@@ -36,8 +36,6 @@ class Downloader:
template_file_music_video: str = None,
cover_size: int = None,
cover_format: str = None,
remux_mode: str = None,
download_mode: str = None,
exclude_tags: str = None,
truncate: int = None,
prefer_hevc: bool = None,
@@ -69,8 +67,6 @@ class Downloader:
self.template_file_music_video = template_file_music_video
self.cover_size = cover_size
self.cover_format = cover_format
self.remux_mode = remux_mode
self.download_mode = download_mode
self.exclude_tags = (
[i.lower() for i in exclude_tags.split(",")]
if exclude_tags is not None
@@ -230,37 +226,38 @@ class Downloader:
def get_lrc_location(self, final_location):
return final_location.with_suffix(".lrc")
def download(self, encrypted_location, stream_url):
if self.download_mode == "yt-dlp":
params = {
def download_yt_dlp(self, encrypted_location, stream_url):
with YoutubeDL(
{
"quiet": True,
"no_warnings": True,
"outtmpl": str(encrypted_location),
"allow_unplayable_formats": True,
"fixup": "never",
}
with YoutubeDL(params) as ydl:
ydl.download(stream_url)
else:
subprocess.run(
[
self.nm3u8dlre_location,
stream_url,
"--binary-merge",
"--no-log",
"--log-level",
"off",
"--ffmpeg-binary-path",
self.ffmpeg_location,
"--save-name",
encrypted_location.stem,
"--save-dir",
encrypted_location.parent,
"--tmp-dir",
encrypted_location.parent,
],
check=True,
)
) as ydl:
ydl.download(stream_url)
def download_nm3u8dlre(self, encrypted_location, stream_url):
subprocess.run(
[
self.nm3u8dlre_location,
stream_url,
"--binary-merge",
"--no-log",
"--log-level",
"off",
"--ffmpeg-binary-path",
self.ffmpeg_location,
"--save-name",
encrypted_location.stem,
"--save-dir",
encrypted_location.parent,
"--tmp-dir",
encrypted_location.parent,
],
check=True,
)
def get_license_b64(self, challenge, track_uri, track_id):
return self.session.post(