Exemplo n.º 1
0
        public void ModifyFeaturing(Func <Song, bool> compare)
        {
            var timer = Top100Timer.Start("ModifyFeaturing");

            foreach (var song in dbSongsList.List.FindAll(x => compare(x)))
            {
                using (var updateCmd = dbConnection.CreateCommand())
                {
                    if (song.Artist.Contains("Featuring", StringComparison.OrdinalIgnoreCase) ||
                        song.Artist.Contains("Feat.", StringComparison.OrdinalIgnoreCase))
                    {
                        string newTitle  = MySqlHelper.EscapeString(song.Title + " " + getFeaturing(song.Artist));
                        string newArtist = MySqlHelper.EscapeString(getArtist(song.Artist));
                        updateCmd.CommandText = String.Format("UPDATE songs set title='{0}', artist='{1}' WHERE id={2}", newTitle, newArtist, song.DbId);
                        Top100Util.Debug(String.Format("Db Featuring: {0}", song));
                        if (!Top100Settings.Preview)
                        {
                            song.Artist = newArtist;
                            song.Title  = newTitle;
                            updateCmd.ExecuteNonQuery();
                        }
                    }
                }
            }
            timer.End();
        }
Exemplo n.º 2
0
        public void UpdateDbOwnership(List <Song> iTunesSongList, Func <Song, bool> compare)
        {
            var timer = Top100Timer.Start("UpdateDbOwnership");

            foreach (Song t in dbSongsList.List.FindAll(x => x.Own.Equals(false) && compare(x)))
            {
                var s = iTunesSongList.Find(x => x.IsMatch(t));
                if (s != null)
                {
                    using (var updateCmd = dbConnection.CreateCommand())
                    {
                        updateCmd.CommandText = "UPDATE songs set title=@title, artist=@artist, own='1' WHERE id=@id";
                        updateCmd.Parameters.AddWithValue("@title", s.Title);
                        updateCmd.Parameters.AddWithValue("@artist", s.Artist);
                        updateCmd.Parameters.AddWithValue("@id", t.DbId);
                        if (!Top100Settings.Preview)
                        {
                            t.Title  = s.Title;
                            t.Artist = s.Artist;
                            t.Own    = true;
                            updateCmd.ExecuteNonQuery();
                        }
                    }
                    Top100Util.Debug(String.Format("Db Ownership: {0} => {1}", t, s));
                }
            }
            timer.End();
        }
Exemplo n.º 3
0
        public static Top100Timer Start(string title)
        {
            Top100Timer timer = new Top100Timer();

            timer.StartTime = DateTime.Now;
            timer.Title     = title;
            Top100Util.Debug(title);
            return(timer);
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            bool              fix_featuring = false;
            Int16             year          = 0;
            Func <Song, bool> compare;

            paramList.Add("debug", a => Top100Settings.Debug     = Boolean.Parse(a));
            paramList.Add("preview", a => Top100Settings.Preview = Boolean.Parse(a));
            paramList.Add("year", a => year = Int16.Parse(a));
            paramList.Add("fix_featuring", a => fix_featuring = Boolean.Parse(a));

            ParseArguments(args);

            var           timer          = Top100Timer.Start("Parsing iTunes library");
            List <Song>   iTunesSongList = new List <Song>();
            LibraryParser library        = new LibraryParser(LibraryParser.GetDefaultLibraryLocation());

            foreach (Playlist p in library.Playlists)
            {
                if (p.Name == "Music")
                {
                    foreach (Song s in p.Songs)
                    {
                        if (!s.AppleMusic)
                        {
                            iTunesSongList.Add(s);
                        }
                        else
                        {
                            Top100Util.Debug("Skipping AppleMusic file: " + s);
                        }
                    }
                }
            }
            timer.End();

            if (year > 0)
            {
                compare = (x) => x.Year == year;
            }
            else
            {
                compare = (x) => true;
            }

            using (var db = new Top100DB())
            {
                if (fix_featuring)
                {
                    db.ModifyFeaturing(compare);
                }
                db.UpdateDbOwnership(iTunesSongList, compare);
                db.FindMissingOwnership(iTunesSongList, compare);
                db.FindMissingTagsAndComments(iTunesSongList, compare);
            }
        }
