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 10 -class Playlist(LastfmBase, Cacheable):
11 """A class representing an XPSF playlist."""
12 - def init(self, api, url):
13 self._api = api 14 self._data = None 15 self._url = url
16 17 @LastfmBase.cached_property
18 - def data(self):
19 """playlist's data""" 20 params = {'method': 'playlist.fetch', 'playlistURL': self._url} 21 tmp = StringIO.StringIO() 22 ElementTree.ElementTree(self._api._fetch_data(params)[0]).write(tmp) 23 return tmp.getvalue()
24 25 @property
26 - def url(self):
27 """url of the playlist""" 28 return self._url
29 30 @staticmethod
31 - def fetch(api, url):
32 return Playlist(api, url = url)
33 34 @staticmethod
35 - def _hash_func(*args, **kwds):
36 try: 37 return hash(kwds['url']) 38 except KeyError: 39 raise InvalidParametersError("url has to be provided for hashing")
40
41 - def __hash__(self):
42 return self.__class__._hash_func(url = self.url)
43
44 - def __eq__(self, other):
45 return self.url == other.url
46
47 - def __lt__(self, other):
48 return self.url < other.url
49
50 - def __repr__(self):
51 return "<lastfm.Playlist: %s>" % self.url
52 53 import StringIO 54 import sys 55 from lastfm.error import InvalidParametersError 56 57 if sys.version_info >= (2, 5): 58 import xml.etree.cElementTree as ElementTree 59 else: 60 try: 61 import cElementTree as ElementTree 62 except ImportError: 63 try: 64 import ElementTree 65 except ImportError: 66 from error import LastfmError 67 raise LastfmError("Install ElementTree package for using python-lastfm") 68