Beispiel #1
0
        public void BindTable()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("filename");
            dt.Columns.Add("itunes");
            dt.Columns.Add("disk");
            dt.Columns.Add("mismatch");
            dt.Columns.Add("approx");
            dt.Columns.Add("propercomp");

            foreach (KeyValuePair <string, WorkingTrack> track in collection)
            {
                WorkingTrack wt = track.Value;

                DataRow dr = dt.NewRow();
                dr["filename"]   = wt.Path;
                dr["disk"]       = wt.isOnDisk ? "X" : "";
                dr["iTunes"]     = wt.isIniTunes ? "X" : "";
                dr["mismatch"]   = wt.LocationMismatch ? "X" : "";
                dr["approx"]     = wt.ApproximateMatch ? "X" : "";
                dr["propercomp"] = wt.ProperlyMarkedAsCompilation ? "X" : "";

                dt.Rows.Add(dr);
            }

            dataGridView1.DataSource = dt;
            dt.DefaultView.Sort      = "filename asc";
            ResizeColumns();
        }
Beispiel #2
0
        private void RescanFile(string x)
        {
            TagLib.File  mp3file    = TagLib.File.Create(x);
            WorkingTrack wtDiskOnly = WorkingTrackFromTagLibFile(mp3file);

            collection[x.ToLower()] = wtDiskOnly;
        }
Beispiel #3
0
        private IITFileOrCDTrack GetITTFileOrCDTrackFromWorkingTrack(WorkingTrack wt)
        {
            iTunes      = new iTunesAppClass();
            mainLibrary = iTunes.LibraryPlaylist;
            tracks      = mainLibrary.Tracks;
            IITFileOrCDTrack track = tracks[wt.Position.Value] as IITFileOrCDTrack;

            return(track);
        }
Beispiel #4
0
 private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
 {
     if (e.StateChanged == DataGridViewElementStates.Selected)
     {
         string filename = e.Row.Cells[0].Value.ToString().ToLower();
         if (collection.ContainsKey(filename))
         {
             ActiveWorkingTrack = collection[filename];
             FieldsFromWorkingTrack(ActiveWorkingTrack);
         }
     }
 }
Beispiel #5
0
 private string CalculateID3Location(WorkingTrack WorkingTrack)
 {
     return(string.Format(LocationCalculation,
                          FileRoot,
                          WorkingTrack.ID3AlbumArtist,
                          WorkingTrack.ID3Year,
                          WorkingTrack.ID3Album,
                          !string.IsNullOrWhiteSpace(WorkingTrack.ID3Comment) ? string.Format(" ({0})", WorkingTrack.ID3Comment) : "",
                          int.Parse(WorkingTrack.ID3TrackNumber),
                          WorkingTrack.ID3Artist,
                          WorkingTrack.ID3Name));
 }
Beispiel #6
0
        private WorkingTrack WorkingTrackFromIITFileOrCDTrack(IITFileOrCDTrack IITFileOrCDTrack, int Position)
        {
            WorkingTrack WorkingTrack;

            if (File.Exists(IITFileOrCDTrack.Location))
            {
                WorkingTrack = WorkingTrackFromTagLibFile(TagLib.File.Create(IITFileOrCDTrack.Location));
            }
            else
            {
                WorkingTrack = new WorkingTrack();
            }

            WorkingTrack.iTunesArtist          = IITFileOrCDTrack.Artist;
            WorkingTrack.iTunesName            = IITFileOrCDTrack.Name;
            WorkingTrack.iTunesAlbum           = IITFileOrCDTrack.Album;
            WorkingTrack.iTunesAlbumArtist     = IITFileOrCDTrack.AlbumArtist;
            WorkingTrack.iTunesSortArtist      = IITFileOrCDTrack.SortArtist;
            WorkingTrack.iTunesSortName        = IITFileOrCDTrack.SortName;
            WorkingTrack.iTunesSortAlbumArtist = IITFileOrCDTrack.SortAlbumArtist;
            WorkingTrack.iTunesTrackNumber     = IITFileOrCDTrack.TrackNumber.ToString();
            WorkingTrack.iTunesYear            = IITFileOrCDTrack.Year.ToString();
            WorkingTrack.iTunesComment         = IITFileOrCDTrack.Comment;
            WorkingTrack.iTunesRating          = IITFileOrCDTrack.Rating.ToString();
            WorkingTrack.iTunesLocation        = IITFileOrCDTrack.Location.ToString();
            WorkingTrack.isIniTunes            = true; // IITFileOrCDTrack means it's from iTunes
            WorkingTrack.isOnDisk         = File.Exists(WorkingTrack.iTunesLocation);
            WorkingTrack.Position         = Position;
            WorkingTrack.LocationMismatch = (WorkingTrack.iTunesLocation != CalculateiTunesLocation(WorkingTrack));

            if (WorkingTrack.LocationMismatch)
            {
                WorkingTrack.ApproximateMatch = (WorkingTrack.iTunesLocation.ToLower() == CalculateiTunesLocation(WorkingTrack).ToLower());
            }

            WorkingTrack.Compilation = IITFileOrCDTrack.Compilation;

            if (WorkingTrack.ID3Comment == "Compilation")
            {
                // If the comment says compilation you need to be flagged as compilation
                WorkingTrack.ProperlyMarkedAsCompilation = WorkingTrack.Compilation;
            }
            else
            {
                // If the comment does not say compilation you need to be NOT flagged as compilation
                WorkingTrack.ProperlyMarkedAsCompilation = !WorkingTrack.Compilation;
            }

            WorkingTrack.Path = IITFileOrCDTrack.Location;

            return(WorkingTrack);
        }