Exemplo n.º 5
0
        public void FindMissingOwnership(List <Song> iTunesSongList, Func <Song, bool> compare)
        {
            var timer = Top100Timer.Start("FindMissingOwnership");

            foreach (Song dbSong in dbSongsList.List.FindAll(x => x.Own.Equals(true) && compare(x)))
            {
                var list = iTunesSongList.FindAll(x => x.IsMatch(dbSong));
                if ((list == null) || (list.Count < 1))
                {
                    Top100Util.Debug(String.Format("iTunes Missing: {0}", dbSong));
                }
            }
            timer.End();
        }
Exemplo n.º 6
0
        public Top100DB()
        {
            string connectionString = "Server=localhost;Database=top40;User ID=kevin;Password=admin;Pooling=false";

            dbConnection = new MySqlConnection(connectionString);
            try
            {
                dbConnection.Open();
                dbSongsList = new Songs(dbConnection);
            }
            catch (MySqlException)
            {
                Top100Util.Error("Could not connect to database.");
                throw;
            }
        }
Exemplo n.º 7
0
        public void FindMissingTagsAndComments(List <Song> iTunesSongList, Func <Song, bool> compare)
        {
            string top100     = "Top 100";
            Regex  comment    = new Regex("(?<year>^[0-9][0-9][0-9][0-9]), #(?<number>[01][0-9][0-9]).*");
            Regex  badComment = new Regex("^[0-9][0-9][0-9][0-9], #[01][0-9][0-9] [0-9][0-9][0-9][0-9], #[0-9]?[1-9].*");

            var timer = Top100Timer.Start("FindMissingTagsAndComments");

            foreach (Song dbSong in dbSongsList.List.FindAll(x => x.Own.Equals(true) && compare(x)))
            {
                var list = iTunesSongList.FindAll(x => x.IsMatch(dbSong));
                if ((list != null) && (list.Count >= 1))
                {
                    foreach (Song s in list)
                    {
                        bool   updateSong  = false;
                        string appleScript = "tell application \"iTunes\"\n" +
                                             "  activate\n" +
                                             String.Format("  set results to (every file track of playlist \"Library\" whose name contains (\"{0}\") and artist contains (\"{1}\"))\n", scrubString(s.Title), scrubString(s.Artist)) +
                                             "  repeat with t in results\n";
                        if (!s.Grouping.Contains(top100))
                        {
                            appleScript += String.Format("    set t's grouping to \"{0}\" as text\n", addTag(s.Grouping, top100));
                            Top100Util.Debug(String.Format("Missing Grouping: {0}=>{1}", s, addTag(s.Grouping, top100)));
                            updateSong = true;
                        }

                        if (badComment.IsMatch(s.Comments))
                        {
                            appleScript += String.Format("    set t's comment to \"{0}\" as text\n", prependComment(s.Comments, dbSong.Year, dbSong.Number));
                            Top100Util.Debug(String.Format("Bad Comment: {0}=>{1}", s, prependComment(s.Comments, dbSong.Year, dbSong.Number)));
                            updateSong = true;
                        }
                        else if (!comment.IsMatch(s.Comments))
                        {
                            appleScript += String.Format("    set t's comment to \"{0}\" as text\n", prependComment(s.Comments, dbSong.Year, dbSong.Number));
                            Top100Util.Debug(String.Format("Missing Comment: {0}=>{1}", s, prependComment(s.Comments, dbSong.Year, dbSong.Number)));
                            updateSong = true;
                        }
                        else if (comment.IsMatch(s.Comments))
                        {
                            if (dbSong.Number < s.Number)
                            {
                                appleScript += String.Format("    set t's comment to \"{0}\" as text\n", prependComment(s.Comments, dbSong.Year, dbSong.Number));
                                Top100Util.Debug(String.Format("Updating Comment: {0}=>{1}", s, prependComment(s.Comments, dbSong.Year, dbSong.Number)));
                                updateSong = true;
                            }
                        }
                        if (updateSong)
                        {
                            appleScript += "  end repeat\n" + "end tell\n";
                            try
                            {
                                if (!Top100Settings.Preview)
                                {
                                    AppleScript.Run(appleScript);
                                }
                            }
                            catch (Exception e)
                            {
                                Top100Util.Error(String.Format("Cannot update song: {0}\n\tException: {1}\n\tUsing: {2}", s, e, appleScript));
                            }
                        }
                    }
                }
                else
                {
                    Top100Util.Error("Cannot find owned song in Library. " + dbSong);
                }
            }
            timer.End();
        }
Exemplo n.º 8
0
        public void End()
        {
            TimeSpan duration = DateTime.Now - StartTime;

            Top100Util.Debug(Title + ": elapsed=" + duration.TotalSeconds);
        }