Ejemplo n.º 1
0
    def login(self, username=None, password=None, blob=None):
        if username is not None:
            self.credentials["username"] = username
        elif self.credentials["username"]:
            username = self.credentials["username"]
        else:
            raise ValueError("No username given, and none stored")

        if password is not None:
            lib.SpConnectionLoginPassword(username.encode(), password.encode())
        elif blob is not None:
            lib.SpConnectionLoginBlob(username.encode(), blob.encode())
        else:
            raise ValueError("Must specify a login method (password, blob)")
Ejemplo n.º 2
0
def login_password():
    global invalid_login
    invalid_login = False
    username = str(request.form.get('username'))
    password = str(request.form.get('password'))

    if not username or not password:
        flash('Username or password not specified', 'danger')
    else:
        flash('Waiting for spotify', 'info')
        lib.SpConnectionLoginPassword(username, password)
        sleep

    return redirect(url_for('index'))
Ejemplo n.º 3
0
    def login(self, username=None, password=None, blob=None, zeroconf=None):
        if username is not None:
            self.credentials['username'] = username
        elif self.credentials['username']:
            username = self.credentials['username']
        else:
            raise ValueError("No username given, and none stored")

        if password is not None:
            lib.SpConnectionLoginPassword(username, password)
        elif blob is not None:
            lib.SpConnectionLoginBlob(username, blob)
        elif zeroconf is not None:
            lib.SpConnectionLoginZeroConf(username, *zeroconf)
        else:
            raise ValueError("Must specify a login method (password, blob or zeroconf)")
Ejemplo n.º 4
0
    def __init__(self, error_cb=error_callback):
        pass_required = False
        if __name__ == "__main__":
            #Require username and password when used without a web server
            pass_required = True
        arg_parser = argparse.ArgumentParser(
            description='Web interface for Spotify Connect',
            parents=[mixer_arg_parser])
        arg_parser.add_argument(
            '--debug',
            '-d',
            help='enable libspotify_embedded/flask debug output',
            action="store_true")
        arg_parser.add_argument('--key',
                                '-k',
                                help='path to spotify_appkey.key',
                                default='spotify_appkey.key',
                                type=file)
        arg_parser.add_argument('--username',
                                '-u',
                                help='your spotify username',
                                required=pass_required)
        arg_parser.add_argument('--password',
                                '-p',
                                help='your spotify password',
                                required=pass_required)
        arg_parser.add_argument(
            '--name',
            '-n',
            help='name that shows up in the spotify client',
            default='TestConnect')
        arg_parser.add_argument(
            '--bitrate',
            '-b',
            help='Sets bitrate of audio stream (may not actually work)',
            choices=[90, 160, 320],
            type=int,
            default=160)
        self.args = arg_parser.parse_args()

        app_key = ffi.new('uint8_t *')
        self.args.key.readinto(ffi.buffer(app_key))
        app_key_size = len(self.args.key.read()) + 1

        self.init_vars = {
            'version': 4,
            'buffer': C.malloc(1048576),
            'buffer_size': 1048576,
            'os_device_id': ffi.new('char[]', 'abcdef-{}'.format(os.getpid())),
            'remoteName': ffi.new('char[]', self.args.name),
            'brandName': ffi.new('char[]', 'DummyBrand'),
            'modelName': ffi.new('char[]', 'DummyModel'),
            'deviceType': lib.kSpDeviceTypeAudioDongle,
            'error_callback': error_cb,
            'zero1': 0,
            'app_key': app_key,
            'app_key_size': app_key_size
        }

        init = ffi.new('struct init_data *', self.init_vars)

        print "SpInit: {}".format(lib.SpInit(init))

        lib.SpRegisterConnectionCallbacks(connection_callbacks, ffi.NULL)
        if self.args.debug:
            lib.SpRegisterDebugCallbacks(debug_callbacks, ffi.NULL)
        #lib.SpRegisterPlaybackCallbacks(playback_callbacks, ffi.NULL)
        lib.setup_audio_callbacks()

        mixer_volume = int(mixer.getvolume()[0] * 655.35)
        lib.SpPlaybackUpdateVolume(mixer_volume)

        bitrates = {
            90: lib.kSpBitrate90,
            160: lib.kSpBitrate160,
            320: lib.kSpBitrate320
        }

        lib.SpPlaybackSetBitrate(bitrates[self.args.bitrate])

        print_zeroconf_vars()

        if self.args.username and self.args.password:
            lib.SpConnectionLoginPassword(self.args.username,
                                          self.args.password)