diff options
author | J0J0 Todos <jojo@peek-a-boo.at> | 2023-03-05 12:39:41 +0100 |
---|---|---|
committer | J0J0 Todos <jojo@peek-a-boo.at> | 2023-03-29 07:46:08 +0200 |
commit | 952aa0baddb92dcacce782f64423d9e27cd16d7b (patch) | |
tree | 33dd01b2e0d2f4f100e26ade2dd9dc2f35e9d335 | |
parent | 46fb8fef914c84a9e1279a09ff131fefd05f0e82 (diff) |
convert: playlist: Handle playlist path subdirs
The M3UFile.write() method now creates potential parent directories in a passed
playlist path.
util.mkdirall() handles errors nicely already and would exit the mainprogram
before potential subsequent failures could happen (it raises
util.FilesystemError).
-rw-r--r-- | beets/util/m3u.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/beets/util/m3u.py b/beets/util/m3u.py index 7903157a5..e026ccf03 100644 --- a/beets/util/m3u.py +++ b/beets/util/m3u.py @@ -15,7 +15,7 @@ """Provides utilities to read, write and manipulate m3u playlist files.""" -from beets.util import syspath, normpath +from beets.util import syspath, normpath, mkdirall class EmptyPlaylistError(Exception): @@ -65,11 +65,17 @@ class M3UFile(): self.extm3u = extm3u def write(self): - """Writes the m3u file to disk.""" + """Writes the m3u file to disk. + + Handles the creation of potential parent directories. + """ header = ["#EXTM3U"] if self.extm3u else [] if not self.media_list: raise EmptyPlaylistError contents = header + self.media_list - with open(syspath(normpath(self.path)), "w", encoding="utf-8") as playlist_file: + pl_normpath = normpath(self.path) + mkdirall(pl_normpath) + + with open(syspath(pl_normpath), "w", encoding="utf-8") as playlist_file: playlist_file.writelines('\n'.join(contents)) playlist_file.write('\n') # Final linefeed to prevent noeol file. |