Esempio n. 1
0
        /// <summary>
        /// Component Initialized
        /// </summary>
        protected override async Task OnInitializedAsync()
        {
            try
            {
                var cursorPage = await SpotifyService.GetArtists(AuthenticationService.AuthenticationToken);

                Artists.AddRange(cursorPage.Items);

                while (cursorPage != null && cursorPage.Next != null)
                {
                    cursorPage = await SpotifyService.GetArtists(AuthenticationService.AuthenticationToken, cursorPage);

                    Artists.AddRange(cursorPage.Items);

                    StateHasChanged();
                }

                await BindPlaylist();
            }
            catch (Exception ex)
            {
                this.PageException = ex;
            }

            Loaded = true;

            StateHasChanged();
        }
Esempio n. 2
0
        public async Task <IEnumerable <Place> > GetRecommendedEstablishmentsForPlaylist(string playlistId, double lat, double lon, double distance)
        {
            string userId = HttpContext.User.Identity.Name;
            var    client = new HttpClient();

            //Get his spotify token
            var user = await _userService.GetUser(userId);

            var token = user.CurrentToken;
            //Get playlist songs from spotify

            var songs = await _spotify.GetSongsFromPlaylist(client, token, playlistId);

            //Match with storedSongs in Db for tags


            var lastFmTagOccurrence    = new ConcurrentDictionary <string, int>();
            var spotifyGenreOccurrence = new ConcurrentDictionary <string, int>();
            var artistsChecked         = new ConcurrentDictionary <string, List <string> >();

            //Call lastFm for the rest, if empty save with flag to not ask for it
            Parallel.ForEach(songs.Items, async(song) =>
            {
                var lastFmTags = await _lastFm.GetTrackTags(client, song.Track.Name, song.Track.Artists[0]?.Name);
                lastFmTags.Toptags.Tag.Sort(new TagComparer());

                lastFmTags.Toptags.Tag.Take(5).ToList().ForEach(t =>
                {
                    lastFmTagOccurrence.AddOrUpdate(t.Name, 1, (k, i) => i++);
                });

                var artists = song.Track.Artists.Select(a => a.Id)
                              .Where(a => !artistsChecked.ContainsKey(a));
                artists.ToList().ForEach(a => artistsChecked.AddOrUpdate(a, new List <string>(), (k, l) => new List <string>()));


                var stringArtists = artists.Aggregate((a, b) => a + "," + b);
                var spotifyTags   = await _spotify.GetArtists(client, token, stringArtists);
                spotifyTags.ForEach(a =>
                {
                    artistsChecked.AddOrUpdate(a.Id, a.Genres.ToList(), (k, l) => a.Genres.ToList());
                    a.Genres.ToList().ForEach(g =>
                    {
                        // Add Genre occurrence
                        spotifyGenreOccurrence.AddOrUpdate(g, 1, (k, l) => l++);
                    });
                });
            });

            //Update tags

            //Algorithm magic (Get every place surrounding that, apply the algorithm for those)
            //With today's playlist
            var places = _placesService.GetPlaces(0, 25, new Geolocation {
                Latitude = lat, Longitude = lon
            }, distance, true);

            throw new NotImplementedException();
        }