Code Duplication    Length = 64-70 lines in 2 locations

pylast/__init__.py 2 locations

@@ 794-863 (lines=70) @@
791
        return self.get_play_links("track", tracks, cacheable)
792
793
794
class LastFMNetwork(_Network):
795
796
    """A Last.fm network object
797
798
    api_key: a provided API_KEY
799
    api_secret: a provided API_SECRET
800
    session_key: a generated session_key or None
801
    username: a username of a valid user
802
    password_hash: the output of pylast.md5(password) where password is the
803
        user's password
804
805
    if username and password_hash were provided and not session_key,
806
    session_key will be generated automatically when needed.
807
808
    Either a valid session_key or a combination of username and password_hash
809
    must be present for scrobbling.
810
811
    Most read-only webservices only require an api_key and an api_secret, see
812
    about obtaining them from:
813
    http://www.last.fm/api/account
814
    """
815
816
    def __init__(
817
            self, api_key="", api_secret="", session_key="", username="",
818
            password_hash=""):
819
        _Network.__init__(
820
            self,
821
            name="Last.fm",
822
            homepage="http://last.fm",
823
            ws_server=("ws.audioscrobbler.com", "/2.0/"),
824
            api_key=api_key,
825
            api_secret=api_secret,
826
            session_key=session_key,
827
            submission_server="http://post.audioscrobbler.com:80/",
828
            username=username,
829
            password_hash=password_hash,
830
            domain_names={
831
                DOMAIN_ENGLISH: 'www.last.fm',
832
                DOMAIN_GERMAN: 'www.lastfm.de',
833
                DOMAIN_SPANISH: 'www.lastfm.es',
834
                DOMAIN_FRENCH: 'www.lastfm.fr',
835
                DOMAIN_ITALIAN: 'www.lastfm.it',
836
                DOMAIN_POLISH: 'www.lastfm.pl',
837
                DOMAIN_PORTUGUESE: 'www.lastfm.com.br',
838
                DOMAIN_SWEDISH: 'www.lastfm.se',
839
                DOMAIN_TURKISH: 'www.lastfm.com.tr',
840
                DOMAIN_RUSSIAN: 'www.lastfm.ru',
841
                DOMAIN_JAPANESE: 'www.lastfm.jp',
842
                DOMAIN_CHINESE: 'cn.last.fm',
843
            },
844
            urls={
845
                "album": "music/%(artist)s/%(album)s",
846
                "artist": "music/%(artist)s",
847
                "event": "event/%(id)s",
848
                "country": "place/%(country_name)s",
849
                "playlist": "user/%(user)s/library/playlists/%(appendix)s",
850
                "tag": "tag/%(name)s",
851
                "track": "music/%(artist)s/_/%(title)s",
852
                "group": "group/%(name)s",
853
                "user": "user/%(name)s",
854
            }
855
        )
856
857
    def __repr__(self):
858
        return "pylast.LastFMNetwork(%s)" % (", ".join(
859
            ("'%s'" % self.api_key,
860
             "'%s'" % self.api_secret,
861
             "'%s'" % self.session_key,
862
             "'%s'" % self.username,
863
             "'%s'" % self.password_hash)))
864
865
866
def get_lastfm_network(
@@ 896-959 (lines=64) @@
893
        api_key, api_secret, session_key, username, password_hash)
894
895
896
class LibreFMNetwork(_Network):
897
    """
898
    A preconfigured _Network object for Libre.fm
899
900
    api_key: a provided API_KEY
901
    api_secret: a provided API_SECRET
902
    session_key: a generated session_key or None
903
    username: a username of a valid user
904
    password_hash: the output of pylast.md5(password) where password is the
905
        user's password
906
907
    if username and password_hash were provided and not session_key,
908
    session_key will be generated automatically when needed.
909
    """
910
911
    def __init__(
912
            self, api_key="", api_secret="", session_key="", username="",
913
            password_hash=""):
914
915
        _Network.__init__(
916
            self,
917
            name="Libre.fm",
918
            homepage="http://libre.fm",
919
            ws_server=("libre.fm", "/2.0/"),
920
            api_key=api_key,
921
            api_secret=api_secret,
922
            session_key=session_key,
923
            submission_server="http://turtle.libre.fm:80/",
924
            username=username,
925
            password_hash=password_hash,
926
            domain_names={
927
                DOMAIN_ENGLISH: "libre.fm",
928
                DOMAIN_GERMAN: "libre.fm",
929
                DOMAIN_SPANISH: "libre.fm",
930
                DOMAIN_FRENCH: "libre.fm",
931
                DOMAIN_ITALIAN: "libre.fm",
932
                DOMAIN_POLISH: "libre.fm",
933
                DOMAIN_PORTUGUESE: "libre.fm",
934
                DOMAIN_SWEDISH: "libre.fm",
935
                DOMAIN_TURKISH: "libre.fm",
936
                DOMAIN_RUSSIAN: "libre.fm",
937
                DOMAIN_JAPANESE: "libre.fm",
938
                DOMAIN_CHINESE: "libre.fm",
939
            },
940
            urls={
941
                "album": "artist/%(artist)s/album/%(album)s",
942
                "artist": "artist/%(artist)s",
943
                "event": "event/%(id)s",
944
                "country": "place/%(country_name)s",
945
                "playlist": "user/%(user)s/library/playlists/%(appendix)s",
946
                "tag": "tag/%(name)s",
947
                "track": "music/%(artist)s/_/%(title)s",
948
                "group": "group/%(name)s",
949
                "user": "user/%(name)s",
950
            }
951
        )
952
953
    def __repr__(self):
954
        return "pylast.LibreFMNetwork(%s)" % (", ".join(
955
            ("'%s'" % self.api_key,
956
             "'%s'" % self.api_secret,
957
             "'%s'" % self.session_key,
958
             "'%s'" % self.username,
959
             "'%s'" % self.password_hash)))
960
961
962
def get_librefm_network(