Beispiel #1
0
    def __init__(self, args):
        threading.Thread.__init__(self)

        # initialize progress meter
        self.progress = Progress(args, self)

        self.args = args

        # initially logged-out
        self.logged_out.set()

        config = spotify.Config()

        self.post = PostActions(args, self)
        self.web = WebAPI(args, self)

        proxy = os.environ.get('http_proxy')
        if proxy is not None:
            config.proxy = proxy

        # Application key
        if not path_exists(settings_dir()):
            os.makedirs(enc_str(settings_dir()))

        app_key_path = os.path.join(settings_dir(), "spotify_appkey.key")
        if not path_exists(app_key_path):
            print("\n" + Fore.RED + "Please copy your spotify_appkey.key to " + settings_dir() + Fore.RESET)
            sys.exit(1)

        config.load_application_key_file(app_key_path)
        config.settings_location = settings_dir()
        config.cache_location = settings_dir()

        self.session = spotify.Session(config=config)
        self.session.volume_normalization = args.normalize

        # disable scrobbling
        self.session.social.set_scrobbling(spotify.SocialProvider.SPOTIFY, spotify.ScrobblingState.LOCAL_DISABLED)
        self.session.social.set_scrobbling(spotify.SocialProvider.FACEBOOK, spotify.ScrobblingState.LOCAL_DISABLED)
        self.session.social.set_scrobbling(spotify.SocialProvider.LASTFM, spotify.ScrobblingState.LOCAL_DISABLED)

        bit_rates = dict([('160', BitRate.BITRATE_160K), ('320', BitRate.BITRATE_320K), ('96', BitRate.BITRATE_96K)])
        self.session.preferred_bitrate(bit_rates[args.quality])
        self.session.on(spotify.SessionEvent.CONNECTION_STATE_UPDATED, self.on_connection_state_changed)
        self.session.on(spotify.SessionEvent.END_OF_TRACK, self.on_end_of_track)
        self.session.on(spotify.SessionEvent.MUSIC_DELIVERY, self.on_music_delivery)
        self.session.on(spotify.SessionEvent.PLAY_TOKEN_LOST, self.play_token_lost)
        self.session.on(spotify.SessionEvent.LOGGED_IN, self.on_logged_in)

        self.event_loop = EventLoop(self.session, 0.1, self)
Beispiel #2
0
    def login(self):
        args = self.args

        print("Logging in...")
        if args.last:
            self.login_as_last()

        if not self.login_success and args.user is not None:
            # remove old saved password
            self.session.forget_me()

            if args.password is None:
                password = getpass.getpass()
                self.login_as_user(args.user, password)
            else:
                self.login_as_user(args.user, args.password)

        self.web = WebAPI(args, self)
        return self.login_success