Skip to content

Commit

Permalink
Create proper m3u files.
Browse files Browse the repository at this point in the history
Format is header, then a list of metadata and filepath pairs.

Fixes #2246.
  • Loading branch information
jessicah committed Nov 27, 2024
1 parent 34f867c commit 5a4a551
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions spotdl/console/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
2 changes: 2 additions & 0 deletions spotdl/console/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down
1 change: 1 addition & 0 deletions spotdl/download/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion spotdl/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 17 additions & 4 deletions spotdl/utils/m3u.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -120,6 +127,7 @@ def gen_m3u_files(
),
song_list,
template,
m3u_template,
file_extension,
restrict,
short,
Expand All @@ -131,6 +139,7 @@ def gen_m3u_files(
file_name.format(list=list(lists_object.keys())),
songs,
template,
m3u_template,
file_extension,
restrict,
short,
Expand All @@ -142,6 +151,7 @@ def gen_m3u_files(
file_name,
songs,
template,
m3u_template,
file_extension,
restrict,
short,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -177,6 +189,7 @@ def create_m3u_file(
m3u_content = create_m3u_content(
song_list,
template,
m3u_template,
file_extension,
restrict,
short,
Expand Down

0 comments on commit 5a4a551

Please sign in to comment.