1
2
3 __author__ = "Abhinav Sarkar <abhinav@abhinavsarkar.net>"
4 __version__ = "0.2"
5 __license__ = "GNU Lesser General Public License"
6
7 from lastfm.base import LastfmBase
8 from lastfm.mixins import Cacheable
9 from lastfm.decorators import cached_property
10
11 -class Playlist(LastfmBase, Cacheable):
12 """A class representing an XPSF playlist."""
13 - def init(self, api, url, **kwargs):
14 self._api = api
15 self._data = None
16 self._url = url
17
18 @cached_property
20 """playlist's data"""
21 params = {'method': 'playlist.fetch', 'playlistURL': self._url}
22 tmp = StringIO.StringIO()
23 ElementTree.ElementTree(self._api._fetch_data(params)[0]).write(tmp)
24 return tmp.getvalue()
25
26 @property
28 """url of the playlist"""
29 return self._url
30
31 @staticmethod
34
35 @staticmethod
37 try:
38 return hash(kwds['url'])
39 except KeyError:
40 raise InvalidParametersError("url has to be provided for hashing")
41
44
46 return self.url == other.url
47
49 return self.url < other.url
50
52 return "<lastfm.Playlist: %s>" % self.url
53
54 import StringIO
55 import sys
56 from lastfm.error import InvalidParametersError
57
58 if sys.version_info >= (2, 5):
59 import xml.etree.cElementTree as ElementTree
60 else:
61 try:
62 import cElementTree as ElementTree
63 except ImportError:
64 try:
65 import ElementTree
66 except ImportError:
67 from error import LastfmError
68 raise LastfmError("Install ElementTree package for using python-lastfm")
69