public void ShowAlbumInfo(int parentWindowID, string artistName, string albumName, string strPath, MusicTag tag) { Log.Debug("Searching for album: {0} - {1}", albumName, artistName); var dlgProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS); var pDlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK); var errorEncountered = true; var album = new AlbumInfo(); var albumInfo = new MusicAlbumInfo(); if (m_database.GetAlbumInfo(albumName, artistName, ref album)) { // we already have album info in database so just use that albumInfo.Set(album); errorEncountered = false; } else {// lookup details. start with artist if (null != pDlgOK && !Win32API.IsConnectedToInternet()) { pDlgOK.SetHeading(703); pDlgOK.SetLine(1, 703); pDlgOK.SetLine(2, string.Empty); pDlgOK.DoModal(GetID); return; } // show dialog box indicating we're searching the album if (dlgProgress != null) { dlgProgress.Reset(); dlgProgress.SetHeading(326); dlgProgress.SetLine(1, albumName); dlgProgress.SetLine(2, artistName); dlgProgress.SetPercentage(0); dlgProgress.StartModal(GetID); dlgProgress.Progress(); dlgProgress.ShowProgressBar(true); } var scraper = new AllmusicSiteScraper(); List<AllMusicArtistMatch> artists; var selectedMatch = new AllMusicArtistMatch(); if (scraper.GetArtists(artistName, out artists)) { if (null != dlgProgress) { dlgProgress.SetPercentage(20); dlgProgress.Progress(); } if (artists.Count == 1) { // only have single match so no need to ask user Log.Debug("Single Artist Match Found"); selectedMatch = artists[0]; } else { // need to get user to choose which one to use Log.Debug("Muliple Artist Match Found ({0}) prompting user", artists.Count); var pDlg = (GUIDialogSelect2) GUIWindowManager.GetWindow((int) Window.WINDOW_DIALOG_SELECT2); if (null != pDlg) { pDlg.Reset(); pDlg.SetHeading(GUILocalizeStrings.Get(1303)); foreach (var i in artists.Select(artistMatch => new GUIListItem { Label = artistMatch.Artist + " - " + artistMatch.Genre, Label2 = artistMatch.YearsActive, Path = artistMatch.ArtistUrl, IconImage = artistMatch.ImageUrl })) { pDlg.Add(i); } pDlg.DoModal(GetID); // and wait till user selects one var iSelectedMatch = pDlg.SelectedLabel; if (iSelectedMatch < 0) { return; } selectedMatch = artists[iSelectedMatch]; } if (null != dlgProgress) { dlgProgress.Reset(); dlgProgress.SetHeading(326); dlgProgress.SetLine(1, albumName); dlgProgress.SetLine(2, artistName); dlgProgress.SetPercentage(40); dlgProgress.StartModal(GetID); dlgProgress.ShowProgressBar(true); dlgProgress.Progress(); } } string strAlbumHtml; if (scraper.GetAlbumHtml(albumName, selectedMatch.ArtistUrl, out strAlbumHtml)) { if (null != dlgProgress) { dlgProgress.SetPercentage(60); dlgProgress.Progress(); } if (albumInfo.Parse(strAlbumHtml)) { if (null != dlgProgress) { dlgProgress.SetPercentage(80); dlgProgress.Progress(); } m_database.AddAlbumInfo(albumInfo.Get()); errorEncountered = false; } } } } if (null != dlgProgress) { dlgProgress.SetPercentage(100); dlgProgress.Progress(); dlgProgress.Close(); dlgProgress = null; } if (!errorEncountered) { var pDlgAlbumInfo = (GUIMusicInfo)GUIWindowManager.GetWindow((int)Window.WINDOW_MUSIC_INFO); if (null != pDlgAlbumInfo) { pDlgAlbumInfo.Album = albumInfo; pDlgAlbumInfo.Tag = tag; pDlgAlbumInfo.DoModal(parentWindowID); if (pDlgAlbumInfo.NeedsRefresh) { m_database.DeleteAlbumInfo(albumName, artistName); ShowAlbumInfo(parentWindowID, artistName, albumName, strPath, tag); return; } } } else { Log.Debug("No Album Found"); if (null != pDlgOK) { pDlgOK.SetHeading(187); pDlgOK.SetLine(1, 187); pDlgOK.SetLine(2, string.Empty); pDlgOK.DoModal(GetID); } } }
protected virtual void ShowArtistInfo(string artistName, string albumName) { Log.Debug("Looking up Artist: {0}", albumName); var dlgProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS); var pDlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK); var errorEncountered = true; var artist = new ArtistInfo(); var artistInfo = new MusicArtistInfo(); if (m_database.GetArtistInfo(artistName, ref artist)) { // we already have artist info in database so just use that artistInfo.Set(artist); errorEncountered = false; } else { // lookup artist details if (null != pDlgOK && !Win32API.IsConnectedToInternet()) { pDlgOK.SetHeading(703); pDlgOK.SetLine(1, 703); pDlgOK.SetLine(2, string.Empty); pDlgOK.DoModal(GetID); return; } // show dialog box indicating we're searching the artist if (dlgProgress != null) { dlgProgress.Reset(); dlgProgress.SetHeading(320); dlgProgress.SetLine(1, artistName); dlgProgress.SetLine(2, string.Empty); dlgProgress.SetPercentage(0); dlgProgress.StartModal(GetID); dlgProgress.Progress(); dlgProgress.ShowProgressBar(true); } var scraper = new AllmusicSiteScraper(); List<AllMusicArtistMatch> artists; if (scraper.GetArtists(artistName, out artists)) { var selectedMatch = new AllMusicArtistMatch(); if (artists.Count == 1) { // only have single match so no need to ask user Log.Debug("Single Artist Match Found"); selectedMatch = artists[0]; errorEncountered = false; } else { // need to get user to choose which one to use Log.Debug("Muliple Artist Match Found ({0}) prompting user", artists.Count); var pDlg = (GUIDialogSelect2)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_SELECT2); if (null != pDlg) { pDlg.Reset(); pDlg.SetHeading(GUILocalizeStrings.Get(1303)); foreach (var i in artists.Select(artistMatch => new GUIListItem { Label = artistMatch.Artist + " - " + artistMatch.Genre, Label2 = artistMatch.YearsActive, Path = artistMatch.ArtistUrl, IconImage = artistMatch.ImageUrl })) { pDlg.Add(i); } pDlg.DoModal(GetID); // and wait till user selects one var iSelectedMatch = pDlg.SelectedLabel; if (iSelectedMatch < 0) { return; } selectedMatch = artists[iSelectedMatch]; } if (null != dlgProgress) { dlgProgress.Reset(); dlgProgress.SetHeading(320); dlgProgress.SetLine(1, artistName); dlgProgress.SetLine(2, string.Empty); dlgProgress.SetPercentage(40); dlgProgress.StartModal(GetID); dlgProgress.ShowProgressBar(true); dlgProgress.Progress(); } } if (null != dlgProgress) { dlgProgress.SetPercentage(60); dlgProgress.Progress(); } if (artistInfo.Parse(selectedMatch.ArtistUrl)) { if (null != dlgProgress) { dlgProgress.SetPercentage(80); dlgProgress.Progress(); } // set values to actual artist to ensure they match track data // rather than values that might be returned from allmusic.com artistInfo.Artist = artistName; m_database.AddArtistInfo(artistInfo.Get()); errorEncountered = false; } } } if (null != dlgProgress) { dlgProgress.SetPercentage(100); dlgProgress.Progress(); dlgProgress.Close(); dlgProgress = null; } if (!errorEncountered) { var pDlgArtistInfo = (GUIMusicArtistInfo)GUIWindowManager.GetWindow((int)Window.WINDOW_ARTIST_INFO); if (null != pDlgArtistInfo) { pDlgArtistInfo.Artist = artistInfo; pDlgArtistInfo.DoModal(GetID); if (pDlgArtistInfo.NeedsRefresh) { m_database.DeleteArtistInfo(artistInfo.Artist); ShowArtistInfo(artistName, albumName); } } } else { Log.Debug("Unable to get artist details"); if (null != pDlgOK) { pDlgOK.SetHeading(702); pDlgOK.SetLine(1, 702); pDlgOK.SetLine(2, string.Empty); pDlgOK.DoModal(GetID); } } }