Move get_wiki_published_date(), get_wiki_summary(), get_wiki_content() up to _BaseObject to remove duplication in Album and Track. Already has test cases.

This commit is contained in:
hugovk 2014-03-06 16:26:50 +02:00
parent 0747d5d20e
commit 7cb8a654ec

117
pylast.py
View file

@ -1489,6 +1489,51 @@ class _BaseObject(object):
self._request(self.ws_prefix + '.share', False, params) self._request(self.ws_prefix + '.share', False, params)
def get_wiki_published_date(self):
"""
Returns the date of publishing this version of the wiki.
Only for Album/Track.
"""
doc = self._request(self.ws_prefix + ".getInfo", True)
if len(doc.getElementsByTagName("wiki")) == 0:
return
node = doc.getElementsByTagName("wiki")[0]
return _extract(node, "published")
def get_wiki_summary(self):
"""
Returns the summary of the wiki.
Only for Album/Track.
"""
doc = self._request(self.ws_prefix + ".getInfo", True)
if len(doc.getElementsByTagName("wiki")) == 0:
return
node = doc.getElementsByTagName("wiki")[0]
return _extract(node, "summary")
def get_wiki_content(self):
"""
Returns the content of the wiki.
Only for Album/Track.
"""
doc = self._request(self.ws_prefix + ".getInfo", True)
if len(doc.getElementsByTagName("wiki")) == 0:
return
node = doc.getElementsByTagName("wiki")[0]
return _extract(node, "content")
class _Taggable(object): class _Taggable(object):
"""Common functions for classes with tags.""" """Common functions for classes with tags."""
@ -1818,42 +1863,6 @@ class Album(_BaseObject, _Taggable):
return self.network._get_url( return self.network._get_url(
domain_name, "album") % {'artist': artist, 'album': album} domain_name, "album") % {'artist': artist, 'album': album}
def get_wiki_published_date(self):
"""Returns the date of publishing this version of the wiki."""
doc = self._request("album.getInfo", True)
if len(doc.getElementsByTagName("wiki")) == 0:
return
node = doc.getElementsByTagName("wiki")[0]
return _extract(node, "published")
def get_wiki_summary(self):
"""Returns the summary of the wiki."""
doc = self._request("album.getInfo", True)
if len(doc.getElementsByTagName("wiki")) == 0:
return
node = doc.getElementsByTagName("wiki")[0]
return _extract(node, "summary")
def get_wiki_content(self):
"""Returns the content of the wiki."""
doc = self._request("album.getInfo", True)
if len(doc.getElementsByTagName("wiki")) == 0:
return
node = doc.getElementsByTagName("wiki")[0]
return _extract(node, "content")
class Artist(_BaseObject, _Taggable): class Artist(_BaseObject, _Taggable):
"""An artist.""" """An artist."""
@ -3114,42 +3123,6 @@ class Track(_BaseObject, _Taggable):
return Album( return Album(
_extract(node, "artist"), _extract(node, "title"), self.network) _extract(node, "artist"), _extract(node, "title"), self.network)
def get_wiki_published_date(self):
"""Returns the date of publishing this version of the wiki."""
doc = self._request("track.getInfo", True)
if len(doc.getElementsByTagName("wiki")) == 0:
return
node = doc.getElementsByTagName("wiki")[0]
return _extract(node, "published")
def get_wiki_summary(self):
"""Returns the summary of the wiki."""
doc = self._request("track.getInfo", True)
if len(doc.getElementsByTagName("wiki")) == 0:
return
node = doc.getElementsByTagName("wiki")[0]
return _extract(node, "summary")
def get_wiki_content(self):
"""Returns the content of the wiki."""
doc = self._request("track.getInfo", True)
if len(doc.getElementsByTagName("wiki")) == 0:
return
node = doc.getElementsByTagName("wiki")[0]
return _extract(node, "content")
def love(self): def love(self):
"""Adds the track to the user's loved tracks. """ """Adds the track to the user's loved tracks. """