コード例 #1
0
ファイル: sconsify.go プロジェクト: KoehlerClem/sconsify
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)
	}
}
コード例 #2
0
ファイル: noui_test.go プロジェクト: KoehlerClem/sconsify
func TestNoUiShuffleAndRepeating(t *testing.T) {
	rand.Seed(123456789) // repeatable

	repeatOn := true
	shuffle := true
	events := sconsify.InitialiseEvents()
	output := &TestPrinter{message: make(chan string)}
	ui := InitialiseNoUserInterface(events, output, &repeatOn, &shuffle)

	finished := make(chan bool)
	go func() {
		err := sconsify.StartMainLoop(events, ui, true)
		finished <- err == nil
	}()

	sendNewPlaylist(events)

	assertPrintFourTracks(t, events, output)

	assertShuffleFirstTrack(t, events, output)
	assertShuffleNextThreeTracks(t, events, output)
	assertShuffleRepeatingAllFourTracks(t, events, output)

	assertShutdown(t, ui, events, finished)
}
コード例 #3
0
func main() {
	infrastructure.ProcessSconsifyrc()

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

	go mock.Initialise(events)

	go testSequence()
	ui := ui.InitialiseConsoleUserInterface(events)
	sconsify.StartMainLoop(events, ui, false)
	println(output.String())
}
コード例 #4
0
ファイル: noui_test.go プロジェクト: KoehlerClem/sconsify
func TestNoUiEmptyPlaylists(t *testing.T) {
	repeatOn := true
	shuffle := true
	events := sconsify.InitialiseEvents()

	go func() {
		playlists := sconsify.InitPlaylists()
		events.NewPlaylist(playlists)
	}()

	ui := InitialiseNoUserInterface(events, nil, &repeatOn, &shuffle)
	err := sconsify.StartMainLoop(events, ui, true)
	if err == nil {
		t.Errorf("No track selected should return an error")
	}
}
コード例 #5
0
func main() {
	runTest := flag.Bool("run-test", false, "Run the test sequence.")
	flag.Parse()

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

	infrastructure.InitialiseLogger()
	defer infrastructure.CloseLogger()

	go mock.Initialise(events)

	if *runTest {
		go runTests()
	}

	ui := ui.InitialiseConsoleUserInterface(events, false)
	sconsify.StartMainLoop(events, ui, false)
	println(output.String())
	sleep() // otherwise gocui eventually fails to quit properly
}
コード例 #6
0
ファイル: noui_test.go プロジェクト: KoehlerClem/sconsify
func TestNoUiSequentialAndNotRepeating(t *testing.T) {
	repeatOn := false
	shuffle := false
	events := sconsify.InitialiseEvents()
	output := &TestPrinter{message: make(chan string)}
	ui := InitialiseNoUserInterface(events, output, &repeatOn, &shuffle)

	finished := make(chan bool)
	go func() {
		sconsify.StartMainLoop(events, ui, true)
		finished <- true
	}()

	sendNewPlaylist(events)

	assertPrintFourTracks(t, events, output)

	assertFirstTrack(t, events, output)
	assertNextThreeTracks(t, events, output)
	assertNoNextTrack(events, finished)
}
コード例 #7
0
ファイル: sconsify.go プロジェクト: ialbors/sconsify
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.")
	providedWebApiCacheToken := flag.Bool("web-api-cache-token", true, "Cache the web-api token as plain text in ~/.sconsify until its expiration.")
	providedWebApiCacheContent := flag.Bool("web-api-cache-content", true, "Cache some of the web-api content as plain text in ~/.sconsify.")
	providedDebug := flag.Bool("debug", false, "Enable debug mode.")
	askingVersion := flag.Bool("version", false, "Print version.")
	providedCommand := flag.String("command", "", "Execute a command in the server: replay, play_pause, next")
	providedServer := flag.Bool("server", true, "Start a background server to accept commands.")
	flag.Parse()

	if *askingVersion {
		fmt.Println("Version: " + version)
		fmt.Println("Git commit: " + commit)
		if i, err := strconv.ParseInt(buildDate, 10, 64); err == nil {
			fmt.Println("Build date: " + time.Unix(i, 0).UTC().String())
		}
		fmt.Println("Go version: " + runtime.Version())
		os.Exit(0)
	}

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

	if *providedCommand != "" {
		rpc.Client(*providedCommand)
		return
	}

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

	initConf := &spotify.SpotifyInitConf{
		WebApiAuth:         *providedWebApi,
		PlaylistFilter:     *providedPlaylists,
		PreferredBitrate:   *providedPreferredBitrate,
		CacheWebApiToken:   *providedWebApiCacheToken,
		CacheWebApiContent: *providedWebApiCacheContent,
		SpotifyClientId:    spotifyClientId,
		AuthRedirectUrl:    authRedirectUrl,
	}
	go spotify.Initialise(initConf, username, pass, events)

	if *providedServer {
		go rpc.StartServer(events)
	}

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