Beispiel #7
0
        private void button3_Click(object sender, EventArgs e)
        {
            foreach (KeyValuePair <string, WorkingTrack> track in collection)
            {
                WorkingTrack wt = track.Value;

                if (wt.ApproximateMatch)
                {
                    MoveFileToiTunesCalcLocation(wt);
                }
            }

            MessageBox.Show("done");
        }
Beispiel #8
0
        private void button11_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                string x = row.Cells[0].Value.ToString();

                TagLib.File mp3file = TagLib.File.Create(x);

                mp3file.Tag.Comment = "";
                mp3file.Save();

                WorkingTrack wtDiskOnly = WorkingTrackFromTagLibFile(mp3file);

                collection[x.ToLower()] = wtDiskOnly;
            }
            MessageBox.Show("done");
        }
Beispiel #9
0
        private WorkingTrack MergeWorkingTrackFromFields(WorkingTrack WorkingTrack)
        {
            WorkingTrack.iTunesArtist          = this.iTunesArtist.Text;
            WorkingTrack.iTunesName            = this.iTunesSongName.Text;
            WorkingTrack.iTunesAlbum           = this.iTunesAlbum.Text;
            WorkingTrack.iTunesAlbumArtist     = this.iTunesAlbumArtist.Text;
            WorkingTrack.iTunesSortArtist      = this.iTunesSortArtist.Text;
            WorkingTrack.iTunesSortName        = this.iTunesSortName.Text;
            WorkingTrack.iTunesSortAlbumArtist = this.iTunesSortAlbumArtist.Text;
            WorkingTrack.iTunesTrackNumber     = this.iTunesTrackNumber.Text;
            WorkingTrack.iTunesYear            = this.iTunesYear.Text;
            WorkingTrack.iTunesComment         = this.iTunesComment.Text;
            WorkingTrack.iTunesRating          = this.iTunesRating.Text;
            WorkingTrack.iTunesLocation        = this.iTunesFileLocation.Text;

            return(WorkingTrack);
        }
Beispiel #10
0
        private void button6_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                string x = row.Cells[0].Value.ToString();

                WorkingTrack wt = collection[x.ToLower()];

                if (wt != null)
                {
                    if (wt.Position != null)
                    {
                        IITFileOrCDTrack track = GetITTFileOrCDTrackFromWorkingTrack(wt);

                        string AlbumArtist = new FileInfo(wt.iTunesLocation).Directory.Parent.Name;

                        if (track.AlbumArtist != AlbumArtist)
                        {
                            track.AlbumArtist = AlbumArtist;
                        }

                        wt.iTunesAlbumArtist = AlbumArtist;
                    }

                    string newID3AlbumArtist = new FileInfo(wt.ID3Location).Directory.Parent.Name;

                    TagLib.File mp3File = TagLib.File.Create(wt.ID3Location);

                    if (mp3File.Tag.FirstAlbumArtist != newID3AlbumArtist)
                    {
                        mp3File.Tag.AlbumArtists = new string[] { newID3AlbumArtist };
                        mp3File.Save();
                    }

                    wt.ID3AlbumArtist = newID3AlbumArtist;

                    collection[x.ToLower()] = wt;
                }
            }
            MessageBox.Show("done");
        }
