Пример #1
0
    def _get_things(self,
                    method,
                    thing,
                    thing_type,
                    params=None,
                    cacheable=True):
        """Returns a list of the most played thing_types by this thing, in a
        tuple with the total number of pages of results. Includes an MBID, if
        found.
        """
        doc = self._request(self.ws_prefix + "." + method, cacheable, params)

        toptracks_node = doc.getElementsByTagName('toptracks')[0]
        total_pages = int(toptracks_node.getAttribute('totalPages'))

        seq = []
        for node in doc.getElementsByTagName(thing):
            title = _extract(node, "name")
            artist = _extract(node, "name", 1)
            mbid = _extract(node, "mbid")
            playcount = _number(_extract(node, "playcount"))

            thing = thing_type(artist, title, self.network)
            thing.mbid = mbid
            seq.append(TopItem(thing, playcount))

        return seq, total_pages
Пример #2
0
 def get_similar(self, limit=None):
     if limit:
         doc = self._request(self.ws_prefix + '.getSimilar', True, params={'artist': self.artist.name,
                                                                           'track': self.title,
                                                                           'limit': limit})
     else:
         doc = self._request(self.ws_prefix + '.getSimilar', True)
     seq = []
     for node in doc.getElementsByTagName(self.ws_prefix):
         title = pylast._extract(node, 'name')
         artist = pylast._extract(node, 'name', 1)
         match = pylast._number(pylast._extract(node, "match"))
         seq.append(pylast.SimilarItem(pylast.Track(artist, title, self.network), match))
     return seq
Пример #3
0
    def _get_things(self, method, thing, thing_type, params=None, cacheable=True):
        """Returns a list of the most played thing_types by this thing, in a
        tuple with the total number of pages of results. Includes an MBID, if
        found.
        """
        doc = self._request(self.ws_prefix + "." + method, cacheable, params)

        toptracks_node = doc.getElementsByTagName("toptracks")[0]
        total_pages = int(toptracks_node.getAttribute("totalPages"))

        seq = []
        for node in doc.getElementsByTagName(thing):
            title = _extract(node, "name")
            artist = _extract(node, "name", 1)
            mbid = _extract(node, "mbid")
            playcount = _number(_extract(node, "playcount"))

            thing = thing_type(artist, title, self.network)
            thing.mbid = mbid
            seq.append(TopItem(thing, playcount))

        return seq, total_pages