Code Duplication    Length = 28-35 lines in 3 locations

pylast/__init__.py 3 locations

@@ 3307-3341 (lines=35) @@
3304
3305
    @_string_output
3306
    def __str__(self):
3307
        return self.get_name()
3308
3309
    def __eq__(self, another):
3310
        if isinstance(another, User):
3311
            return self.get_name() == another.get_name()
3312
        else:
3313
            return False
3314
3315
    def __ne__(self, another):
3316
        if isinstance(another, User):
3317
            return self.get_name() != another.get_name()
3318
        else:
3319
            return True
3320
3321
    def _get_params(self):
3322
        return {self.ws_prefix: self.get_name()}
3323
3324
    def get_name(self, properly_capitalized=False):
3325
        """Returns the user name."""
3326
3327
        if properly_capitalized:
3328
            self.name = _extract(
3329
                self._request(self.ws_prefix + ".getInfo", True), "name")
3330
3331
        return self.name
3332
3333
    def get_upcoming_events(self):
3334
        """Returns all the upcoming events for this user."""
3335
3336
        doc = self._request(self.ws_prefix + '.getEvents', True)
3337
3338
        return _extract_events_from_doc(doc, self.network)
3339
3340
    def get_artist_tracks(self, artist, cacheable=False):
3341
        """
3342
        Get a list of tracks by a given artist scrobbled by this user,
3343
        including scrobble time.
3344
        """
@@ 3264-3292 (lines=29) @@
3261
3262
    def __ne__(self, other):
3263
        return self.get_uri() != other.get_uri()
3264
3265
    def get_uri(self):
3266
        """Returns the Last.fm playlist URI. """
3267
3268
        return self.uri
3269
3270
    def get_tracks(self):
3271
        """Returns the tracks on this playlist."""
3272
3273
        doc = self._request('playlist.fetch', True)
3274
3275
        seq = []
3276
        for node in doc.getElementsByTagName('track'):
3277
            title = _extract(node, 'title')
3278
            artist = _extract(node, 'creator')
3279
3280
            seq.append(Track(artist, title, self.network))
3281
3282
        return seq
3283
3284
3285
class User(_BaseObject, _Chartable):
3286
    """A Last.fm user."""
3287
3288
    name = None
3289
3290
    __hash__ = _BaseObject.__hash__
3291
3292
    def __init__(self, user_name, network):
3293
        _BaseObject.__init__(self, network, 'user')
3294
        _Chartable.__init__(self, 'user')
3295
@@ 2682-2709 (lines=28) @@
2679
2680
        params = self._get_params()
2681
        if type(artist) == str:
2682
            params["artist"] = artist
2683
        else:
2684
            params["artist"] = artist.get_name()
2685
2686
        self._request(self.ws_prefix + ".addArtist", False, params)
2687
2688
    def remove_artist(self, artist):
2689
        """Remove an artist from this library."""
2690
2691
        params = self._get_params()
2692
        if type(artist) == str:
2693
            params["artist"] = artist
2694
        else:
2695
            params["artist"] = artist.get_name()
2696
2697
        self._request(self.ws_prefix + ".removeArtist", False, params)
2698
2699
    def add_track(self, track):
2700
        """Add a track to this library."""
2701
2702
        params = self._get_params()
2703
        params["track"] = track.get_title()
2704
2705
        self._request(self.ws_prefix + ".addTrack", False, params)
2706
2707
    def get_albums(self, artist=None, limit=50, cacheable=True):
2708
        """
2709
        Returns a sequence of Album objects
2710
        If no artist is specified, it will return all, sorted by decreasing
2711
        play count.
2712
        If limit==None it will return all (may take a while)