Exemple #1
0
    def _rename_m3u(self, playlist):
        dst_name = formatting.slugify(playlist.name)
        dst_uri = 'local:playlist:%s.m3u' % dst_name

        src_file_path = self._m3u_uri_to_path(playlist.uri)
        dst_file_path = self._m3u_uri_to_path(dst_uri)

        shutil.move(src_file_path, dst_file_path)
        return playlist.copy(uri=dst_uri)
Exemple #2
0
    def _rename_m3u(self, playlist):
        dst_name = formatting.slugify(playlist.name)
        dst_uri = 'local:playlist:%s.m3u' % dst_name

        src_file_path = self._m3u_uri_to_path(playlist.uri)
        dst_file_path = self._m3u_uri_to_path(dst_uri)

        shutil.move(src_file_path, dst_file_path)
        return playlist.copy(uri=dst_uri)
Exemple #3
0
 def create_stored(self, name, tracks):
     name = formatting.slugify(name)
     uri = 'local:stored:%s.json' % name
     playlist = Playlist(uri=uri, name=name, tracks=tracks)
     self._playlists = filter(lambda p: p.name != name, self._playlists)
     self._playlists.append(playlist)
     file_path = os.path.join(self._playlists_dir, name + '.json')
     create_stored_playlist(file_path, playlist)
     return playlist
Exemple #4
0
    def save(self, playlist):
        assert playlist.uri, 'Cannot save playlist without URI'

        old_playlist = self.lookup(playlist.uri)

        if old_playlist and playlist.name != old_playlist.name:
            playlist = playlist.copy(name=formatting.slugify(playlist.name))
            playlist = self._rename_m3u(playlist)

        self._save_m3u(playlist)

        if old_playlist is not None:
            index = self._playlists.index(old_playlist)
            self._playlists[index] = playlist
        else:
            self._playlists.append(playlist)

        return playlist
Exemple #5
0
 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
Exemple #6
0
 def create(self, name):
     name = formatting.slugify(name)
     uri = path.path_to_uri(self._get_m3u_path(name))
     playlist = Playlist(uri=uri, name=name)
     return self.save(playlist)
Exemple #7
0
 def create(self, name):
     name = formatting.slugify(name)
     uri = 'local:playlist:%s.m3u' % name
     playlist = Playlist(uri=uri, name=name)
     return self.save(playlist)
Exemple #8
0
 def create(self, name):
     name = formatting.slugify(name)
     uri = 'local:playlist:%s.m3u' % name
     playlist = Playlist(uri=uri, name=name)
     return self.save(playlist)