Writes the m3u file to disk. Handles the creation of potential parent directories.
(self)
| 73 | self.extm3u = extm3u |
| 74 | |
| 75 | def write(self): |
| 76 | """Writes the m3u file to disk. |
| 77 | |
| 78 | Handles the creation of potential parent directories. |
| 79 | """ |
| 80 | header = [b"#EXTM3U"] if self.extm3u else [] |
| 81 | if not self.media_list: |
| 82 | raise EmptyPlaylistError |
| 83 | contents = header + self.media_list |
| 84 | pl_normpath = normpath(self.path) |
| 85 | mkdirall(pl_normpath) |
| 86 | |
| 87 | try: |
| 88 | with open(syspath(pl_normpath), "wb") as pl_file: |
| 89 | for line in contents: |
| 90 | pl_file.write(line + b"\n") |
| 91 | pl_file.write(b"\n") # Final linefeed to prevent noeol file. |
| 92 | except OSError as exc: |
| 93 | raise FilesystemError( |
| 94 | exc, "create", (pl_normpath,), traceback.format_exc() |
| 95 | ) |