mirror of
https://github.com/glomatico/gamdl.git
synced 2025-01-22 11:18:39 +00:00
add save_playlist_file
option
This commit is contained in:
parent
0cd87254d3
commit
19fdd85c35
18
gamdl/cli.py
18
gamdl/cli.py
@ -97,6 +97,11 @@ def load_config_file(
|
|||||||
is_flag=True,
|
is_flag=True,
|
||||||
help="Interpret URLs as paths to text files containing URLs separated by newlines",
|
help="Interpret URLs as paths to text files containing URLs separated by newlines",
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"--save-playlist-file",
|
||||||
|
is_flag=True,
|
||||||
|
help="Save a M3U8 playlist file when downloading a playlist.",
|
||||||
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--synced-lyrics-only",
|
"--synced-lyrics-only",
|
||||||
is_flag=True,
|
is_flag=True,
|
||||||
@ -237,6 +242,12 @@ def load_config_file(
|
|||||||
default=downloader_sig.parameters["template_file_no_album"].default,
|
default=downloader_sig.parameters["template_file_no_album"].default,
|
||||||
help="Template file for the tracks that are not part of an album.",
|
help="Template file for the tracks that are not part of an album.",
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"--template-file-playlist",
|
||||||
|
type=str,
|
||||||
|
default=downloader_sig.parameters["template_file_playlist"].default,
|
||||||
|
help="Template file for the M3U8 playlist.",
|
||||||
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--template-date",
|
"--template-date",
|
||||||
type=str,
|
type=str,
|
||||||
@ -302,6 +313,7 @@ def main(
|
|||||||
save_cover: bool,
|
save_cover: bool,
|
||||||
overwrite: bool,
|
overwrite: bool,
|
||||||
read_urls_as_txt: bool,
|
read_urls_as_txt: bool,
|
||||||
|
save_playlist_file: bool,
|
||||||
synced_lyrics_only: bool,
|
synced_lyrics_only: bool,
|
||||||
no_synced_lyrics: bool,
|
no_synced_lyrics: bool,
|
||||||
config_path: Path,
|
config_path: Path,
|
||||||
@ -325,6 +337,7 @@ def main(
|
|||||||
template_file_multi_disc: str,
|
template_file_multi_disc: str,
|
||||||
template_folder_no_album: str,
|
template_folder_no_album: str,
|
||||||
template_file_no_album: str,
|
template_file_no_album: str,
|
||||||
|
template_file_playlist: str,
|
||||||
template_date: str,
|
template_date: str,
|
||||||
exclude_tags: str,
|
exclude_tags: str,
|
||||||
cover_size: int,
|
cover_size: int,
|
||||||
@ -372,6 +385,7 @@ def main(
|
|||||||
template_file_multi_disc,
|
template_file_multi_disc,
|
||||||
template_folder_no_album,
|
template_folder_no_album,
|
||||||
template_file_no_album,
|
template_file_no_album,
|
||||||
|
template_file_playlist,
|
||||||
template_date,
|
template_date,
|
||||||
exclude_tags,
|
exclude_tags,
|
||||||
cover_size,
|
cover_size,
|
||||||
@ -731,6 +745,10 @@ def main(
|
|||||||
downloader.apply_tags(remuxed_path, tags, cover_url)
|
downloader.apply_tags(remuxed_path, tags, cover_url)
|
||||||
logger.debug(f'Moving to "{final_path}"')
|
logger.debug(f'Moving to "{final_path}"')
|
||||||
downloader.move_to_output_path(remuxed_path, final_path)
|
downloader.move_to_output_path(remuxed_path, final_path)
|
||||||
|
if save_playlist_file and download_queue.playlist_attributes:
|
||||||
|
playlist_file_path = downloader.get_playlist_file_path(tags)
|
||||||
|
logger.debug("Saving M3U8 playlist")
|
||||||
|
downloader.update_playlist_file(playlist_file_path, final_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_count += 1
|
error_count += 1
|
||||||
logger.error(
|
logger.error(
|
||||||
|
@ -50,6 +50,7 @@ class Downloader:
|
|||||||
template_file_multi_disc: str = "{disc}-{track:02d} {title}",
|
template_file_multi_disc: str = "{disc}-{track:02d} {title}",
|
||||||
template_folder_no_album: str = "{artist}/Unknown Album",
|
template_folder_no_album: str = "{artist}/Unknown Album",
|
||||||
template_file_no_album: str = "{title}",
|
template_file_no_album: str = "{title}",
|
||||||
|
template_file_playlist: str = "{playlist_title}",
|
||||||
template_date: str = "%Y-%m-%dT%H:%M:%SZ",
|
template_date: str = "%Y-%m-%dT%H:%M:%SZ",
|
||||||
exclude_tags: str = None,
|
exclude_tags: str = None,
|
||||||
cover_size: int = 1200,
|
cover_size: int = 1200,
|
||||||
@ -74,6 +75,7 @@ class Downloader:
|
|||||||
self.template_file_multi_disc = template_file_multi_disc
|
self.template_file_multi_disc = template_file_multi_disc
|
||||||
self.template_folder_no_album = template_folder_no_album
|
self.template_folder_no_album = template_folder_no_album
|
||||||
self.template_file_no_album = template_file_no_album
|
self.template_file_no_album = template_file_no_album
|
||||||
|
self.template_file_playlist = template_file_playlist
|
||||||
self.template_date = template_date
|
self.template_date = template_date
|
||||||
self.exclude_tags = exclude_tags
|
self.exclude_tags = exclude_tags
|
||||||
self.cover_size = cover_size
|
self.cover_size = cover_size
|
||||||
@ -259,6 +261,29 @@ class Downloader:
|
|||||||
}
|
}
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
def get_playlist_file_path(
|
||||||
|
self,
|
||||||
|
tags: dict,
|
||||||
|
):
|
||||||
|
template_folder = self.template_file_playlist.split("/")[0:-1]
|
||||||
|
template_file = self.template_file_playlist.split("/")[-1]
|
||||||
|
return self.output_path.joinpath(
|
||||||
|
*[
|
||||||
|
self.get_sanitized_string(i.format(**tags), True)
|
||||||
|
for i in template_folder
|
||||||
|
]
|
||||||
|
).joinpath(
|
||||||
|
*[self.get_sanitized_string(template_file.format(**tags), False) + ".m3u8"]
|
||||||
|
)
|
||||||
|
|
||||||
|
def update_playlist_file(
|
||||||
|
self,
|
||||||
|
playlist_file_path: Path,
|
||||||
|
final_path: Path,
|
||||||
|
):
|
||||||
|
with playlist_file_path.open("a") as playlist_file:
|
||||||
|
playlist_file.write(final_path.relative_to(self.output_path).as_posix() + "\n")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def millis_to_min_sec(millis):
|
def millis_to_min_sec(millis):
|
||||||
minutes, seconds = divmod(millis // 1000, 60)
|
minutes, seconds = divmod(millis // 1000, 60)
|
||||||
@ -344,30 +369,28 @@ class Downloader:
|
|||||||
|
|
||||||
def get_final_path(self, tags: dict, file_extension: str) -> Path:
|
def get_final_path(self, tags: dict, file_extension: str) -> Path:
|
||||||
if tags.get("album"):
|
if tags.get("album"):
|
||||||
final_path_folder = (
|
template_folder = (
|
||||||
self.template_folder_compilation.split("/")
|
self.template_folder_compilation.split("/")
|
||||||
if tags.get("compilation")
|
if tags.get("compilation")
|
||||||
else self.template_folder_album.split("/")
|
else self.template_folder_album.split("/")
|
||||||
)
|
)[0:-1]
|
||||||
final_path_file = (
|
template_file = (
|
||||||
self.template_file_multi_disc.split("/")
|
self.template_file_multi_disc.split("/")
|
||||||
if tags["disc_total"] > 1
|
if tags["disc_total"] > 1
|
||||||
else self.template_file_single_disc.split("/")
|
else self.template_file_single_disc.split("/")
|
||||||
)
|
)[-1]
|
||||||
else:
|
else:
|
||||||
final_path_folder = self.template_folder_no_album.split("/")
|
template_folder = self.template_folder_no_album.split("/")[0:-1]
|
||||||
final_path_file = self.template_file_no_album.split("/")
|
template_file = self.template_file_no_album.split("/")[-1]
|
||||||
final_path_folder = [
|
return self.output_path.joinpath(
|
||||||
self.get_sanitized_string(i.format(**tags), True) for i in final_path_folder
|
*[
|
||||||
]
|
self.get_sanitized_string(i.format(**tags), True)
|
||||||
final_path_file = [
|
for i in template_folder
|
||||||
self.get_sanitized_string(i.format(**tags), True)
|
]
|
||||||
for i in final_path_file[:-1]
|
).joinpath(
|
||||||
] + [
|
self.get_sanitized_string(template_file.format(**tags), False)
|
||||||
self.get_sanitized_string(final_path_file[-1].format(**tags), False)
|
|
||||||
+ file_extension
|
+ file_extension
|
||||||
]
|
)
|
||||||
return self.output_path.joinpath(*final_path_folder).joinpath(*final_path_file)
|
|
||||||
|
|
||||||
def get_cover_file_extension(self, cover_url: str) -> str:
|
def get_cover_file_extension(self, cover_url: str) -> str:
|
||||||
image_obj = Image.open(io.BytesIO(self.get_url_response_bytes(cover_url)))
|
image_obj = Image.open(io.BytesIO(self.get_url_response_bytes(cover_url)))
|
||||||
|
Loading…
Reference in New Issue
Block a user