예제 #1
0
        public void FromUri()
        {
            ByteVector vector = ByteVector.FromPath("samples/vector.bin");

            Assert.AreEqual(3282169185, vector.Checksum);
            Assert.AreEqual("1aaa46c484d70c7c80510a5f99e7805d", MD5Hash(vector.Data));
        }
예제 #2
0
        public Picture(string filename)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }

            Data = ByteVector.FromPath(filename);
            FillInMimeFromData();
            Description = filename;
        }
예제 #3
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="Picture" /> by reading in the contents of a
        ///    specified file.
        /// </summary>
        /// <param name="path">
        ///    A <see cref="string"/> object containing the path of the
        ///    file to read.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="path" /> is <see langword="null" />.
        /// </exception>
        public Picture(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            Data = ByteVector.FromPath(path);
            FillInMimeFromData();
            Description = path;
        }
예제 #4
0
        private void customButton1_Click(object sender, EventArgs e)
        {
            Form1 Form1Instance = (Form1)Application.OpenForms["Form1"]; //Ανιχνεύω την παρουσία του Form1

            if (_FilePaths == null || _FilePaths.Length == 0)            //Αν έχει φορτωθεί μόνο ένα τραγούδι
            {
                TagLib.File Song = TagLib.File.Create(Filepath);         //Δημιουργία αντικειμένου TagLib.File από την διαδρομή αρχείου του τραγουδιού
                //Ανάθεση των ετικετών του τραγουδιού μέσω των πεδίων εισόδου του παραθύρου
                Song.Tag.Title      = titletextbox.Text;
                Song.Tag.Album      = albumtextbox.Text;
                Song.Tag.Year       = Convert.ToUInt32(yeartextbox.Text);
                Song.Tag.Track      = Convert.ToUInt32(tracktextbox.Text);
                Song.Tag.Comment    = commenttextbox.Text;
                Song.Tag.Genres     = MultipleValuesProcessor(genretextbox.Text.Split(',').ToArray());
                Song.Tag.Performers = MultipleValuesProcessor(artisttextbox.Text.Split(',').ToArray());
                //Αν έχει επιλεχθεί τοπικά εικόνα για το άλμπουμ, τότε την αναθέτω στο τραγούδι
                if (AlbumArtPath != null)
                {
                    TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame();
                    pic.TextEncoding  = TagLib.StringType.Latin1;
                    pic.MimeType      = System.Net.Mime.MediaTypeNames.Image.Jpeg;
                    pic.Type          = TagLib.PictureType.FrontCover;
                    pic.Data          = TagLib.ByteVector.FromPath(AlbumArtPath);
                    Song.Tag.Pictures = new TagLib.IPicture[1] {
                        pic
                    };
                }
                //Αν έχει ληφθεί online η εικόνα, τότε την αναθέτω στο τραγούδι
                if (DownloaderAlbumArtPath != null)
                {
                    TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame();
                    pic.TextEncoding  = StringType.Latin1;
                    pic.MimeType      = System.Net.Mime.MediaTypeNames.Image.Jpeg;
                    pic.Type          = PictureType.FrontCover;
                    pic.Data          = ByteVector.FromPath(DownloaderAlbumArtPath);
                    Song.Tag.Pictures = new IPicture[1] {
                        pic
                    };
                }
                Song.Save();
                AddRecentSong(Form1Instance, Song, Filepath);
            }
            else
            {
                //Αν έχουν επιλεχθεί πολλά τραγούδια, τότε ακολουθώ την ίδια διαδικασία που ακολουθώ για ένα τραγούδι, για κάθε τραγούδι
                for (int i = 0; i < _FilePaths.Length; i++)
                {
                    TagLib.File song = TagLib.File.Create(_FilePaths[i]);
                    if (titletextbox.Text != "<Διατήρηση τιμής>")
                    {
                        song.Tag.Title = titletextbox.Text;
                    }
                    if (artisttextbox.Text != "<Διατήρηση τιμής>")
                    {
                        song.Tag.Performers = MultipleValuesProcessor(artisttextbox.Text.Split(',').ToArray());
                    }
                    if (albumtextbox.Text != "<Διατήρηση τιμής>")
                    {
                        song.Tag.Album = albumtextbox.Text;
                    }
                    if (yeartextbox.Text != "<Διατήρηση τιμής>")
                    {
                        song.Tag.Year = Convert.ToUInt32(yeartextbox.Text);
                    }
                    if (tracktextbox.Text != "<Διατήρηση τιμής>")
                    {
                        song.Tag.Track = Convert.ToUInt32(tracktextbox.Text);
                    }
                    if (genretextbox.Text != "<Διατήρηση τιμής>")
                    {
                        song.Tag.Genres = MultipleValuesProcessor(genretextbox.Text.Split(',').ToArray());
                    }
                    if (commenttextbox.Text != "<Διατήρηση τιμής>")
                    {
                        song.Tag.Comment = commenttextbox.Text;
                    }
                    if (AlbumArtPath != null)
                    {
                        TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame();
                        pic.TextEncoding  = TagLib.StringType.Latin1;
                        pic.MimeType      = System.Net.Mime.MediaTypeNames.Image.Jpeg;
                        pic.Type          = TagLib.PictureType.FrontCover;
                        pic.Data          = TagLib.ByteVector.FromPath(AlbumArtPath);
                        song.Tag.Pictures = new TagLib.IPicture[1] {
                            pic
                        };
                    }
                    if (DownloaderAlbumArtPath != null)
                    {
                        TagLib.Id3v2.AttachedPictureFrame pic = new TagLib.Id3v2.AttachedPictureFrame();
                        pic.TextEncoding  = TagLib.StringType.Latin1;
                        pic.MimeType      = System.Net.Mime.MediaTypeNames.Image.Jpeg;
                        pic.Type          = TagLib.PictureType.FrontCover;
                        pic.Data          = TagLib.ByteVector.FromPath(DownloaderAlbumArtPath);
                        song.Tag.Pictures = new TagLib.IPicture[1] {
                            pic
                        };
                    }
                    song.Save();
                    AddRecentSong(Form1Instance, song, _FilePaths[i]);
                }
            }
        }
