Example #1
0
class GMusic(object):
    def __init__(self):
        self.webclient = Webclient(debug_logging=False)
        self.mobileclient = Mobileclient(debug_logging=False)
        self.email = None
        self.password = None
        self.mc_authenticated = False
        self.wc_authenticated = False
        self.authenticated = False
        self.device = None
        self.all_songs = list()
        self.playlists = list()

    ###########################################################################
    # Name: authenticate()                                                    #
    # Description: Attempts to authenticate class Mobileclient and Webclient  #
    #              instances.                                                 #
    # Inputs: login credentials: email, password                              #
    # Outputs: returns True if both Mobileclient and Webclient auth is True   #
    ###########################################################################
    def authenticate(self, email=None, password=None):
        if email:
            self.email = email
        if password:
            self.password = password

        try:
            Log("Authenticating mobileclient...")
            self.mc_authenticated = self.mobileclient.login(
                self.email, self.password)
        except AlreadyLoggedIn:
            self.mc_authenticated = True

        try:
            Log("Authenticating webclient...")
            self.wc_authenticated = self.webclient.login(
                self.email, self.password)
        except AlreadyLoggedIn:
            self.wc_authenticated = True

        self.authenticated = self.mc_authenticated and self.wc_authenticated

        return self.authenticated

    ###########################################################################
    # Name: get_all_songs()                                                   #
    # Description: Returns a list of all songs                                #
    # Inputs: None                                                            #
    # Outputs: A list of all the songs a user owns.                           #
    ###########################################################################
    def get_all_songs(self):
        try:
            self.all_songs = self.mobileclient.get_all_songs()
        except NotLoggedIn:
            if self.authenticate():
                self.all_songs = self.mobileclient.get_all_songs()
            else:
                Log("LOGIN FAILURE")
                return

        return self.all_songs

    def get_all_playlists(self):
        try:
            self.playlists = self.mobileclient.get_all_playlist_ids()
        except NotLoggedIn:
            if self.authenticate():
                self.playlists = self.mobileclient.get_all_playlist_ids()
            else:
                Log("LOGIN FAILURE")
                return

        return self.playlists

    def get_stream_url(self, song_id):
        try:
            stream_url = self.mobileclient.get_stream_url(song_id)
        except NotLoggedIn:
            if self.authenticate():
                stream_url = self.mobileclient.get_stream_url(song_id)
            else:
                Log("LOGIN FAILURE")
                return

        return stream_url
Example #2
0
class GMusic(object):
    def __init__(self):
        self.webclient = Webclient(debug_logging=False)
        self.mobileclient = Mobileclient(debug_logging=False)
        self.email = None
        self.password = None
        self.mc_authenticated = False
        self.wc_authenticated = False
        self.authenticated = False
        self.device = None
        self.all_songs = list()
        self.playlists = list()

    ###########################################################################
    # Name: authenticate()                                                    #
    # Description: Attempts to authenticate class Mobileclient and Webclient  #
    #              instances.                                                 #
    # Inputs: login credentials: email, password                              #
    # Outputs: returns True if both Mobileclient and Webclient auth is True   #
    ###########################################################################
    def authenticate(self, email=None, password=None):
        if email:
            self.email = email
        if password:
            self.password = password

        try:
            Log("Authenticating mobileclient...")
            self.mc_authenticated = self.mobileclient.login(self.email, self.password)
        except AlreadyLoggedIn:
            self.mc_authenticated = True

        try:
            Log("Authenticating webclient...")
            self.wc_authenticated = self.webclient.login(self.email, self.password)
        except AlreadyLoggedIn:
            self.wc_authenticated = True

        self.authenticated = self.mc_authenticated and self.wc_authenticated

        return self.authenticated

    ###########################################################################
    # Name: get_all_songs()                                                   #
    # Description: Returns a list of all songs                                #
    # Inputs: None                                                            #
    # Outputs: A list of all the songs a user owns.                           #
    ###########################################################################
    def get_all_songs(self):
        try:
            self.all_songs = self.mobileclient.get_all_songs()
        except NotLoggedIn:
            if self.authenticate():
                self.all_songs = self.mobileclient.get_all_songs()
            else:
                Log("LOGIN FAILURE")
                return

        return self.all_songs

    def get_all_playlists(self):
        try:
            self.playlists = self.mobileclient.get_all_playlist_ids()
        except NotLoggedIn:
            if self.authenticate():
                self.playlists = self.mobileclient.get_all_playlist_ids()
            else:
                Log("LOGIN FAILURE")
                return

        return self.playlists

    def get_stream_url(self, song_id):
        try:
            stream_url = self.mobileclient.get_stream_url(song_id)
        except NotLoggedIn:
            if self.authenticate():
                stream_url = self.mobileclient.get_stream_url(song_id)
            else:
                Log("LOGIN FAILURE")
                return

        return stream_url