Exemplo n.º 1
0
func persistToken(token *oauth2.Token) {
	if b, err := json.Marshal(token); err == nil {
		if fileLocation := infrastructure.GetWebApiTokenLocation(); fileLocation != "" {
			infrastructure.SaveFile(fileLocation, b)
		}
	}
}
Exemplo n.º 2
0
func (spotify *Spotify) persistWebApiCache(webApiCache *WebApiCache) {
	if b, err := json.Marshal(webApiCache); err == nil {
		var compressed bytes.Buffer
		w := gzip.NewWriter(&compressed)
		w.Write([]byte(b))
		w.Close()
		if fileLocation := infrastructure.GetWebApiCacheFileLocation(); fileLocation != "" {
			infrastructure.SaveFile(fileLocation, compressed.Bytes())
		}
	}
}
Exemplo n.º 3
0
func persistState() {
	state := State{
		ClosedFolders: make([]string, 0),
		Queue:         make([]*sconsify.Track, 0)}
	selectedPlaylist, index := gui.getSelectedPlaylistAndTrack()

	if selectedPlaylist != nil && !selectedPlaylist.IsOnDemand() {
		state.SelectedPlaylist = selectedPlaylist.Name()
		if index != -1 {
			selectedTrack := selectedPlaylist.Track(index)
			if selectedTrack != nil {
				state.SelectedTrack = selectedTrack.URI
			}
		}
	}

	if playingTrack := playlists.GetPlayingTrack(); playingTrack != nil {
		if playingPlaylist := playlists.GetPlayingPlaylist().URI; playingPlaylist != "premade" {
			state.PlayingTrackUri = playingTrack.URI
			state.PlayingTrackFullTitle = playingTrack.GetFullTitle()
			state.PlayingPlaylist = playingPlaylist
		}
	}

	for _, playlistName := range playlists.Names() {
		playlist := playlists.Get(playlistName)
		if playlist.IsFolder() && !playlist.IsFolderOpen() && !playlist.IsOnDemand() {
			state.ClosedFolders = append(state.ClosedFolders, playlist.URI)
		}
	}

	for _, track := range queue.Contents() {
		state.Queue = append(state.Queue, track)
	}

	if b, err := json.Marshal(state); err == nil {
		if fileLocation := infrastructure.GetStateFileLocation(); fileLocation != "" {
			infrastructure.SaveFile(fileLocation, b)
		}
	}
}