Code Duplication    Length = 28-35 lines in 3 locations

pylast/__init__.py 3 locations

@@ 3307-3341 (lines=35) @@
3304
3305
        return seq
3306
3307
    def get_loved_tracks(self, limit=50, cacheable=True):
3308
        """
3309
        Returns this user's loved track as a sequence of LovedTrack objects in
3310
        reverse order of their timestamp, all the way back to the first track.
3311
3312
        If limit==None, it will try to pull all the available data.
3313
3314
        This method uses caching. Enable caching only if you're pulling a
3315
        large amount of data.
3316
3317
        Use extract_items() with the return of this function to
3318
        get only a sequence of Track objects with no playback dates.
3319
        """
3320
3321
        params = self._get_params()
3322
        if limit:
3323
            params['limit'] = limit
3324
3325
        seq = []
3326
        for track in _collect_nodes(
3327
                limit,
3328
                self,
3329
                self.ws_prefix + ".getLovedTracks",
3330
                cacheable,
3331
                params):
3332
            title = _extract(track, "name")
3333
            artist = _extract(track, "name", 1)
3334
            date = _extract(track, "date")
3335
            timestamp = track.getElementsByTagName(
3336
                "date")[0].getAttribute("uts")
3337
3338
            seq.append(LovedTrack(
3339
                Track(artist, title, self.network), date, timestamp))
3340
3341
        return seq
3342
3343
    def get_neighbours(self, limit=50, cacheable=True):
3344
        """Returns a list of the user's friends."""
@@ 3264-3292 (lines=29) @@
3261
3262
        return _extract_events_from_doc(doc, self.network)
3263
3264
    def get_artist_tracks(self, artist, cacheable=False):
3265
        """
3266
        Get a list of tracks by a given artist scrobbled by this user,
3267
        including scrobble time.
3268
        """
3269
        # Not implemented:
3270
        # "Can be limited to specific timeranges, defaults to all time."
3271
3272
        params = self._get_params()
3273
        params['artist'] = artist
3274
3275
        seq = []
3276
        for track in _collect_nodes(
3277
                None,
3278
                self,
3279
                self.ws_prefix + ".getArtistTracks",
3280
                cacheable,
3281
                params):
3282
            title = _extract(track, "name")
3283
            artist = _extract(track, "artist")
3284
            date = _extract(track, "date")
3285
            album = _extract(track, "album")
3286
            timestamp = track.getElementsByTagName(
3287
                "date")[0].getAttribute("uts")
3288
3289
            seq.append(PlayedTrack(
3290
                Track(artist, title, self.network), album, date, timestamp))
3291
3292
        return seq
3293
3294
    def get_friends(self, limit=50, cacheable=False):
3295
        """Returns a list of the user's friends. """
@@ 2682-2709 (lines=28) @@
2679
2680
        return seq
2681
2682
    def get_tracks(self, artist=None, album=None, limit=50, cacheable=True):
2683
        """
2684
        Returns a sequence of Album objects
2685
        If limit==None it will return all (may take a while)
2686
        """
2687
2688
        params = self._get_params()
2689
        if artist:
2690
            params["artist"] = artist
2691
        if album:
2692
            params["album"] = album
2693
2694
        seq = []
2695
        for node in _collect_nodes(
2696
                limit,
2697
                self,
2698
                self.ws_prefix + ".getTracks",
2699
                cacheable,
2700
                params):
2701
            name = _extract(node, "name")
2702
            artist = _extract(node, "name", 1)
2703
            playcount = _number(_extract(node, "playcount"))
2704
            tagcount = _number(_extract(node, "tagcount"))
2705
2706
            seq.append(LibraryItem(
2707
                Track(artist, name, self.network), playcount, tagcount))
2708
2709
        return seq
2710
2711
    def remove_scrobble(self, artist, title, timestamp):
2712
        """Remove a scrobble from a user's Last.fm library. Parameters: