mirror of
https://github.com/glomatico/gamdl.git
synced 2026-06-13 12:15:18 +03:00
split download function
This commit is contained in:
+8
-4
@@ -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
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user