Beispiel #11
0
        private string MoveFileToiTunesCalcLocation(WorkingTrack wt)
        {
            string CalcLocation = CalculateiTunesLocation(wt);

            if (!Directory.Exists(Path.GetDirectoryName(CalcLocation)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(CalcLocation));
            }

            File.Move(wt.iTunesLocation, CalcLocation);

            if (wt.Position != null)
            {
                IITFileOrCDTrack track = GetITTFileOrCDTrackFromWorkingTrack(wt);
                track.Location = CalcLocation;

                track.Compilation = (wt.ID3Comment == "Compilation");
            }

            return(CalcLocation);
        }
Beispiel #12
0
        private WorkingTrack WorkingTrackFromTagLibFile(TagLib.File TagLibFile)
        {
            WorkingTrack WorkingTrack = new WorkingTrack();

            WorkingTrack.ID3Artist          = TagLibFile.Tag.FirstPerformer; //??
            WorkingTrack.ID3Name            = TagLibFile.Tag.Title;
            WorkingTrack.ID3Album           = TagLibFile.Tag.Album;
            WorkingTrack.ID3AlbumArtist     = TagLibFile.Tag.FirstAlbumArtist;
            WorkingTrack.ID3SortArtist      = TagLibFile.Tag.FirstPerformerSort;
            WorkingTrack.ID3SortName        = TagLibFile.Tag.TitleSort;
            WorkingTrack.ID3SortAlbumArtist = TagLibFile.Tag.FirstAlbumArtistSort;
            WorkingTrack.ID3TrackNumber     = TagLibFile.Tag.Track.ToString();
            WorkingTrack.ID3Year            = TagLibFile.Tag.Year.ToString();
            WorkingTrack.ID3Comment         = TagLibFile.Tag.Comment;
            //WorkingTrack.iTunesRating = TagLibFile.Tag.ra.ToString();
            WorkingTrack.ID3Location = TagLibFile.Name;
            //WorkingTrack.isIniTunes = true; // IITFileOrCDTrack means it's from iTunes
            WorkingTrack.isOnDisk = File.Exists(TagLibFile.Name);
            WorkingTrack.Path     = TagLibFile.Name;
            //WorkingTrack.Position = Position;
            //WorkingTrack.LocationMismatch = (WorkingTrack.ID3Location != CalculateLocation(WorkingTrack));

            //if (WorkingTrack.LocationMismatch)
            //{
            //    WorkingTrack.ApproximateMatch = (WorkingTrack.iTunesLocation.ToLower() == CalculateLocation(WorkingTrack).ToLower());
            //}

            try
            {
                //TagLib.IPicture pic = TagLibFile.Tag.Pictures[0];
                //MemoryStream stream = new MemoryStream(pic.Data.Data);
                //WorkingTrack.Artwork = Image.FromStream(stream);
            }
            catch
            {
            }

            return(WorkingTrack);
        }
Beispiel #13
0
        private void FileSystemParse()
        {
            int x = 0;

            totalTracks = files.Count;

            foreach (string file in files)
            {
                if (!collection.ContainsKey(file.ToLower()))
                {
                    //WorkingTrack wtDiskOnly = new WorkingTrack();
                    //wtDiskOnly.iTunesLocation = file;
                    //wtDiskOnly.isIniTunes = false;
                    //wtDiskOnly.isOnDisk = true;

                    try
                    {
                        TagLib.File  mp3file    = TagLib.File.Create(file);
                        WorkingTrack wtDiskOnly = WorkingTrackFromTagLibFile(mp3file);
                        collection.Add(file.ToLower(), wtDiskOnly);
                    }
                    catch
                    {
                        System.Diagnostics.Debug.WriteLine(file + " <-- ERROR");
                    }
                }

                x++;

                OverallPosition++;

                int progress = (int)Math.Ceiling(((float)OverallPosition / (float)OverallTotal) * 100);

                //System.Diagnostics.Debug.WriteLine(progress.ToString());

                //backgroundWorker1.ReportProgress(progress);
                //numTracks--;
            }
        }
Beispiel #14
0
        private string MoveFileToID3CalcLocation(WorkingTrack wt)
        {
            string CalcLocation = CalculateID3Location(wt);

            if (!Directory.Exists(Path.GetDirectoryName(CalcLocation)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(CalcLocation));
            }

            dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Visible);

            File.Move(wt.ID3Location, CalcLocation);

            if (wt.Position != null)
            {
                IITFileOrCDTrack track = GetITTFileOrCDTrackFromWorkingTrack(wt);
                track.Location = CalcLocation;

                track.Compilation = (wt.ID3Comment == "Compilation");
            }

            return(CalcLocation);
        }
