Пример #1
0
        public Track GetTrack(string link, string provider, string user)
        {
            var foundProvider = musicProviderFactory.GetMusicProviderByIdentifier(provider);

            return(foundProvider.IsEnabled
                ? foundProvider.GetTrack(link, user)
                : null);
        }
Пример #2
0
        private void FillBagWithAutoplayTracks(object stateInfo)
        {
            var scoredTracks = PickTracks();

            if (scoredTracks == null)
            {
                return;
            }

            var chosenTracks = scoredTracks;

            foreach (var qt in chosenTracks)
            {
                var queuedTrack         = new QueuedTrack();
                var tracksMusicProvider = musicProviderFactory.GetMusicProviderByIdentifier(qt.value.Track.MusicProvider.Identifier);
                if (!tracksMusicProvider.IsEnabled)
                {
                    continue;
                }
                var t = tracksMusicProvider.GetTrack(qt._id, Constants.AutoplayUserName);
                if (t == null)
                {
                    continue;
                }
                queuedTrack.Track = t;
                queuedTrack.User  = Constants.AutoplayUserName;

                _tracksForAutoplaying.Push(queuedTrack);
            }
        }
Пример #3
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);
        }
Пример #4
0
        public QueuedTrack Execute(QueuedTrack trackToQueue)
        {
            if (DateTime.Now.Second % settings.RandomizerRatio == 0)
            {
                return(trackToQueue);
            }

            if (trackToQueue.Track.MusicProvider == null || trackToQueue.Track.MusicProvider.Identifier != "sp")
            {
                return(trackToQueue);
            }

            musicProvider = musicProviderFactory.GetMusicProviderByIdentifier(trackToQueue.Track.MusicProvider.Identifier);

            var browse = musicProvider.BrowseArtist(trackToQueue.Track.Artists.First().Link, false);
            var artist = browse.Profile.SimilarArtists.Random().FirstOrDefault();

            if (artist == null)
            {
                return(trackToQueue);
            }

            var randomAlbum = musicProvider.BrowseArtist(artist.Link, false).Albums.Random().Take(1).ToList();

            if (randomAlbum.Any())
            {
                var albumLink = randomAlbum.Random().First();
                var tracks    = musicProvider.BrowseAlbum(albumLink.Link, trackToQueue.User);

                if (tracks.Tracks != null && tracks.Tracks.Any())
                {
                    var track = tracks.Tracks.Random().FirstOrDefault();

                    if (track != null)
                    {
                        logger.Debug("Similar Artist Randomizer, converting track {0}", trackToQueue.ToLoggerFriendlyTrackName());

                        trackToQueue.Track       = track;
                        trackToQueue.Track.Album = albumLink;
                        trackToQueue.User        = "******";
                        trackToQueue.Id          = DataObject.GenerateId(); //if you don't do this then the autoplayed song will update over the user requested song
                    }
                }
            }

            return(trackToQueue);
        }
Пример #5
0
        public QueuedTrack Execute(QueuedTrack trackToQueue)
        {
            if (trackToQueue.Track.MusicProvider == null || trackToQueue.Track.MusicProvider.Identifier != "sp")
            {
                return(trackToQueue);
            }

            if (DateTime.Now.Second % settings.RandomizerRatio == 0)
            {
                return(trackToQueue);
            }

            musicProvider = musicProviderFactory.GetMusicProviderByIdentifier(trackToQueue.Track.MusicProvider.Identifier);

            var album = trackToQueue.Track.Album;

            if (album == null)
            {
                return(trackToQueue);
            }

            var tracks = musicProvider.BrowseAlbum(album.Link, trackToQueue.User);

            if (tracks.Tracks != null && tracks.Tracks.Any())
            {
                var track = tracks.Tracks.Random().FirstOrDefault();

                if (track != null)
                {
                    logger.Debug("Off Same Album Randomizer, converting track {0}", trackToQueue.ToLoggerFriendlyTrackName());

                    trackToQueue.Track       = track;
                    trackToQueue.Track.Album = album;
                    trackToQueue.User        = "******";
                    trackToQueue.Id          = DataObject.GenerateId(); //if you don't do this then the autoplayed song will update over the user requested song
                }
            }


            return(trackToQueue);
        }
Пример #6
0
 public Track RickRoll(Track track, string user)
 {
     logger.Trace("RickRoll");
     if ((track.Artists != null && track.Artists.Any(a => RickRollExists(a.Link))) || (track.Album != null && RickRollExists(track.Album.Link)) || RickRollExists(track.Link))
     {
         const string rickRollTrackId = "6JEK0CvvjDjjMUBFoXShNZ";
         var          rickRollTrack   = musicProviderFactory.GetMusicProviderByIdentifier(track.MusicProvider.Identifier).GetTrack(rickRollTrackId, user);
         //Create a new track that looks like the the original but is in fact 'Never give you up'
         var rickRolledTrack = new Track
         {
             Link                 = rickRollTrack.Link,
             Name                 = track.Name,
             Album                = track.Album,
             Artists              = track.Artists,
             Duration             = rickRollTrack.Duration,
             DurationMilliseconds = (long)rickRollTrack.Duration.TotalMilliseconds,
             IsAvailable          = track.IsAvailable,
         };
         logger.Debug("Rick rolling track {0}", track);
         return(rickRolledTrack);
     }
     return(track);
 }