def _save_m3u(self, playlist): file_path = path.uri_to_path(playlist.uri) path.check_file_path_is_inside_base_dir(file_path, self._path) with open(file_path, 'w') as file_handle: for track in playlist.tracks: if track.uri.startswith('file://'): uri = path.uri_to_path(track.uri) else: uri = track.uri file_handle.write(uri + '\n')
def _rename_m3u(self, playlist): src_file_path = path.uri_to_path(playlist.uri) path.check_file_path_is_inside_base_dir(src_file_path, self._path) dst_file_path = self._get_m3u_path(playlist.name) path.check_file_path_is_inside_base_dir(dst_file_path, self._path) shutil.move(src_file_path, dst_file_path) return playlist.copy(uri=path.path_to_uri(dst_file_path))
def _get_m3u_path(self, name): name = formatting.slugify(name) file_path = os.path.join(self._path, name + '.m3u') path.check_file_path_is_inside_base_dir(file_path, self._path) return file_path
def _delete_m3u(self, uri): file_path = path.uri_to_path(uri) path.check_file_path_is_inside_base_dir(file_path, self._path) if os.path.exists(file_path): os.remove(file_path)
def _m3u_uri_to_path(self, uri): # TODO: create uri handling helpers for local uri types. file_path = path.uri_to_path(uri).split(':', 1)[1] file_path = os.path.join(self._playlists_dir, file_path) path.check_file_path_is_inside_base_dir(file_path, self._playlists_dir) return file_path
def _m3u_uri_to_path(self, uri): # TODO: create uri handling helpers for local uri types. file_path = path.uri_to_path(uri).split(':', 1)[1] file_path = os.path.join(self._playlists_dir, file_path) path.check_file_path_is_inside_base_dir(file_path, self._playlists_dir) return file_path