mirror of
https://github.com/beetbox/beets.git
synced 2026-01-08 17:08:12 +01:00
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).
This commit is contained in:
parent
46fb8fef91
commit
952aa0badd
1 changed files with 9 additions and 3 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue