Beispiel #1
0
        public static bool SynchronizeDBs(string srcDBFilename1,
                                          string srcDBFilename2, string outputFilename)
        {
            DB destination;
            DB source;

            bool loaded = MusicDBLoader.LoadDB(srcDBFilename1, out destination);

            if (loaded)
            {
                loaded = MusicDBLoader.LoadDB(srcDBFilename2, out source);

                if (loaded)
                {
                    // TODO: recode this
                    //destination.albums.AddRange(source.albums);

                    MusicDBLoader.SaveDB(outputFilename, destination);

                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        //Constructor
        public MusicDBParser(Form1 aForm)
        {
            iForm      = aForm;
            iLineCount = new Hashtable();

            // try to load DataBase
            bool loaded = MusicDBLoader.LoadDB(iDBFileName, out dataBase);

            if (!loaded)
            {
                dataBase           = new DB();
                dataBase.albums    = new Hashtable();
                dataBase.countries = new Hashtable();
                dataBase.styles    = new Hashtable();
                dataBase.artists   = new Hashtable();
                dataBase.dates     = new Hashtable();

                this.ParseCountries(iCountriesInfoFileName);
                MusicDBLoader.SaveDB(iDBFileName, this.dataBase);
            }
        }
Beispiel #3
0
        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);
        }