Beispiel #15
0
        private string MoveFileToID3CalcLocation(string FileLocation)
        {
            WorkingTrack wt = collection[FileLocation.ToLower()];

            return(MoveFileToID3CalcLocation(wt));
        }
Beispiel #16
0
        private void FieldsFromWorkingTrack(WorkingTrack WorkingTrack)
        {
            this.Message.Text = "";

            this.iTunesArtist.Text          = WorkingTrack.iTunesArtist;
            this.iTunesSongName.Text        = WorkingTrack.iTunesName;
            this.iTunesAlbum.Text           = WorkingTrack.iTunesAlbum;
            this.iTunesAlbumArtist.Text     = WorkingTrack.iTunesAlbumArtist;
            this.iTunesSortArtist.Text      = WorkingTrack.iTunesSortArtist;
            this.iTunesSortName.Text        = WorkingTrack.iTunesSortName;
            this.iTunesSortAlbumArtist.Text = WorkingTrack.iTunesSortAlbumArtist;
            this.iTunesTrackNumber.Text     = WorkingTrack.iTunesTrackNumber;
            this.iTunesYear.Text            = WorkingTrack.iTunesYear;
            this.iTunesComment.Text         = WorkingTrack.iTunesComment;
            this.iTunesRating.Text          = WorkingTrack.iTunesRating;

            this.iTunesFileLocation.Text = string.IsNullOrWhiteSpace(WorkingTrack.iTunesLocation) ? WorkingTrack.ID3Location : WorkingTrack.iTunesLocation;

            this.ID3Artist.Text          = WorkingTrack.ID3Artist;
            this.ID3SongName.Text        = WorkingTrack.ID3Name;
            this.ID3Album.Text           = WorkingTrack.ID3Album;
            this.ID3AlbumArtist.Text     = WorkingTrack.ID3AlbumArtist;
            this.ID3SortArtist.Text      = WorkingTrack.ID3SortArtist;
            this.ID3SortName.Text        = WorkingTrack.ID3SortName;
            this.ID3SortAlbumArtist.Text = WorkingTrack.ID3SortAlbumArtist;
            this.ID3TrackNumber.Text     = WorkingTrack.ID3TrackNumber;
            this.ID3Year.Text            = WorkingTrack.ID3Year;
            this.ID3Comment.Text         = WorkingTrack.ID3Comment;
            this.ID3Rating.Text          = WorkingTrack.ID3Rating;
            //this.ID3FileLocation.Text = WorkingTrack.ID3Location;
            this.iTunesCompilation.Checked = WorkingTrack.Compilation;

            if (!string.IsNullOrWhiteSpace(iTunesTrackNumber.Text))
            {
                this.iTunesCalcLocation.Text = CalculateiTunesLocation(WorkingTrack);

                if (WorkingTrack.iTunesLocation != this.iTunesCalcLocation.Text)
                {
                    this.Message.Text = "iTunes Location mismatch";

                    for (int i = 0; i < WorkingTrack.iTunesLocation.Length; i++)
                    {
                        if (this.iTunesCalcLocation.Text.Length > i)
                        {
                            char c1 = WorkingTrack.iTunesLocation[i];
                            char c2 = this.iTunesCalcLocation.Text[i];

                            if (c1 != c2)
                            {
                                this.Message.Text += string.Format(" (Starting at position {0})", i);
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                this.iTunesCalcLocation.Text = "";
            }

            if (!string.IsNullOrWhiteSpace(ID3TrackNumber.Text))
            {
                this.ID3CalcLocation.Text = CalculateID3Location(WorkingTrack);

                if (WorkingTrack.ID3Location != this.ID3CalcLocation.Text)
                {
                    this.Message.Text = "ID3 Location mismatch";

                    for (int i = 0; i < WorkingTrack.ID3Location.Length; i++)
                    {
                        if (this.ID3CalcLocation.Text.Length > i)
                        {
                            char c1 = WorkingTrack.ID3Location[i];
                            char c2 = this.ID3CalcLocation.Text[i];

                            if (c1 != c2)
                            {
                                this.Message.Text += string.Format(" (Starting at position {0})", i);
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                this.ID3CalcLocation.Text = "";
            }

            try
            {
                Artwork.Image = Image.FromStream(new MemoryStream(TagLib.File.Create(WorkingTrack.Path).Tag.Pictures[0].Data.Data));
            }
            catch
            {
                Artwork.Image = null;
            }
        }