Exemplo n.º 1
0
def load_login(_auth, _master):
    try:
        locale = 'en_US'
        android_id = gm_api_mob.FROM_MAC_ADDRESS
        is_mac = android_id is gm_api_mob.FROM_MAC_ADDRESS
        if is_mac:
            mac_int = getmac()
            if (mac_int >> 40) % 2:
                raise OSError("a valid MAC could not be determined."
                              " Provide an android_id (and be"
                              " sure to provide the same one on future runs).")

            device_id = utils.create_mac_string(mac_int)
            device_id = device_id.replace(':', '')
        else:
            device_id = android_id

        gm_api_mob.session._master_token = _master
        gm_api_mob.session._authtoken = _auth
        gm_api_mob.session.is_authenticated = True

        gm_api_mob.android_id = gm_api_mob._validate_device_id(device_id,
                                                               is_mac=is_mac)
        gm_api_mob.logger.info("authenticated")

        gm_api_mob.locale = locale

        if gm_api_mob.is_subscribed:
            gm_api_mob.logger.info("subscribed")

        return True
    except:
        traceback.print_exc(file=sys.stdout)
        return False
Exemplo n.º 2
0
    def _perform_upauth(self, uploader_id, uploader_name):
        """Auth or register ourselves as an upload client.

        Return True on success; see :py:func:`login` for params.
        """

        if uploader_id is None:
            mac_int = getmac()
            if (mac_int >> 40) % 2:
                self.session.logout()
                raise OSError('a valid MAC could not be determined.'
                              ' Provide uploader_id (and be'
                              ' sure to provide the same one on future runs).')

            else:
                # distinguish us from a Music Manager on this machine
                mac_int = (mac_int + 1) % (1 << 48)

            uploader_id = utils.create_mac_string(mac_int)

        if not utils.is_valid_mac(uploader_id):
            self.session.logout()
            raise ValueError(
                'uploader_id is not in a valid form.'
                '\nProvide 6 pairs of hex digits'
                ' with capital letters', ' (eg "00:11:22:33:AA:BB")')

        if uploader_name is None:
            uploader_name = gethostname(
            ) + u" (gmusicapi-%s)" % gmusicapi.__version__

        try:
            # this is a MM-specific step that might register a new device.
            self._make_call(musicmanager.AuthenticateUploader, uploader_id,
                            uploader_name)
            self.logger.info("successful upauth")
            self.uploader_id = uploader_id
            self.uploader_name = uploader_name

        except CallFailure:
            self.logger.exception("upauth failure")
            self.session.logout()
            return False

        return True
Exemplo n.º 3
0
    def _perform_upauth(self, uploader_id, uploader_name):
        """Auth or register ourselves as an upload client.

        Return True on success; see :py:func:`login` for params.
        """

        if uploader_id is None:
            mac_int = getmac()
            if (mac_int >> 40) % 2:
                self.session.logout()
                raise OSError('a valid MAC could not be determined.'
                              ' Provide uploader_id (and be'
                              ' sure to provide the same one on future runs).')

            else:
                # distinguish us from a Music Manager on this machine
                mac_int = (mac_int + 1) % (1 << 48)

            uploader_id = utils.create_mac_string(mac_int)

        if not utils.is_valid_mac(uploader_id):
            self.session.logout()
            raise ValueError('uploader_id is not in a valid form.'
                             '\nProvide 6 pairs of hex digits'
                             ' with capital letters',
                             ' (eg "00:11:22:33:AA:BB")')

        if uploader_name is None:
            uploader_name = gethostname() + u" (gmusicapi-%s)" % gmusicapi.__version__

        try:
            # this is a MM-specific step that might register a new device.
            self._make_call(musicmanager.AuthenticateUploader,
                            uploader_id,
                            uploader_name)
            self.logger.info("successful upauth")
            self.uploader_id = uploader_id
            self.uploader_name = uploader_name

        except CallFailure:
            self.logger.exception("upauth failure")
            self.session.logout()
            return False

        return True
Exemplo n.º 4
0
def load_login(_auth, _master):
    try:
        gm_api_mob.session.is_authenticated = True
        gm_api_mob.session._authtoken = _auth
        gm_api_mob.session._master_token = _master
        mac_int = getmac()
        if (mac_int >> 40) % 2:
            raise OSError("a valid MAC could not be determined."
                          " Provide an android_id (and be"
                          " sure to provide the same one on future runs).")

        android_id = utils.create_mac_string(mac_int)
        android_id = android_id.replace(':', '')
        gm_api_mob.android_id = android_id
    except:
        traceback.print_exc(file=sys.stdout)
        return False
    return True
Exemplo n.º 5
0
    def login(self, email, password, android_id):
        """Authenticates the Mobileclient.
        Returns ``True`` on success, ``False`` on failure.

        :param email: eg ``'*****@*****.**'`` or just ``'test'``.
        :param password: the account's password.
          This is not stored locally, and is sent securely over SSL.
          App-specific passwords are not supported.
        :param android_id: 16 hex digits, eg ``'1234567890abcdef'``.

          Pass Mobileclient.FROM_MAC_ADDRESS instead to attempt to use
          this machine's MAC address as an android id.
          **Use this at your own risk**:
          the id will be a non-standard 12 characters,
          but appears to work fine in testing.
          If a valid MAC address cannot be determined on this machine
          (which is often the case when running on a VPS), raise OSError.

        #TODO 2fa
        """

        if android_id is None:
            raise ValueError("android_id cannot be None.")

        if android_id is self.FROM_MAC_ADDRESS:
            mac_int = getmac()
            if (mac_int >> 40) % 2:
                raise OSError("a valid MAC could not be determined."
                              " Provide an android_id (and be"
                              " sure to provide the same one on future runs).")

            android_id = utils.create_mac_string(mac_int)
            android_id = android_id.replace(':', '')

        if not self.session.login(email, password, android_id):
            self.logger.info("failed to authenticate")
            return False

        self.android_id = android_id
        self.logger.info("authenticated")

        return True
Exemplo n.º 6
0
    def login(self, email, password, android_id):
        """Authenticates the Mobileclient.
        Returns ``True`` on success, ``False`` on failure.

        :param email: eg ``'*****@*****.**'`` or just ``'test'``.
        :param password: the account's password.
          This is not stored locally, and is sent securely over SSL.
          App-specific passwords are not supported.
        :param android_id: 16 hex digits, eg ``'1234567890abcdef'``.

          Pass Mobileclient.FROM_MAC_ADDRESS instead to attempt to use
          this machine's MAC address as an android id.
          **Use this at your own risk**:
          the id will be a non-standard 12 characters,
          but appears to work fine in testing.
          If a valid MAC address cannot be determined on this machine
          (which is often the case when running on a VPS), raise OSError.

        #TODO 2fa
        """

        if android_id is None:
            raise ValueError("android_id cannot be None.")

        if android_id is self.FROM_MAC_ADDRESS:
            mac_int = getmac()
            if (mac_int >> 40) % 2:
                raise OSError("a valid MAC could not be determined."
                              " Provide an android_id (and be"
                              " sure to provide the same one on future runs).")

            android_id = utils.create_mac_string(mac_int)
            android_id = android_id.replace(':', '')

        if not self.session.login(email, password, android_id):
            self.logger.info("failed to authenticate")
            return False

        self.android_id = android_id
        self.logger.info("authenticated")

        return True