Ejemplo n.º 1
0
func (spotify *Spotify) search(query string) {
	searchOptions := &sp.SearchOptions{
		Tracks:    sp.SearchSpec{Offset: 0, Count: 100},
		Albums:    sp.SearchSpec{Offset: 0, Count: 100},
		Artists:   sp.SearchSpec{Offset: 0, Count: 100},
		Playlists: sp.SearchSpec{Offset: 0, Count: 100},
		Type:      sp.SearchStandard,
	}
	search, err := spotify.session.Search(query, searchOptions)
	if err != nil {
		return
	}
	search.Wait()

	numberOfTracks := search.Tracks()
	tracks := make([]*sconsify.Track, numberOfTracks)
	for i := 0; i < numberOfTracks; i++ {
		tracks[i] = sconsify.ToSconsifyTrack(search.Track(i))
	}

	playlists := sconsify.InitPlaylists()
	name := " " + query
	playlists.AddPlaylist(sconsify.InitSearchPlaylist(name, name, tracks))

	spotify.events.NewPlaylist(playlists)
}
Ejemplo n.º 2
0
func (spotify *Spotify) play(trackUri *sconsify.Track) {
	link, err := spotify.session.ParseLink(trackUri.Uri)
	if err != nil {
		return
	}

	track, err := link.Track()
	if err != nil {
		return
	}

	if trackUri.IsPartial() {
		trackUri = sconsify.ToSconsifyTrack(track)
	}

	if !spotify.isTrackAvailable(track) {
		spotify.events.TrackNotAvailable(trackUri)
		return
	}
	player := spotify.session.Player()
	if err := player.Load(track); err != nil {
		return
	}
	player.Play()

	spotify.events.TrackPlaying(trackUri)
	spotify.currentTrack = trackUri
}
Ejemplo n.º 3
0
func (spotify *Spotify) initTrack(playlistTrack *sp.PlaylistTrack) *sconsify.Track {
	track := playlistTrack.Track()
	track.Wait()
	for i := 0; i < track.Artists(); i++ {
		track.Artist(i).Wait()
	}
	return sconsify.ToSconsifyTrack(track)
}
Ejemplo n.º 4
0
func (spotify *Spotify) initTrack(playlistTrack *sp.PlaylistTrack) *sconsify.Track {
	track := playlistTrack.Track()
	track.Wait()
	for i := 0; i < track.Artists(); i++ {
		track.Artist(i).Wait()
	}
	infrastructure.Debugf("\tTrack '%v' (%v)", track.Link().String(), track.Name())
	return sconsify.ToSconsifyTrack(track)
}
Ejemplo n.º 5
0
func (spotify *Spotify) play(trackUri *sconsify.Track) {
	link, err := spotify.session.ParseLink(trackUri.URI)
	if err != nil {
		return
	}

	track, err := link.Track()
	if err != nil {
		return
	}

	if trackUri.IsPartial() {
		trackUri = sconsify.ToSconsifyTrack(track)
	}

	if !spotify.isTrackAvailable(track) {
		if trackUri.IsFromWebApi() {
			retry := trackUri.RetryLoading()
			if retry < 4 {
				go func() {
					time.Sleep(100 * time.Millisecond)
					spotify.events.Play(trackUri)
				}()
				return
			}
		}
		spotify.events.TrackNotAvailable(trackUri)
		return
	}
	player := spotify.session.Player()
	if err := player.Load(track); err != nil {
		return
	}
	player.Play()

	spotify.events.TrackPlaying(trackUri)
	spotify.currentTrack = trackUri
	spotify.paused = false
	return
}