private void Button_Click(object sender, RoutedEventArgs e)
        {
            var api = ((App)App.Current).Api;
            api.CatalogUpdateCompleted += new EventHandler<EchoNestApiEventArgs>(api_CatalogUpdateCompleted);

            var songsActions = new List<CatalogAction<BMSong>>();
            using (var mediaLib = new MediaLibrary())
            {
                foreach (var song in mediaLib.Songs)
                {
                    var catalogAction = new CatalogAction<BMSong>();
                    catalogAction.Action = CatalogAction<BMSong>.ActionType.update;
                    catalogAction.Item = new BMSong
                    {
                        ItemId = Guid.NewGuid().ToString("D"),
                        ArtistName = song.Artist.Name,
                        SongName = song.Name,
                    };

                    songsActions.Add(catalogAction);
                }
            }

            var catalog = new Catalog();
            catalog.Id = catalogId.Text;
            catalog.SongActions = songsActions;

            api.CatalogUpdateAsync(catalog, null, null);
        }
Exemplo n.º 2
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     EchoNestApi api = ((App)App.Current).Api;
     api.CatalogUpdateCompleted += new EventHandler<EchoNestApiEventArgs>(api_CatalogUpdateCompleted);
     Catalog cat = new Catalog
     {
         Id = catalogId.Text,
         SongActions = new List<CatalogAction<Song>> {
             new CatalogAction<Song>{
                 Item = new Song{
                     ItemId = catalogId.Text + title.Text,
                     SongName = title.Text,
                     ArtistName = artist.Text
                 }
             }
         }
     };
     api.CatalogUpdateAsync(cat, null, null);
 }
Exemplo n.º 3
0
        private void StoreDownloadedSongs(Catalog cat)
        {
            logger.Debug("Downloaded {0} songs", cat.Items.Count);

            var analyzedSongs = cat.Items.
                Select<Song, AnalyzedSong>(s => new AnalyzedSong
                {
                    ItemId = s.Request.ItemId,
                    ArtistName = s.ArtistName ?? s.Request.ArtistName,
                    SongName = s.SongName ?? s.Request.SongName,
                    AudioSummary = s.AudioSummary != null ?
                    new AnalyzedSong.Summary
                    {
                        Tempo = s.AudioSummary.Tempo,
                        ItemId = s.Request.ItemId
                    } : null
                }).
                Where<AnalyzedSong>(s =>
                {
                    bool matches = SongsToAnalyzeIds.Contains(s.ItemId);
                    if (matches)
                    {
                        logger.Trace("Song '{0}' matches a song we're looking for", s);
                    }
                    return matches;
                });

            int analyzedCount = analyzedSongs.Count();

            logger.Debug("Matched {0} songs", analyzedCount);

            if (analyzedCount > 0)
            {
                using (BeatMachineDataContext context = new BeatMachineDataContext(
                    BeatMachineDataContext.DBConnectionString))
                {
                    context.AnalyzedSongs.InsertAllOnSubmit(analyzedSongs);
                    context.SubmitChanges();
                }

                logger.Debug("Stored all matches to database");

                foreach (AnalyzedSong s in analyzedSongs)
                {
                    SongsToAnalyze.Remove(
                        SongsToAnalyze.Where(x => String.Equals(x.ItemId, s.ItemId)).First());
                    SongsToAnalyzeIds.Remove(s.ItemId);
                }

                logger.Debug("Removed matches from list of songs to analyze");

                NewSongsAdded = true;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates a catalog as documented here
        /// http://developer.echonest.com/docs/v4/catalog.html#update
        /// </summary>
        /// <param name="cat">Catalog to update, which should have at least the
        /// Id set, as well as either the SongActions or ArtistActions 
        /// properties. An update can either include songs or artists, but not 
        /// both, so one of these two has to be either null or contain 0 
        /// members.</param>
        /// <param name="parameters">See link for list of parameters</param>
        public void CatalogUpdateAsync(Catalog cat, 
            Dictionary<string, string> parameters, object state)
        {
            InitializeParameters(ref parameters);
            parameters["id"] = cat.Id;
            parameters["data_type"] = "json";

            // TODO Add support for artist catalogs
            SendHttpRequest(EchoNestPaths.CatalogUpdate, parameters,
                cat.SongActions, state);
        }