示例#1
0
        private void DoSearchAlbum()
        {
            Cursor           = Cursors.WaitCursor;
            tbArtist.Enabled = false;
            tbAlbum.Enabled  = false;
            btSearch.Enabled = false;
            btUpdate.Enabled = false;
            using (AmazonAlbumInfo amazonInfo = new AmazonAlbumInfo())
            {
                _albums = amazonInfo.AmazonAlbumSearch(_artist, _album);
            }

            if (_albums.Count > 0)
            {
                btUpdate.Enabled = true;
                groupBoxAmazonMultipleAlbums.Text = ServiceScope.Get <ILocalisation>().ToString("AmazonAlbumSearch", "GroupBoxResults");
                if (_albums.Count == 1)
                {
                    _amazonAlbum = _albums[0];
                    btUpdate.PerformClick(); // Close the Dialog
                }
                else
                {
                    FillResults();
                }
            }
            else
            {
                groupBoxAmazonMultipleAlbums.Text = ServiceScope.Get <ILocalisation>().ToString("AmazonAlbumSearch", "NotFound");
                ServiceScope.Get <ILogger>().GetLogger.Debug("No Cover Art found");
                btUpdate.Enabled = false;
            }
            tbArtist.Enabled = true;
            tbAlbum.Enabled  = true;
            btSearch.Enabled = true;
            Cursor           = Cursors.Default;
        }
示例#2
0
        public AmazonAlbum GetAlbumInformation()
        {
            main.Cursor = Cursors.WaitCursor;
            List <AmazonAlbum> albums = new List <AmazonAlbum>();

            using (AmazonAlbumInfo amazonInfo = new AmazonAlbumInfo())
            {
                albums = amazonInfo.AmazonAlbumSearch(_selectedArtist, _selectedAlbum);
            }

            // Show the Album Selection dialog, if we got more than one album
            AmazonAlbum amazonAlbum = null;

            _askForAlbum = true;
            if (albums.Count > 0)
            {
                _askForAlbum = false;
                if (albums.Count == 1)
                {
                    amazonAlbum = albums[0];
                    // If we didn't get any disc info, consider the album as not found
                    if (amazonAlbum.Discs.Count == 0)
                    {
                        _askForAlbum = true;
                    }
                }
                else
                {
                    dlgSearchResult = new AlbumSearchResult();
                    foreach (AmazonAlbum foundAlbum in albums)
                    {
                        // Skip Albums with no Discs returned
                        if (foundAlbum.Discs.Count == 0)
                        {
                            continue;
                        }

                        // count the number of tracks, as we may have multiple discs
                        int trackCount = 0;
                        foreach (List <AmazonAlbumTrack> tracks in foundAlbum.Discs)
                        {
                            trackCount += tracks.Count;
                        }

                        ListViewItem lvItem = new ListViewItem(foundAlbum.Artist);
                        lvItem.SubItems.Add(foundAlbum.Title);
                        lvItem.SubItems.Add(trackCount.ToString());
                        lvItem.SubItems.Add(foundAlbum.Year);
                        lvItem.SubItems.Add(foundAlbum.Label);
                        dlgSearchResult.ResultView.Items.Add(lvItem);
                    }
                    main.Cursor = Cursors.Default;

                    // When the Listview contains no items, none of the found albums has track information
                    if (dlgSearchResult.ResultView.Items.Count == 0)
                    {
                        _askForAlbum = true;
                    }
                    else
                    {
                        if (main.ShowModalDialog(dlgSearchResult) == DialogResult.OK)
                        {
                            if (dlgSearchResult.ResultView.SelectedIndices.Count > 0)
                            {
                                amazonAlbum = albums[dlgSearchResult.ResultView.SelectedIndices[0]];
                            }
                            else
                            {
                                amazonAlbum = albums[0];
                            }
                        }
                        else
                        {
                            // Don't ask for album again, since the user cancelled
                            _askForAlbum = false;
                            dlgSearchResult.Dispose();
                            return(amazonAlbum);
                        }
                    }
                    dlgSearchResult.Dispose();
                }
            }
            main.Cursor = Cursors.Default;
            return(amazonAlbum);
        }
        public MusicBrainzAlbum GetMusicBrainzAlbumById(string albumID)
        {
            MusicBrainzAlbum album = new MusicBrainzAlbum();

            string requestString = musicBrainzUrl + string.Format(requestByID, albumID);
            string responseXml   = Util.GetWebPage(requestString);

            if (responseXml == null)
            {
                return(null);
            }

            XmlDocument xml = new XmlDocument();

            xml.LoadXml(responseXml);
            XmlNamespaceManager nsMgr = new XmlNamespaceManager(xml.NameTable);

            nsMgr.AddNamespace("m", "http://musicbrainz.org/ns/mmd-1.0#");

            XmlNodeList nodes = xml.SelectNodes("/m:metadata/m:release", nsMgr);

            if (nodes.Count > 0)
            {
                album.Id = new Guid(nodes[0].Attributes["id"].InnerXml);
                foreach (XmlNode childNode in nodes[0])
                {
                    if (childNode.Name == "title")
                    {
                        album.Title = childNode.InnerText;
                    }

                    if (childNode.Name == "asin")
                    {
                        album.Asin = childNode.InnerText;
                    }

                    if (childNode.Name == "artist")
                    {
                        foreach (XmlNode artistNode in childNode)
                        {
                            if (artistNode.Name == "name")
                            {
                                album.Artist = artistNode.InnerText;
                                break;
                            }
                        }
                    }

                    if (childNode.Name == "release-event-list")
                    {
                        foreach (XmlNode releaseNode in childNode)
                        {
                            if (releaseNode.Name == "event")
                            {
                                album.Year = releaseNode.Attributes["date"].InnerXml;
                            }
                        }
                    }

                    if (childNode.Name == "track-list")
                    {
                        foreach (XmlNode trackNode in childNode.ChildNodes)
                        {
                            MusicBrainzTrack track = new MusicBrainzTrack();
                            track.Id      = new Guid(trackNode.Attributes["id"].InnerXml);
                            track.AlbumID = album.Id;
                            track.Album   = album.Title;
                            track.Artist  = album.Artist;
                            foreach (XmlNode trackDetail in trackNode.ChildNodes)
                            {
                                if (trackDetail.Name == "title")
                                {
                                    track.Title = trackDetail.InnerText;
                                }

                                if (trackDetail.Name == "duration")
                                {
                                    track.Duration = Convert.ToInt32(trackDetail.InnerText);
                                }
                            }
                            album.Tracks.Add(track);
                        }
                    }
                }

                if (album.Asin != null)
                {
                    // Now do a lookup on Amazon for the Image Url
                    using (AmazonAlbumInfo amazonInfo = new AmazonAlbumInfo())
                    {
                        AmazonAlbum amazonAlbum = amazonInfo.AmazonAlbumLookup(album.Asin);
                        album.Amazon = amazonAlbum;
                    }
                }
            }

            return(album);
        }