예제 #1
0
func Initialise(events *sconsify.Events) {
	playlists := sconsify.InitPlaylists()

	tracks := make([]*sconsify.Track, 2)
	tracks[0] = sconsify.InitTrack("bobmarley0", bobMarley, "Waiting in vain", "2m3s")
	tracks[1] = sconsify.InitTrack("bobmarley1", bobMarley, "Testing", "5m3s")
	playlists.AddPlaylist(sconsify.InitPlaylist("bobmarleyplaylist0", "Bob Marley", tracks))

	folderPlaylists := make([]*sconsify.Playlist, 2)

	tracks = make([]*sconsify.Track, 2)
	tracks[0] = sconsify.InitTrack("bobmarley2", bobMarley, "Waiting in vain", "2m3s")
	tracks[1] = sconsify.InitTrack("bobmarley3", bobMarley, "Testing", "5m3s")
	folderPlaylists[0] = sconsify.InitPlaylist("bobmarleyplaylist1", " Bob Marley and The Wailers", tracks)

	tracks = make([]*sconsify.Track, 3)
	tracks[0] = sconsify.InitTrack("ramones0", theRamones, "Ramones", "2m3s")
	tracks[1] = sconsify.InitTrack("ramones1", theRamones, "Ramones...", "3m21s")
	tracks[2] = sconsify.InitTrack("ramones2", theRamones, "The Ramones", "1m9s")
	folderPlaylists[1] = sconsify.InitPlaylist("ramonesplaylist0", " The Ramones", tracks)

	playlists.AddPlaylist(sconsify.InitFolder("folder", "My folder", folderPlaylists))

	tracks = make([]*sconsify.Track, 3)
	tracks[0] = sconsify.InitTrack("ramones3", theRamones, "I wanna be sedated", "2m3s")
	tracks[1] = sconsify.InitTrack("ramones4", theRamones, "Pet semetary", "3m21s")
	tracks[2] = sconsify.InitTrack("ramones5", theRamones, "Judy is a punk", "1m9s")
	playlists.AddPlaylist(sconsify.InitPlaylist("ramonesplaylist1", "Ramones", tracks))

	events.NewPlaylist(playlists)
	waitForMockEvents(events)
}
예제 #2
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)
}
예제 #3
0
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
}
예제 #4
0
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
}
예제 #5
0
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")
	}
}
예제 #6
0
func (spotify *Spotify) initPlaylist() error {
	playlists := sconsify.InitPlaylists()

	allPlaylists, err := spotify.session.Playlists()
	if err != nil {
		return err
	}
	allPlaylists.Wait()
	var folderPlaylists []*sconsify.Playlist
	var folder *sp.PlaylistFolder
	for i := 0; i < allPlaylists.Playlists(); i++ {
		if allPlaylists.PlaylistType(i) == sp.PlaylistTypeStartFolder {
			folder, _ = allPlaylists.Folder(i)
			folderPlaylists = make([]*sconsify.Playlist, 0)
		} else if allPlaylists.PlaylistType(i) == sp.PlaylistTypeEndFolder {
			playlists.AddPlaylist(sconsify.InitFolder(strconv.Itoa(int(folder.Id())), folder.Name(), folderPlaylists))
			folderPlaylists = nil
			folder = nil
		}

		if allPlaylists.PlaylistType(i) != sp.PlaylistTypePlaylist {
			continue
		}

		playlist := allPlaylists.Playlist(i)
		playlist.Wait()
		if spotify.canAddPlaylist(playlist, allPlaylists.PlaylistType(i)) {
			tracks := make([]*sconsify.Track, playlist.Tracks())
			for i := 0; i < playlist.Tracks(); i++ {
				tracks[i] = spotify.initTrack(playlist.Track(i))
			}
			id := playlist.Link().String()
			if folderPlaylists == nil {
				playlists.AddPlaylist(sconsify.InitPlaylist(id, playlist.Name(), tracks))
			} else {
				folderPlaylists = append(folderPlaylists, sconsify.InitSubPlaylist(id, playlist.Name(), tracks))
			}
		}
	}

	spotify.events.NewPlaylist(playlists)
	return nil
}
예제 #7
0
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)
}
예제 #8
0
func (spotify *Spotify) initPlaylist() error {
	playlists := sconsify.InitPlaylists()

	allPlaylists, err := spotify.session.Playlists()
	if err != nil {
		return err
	}
	allPlaylists.Wait()
	var folderPlaylists []*sconsify.Playlist
	var folder *sp.PlaylistFolder
	for i := 0; i < allPlaylists.Playlists(); i++ {
		if allPlaylists.PlaylistType(i) == sp.PlaylistTypeStartFolder {
			folder, _ = allPlaylists.Folder(i)
			folderPlaylists = make([]*sconsify.Playlist, 0)
		} else if allPlaylists.PlaylistType(i) == sp.PlaylistTypeEndFolder {
			if folder != nil {
				playlists.AddPlaylist(sconsify.InitFolder(strconv.Itoa(int(folder.Id())), folder.Name(), folderPlaylists))
			}
			folderPlaylists = nil
			folder = nil
		}

		if allPlaylists.PlaylistType(i) != sp.PlaylistTypePlaylist {
			continue
		}

		playlist := allPlaylists.Playlist(i)
		playlist.Wait()
		if spotify.canAddPlaylist(playlist, allPlaylists.PlaylistType(i)) {
			tracks := make([]*sconsify.Track, playlist.Tracks())
			for i := 0; i < playlist.Tracks(); i++ {
				tracks[i] = spotify.initTrack(playlist.Track(i))
			}
			id := playlist.Link().String()
			if folderPlaylists == nil {
				playlists.AddPlaylist(sconsify.InitPlaylist(id, playlist.Name(), tracks))
			} else {
				folderPlaylists = append(folderPlaylists, sconsify.InitSubPlaylist(id, playlist.Name(), tracks))
			}
		}
	}

	webApiCache := spotify.loadWebApiCacheIfNecessary()
	if spotify.client != nil {
		playlists.AddPlaylist(sconsify.InitOnDemandFolder("Albums", "*Albums", make([]*sconsify.Playlist, 0), true, func(playlist *sconsify.Playlist) {
			spotify.loadAlbums(playlist, webApiCache)
			spotify.persistWebApiCache(webApiCache)
		}))
		playlists.AddPlaylist(sconsify.InitOnDemandPlaylist("Songs", "*Songs", make([]*sconsify.Track, 0), false, func(playlist *sconsify.Playlist) {
			spotify.loadSongs(playlist, webApiCache)
			spotify.persistWebApiCache(webApiCache)
		}))
		playlists.AddPlaylist(sconsify.InitOnDemandFolder("New Releases", "*New Releases", make([]*sconsify.Playlist, 0), true, func(playlist *sconsify.Playlist) {
			spotify.loadNewReleases(playlist, webApiCache)
			spotify.persistWebApiCache(webApiCache)
		}))
	} else {
		if webApiCache.Albums != nil {
			playlist := sconsify.InitOnDemandFolder("Albums", "*Albums", make([]*sconsify.Playlist, 0), true, func(playlist *sconsify.Playlist) {
				spotify.loadAlbums(playlist, webApiCache)
			})
			playlist.ExecuteLoad()
			playlists.AddPlaylist(playlist)
		}
		if webApiCache.Songs != nil {
			playlist := sconsify.InitOnDemandPlaylist("Songs", "*Songs", make([]*sconsify.Track, 0), true, func(playlist *sconsify.Playlist) {
				spotify.loadSongs(playlist, webApiCache)
			})
			playlist.ExecuteLoad()
			playlists.AddPlaylist(playlist)
		}
		if webApiCache.NewReleases != nil {
			playlist := sconsify.InitOnDemandFolder("New Releases", "*New Releases", make([]*sconsify.Playlist, 0), true, func(playlist *sconsify.Playlist) {
				spotify.loadNewReleases(playlist, webApiCache)
			})
			playlist.ExecuteLoad()
			playlists.AddPlaylist(playlist)
		}
	}

	spotify.events.NewPlaylist(playlists)
	return nil
}
예제 #9
0
func sendNewPlaylist(events *sconsify.Events) {
	playlists := sconsify.InitPlaylists()
	playlists.AddPlaylist(createDummyPlaylist())
	events.NewPlaylist(playlists)
}