Esempio n. 1
0
        public IActionResult Index()
        {
            var playlistTracks = new List <PlaylistTrack>();

            if (_spotifyAuthService.GetToken() != null)
            {
                var api = new SpotifyWebApi.SpotifyWebApi(_spotifyAuthService.GetToken());
                var fullPlaylistTracks = api.Playlist.GetPlaylistTracks(SpotifyUri.Make("1233033915", "3bdydssu6hXzOP4kLrI8cL")).Result;

                foreach (var track in fullPlaylistTracks)
                {
                    playlistTracks.Add(new PlaylistTrack
                    {
                        Name    = track.Track.Name,
                        Artist  = track.Track.Artists.FirstOrDefault().Name,
                        AddedBy = _usernames.GetValueOrDefault(track.AddedBy.Id)
                    });
                }
            }

            List <PlayedTrackViewModel> playedTrackViewModels = new List <PlayedTrackViewModel>();
            var playedTrackEntities = _storageService.GetPlayedTracks().Result;

            for (var i = 0; i < playedTrackEntities.Count(); i++)
            {
                playedTrackViewModels.Add(TrackEntityToPlayedTrackViewModel.Map(playedTrackEntities[i], i, playlistTracks));
            }

            ViewBag.PlayedTracks = playedTrackViewModels;
            return(View());
        }
        public IActionResult Index()
        {
            var api = new SpotifyWebApi.SpotifyWebApi(_spotifyAuthService.GetToken());
            var fullPlaylistTracks = api.Playlist.GetPlaylistTracks(SpotifyUri.Make("1233033915", "3bdydssu6hXzOP4kLrI8cL")).Result;

            var playlistTracks = new List <PlaylistTrack>();

            foreach (var track in fullPlaylistTracks)
            {
                playlistTracks.Add(new PlaylistTrack
                {
                    Name    = track.Track.Name,
                    Artist  = track.Track.Artists.FirstOrDefault().Name,
                    AddedBy = track.AddedBy.DisplayName
                });
            }

            List <TopArtist> top5Artists = playlistTracks
                                           .GroupBy(q => q.Artist)
                                           .OrderByDescending(gp => gp.Count())
                                           .Take(5)
                                           .Select(g => new TopArtist {
                Artist = g.Key, Count = g.Count()
            }).ToList();

            return(View());
        }
Esempio n. 3
0
        private static void FetchTrackAndAdd(ISpotifyAuthService spotifyAuthService, IStorageService storageService)
        {
            while (true && spotifyAuthService.IsListening)
            {
                var api = new SpotifyWebApi.SpotifyWebApi(spotifyAuthService.GetToken());
                var currentlyPlayingContext = api.Player.GetCurrentlyPlayingContext().Result;
                if (currentlyPlayingContext != null)
                {
                    var track = CurrentlyPlayingContextToTrackEntity.Map(currentlyPlayingContext);
                    storageService.AddTrack(track);

                    Thread.Sleep(currentlyPlayingContext.Item.DurationMs - currentlyPlayingContext.ProgressMs.Value + 2000);
                }
                else
                {
                    Thread.Sleep(30 * 1000);
                }
            }
        }
Esempio n. 4
0
 public IActionResult Index()
 {
     ViewBag.HasToken    = _spotifyAuthService.GetToken() != null;
     ViewBag.IsListening = _spotifyAuthService.IsListening;
     return(View());
 }