From 5a4a5514876152c1a079f84bbfa3abb8caefa168 Mon Sep 17 00:00:00 2001 From: Jessica Hamilton Date: Wed, 27 Nov 2024 13:44:58 +1300 Subject: [PATCH] Create proper m3u files. Format is header, then a list of metadata and filepath pairs. Fixes #2246. --- docs/usage.md | 2 +- spotdl/console/save.py | 1 + spotdl/console/sync.py | 2 ++ spotdl/download/downloader.py | 1 + spotdl/utils/config.py | 2 +- spotdl/utils/m3u.py | 21 +++++++++++++++++---- 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index e0debd881..4f5597977 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -281,7 +281,7 @@ If you don't want config to load automatically change `load_config` option in co "scan_for_songs": false, "m3u": null, "output": "{artists} - {title}.{output-ext}", - "m3u_output": "#EXTINF:{duration}, {artists} - {title}.{output-ext}", + "m3u_output": "#EXTINF:{duration},{album-artist} - {title}", "overwrite": "skip", "search_query": null, "ffmpeg": "ffmpeg", diff --git a/spotdl/console/save.py b/spotdl/console/save.py index 54fcb64c9..80e098921 100644 --- a/spotdl/console/save.py +++ b/spotdl/console/save.py @@ -108,6 +108,7 @@ async def pool_worker(song: Song): gen_m3u_files( songs, m3u_file, + downloader.settings["output"], downloader.settings["m3u_output"], downloader.settings["format"], downloader.settings["restrict"], diff --git a/spotdl/console/sync.py b/spotdl/console/sync.py index ce340ae53..1e989eb7a 100644 --- a/spotdl/console/sync.py +++ b/spotdl/console/sync.py @@ -82,6 +82,7 @@ def sync( gen_m3u_files( songs_list, m3u_file, + downloader.settings["output"], downloader.settings["m3u_output"], downloader.settings["format"], downloader.settings["restrict"], @@ -232,6 +233,7 @@ def sync( gen_m3u_files( songs_playlist, m3u_file, + downloader.settings["output"], downloader.settings["m3u_output"], downloader.settings["format"], downloader.settings["restrict"], diff --git a/spotdl/download/downloader.py b/spotdl/download/downloader.py index 36a2e2158..72de1864c 100644 --- a/spotdl/download/downloader.py +++ b/spotdl/download/downloader.py @@ -339,6 +339,7 @@ def download_multiple_songs( gen_m3u_files( song_list, self.settings["m3u"], + self.settings["output"], self.settings["m3u_output"], self.settings["format"], self.settings["restrict"], diff --git a/spotdl/utils/config.py b/spotdl/utils/config.py index 7add380fc..b1fdf825d 100644 --- a/spotdl/utils/config.py +++ b/spotdl/utils/config.py @@ -313,7 +313,7 @@ def get_parameter(cls, key): "scan_for_songs": False, "m3u": None, "output": "{artists} - {title}.{output-ext}", - "m3u_output": "#EXTINF:{duration}, {artists} - {title}.{output-ext}", + "m3u_output": "#EXTINF:{duration},{album-artist} - {title}", "overwrite": "skip", "search_query": None, "ffmpeg": "ffmpeg", diff --git a/spotdl/utils/m3u.py b/spotdl/utils/m3u.py index 908d29388..29ed94a06 100644 --- a/spotdl/utils/m3u.py +++ b/spotdl/utils/m3u.py @@ -18,6 +18,7 @@ def create_m3u_content( song_list: List[Song], template: str, + m3u_template: str, file_extension: str, restrict: Optional[str] = None, short: bool = False, @@ -28,7 +29,8 @@ def create_m3u_content( ### Arguments - song_list: the list of songs - - template: the template to use + - template: the template to use for song files + - m3u_template: the template to use for song metadata - file_extension: the file extension to use - restrict: sanitization to apply to the filename - short: whether to use the short version of the template @@ -37,8 +39,11 @@ def create_m3u_content( - the m3u content as a string """ - text = "" + text = "#EXTM3U\n" for song in song_list: + m3u_info = create_file_name(song, m3u_template, "") + text += str(m3u_info) + "\n" + if not detect_formats: file_name = create_file_name( song, template, file_extension, restrict, short @@ -65,6 +70,7 @@ def gen_m3u_files( songs: List[Song], file_name: Optional[str], template: str, + m3u_template: str, file_extension: str, restrict: Optional[str] = None, short: bool = False, @@ -77,7 +83,8 @@ def gen_m3u_files( - query: the query - file_name: the file name to use - song_list: the list of songs - - template: the output file template to use + - template: the template to use for song files + - m3u_template: the template to use for song metadata - file_extension: the file extension to use - restrict: sanitization to apply to the filename - short: whether to use the short version of the template @@ -120,6 +127,7 @@ def gen_m3u_files( ), song_list, template, + m3u_template, file_extension, restrict, short, @@ -131,6 +139,7 @@ def gen_m3u_files( file_name.format(list=list(lists_object.keys())), songs, template, + m3u_template, file_extension, restrict, short, @@ -142,6 +151,7 @@ def gen_m3u_files( file_name, songs, template, + m3u_template, file_extension, restrict, short, @@ -153,6 +163,7 @@ def create_m3u_file( file_name: str, song_list: List[Song], template: str, + m3u_template: str, file_extension: str, restrict: Optional[str] = None, short: bool = False, @@ -164,7 +175,8 @@ def create_m3u_file( ### Arguments - file_name: the file name to use - song_list: the list of songs - - template: the template to use + - template: the template to use for song files + - m3u_template: the template to use for song metadata - file_extension: the file extension to use - restrict: sanitization to apply to the filename - short: whether to use the short version of the template @@ -177,6 +189,7 @@ def create_m3u_file( m3u_content = create_m3u_content( song_list, template, + m3u_template, file_extension, restrict, short,