Code Duplication    Length = 64-72 lines in 2 locations

pylast/__init__.py 2 locations

@@ 873-944 (lines=72) @@
870
        return self.get_play_links("track", tracks, cacheable)
871
872
873
class LastFMNetwork(_Network):
874
875
    """A Last.fm network object
876
877
    api_key: a provided API_KEY
878
    api_secret: a provided API_SECRET
879
    session_key: a generated session_key or None
880
    username: a username of a valid user
881
    password_hash: the output of pylast.md5(password) where password is the
882
        user's password
883
884
    if username and password_hash were provided and not session_key,
885
    session_key will be generated automatically when needed.
886
887
    Either a valid session_key or a combination of username and password_hash
888
    must be present for scrobbling.
889
890
    Most read-only webservices only require an api_key and an api_secret, see
891
    about obtaining them from:
892
    http://www.last.fm/api/account
893
    """
894
895
    def __init__(
896
            self, api_key="", api_secret="", session_key="", username="",
897
            password_hash="", token=""):
898
        _Network.__init__(
899
            self,
900
            name="Last.fm",
901
            homepage="http://last.fm",
902
            ws_server=("ws.audioscrobbler.com", "/2.0/"),
903
            api_key=api_key,
904
            api_secret=api_secret,
905
            session_key=session_key,
906
            submission_server="http://post.audioscrobbler.com:80/",
907
            username=username,
908
            password_hash=password_hash,
909
            token=token,
910
            domain_names={
911
                DOMAIN_ENGLISH: 'www.last.fm',
912
                DOMAIN_GERMAN: 'www.lastfm.de',
913
                DOMAIN_SPANISH: 'www.lastfm.es',
914
                DOMAIN_FRENCH: 'www.lastfm.fr',
915
                DOMAIN_ITALIAN: 'www.lastfm.it',
916
                DOMAIN_POLISH: 'www.lastfm.pl',
917
                DOMAIN_PORTUGUESE: 'www.lastfm.com.br',
918
                DOMAIN_SWEDISH: 'www.lastfm.se',
919
                DOMAIN_TURKISH: 'www.lastfm.com.tr',
920
                DOMAIN_RUSSIAN: 'www.lastfm.ru',
921
                DOMAIN_JAPANESE: 'www.lastfm.jp',
922
                DOMAIN_CHINESE: 'cn.last.fm',
923
            },
924
            urls={
925
                "album": "music/%(artist)s/%(album)s",
926
                "artist": "music/%(artist)s",
927
                "event": "event/%(id)s",
928
                "country": "place/%(country_name)s",
929
                "playlist": "user/%(user)s/library/playlists/%(appendix)s",
930
                "tag": "tag/%(name)s",
931
                "track": "music/%(artist)s/_/%(title)s",
932
                "group": "group/%(name)s",
933
                "user": "user/%(name)s",
934
            }
935
        )
936
937
    def __repr__(self):
938
        return "pylast.LastFMNetwork(%s)" % (", ".join(
939
            ("'%s'" % self.api_key,
940
             "'%s'" % self.api_secret,
941
             "'%s'" % self.session_key,
942
             "'%s'" % self.username,
943
             "'%s'" % self.password_hash,
944
             "'%s'" % self.token)))
945
946
947
def get_lastfm_network(
@@ 978-1041 (lines=64) @@
975
        api_key, api_secret, session_key, username, password_hash, token)
976
977
978
class LibreFMNetwork(_Network):
979
    """
980
    A preconfigured _Network object for Libre.fm
981
982
    api_key: a provided API_KEY
983
    api_secret: a provided API_SECRET
984
    session_key: a generated session_key or None
985
    username: a username of a valid user
986
    password_hash: the output of pylast.md5(password) where password is the
987
        user's password
988
989
    if username and password_hash were provided and not session_key,
990
    session_key will be generated automatically when needed.
991
    """
992
993
    def __init__(
994
            self, api_key="", api_secret="", session_key="", username="",
995
            password_hash=""):
996
997
        _Network.__init__(
998
            self,
999
            name="Libre.fm",
1000
            homepage="http://libre.fm",
1001
            ws_server=("libre.fm", "/2.0/"),
1002
            api_key=api_key,
1003
            api_secret=api_secret,
1004
            session_key=session_key,
1005
            submission_server="http://turtle.libre.fm:80/",
1006
            username=username,
1007
            password_hash=password_hash,
1008
            domain_names={
1009
                DOMAIN_ENGLISH: "libre.fm",
1010
                DOMAIN_GERMAN: "libre.fm",
1011
                DOMAIN_SPANISH: "libre.fm",
1012
                DOMAIN_FRENCH: "libre.fm",
1013
                DOMAIN_ITALIAN: "libre.fm",
1014
                DOMAIN_POLISH: "libre.fm",
1015
                DOMAIN_PORTUGUESE: "libre.fm",
1016
                DOMAIN_SWEDISH: "libre.fm",
1017
                DOMAIN_TURKISH: "libre.fm",
1018
                DOMAIN_RUSSIAN: "libre.fm",
1019
                DOMAIN_JAPANESE: "libre.fm",
1020
                DOMAIN_CHINESE: "libre.fm",
1021
            },
1022
            urls={
1023
                "album": "artist/%(artist)s/album/%(album)s",
1024
                "artist": "artist/%(artist)s",
1025
                "event": "event/%(id)s",
1026
                "country": "place/%(country_name)s",
1027
                "playlist": "user/%(user)s/library/playlists/%(appendix)s",
1028
                "tag": "tag/%(name)s",
1029
                "track": "music/%(artist)s/_/%(title)s",
1030
                "group": "group/%(name)s",
1031
                "user": "user/%(name)s",
1032
            }
1033
        )
1034
1035
    def __repr__(self):
1036
        return "pylast.LibreFMNetwork(%s)" % (", ".join(
1037
            ("'%s'" % self.api_key,
1038
             "'%s'" % self.api_secret,
1039
             "'%s'" % self.session_key,
1040
             "'%s'" % self.username,
1041
             "'%s'" % self.password_hash)))
1042
1043
1044
def get_librefm_network(