예제 #5
0
        public static void WriteStandardPictures(string sample_file, string tmp_file,
                                                 ReadStyle readStyle = ReadStyle.Average,
                                                 TestTagLevel level  = TestTagLevel.Medium)
        {
            if (System.IO.File.Exists(tmp_file))
            {
                System.IO.File.Delete(tmp_file);
            }

            System.IO.File.Copy(sample_file, tmp_file);
            var file = File.Create(tmp_file, readStyle);

            Assert.NotNull(file);

            var pics = file.Tag.Pictures;

            // Raw Picture data references
            var raws = new ByteVector[3];

            // Insert new picture
            Array.Resize(ref pics, 3);
            raws[0] = ByteVector.FromPath(sample_picture);
            pics[0] = new Picture(sample_picture)
            {
                Type        = PictureType.BackCover,
                Description = "TEST description 1"
            };

            raws[1] = ByteVector.FromPath(sample_other);
            pics[1] = new Picture(sample_other)
            {
                Description = "TEST description 2"
            };

            raws[2] = raws[0];
            pics[2] = new Picture(sample_picture)
            {
                Filename    = "renamed.gif",
                Type        = PictureType.Other,
                Description = "TEST description 3"
            };
            file.Tag.Pictures = pics;

            file.Save();

            // Read back the tags
            file = File.Create(tmp_file, readStyle);
            Assert.NotNull(file);
            pics = file.Tag.Pictures;

            Assert.AreEqual(3, pics.Length);

            // Lazy picture check
            var isLazy = (readStyle & ReadStyle.PictureLazy) != 0;

            for (int i = 0; i < 3; i++)
            {
                if (isLazy)
                {
                    Assert.IsTrue(pics[i] is ILazy);
                    if (pics[i] is ILazy lazy)
                    {
                        Assert.IsFalse(lazy.IsLoaded);
                    }
                }
                else
                {
                    if (pics[i] is ILazy lazy)
                    {
                        Assert.IsTrue(lazy.IsLoaded);
                    }
                }
            }

            Assert.AreEqual("TEST description 1", pics[0].Description);
            Assert.AreEqual("image/gif", pics[0].MimeType);
            Assert.AreEqual(73, pics[0].Data.Count);
            Assert.AreEqual(raws[0], pics[0].Data);

            Assert.AreEqual("TEST description 2", pics[1].Description);
            Assert.AreEqual(102400, pics[1].Data.Count);
            Assert.AreEqual(raws[1], pics[1].Data);

            Assert.AreEqual("TEST description 3", pics[2].Description);
            Assert.AreEqual("image/gif", pics[2].MimeType);
            Assert.AreEqual(73, pics[2].Data.Count);
            Assert.AreEqual(raws[2], pics[2].Data);

            // Types and Mime-Types assumed to be properly supported at Medium level test
            if (level >= TestTagLevel.Medium)
            {
                Assert.AreEqual("audio/mp4", pics[1].MimeType);
                Assert.AreEqual(PictureType.BackCover, pics[0].Type);
                Assert.AreEqual(PictureType.NotAPicture, pics[1].Type);
                Assert.AreEqual(PictureType.Other, pics[2].Type);
            }
            else
            {
                Assert.AreNotEqual(PictureType.NotAPicture, pics[0].Type);
                Assert.AreEqual(PictureType.NotAPicture, pics[1].Type);
                Assert.AreNotEqual(PictureType.NotAPicture, pics[2].Type);
            }

            // Filename assumed to be properly supported at High level test
            if (level >= TestTagLevel.High)
            {
                Assert.AreEqual("apple_tags.m4a", pics[1].Filename);
            }
            else if (level >= TestTagLevel.Medium)
            {
                if (pics[1].Filename != null)
                {
                    Assert.AreEqual("apple_tags.m4a", pics[1].Filename);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Edits the Song data via a dialog, and attempts to save the new tag information onto the Song's respective filepath
        /// </summary>
        /// <param name="selectedSong">The Song to modify</param>
        public void EditSongData(Song selectedSong)
        {
            EditSongDialog esd = new EditSongDialog(selectedSong);

            esd.ShowDialog();
            if (esd.DialogResult ?? false)
            {
                selectedSong.Name        = esd.SongNameTextBox.Text;
                selectedSong.Artist      = esd.SongArtistTextBox.Text;
                selectedSong.AlbumName   = esd.AlbumTextBox.Text;
                selectedSong.AlbumArtist = esd.AlbumArtistTextBox.Text;
                selectedSong.Genre       = esd.GenreTextBox.Text;
                selectedSong.TrackNumber = int.Parse(esd.TrackNumberTextBox.Text);
                selectedSong.Year        = esd.YearTextBox.Text;
                selectedSong.FilePath    = esd.FilepathTextBox.Text;

                try
                {
                    using (TagLib.File file = TagLib.File.Create(selectedSong.FilePath))
                    {
                        //set the file metadata
                        file.Tag.Title = selectedSong.Name;

                        if (file.Tag.Performers.Length == 0)
                        {
                            file.Tag.Performers = null;
                            file.Tag.Performers = new string[1] {
                                selectedSong.Artist
                            };                                                           //to edit the array tags, change out the ENTIRE array with values already in it
                        }
                        else
                        {
                            file.Tag.Performers[0] = selectedSong.Artist;
                        }

                        file.Tag.Album = selectedSong.AlbumName;

                        if (file.Tag.AlbumArtists.Length == 0)
                        {
                            file.Tag.AlbumArtists = null;
                            file.Tag.AlbumArtists = new string[1] {
                                selectedSong.AlbumArtist
                            };
                        }
                        else
                        {
                            file.Tag.AlbumArtists[0] = selectedSong.AlbumArtist;
                        }

                        if (file.Tag.Genres.Length == 0)
                        {
                            file.Tag.Genres = null;
                            file.Tag.Genres = new string[1] {
                                selectedSong.Genre
                            };
                        }
                        else
                        {
                            file.Tag.Genres[0] = selectedSong.Genre;
                        }

                        file.Tag.Year  = (uint)int.Parse(selectedSong.Year);
                        file.Tag.Track = (uint)selectedSong.TrackNumber;
                        if (!string.IsNullOrEmpty(esd.ImageSelectedPath))
                        {
                            ByteVector imageBytes = ByteVector.FromPath(esd.ImageSelectedPath);
                            IPicture   pic        = new Picture(imageBytes);
                            file.Tag.Pictures = new IPicture[1] {
                                pic
                            };
                        }
                        file.Save();
                    }
                    UpdateLists();
                    AsyncSerialize(BackgroundCallback);
                }
                catch (NotSupportedException nse)
                {
                    MessageBox.Show("Cannot save tags to the given file, but the tags will still be saved on the program.");
                }
                catch (UnsupportedFormatException ufe)
                {
                    MessageBox.Show("Cannot save tags to the given file, but the tags will still be saved on the program.");
                }
                catch (DirectoryNotFoundException dnfe)
                {
                    MessageBox.Show("Cannot save tags to the given file, but the tags will still be saved on the program.");
                }
            }
        }
예제 #7
0
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            var file = TagLib.File.Create(rota);

            string[] artista = new string[1];
            string[] genero  = new string[1];
            artista[0] = txtArtista.Text;
            int i = 0;

            genero[0] = txtGenero.Text;
            try
            {
                i = int.Parse(txtAno.Text);
            }
            catch { }
            if (string.IsNullOrEmpty(txtArtista.Text) &&
                string.IsNullOrEmpty(txtAno.Text) &&
                string.IsNullOrEmpty(txtGenero.Text) &&
                string.IsNullOrEmpty(txtAlbum.Text) &&
                string.IsNullOrEmpty(txtTitulo.Text))
            {
                System.Windows.Forms.MessageBox.Show("Por favor preencha uma caixa de texto para modificar a tag", "Alerta",
                                                     System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
            }
            if (!string.IsNullOrEmpty(txtTitulo.Text))
            {
                file.Tag.Title = txtTitulo.Text;
            }
            if (!string.IsNullOrEmpty(txtAno.Text) && i > 0)
            {
                file.Tag.Year = Convert.ToUInt32(txtAno.Text);
            }
            if (!string.IsNullOrEmpty(txtAlbum.Text))
            {
                file.Tag.Album = txtAlbum.Text;
            }
            if (!string.IsNullOrEmpty(artista[0]))
            {
                file.Tag.Artists = artista;
            }
            if (!string.IsNullOrEmpty(genero[0]))
            {
                file.Tag.Genres = genero;
            }
            if (!string.IsNullOrEmpty(rotaImg))
            {
                pic.Type          = PictureType.FrontCover;
                pic.Description   = "Cover";
                pic.MimeType      = System.Net.Mime.MediaTypeNames.Image.Jpeg;
                pic.Data          = ByteVector.FromPath(rotaImg);
                file.Tag.Pictures = new IPicture[] { pic };
            }
            if (!string.IsNullOrEmpty(artista[0]) && !string.IsNullOrEmpty(txtAlbum.Text))
            {
                file.Tag.AlbumArtists = artista;
            }

            file.Save();
            System.Windows.Forms.MessageBox.Show("Alteração Concluida", "alerta",
                                                 System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
        }