Example #1
0
 def delete(id) -> bool:
     """
     Delete the
     :param id:  The ID of the playlist
     :return:  Always true
     """
     library.Playlist(id).delete()
     return True
Example #2
0
 def put(self, id) -> bool:
     """
     Change the name of the playlist
     :param id:  The ID of the playlist
     :return:  Always true
     """
     args = self._parser.parse_args(strict=True)
     playlist = library.Playlist(id)
     if args['name'] is not None:
         playlist.name = args['name']
     if args['tracks'] is not None:
         playlist.tracks = args['tracks']
     return True
Example #3
0
    def send(self, playlist_name=None, limit=10, offset=None):

        self.playlist = playlist_name
        if self.request_type == 'playlists':
            self.user.playlists = library.get_user_playlists(self)
            self.results = self.user.playlists
        elif self.request_type == 'playlist':
            if playlist_name is None:
                raise ValueError('No playlist name specified')
            if self.user.playlists is None:  # need playlist ids first
                self.user.playlists = library.get_user_playlists(self)
            else:
                pass
            playlist = library.Playlist(self, playlist_name)
            self.results = playlist.get()
        elif self.request_type == 'all_playlists':
            if self.user.playlists is None:  # need playlist ids first
                self.user.playlists = library.get_user_playlists(self)
            else:
                pass
            print(
                '\n\n When using all_playlists request, results are published automatically.'
                '\'publish\' method will not return results\n\n')

            for i, item in zip(range(limit + offset), self.user.playlists):
                if i >= offset:
                    self.playlist = self.user.playlists.iloc[i]['name']
                    playlist = library.Playlist(
                        self, self.user.playlists.iloc[i]['name'])
                    self.results = playlist.get()
                    print('fetching playlist \"{}\"'.format(
                        self.user.playlists.iloc[i]['name']))
                    self.publish()
            self.results = None  # results returned to empty to avoid re-publishing
            self.playlist = None

        else:
            print('sorry, this request isn\'t configured yet')
Example #4
0
 def get(self, id) -> typing.List[typing.Dict]:
     """
     Get the tracks for a playlist
     :param id:  The ID of the playlist
     :return:  A list of the tracks in the playlist
     """
     playlist = library.Playlist(id)
     return [{
         'id': track.id,
         'location': track.location,
         'title': track.title,
         'artist': track.artist,
         'length': track.length
     } for track in playlist]