Beispiel #1
0
func (spotify *Spotify) finishInitialisation(webApiAuth bool, pa *portAudio) error {
	if webApiAuth {
		if spotify.client = webapi.Auth(); spotify.client != nil {
			if privateUser, err := spotify.client.CurrentUser(); err == nil {
				if privateUser.ID != spotify.session.LoginUsername() {
					return errors.New("Username doesn't match with web-api authorization")
				}
			} else {
				spotify.client = nil
			}
		}
	}
	// init audio could happen after initPlaylist but this logs to output therefore
	// the screen isn't built properly
	portaudio.Initialize()
	go pa.player()
	defer portaudio.Terminate()

	if err := spotify.initPlaylist(); err != nil {
		return err
	}

	spotify.waitForEvents()
	return nil
}
Beispiel #2
0
func main() {
	infrastructure.ProcessSconsifyrc()

	providedUsername := flag.String("username", "", "Spotify username.")
	providedWebApi := flag.Bool("web-api", false, "Use Spotify WEB API for more features. It requires web authorization.")
	providedUi := flag.Bool("ui", true, "Run Sconsify with Console User Interface. If false then no User Interface will be presented and it'll shuffle tracks.")
	providedPlaylists := flag.String("playlists", "", "Select just some Playlists to play. Comma separated list.")
	providedPreferredBitrate := flag.String("preferred-bitrate", "320k", "Preferred bitrate: 96k, 160k, 320k (default).")
	providedNoUiSilent := flag.Bool("noui-silent", false, "Silent mode when no UI is used.")
	providedNoUiRepeatOn := flag.Bool("noui-repeat-on", true, "Play your playlist and repeat it after the last track.")
	providedNoUiShuffle := flag.Bool("noui-shuffle", true, "Shuffle tracks or follow playlist order.")
	providedDebug := flag.Bool("debug", false, "Enable debug mode.")
	askingVersion := flag.Bool("version", false, "Print version.")
	flag.Parse()

	if *askingVersion {
		fmt.Println("Version: " + version)
		fmt.Println("Git commit: " + commit)
		fmt.Println("Build date: " + buildDate)
		os.Exit(0)
	}

	if *providedDebug {
		infrastructure.InitialiseLogger()
		defer infrastructure.CloseLogger()
	}

	fmt.Println("Sconsify - your awesome Spotify music service in a text-mode interface.")
	username, pass := credentials(providedUsername)
	events := sconsify.InitialiseEvents()

	var client *webspotify.Client
	if *providedWebApi {
		client = webapi.Auth(spotifyClientId, authRedirectUrl)
	}

	go spotify.Initialise(client, username, pass, events, providedPlaylists, providedPreferredBitrate)

	if *providedUi {
		ui := ui.InitialiseConsoleUserInterface(events, true)
		sconsify.StartMainLoop(events, ui, false)
	} else {
		var output ui.Printer
		if *providedNoUiSilent {
			output = new(ui.SilentPrinter)
		}
		ui := ui.InitialiseNoUserInterface(events, output, providedNoUiRepeatOn, providedNoUiShuffle)
		sconsify.StartMainLoop(events, ui, true)
	}
}