コード例 #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)
}
コード例 #2
0
ファイル: spotify_mock.go プロジェクト: KoehlerClem/sconsify
func getSearchedPlaylist() *sconsify.Playlists {
	playlists := sconsify.InitPlaylists()
	tracks := make([]*sconsify.Track, 3)
	tracks[0] = sconsify.InitTrack("elvispreley0", elvisPresley, "Burning Love", "2m3s")
	tracks[1] = sconsify.InitTrack("elvispreley1", elvisPresley, "Love me tender", "2m4s")
	tracks[2] = sconsify.InitTrack("elvispreley2", elvisPresley, "It's now or never", "2m5s")
	playlists.AddPlaylist(sconsify.InitSearchPlaylist("elvispresley1", " Elvis Presley", tracks))

	return playlists
}
コード例 #3
0
ファイル: spotify_mock.go プロジェクト: ialbors/sconsify
func getSearchedPlaylist() *sconsify.Playlists {
	playlists := sconsify.InitPlaylists()
	playlists.AddPlaylist(sconsify.InitSearchPlaylist("elvispresley1", " Elvis Presley", func(playlist *sconsify.Playlist) {
		playlist.AddTrack(sconsify.InitTrack("elvispreley0", elvisPresley, "Burning Love", "2m3s"))
		playlist.AddTrack(sconsify.InitTrack("elvispreley1", elvisPresley, "Love me tender", "2m4s"))
		playlist.AddTrack(sconsify.InitTrack("elvispreley2", elvisPresley, "It's now or never", "2m5s"))
	}))

	return playlists
}
コード例 #4
0
ファイル: spotify_actions.go プロジェクト: ialbors/sconsify
func (spotify *Spotify) search(query string) {
	playlists := sconsify.InitPlaylists()
	name := " " + query

	playlist := sconsify.InitSearchPlaylist(name, name, func(playlist *sconsify.Playlist) {
		options := createWebSpotifyOptions(50, playlist.Tracks())
		if searchResult, err := spotify.getWebApiClient().SearchOpt(query, webspotify.SearchTypeTrack, options); err == nil {
			numberOfTracks := len(searchResult.Tracks.Tracks)
			infrastructure.Debugf("Search '%v' returned %v track(s)", query, numberOfTracks)
			for _, track := range searchResult.Tracks.Tracks {
				webArtist := track.Artists[0]
				artist := sconsify.InitArtist(string(webArtist.URI), webArtist.Name)
				playlist.AddTrack(sconsify.InitWebApiTrack(string(track.URI), artist, track.Name, track.TimeDuration().String()))
				infrastructure.Debugf("\tTrack '%v' (%v)", track.URI, track.Name)
			}
		} else {
			infrastructure.Debugf("Spotify search returning error: %v", err)
		}
	})
	playlist.ExecuteLoad()
	playlists.AddPlaylist(playlist)

	spotify.events.NewPlaylist(playlists)
}