public void ShowAlbumInfo(int parentWindowID, bool isFolder, string artistName, string albumName, string strPath, MusicTag tag) { GUIDialogOK pDlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK); GUIDialogProgress dlgProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS); bool bDisplayErr = false; AlbumInfo album = new AlbumInfo(); MusicAlbumInfo albumInfo = new MusicAlbumInfo(); if (m_database.GetAlbumInfo(albumName, artistName, ref album)) { albumInfo.Set(album); } else { 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(185); dlgProgress.SetLine(1, albumName); dlgProgress.SetLine(2, artistName); dlgProgress.SetLine(3, tag.Year.ToString()); dlgProgress.SetPercentage(0); //dlgProgress.StartModal(GetID); dlgProgress.StartModal(parentWindowID); dlgProgress.ShowProgressBar(true); dlgProgress.Progress(); } // find album info AllmusicSiteScraper scraper = new AllmusicSiteScraper(); if (scraper.FindAlbumInfo(albumName, artistName, tag.Year)) { if (dlgProgress != null) { dlgProgress.SetPercentage(30); dlgProgress.Progress(); dlgProgress.Close(); } // Did we find multiple albums? int iSelectedAlbum = 0; if (scraper.IsMultiple()) { string szText = GUILocalizeStrings.Get(181); GUIDialogSelect pDlg = (GUIDialogSelect)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_SELECT); if (null != pDlg) { pDlg.Reset(); pDlg.SetHeading(szText); foreach (MusicAlbumInfo foundAlbum in scraper.GetAlbumsFound()) { pDlg.Add(string.Format("{0} - {1}", foundAlbum.Title, foundAlbum.Artist)); } pDlg.DoModal(parentWindowID); // and wait till user selects one iSelectedAlbum = pDlg.SelectedLabel; if (iSelectedAlbum < 0) { return; } } // ok, now show dialog we're downloading the album info MusicAlbumInfo selectedAlbum = scraper.GetAlbumsFound()[iSelectedAlbum]; if (null != dlgProgress) { dlgProgress.Reset(); dlgProgress.SetHeading(185); dlgProgress.SetLine(1, selectedAlbum.Title2); dlgProgress.SetLine(2, selectedAlbum.Artist); dlgProgress.StartModal(parentWindowID); dlgProgress.ShowProgressBar(true); dlgProgress.SetPercentage(40); dlgProgress.Progress(); } if (!scraper.FindInfoByIndex(iSelectedAlbum)) { if (null != dlgProgress) { dlgProgress.Close(); } return; } } if (null != dlgProgress) { dlgProgress.SetPercentage(60); dlgProgress.Progress(); } // Now we have either a Single hit or a selected Artist // Parse it if (albumInfo.Parse(scraper.GetHtmlContent())) { if (null != dlgProgress) { dlgProgress.SetPercentage(80); dlgProgress.Progress(); } // set album title and artist from musicinfotag, not the one we got from allmusic.com albumInfo.Title = albumName; albumInfo.Artist = artistName; // set path, needed to store album in database albumInfo.AlbumPath = strPath; album = new AlbumInfo(); album.Album = albumInfo.Title; album.Artist = albumInfo.Artist; album.Genre = albumInfo.Genre; album.Tones = albumInfo.Tones; album.Styles = albumInfo.Styles; album.Review = albumInfo.Review; album.Image = albumInfo.ImageURL; album.Rating = albumInfo.Rating; album.Tracks = albumInfo.Tracks; try { album.Year = Int32.Parse(albumInfo.DateOfRelease); } catch (Exception) {} // save to database m_database.AddAlbumInfo(album); if (null != dlgProgress) { dlgProgress.SetPercentage(100); dlgProgress.Progress(); dlgProgress.Close(); } if (isFolder) { // if there's an album thumb string thumb = Util.Utils.GetAlbumThumbName(albumInfo.Artist, albumInfo.Title); // use the better one thumb = Util.Utils.ConvertToLargeCoverArt(thumb); // to create a folder.jpg from it if (Util.Utils.FileExistsInCache(thumb) && _createMissingFolderThumbs) { try { string folderjpg = Util.Utils.GetFolderThumbForDir(strPath); Util.Utils.FileDelete(folderjpg); File.Copy(thumb, folderjpg); } catch (Exception) {} } } } else { bDisplayErr = true; } } else { bDisplayErr = true; } } if (null != dlgProgress) { dlgProgress.Close(); } if (!bDisplayErr) { GUIMusicInfo 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(isFolder, artistName, albumName, strPath, tag); return; } } else { if (null != dlgProgress) { dlgProgress.Close(); } if (null != pDlgOK) { pDlgOK.SetHeading(702); pDlgOK.SetLine(1, 702); pDlgOK.SetLine(2, string.Empty); pDlgOK.DoModal(GetID); } } } }
protected virtual void ShowArtistInfo(string artistName, string albumName) { GUIDialogOK pDlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK); GUIDialogProgress dlgProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS); bool bSaveDb = true; bool bDisplayErr = false; ArtistInfo artist = new ArtistInfo(); MusicArtistInfo artistInfo = new MusicArtistInfo(); if (m_database.GetArtistInfo(artistName, ref artist)) { artistInfo.Set(artist); } else { 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); } // find artist info AllmusicSiteScraper scraper = new AllmusicSiteScraper(); if (scraper.FindInfo(AllmusicSiteScraper.SearchBy.Artists, artistName)) { // did we find at least 1 artist? if (scraper.IsMultiple()) { // let user choose one int iSelectedArtist = 0; string szText = GUILocalizeStrings.Get(181); GUIDialogSelect pDlg = (GUIDialogSelect)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_SELECT); if (null != pDlg) { pDlg.Reset(); pDlg.SetHeading(szText); foreach (string selectedArtist in scraper.GetItemsFound()) { pDlg.Add(selectedArtist); } pDlg.DoModal(GetID); // and wait till user selects one iSelectedArtist = pDlg.SelectedLabel; if (iSelectedArtist < 0) { return; } } // ok, now show dialog we're downloading the artist info 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(); } // download the artist info if (!scraper.FindInfoByIndex(iSelectedArtist)) { if (null != dlgProgress) { dlgProgress.Close(); } return; } } if (null != dlgProgress) { dlgProgress.SetPercentage(60); dlgProgress.Progress(); } // Now we have either a Single hit or a selected Artist // Parse it if (artistInfo.Parse(scraper.GetHtmlContent())) { // if the artist selected from allmusic.com does not match // the one from the file, override the one from the allmusic // with the one from the file so the info is correct in the // database... if (!artistInfo.Artist.Equals(artistName)) { artistInfo.Artist = artistName; } if (bSaveDb) { // save to database m_database.AddArtistInfo(artistInfo.Get()); } if (null != dlgProgress) { dlgProgress.SetPercentage(100); dlgProgress.Progress(); dlgProgress.Close(); dlgProgress = null; } } else { bDisplayErr = true; } } else { bDisplayErr = true; } } if (null != dlgProgress) { dlgProgress.Close(); } if (!bDisplayErr) { // ok, show Artist info GUIMusicArtistInfo 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); return; } } } else { if (null != dlgProgress) { dlgProgress.Close(); } if (null != pDlgOK) { pDlgOK.SetHeading(702); pDlgOK.SetLine(1, 702); pDlgOK.SetLine(2, string.Empty); pDlgOK.DoModal(GetID); } } }