Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions spotdl/utils/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def sanitize_string(string: str) -> str:
# this is windows specific (disallowed chars)
output = "".join(char for char in output if char not in "/?\\*|<>")

# clean up double spaces caused by the removal of these chars
output = output.replace(" ", " ")

# double quotes (") and semi-colons (:) are also disallowed characters but we would
# like to retain their equivalents, so they aren't removed in the prior loop
output = output.replace('"', "'").replace(":", "-")
Expand Down
6 changes: 4 additions & 2 deletions spotdl/utils/m3u.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def gen_m3u_files(
for list_name, song_list in lists_object.items():
create_m3u_file(
file_name.format(
list=list_name,
list=sanitize_string(list_name),
),
song_list,
template,
Expand All @@ -144,7 +144,9 @@ def gen_m3u_files(
elif "{list[" in file_name and "]}" in file_name:
# Create a single m3u file for specified song list name
create_m3u_file(
file_name.format(list=list(lists_object.keys())),
file_name.format(
list=[sanitize_string(key) for key in lists_object.keys()]
),
songs,
template,
file_extension,
Expand Down
11 changes: 10 additions & 1 deletion tests/utils/test_m3u.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from spotdl.types.playlist import Playlist
from spotdl.utils.m3u import create_m3u_content, create_m3u_file
from spotdl.utils.m3u import create_m3u_content, create_m3u_file, gen_m3u_files

PLAYLIST = "https://open.spotify.com/playlist/5LkNhFidYyyjRWwnkcMbQs"

Expand All @@ -23,3 +23,12 @@ def test_create_m3u_file(tmpdir, monkeypatch):
playlist = Playlist.from_url(PLAYLIST)
create_m3u_file("test.m3u", playlist.songs, "", "mp3")
assert tmpdir.join("test.m3u").isfile() is True

def test_gen_m3u_files(tmpdir, monkeypatch):
monkeypatch.chdir(tmpdir)
playlist = Playlist.from_url(PLAYLIST)
for song in playlist.songs:
song.list_name = "something / or other"
gen_m3u_files(playlist.songs, "./{list}", "", "mp3")
assert tmpdir.join("something or other.m3u8").isfile()