////////////////////////////////////////////////////////////////////////// // Method: AddReleaseDate // FullName: MusicDataminer.MusicDBParser.AddReleaseDate // Access: private // Returns: void // Parameter: MusicBrainzRelease release ////////////////////////////////////////////////////////////////////////// private void AddReleaseDate(MusicBrainzRelease release) { int key = release.date; List <MusicBrainzRelease> dates; if (!this.dataBase.dates.ContainsKey(key)) { dates = new List <MusicBrainzRelease>(); this.dataBase.dates[key] = dates; } else { dates = (List <MusicBrainzRelease>) this.dataBase.dates[key]; } dates.Add(release); }
////////////////////////////////////////////////////////////////////////// // Method: GetMusicBrainzReleases // FullName: MusicDataminer.MusicDBParser.GetMusicBrainzReleases // Access: public // Returns: bool // Parameter: string artist // Parameter: string albumName // Parameter: MusicBrainz o // Parameter: List<MusicBrainzAlbum> releasesList // Parameter: out string retrievedName ////////////////////////////////////////////////////////////////////////// public bool GetMusicBrainzReleases(string artist, string albumName, List <MusicBrainzRelease> releasesList, out string retrievedName, string aStyle) { MusicBrainz o; // Create the musicbrainz object, which will be needed for subsequent calls o = new MusicBrainz(); // Set the proper server to use. Defaults to mm.musicbrainz.org:80 if (Environment.GetEnvironmentVariable("MB_SERVER") != null) { o.SetServer(Environment.GetEnvironmentVariable("MB_SERVER"), 80); } // Check to see if the debug env var has been set if (Environment.GetEnvironmentVariable("MB_DEBUG") != null) { o.SetDebug(Environment.GetEnvironmentVariable("MB_DEBUG") != "0"); } // Tell the server to only return 4 levels of data, unless the MB_DEPTH env var is set if (Environment.GetEnvironmentVariable("MB_DEPTH") != null) { o.SetDepth(int.Parse(Environment.GetEnvironmentVariable("MB_DEPTH"))); } else { o.SetDepth(4); } retrievedName = albumName; bool foundRelevantRelease = false; //Console.WriteLine("Searching for occurrences for: " + artist + " / " + albumName); iForm.PrintLine("(" + aStyle + ") LOOK: " + artist + " / " + albumName); bool found = o.Query(MusicBrainz.MBQ_FileInfoLookup, new String[] { "", artist, albumName, "", "", "" }); if (!found) { return(found); } // Select the first album o.Select(MusicBrainz.MBS_SelectLookupResult, 1); string type; o.GetResultData(MusicBrainz.MBE_LookupGetType, out type); string fragment; o.GetFragmentFromURL(type, out fragment); // iterate through all the results o.Select(MusicBrainz.MBS_Rewind); if (!o.Select(MusicBrainz.MBS_SelectLookupResult, 1)) { return(foundRelevantRelease); } // NOTE: must be done before the next Select int relevance = o.GetResultInt(MusicBrainz.MBE_LookupGetRelevance); // if not sure about it, quit if (relevance < 80) { return(foundRelevantRelease); } // select the album o.Select(MusicBrainz.MBS_SelectLookupResultAlbum); o.GetResultData(MusicBrainz.MBE_AlbumGetAlbumName, out retrievedName); int nReleases = o.GetResultInt(MusicBrainz.MBE_AlbumGetNumReleaseDates); if (nReleases != 0) { albumName = retrievedName; for (int i = 1; i <= nReleases; i++) { if (o.Select(MusicBrainz.MBS_SelectReleaseDate, i)) { foundRelevantRelease = true; string country; o.GetResultData(MusicBrainz.MBE_ReleaseGetCountry, out country); string date; o.GetResultData(MusicBrainz.MBE_ReleaseGetDate, out date); if (dataBase.countries.ContainsKey(country.ToUpper())) { // add it to the list MusicBrainzRelease release = new MusicBrainzRelease(); release.country = (Country)dataBase.countries[country]; if (date.Length >= 4) { release.date = int.Parse(date.Substring(0, 4)); } else { return(false); //release.date = int.Parse(date); } // Add the release both to the Album and Country releasesList.Add(release); release.country.releases.Add(release); } } o.Select(MusicBrainz.MBS_Back); } } return(foundRelevantRelease); }
public static bool FilterDB(string srcDBFilename, string outputFilename) { DB destination; string iGeoDataPath = "./geodata/"; List <string> countryFilter = ParseCountryFilter(iGeoDataPath + "countries_acronyms_europe.txt"); bool loaded = MusicDBLoader.LoadDB(srcDBFilename, out destination); if (loaded) { ArrayList albums = new ArrayList(destination.albums.Values); for (int i = 0; i < albums.Count; i++) { Album album = (Album)albums[i]; for (int j = 0; j < album.releases.Count; j++) { MusicBrainzRelease release = album.releases[j]; if (!countryFilter.Contains(release.country.acronym)) { album.releases.RemoveAt(j--); release.freeDBAlbum = null; } } // if it became an empty album if (album.releases.Count == 0) { string key = album.artist.name + "€" + album.title; key = key.ToLowerInvariant(); key = ClearString(key); destination.albums.Remove(key); key = ClearString(album.artist.name.ToLowerInvariant()); Artist artist = (Artist)destination.artists[key]; artist.albums.Remove(album); if (album.artist.albums.Count == 0) { destination.artists.Remove(key); } } } // filter releases in styles foreach (Style style in destination.styles.Values) { for (int k = 0; k < style.releases.Count; k++) { MusicBrainzRelease release = style.releases[k]; if (release.freeDBAlbum == null || !countryFilter.Contains(release.country.acronym)) { style.releases.RemoveAt(k--); } } } // filter countries ArrayList countries = new ArrayList(destination.countries.Values); foreach (Country country in countries) { if (!countryFilter.Contains(country.acronym)) { destination.countries.Remove(country.acronym); } else { for (int k = 0; k < country.releases.Count; k++) { MusicBrainzRelease release = country.releases[k]; if (release.freeDBAlbum == null) { country.releases.RemoveAt(k--); } } } } // filter styles ArrayList styles = new ArrayList(destination.styles.Keys); for (int k = 0; k < styles.Count; k++) { object key = styles[k]; Style style = (Style)destination.styles[key]; if (style.releases.Count == 0) { destination.styles.Remove(key); } } MusicDBLoader.SaveDB(outputFilename, destination); return(true); } return(false); }