Package lastfm :: Module playlist
[hide private]
[frames] | no frames]

Source Code for Module lastfm.playlist

 1  #!/usr/bin/env python 
 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
19 - def data(self):
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
27 - def url(self):
28 """url of the playlist""" 29 return self._url
30 31 @staticmethod
32 - def fetch(api, url):
33 return Playlist(api, url = url)
34 35 @staticmethod
36 - def _hash_func(*args, **kwds):
37 try: 38 return hash(kwds['url']) 39 except KeyError: 40 raise InvalidParametersError("url has to be provided for hashing")
41
42 - def __hash__(self):
43 return self.__class__._hash_func(url = self.url)
44
45 - def __eq__(self, other):
46 return self.url == other.url
47
48 - def __lt__(self, other):
49 return self.url < other.url
50
51 - def __repr__(self):
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