Exemplo n.º 1
0
        public void PlayTrack(QueuedTrack trackToPlay)
        {
            logger.Trace("MusicService.PlayTrack");
            logger.Debug("Attempting to play track {0}", trackToPlay.ToLoggerFriendlyTrackName());

            //Reset the paused data
            lastPaused          = null;
            totalPausedDuration = 0;

            currentProvider = musicProviderFactory.GetMusicProviderByIdentifier(trackToPlay.Track.MusicProvider.Identifier);

            //Either play the original queued track or the Big Rick if tthe track is rickrolled
            var rickRollTrack = rickRollService.RickRoll(trackToPlay.Track, trackToPlay.User);

            currentProvider.PlayTrack(rickRollTrack);
            trackToPlay.StartedPlayingDateTime = nowHelper.Now;
            queuedTrackDataService.InsertOrUpdate(trackToPlay);
            int total;
            var recentlyPlayed = queuedTrackDataService.GetAll()
                                 .GetQueuedTracksByUser(null, 1, 5, out total)
                                 .Select(r => alreadyQueuedHelper.ResetAlreadyQueued(r, trackToPlay.User)).ToList();

            callbackClient.TrackHistoryChanged(new PagedResult <QueuedTrack> {
                HasMorePages = false, PageData = recentlyPlayed
            });

            currentlyPlayingTrack = trackToPlay;
            callbackClient.PlayingTrackChanged(CurrentlyPlayingTrack);
            logger.Debug("Playing track {0} queued by {1}", trackToPlay.ToLoggerFriendlyTrackName(), trackToPlay.User);
        }
Exemplo n.º 2
0
        public Track Map(S.ITrack track, SpotifyMusicProvider musicProvider, string user, bool mapAlbum = false, bool mapArtists = false)
        {
            string trackLink   = track.GetLinkString();
            var    trackResult = new Track
            {
                Link                 = trackLink,
                Name                 = track.Name,
                IsAvailable          = track.IsAvailable,
                Duration             = track.Duration,
                DurationMilliseconds = (long)track.Duration.TotalMilliseconds,
                MusicProvider        = musicProvider.Descriptor,
                ExternalLink         = new Uri(musicProvider.ExternalLinkBaseUrl, "/track/" + trackLink)
            };

            if (mapAlbum && track.Album != null)
            {
                trackResult.Album = albumMapper.Map(track.Album, musicProvider);
            }
            if (mapArtists && track.Artists != null)
            {
                trackResult.Artists = track.Artists.Select(t => artistMapper.Map(t, musicProvider)).ToArray();
            }

            //We want to set whether the track is already queued
            if (alreadyQueuedHelper != null)
            {
                trackResult = alreadyQueuedHelper.ResetAlreadyQueued((trackResult), user);
            }
            return(trackResult);
        }
Exemplo n.º 3
0
        public SearchResults SearchAll(string searchTerm, string provider, string user)
        {
            logger.Debug("User {0} searched for '{1}'", user, searchTerm);

            // currently only searching spotify
            var musicProvider = musicProviderFactory.GetMusicProviderByIdentifier(provider);

            var searchResults = musicProvider.SearchAll(searchTerm, user);

            searchResults.PagedTracks.Tracks = searchResults.PagedTracks.Tracks.Select(t => alreadyQueuedHelper.ResetAlreadyQueued(t, user));
            searchResults.PagedTracks        = searchRuleHelper.FilterTracks(searchResults.PagedTracks);
            searchResults.PagedAlbums        = searchRuleHelper.FilterAlbums(searchResults.PagedAlbums);
            searchResults.PagedArtists       = searchRuleHelper.FilterArtists(searchResults.PagedArtists);

            // save the search if there were results
            if (searchResults.PagedAlbums.Albums.Any() ||
                searchResults.PagedArtists.Artists.Any() ||
                searchResults.PagedTracks.Tracks.Any())
            {
                searchSuggestionService.UpdateSearchTermRecords(searchTerm);
            }

            return(searchResults);
        }
Exemplo n.º 4
0
        public Track Map(Model.Track track, SoundCloudMusicProvider musicProvider, string user, bool mapArtists = false)
        {
            var trackLink   = track.id;
            var trackResult = new Track
            {
                Link                 = trackLink.ToString(CultureInfo.InvariantCulture),
                Name                 = track.title,
                IsAvailable          = track.streamable,
                Duration             = new TimeSpan(0, 0, 0, 0, track.duration),
                DurationMilliseconds = track.duration,
                MusicProvider        = musicProvider.Descriptor,
                TrackArtworkUrl      = track.artwork_url ?? "content/styles/Images/soundcloud-icon.png",
                ExternalLink         = new Uri(track.permalink_url)
            };

            alreadyQueuedHelper.ResetAlreadyQueued((trackResult), user);

            return(trackResult);
        }