Ejemplo n.º 1
0
        public static void Commercial(ID3v2TagVersion tagVersion, bool useLogo)
        {
            if (tagVersion == ID3v2TagVersion.ID3v22)
                throw new NotSupportedException();

            IID3v2Tag id3 = new ID3v2Tag();
            ICommercial aud = id3.CommercialInfoList.AddNew();

            using (MemoryStream ms = new MemoryStream())
            {
                ms.WriteByte(0); // text encoding
                Write(ms, Encoding.ASCII.GetBytes("usd10.00/cad15.00"));
                ms.WriteByte(0); // terminate
                Write(ms, Encoding.ASCII.GetBytes("20070610"));
                Write(ms, Encoding.ASCII.GetBytes("www.google.com"));
                ms.WriteByte(0); // terminate
                ms.WriteByte((byte)ReceivedAs.FileOverTheInternet);
                Write(ms, Encoding.ASCII.GetBytes("name of seller"));
                ms.WriteByte(0); // terminate
                Write(ms, Encoding.ASCII.GetBytes("description"));
                ms.WriteByte(0); // terminate
                if (useLogo)
                {
                    Write(ms, Encoding.ASCII.GetBytes("image/jpeg"));
                    ms.WriteByte(0); // terminate
                    Write(ms, new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04 });
                }

                TestFrame(aud, tagVersion, ms.ToArray());
            }
        }
Ejemplo n.º 2
0
        public static bool SaveTrack(Track track)
        {
            var tags = new ID3v2Tag(track.Filename)
            {
                Genre = track.Genre.Replace(NoValue, ""),
                Album = track.Album.Replace(NoValue, ""),
                TrackNumber = track.TrackNumber.ToString(),
                LengthMilliseconds = Convert.ToInt32(track.FullLength*1000M),
                BPM = track.Bpm.ToString("0.00"),
                InitialKey = track.Key
            };

            if (track.Artist == track.AlbumArtist)
            {
                tags.Artist = track.Artist.Replace(NoValue, "");
                tags.Title = track.Title.Replace(NoValue, "");
            }
            else
            {
                tags.Artist = track.AlbumArtist.Replace(NoValue, "");
                tags.Title = track.Artist.Replace(NoValue, "") + " / " + track.Title.Replace(NoValue, "");
            }
            try
            {
                tags.Save(track.Filename);
            }
            catch
            {
                return false;
            }

            track.OriginalDescription = track.Description;

            return true;
        }
        /// <summary>
        ///     Loads and caches an album cover.
        /// </summary>
        /// <param name="track">The track.</param>
        public static void LoadAlbumCover(Track track)
        {
            try
            {
                var path = Path.GetDirectoryName(track.Filename);
                if (path == null) return;

                var albumArtImagePath = Path.Combine(path, "AlbumArtSmall.jpg");
                var folderImagePath = Path.Combine(path, "folder.jpg");

                var albumArtImageDate = DateTime.MinValue;
                if (File.Exists(albumArtImagePath)) albumArtImageDate = File.GetLastWriteTime(albumArtImagePath);

                var folderImageDate = DateTime.MinValue;
                if (File.Exists(folderImagePath)) folderImageDate = File.GetLastWriteTime(folderImagePath);

                if (!File.Exists(folderImagePath))
                {
                    if (ID3v2Tag.DoesTagExist(track.Filename))
                    {
                        var tags = new ID3v2Tag(track.Filename);
                        if (tags.PictureList.Count > 0)
                        {
                            using (Image folderImage = new Bitmap(tags.PictureList[0].Picture))
                            {
                                ImageHelper.SaveJpg(folderImagePath, folderImage);
                            }
                        }
                    }
                }

                if (!File.Exists(albumArtImagePath) || albumArtImageDate < folderImageDate)
                {
                    if (File.Exists(folderImagePath))
                    {
                        using (Image image = new Bitmap(folderImagePath))
                        {
                            using (var smallImage = ImageHelper.Resize(image, new Size(150, 150)))
                            {
                                ImageHelper.SaveJpg(albumArtImagePath, smallImage);
                                File.SetAttributes(albumArtImagePath, FileAttributes.Hidden);
                            }
                        }
                    }
                }

                if (File.Exists(albumArtImagePath))
                {
                    Image image = new Bitmap(albumArtImagePath);
                    AlbumCovers.Add(track.Album, image);
                }
            }
            catch (Exception e)
            {
                DebugHelper.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 4
0
        public static void AudioEncryption(ID3v2TagVersion tagVersion)
        {
            IID3v2Tag id3 = new ID3v2Tag();
            IAudioEncryption aud = id3.AudioEncryptionList.AddNew();
            byte[] data = {
              0x61, 0x62, 0x63, 0x00, // "abc"
              0x00, 0x10, // PreviewStart
              0x10, 0x00, // PreviewLength
              0x01, 0x02, 0x03, 0x04, 0x05 // Encryption data
            };

            TestFrame(aud, tagVersion, data);
        }
Ejemplo n.º 5
0
        private static void Main(string[] args)
        {
            // C:\Users\cent082\AppData\Local\Google\Chrome\User Data\Default\Cache
            string searchDirectory = "";
            string destinationDirectory = "";

            if (args.Length > 0)
                searchDirectory = args[0];
            if (args.Length > 1)
                destinationDirectory = args[1];

            if (String.IsNullOrWhiteSpace(searchDirectory) || String.IsNullOrWhiteSpace(destinationDirectory))
            {
                searchDirectory = String.Format(@"C:\Users\{0}\AppData\Local\Google\Chrome\User Data\Default\Cache",
                                                Environment.UserName);
                destinationDirectory = String.Format(@"C:\Users\{0}\Desktop\tt-rip-{1}",
                                                     Environment.UserName, DateTime.Now.ToString("MMddyyyy"));

                Console.WriteLine("Where do you want to look? (" + searchDirectory + ")");

                string temp = Console.ReadLine();
                searchDirectory = String.IsNullOrEmpty(temp) ? searchDirectory : temp;

                Console.WriteLine(String.Format("Where do you want to move the files to? ({0})", destinationDirectory));
                temp = Console.ReadLine();
                destinationDirectory = String.IsNullOrEmpty(temp) ? destinationDirectory : temp;
            }

            if (!Directory.Exists(destinationDirectory))
            {
                Directory.CreateDirectory(destinationDirectory);
            }

            var directory = new DirectoryInfo(searchDirectory);
            FileInfo[] files = directory.GetFiles();

            foreach (FileInfo fileInfo in files)
            {
                Console.Write(fileInfo.Name);

                var tag = new ID3v2Tag(fileInfo.FullName);
                if (!String.IsNullOrWhiteSpace(tag.Title))
                {
                    Console.WriteLine(" -> " + tag.Title);
                    fileInfo.CopyTo(String.Format("{0}/{1}.mp3", destinationDirectory, tag.Title), true);
                }
            }

            Console.ReadLine();
        }
Ejemplo n.º 6
0
        public static Track Getv2tags(string fname)
        {
            var mytrack = new Track("", "", "", "", "", "", "", "");

            if (File.Exists(fname))
            {
                var id3 = new ID3v2Tag(fname);
                mytrack.Album = id3.Album;
                mytrack.Artist = id3.Artist;
                mytrack.Title = id3.Title;
                mytrack.Trackno = id3.TrackNumber.ToString();
                mytrack.Year = id3.Year;
            }
            return mytrack;
        }
Ejemplo n.º 7
0
        public static void EncryptionMethod(ID3v2TagVersion tagVersion, bool useData)
        {
            if (tagVersion == ID3v2TagVersion.ID3v22)
                throw new NotSupportedException();

            IID3v2Tag id3 = new ID3v2Tag();
            IEncryptionMethod aud = id3.EncryptionMethodList.AddNew();

            using (MemoryStream ms = new MemoryStream())
            {
                Write(ms, Encoding.ASCII.GetBytes("http://owneridentifier.org"));
                ms.WriteByte(0); // terminate
                ms.WriteByte(0x95); // method symbol
                if (useData)
                {
                    Write(ms, new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04 });
                }

                TestFrame(aud, tagVersion, ms.ToArray());
            }
        }
Ejemplo n.º 8
0
        private void ScanDirectory(object basePathObject)
        {
            int totalFiles = 0;
            ObservableCollection<Track> trackList = new ObservableCollection<Track>();
            try
            {
                string basePath = (string)basePathObject;

                DirectoryInfo di = new DirectoryInfo(basePath);
                FileInfo[] fileList = di.GetFiles("*.mp3", SearchOption.AllDirectories);

                totalFiles = fileList.Length;

                for (int i = 0; i < totalFiles; i++)
                {
                    if (_cancelScanning)
                    {
                        totalFiles = i;
                        break;
                    }

                    IID3v2Tag id3 = new ID3v2Tag(fileList[i].FullName);

                    Track track = new Track
                    {
                        Artist = id3.Artist,
                        Title = id3.Title,
                        Album = id3.Album,
                        Year = id3.Year,
                        Genre = id3.Genre,
                        FullFileName = fileList[i].FullName
                    };

                    if (id3.PictureList != null && id3.PictureList.Count > 0)
                    {
                        IAttachedPicture picture = id3.PictureList[0];
                        if (picture.PictureType != PictureType.CoverFront)
                        {
                            foreach (var apic in id3.PictureList)
                            {
                                if (apic.PictureType == PictureType.CoverFront)
                                {
                                    picture = apic;
                                    break;
                                }
                            }
                        }

                        CreatePictureOnUIThread(track, picture);
                    }

                    trackList.Add(track);

                    double percent = i * 100.0 / totalFiles;
                    if (percent - PercentComplete >= 0.9 || (i % 100) == 0)
                    {
                        UpdateProgress(percent);
                    }
                }

                if (!_cancelScanning)
                {
                    UpdateProgress(100);
                }
            }
            finally
            {
                EndRecursiveScanning(totalFiles, trackList);
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            bool success = ParseArguments(args);
            if (!success)
                return;

            DateTime start = DateTime.Now;

            if (_isTest && _verbosity >= Verbosity.Default)
            {
                WriteLine("TEST - NO ACTUAL FILES WILL BE CHANGED");
                WriteLine();
            }

            if (_verbosity >= Verbosity.Default)
            {
                if (_directory != null)
                    WriteLine(string.Format("Directory: \"{0}\"", _directory));
                else
                    WriteLine(string.Format("File: \"{0}\"", _fileName));

                string options = "Options: Convert to " + _newTagVersion;
                if (_isTest)
                    options += ", test";
                if (_isRecursive)
                    options += ", recurisve";
                if (_upgradeOnly)
                    options += ", upgrade only";

                WriteLine(options);
            }

            string[] files;
            if (_directory != null)
            {
                WriteLine(string.Format("Getting '{0}' files...", _directory), Verbosity.Full);

                files = Directory.GetFiles(_directory, "*.mp3", _isRecursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
            }
            else
            {
                files = new[] { _fileName };
            }

            int updated = 0, skipped = 0, failed = 0;
            int id3v22Count = 0, id3v23Count = 0, id3v24Count = 0, noid3v2Count = 0;
            for (int i = 0; i < files.Length; i++)
            {
                string file = files[i];

                try
                {
                    WriteLine(string.Format("File {0:#,0}/{1:#,0}: '{2}'", i + 1, files.Length, file), Verbosity.Full);

                    ID3v2Tag id3v2 = new ID3v2Tag(file);
                    if (id3v2.Header != null)
                    {
                        switch (id3v2.Header.TagVersion)
                        {
                            case ID3v2TagVersion.ID3v22:
                                id3v22Count++;
                                break;
                            case ID3v2TagVersion.ID3v23:
                                id3v23Count++;
                                break;
                            case ID3v2TagVersion.ID3v24:
                                id3v24Count++;
                                break;
                        }

                        if (id3v2.Header.TagVersion != _newTagVersion.Value)
                        {
                            if (!_upgradeOnly || _newTagVersion.Value > id3v2.Header.TagVersion)
                            {
                                ID3v2TagVersion oldTagVersion = id3v2.Header.TagVersion;

                                if (!_isTest)
                                {
                                    id3v2.Header.TagVersion = _newTagVersion.Value;
                                    id3v2.Save(file);
                                }

                                WriteLine(string.Format("- Converted {0} to {1}", oldTagVersion, _newTagVersion.Value), Verbosity.Full);

                                updated++;
                            }
                            else
                            {
                                WriteLine(string.Format("- Skipped, existing tag {0} > {1}", id3v2.Header.TagVersion, _newTagVersion.Value), Verbosity.Full);

                                skipped++;
                            }
                        }
                        else
                        {
                            WriteLine("- Skipped, ID3v2 tag version equal to requested version", Verbosity.Full);

                            skipped++;
                        }
                    }
                    else
                    {
                        WriteLine("- Skipped, ID3v2 tag does not exist", Verbosity.Full);

                        skipped++;
                        noid3v2Count++;
                    }
                }
                catch (Exception ex)
                {
                    if (_verbosity >= Verbosity.Default)
                    {
                        string header = string.Format("File: {0}", file);
                        WriteLine(header);
                        WriteLine(new string('=', header.Length));
                        WriteLine(ex.ToString());
                        WriteLine();
                    }

                    failed++;
                }
            }

            if (_verbosity >= Verbosity.Default)
            {
                DateTime end = DateTime.Now;
                TimeSpan duration = end - start;

                if (_hasWritten)
                    WriteLine();
                WriteLine(string.Format("ID3v2.2:   {0:#,0}", id3v22Count));
                WriteLine(string.Format("ID3v2.3:   {0:#,0}", id3v23Count));
                WriteLine(string.Format("ID3v2.4:   {0:#,0}", id3v24Count));
                WriteLine(string.Format("No ID3v2:  {0:#,0}", noid3v2Count));
                WriteLine();
                WriteLine(string.Format("Start:     {0:HH:mm:ss}", start));
                WriteLine(string.Format("End:       {0:HH:mm:ss}", end));
                WriteLine(string.Format("Duration:  {0:hh}:{0:mm}:{0:ss}.{0:fff}", duration));
                WriteLine();
                WriteLine(string.Format("Updated:   {0:#,0}", updated));
                WriteLine(string.Format("Skipped:   {0:#,0}", skipped));
                WriteLine(string.Format("Failed:    {0:#,0}", failed));
            }
        }
Ejemplo n.º 10
0
        private void CreateAudioFile(string artist, string album, string song)
        {
            var outputDirectoryPath = Path.Combine(OutputPath, artist, album);
            var outputFilePath = Path.Combine(outputDirectoryPath, song + ".mp3");

            if (File.Exists(outputFilePath))
            {
                return;
            }

            if (!Directory.Exists(outputDirectoryPath))
            {
                Directory.CreateDirectory(outputDirectoryPath);
            }

            //if (File.Exists(outputFilePath))
            //{
            //    File.Delete(outputFilePath);
            //}

            File.Copy(SourceFile, outputFilePath);

            var tag = new ID3v2Tag(outputFilePath);
            tag.Artist = artist;
            tag.Album = album;
            tag.AlbumArtist = artist;
            tag.Title = song;

            tag.Save(outputFilePath);
        }
Ejemplo n.º 11
0
        private void Runscan()
        {
            Int32 totalFiles = 0;
            string tagstrV1 = null;
            string tagstrV2 = null;

            DirectoryInfo di = new DirectoryInfo(Dir);
            FileInfo[] fileList = di.GetFiles("*.mp3", SearchOption.AllDirectories);
            totalFiles = fileList.Length;

            for (Int32 i = 0; i < totalFiles; i++)
            {
                tagstrV1 = string.Empty;
                tagstrV2 = string.Empty;

               // Currentfile(fileList[i].FullName);
                if (ID3v1Tag.DoesTagExist(fileList[i].FullName))
                    tagstrV1 = "V1";
                if (ID3v2Tag.DoesTagExist(fileList[i].FullName))
                    tagstrV2 = "V2";

                if (tagstrV1 == "V1" & tagstrV2 == "")
                {
                    var id3 = new ID3v1Tag(fileList[i].FullName);
                    var mytrack = new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber.ToString(), GenreHelper.GenreByIndex[id3.GenreIndex], fileList[i].FullName, tagstrV1 + "/" + tagstrV2);
                    if (OnListFiles != null) { OnListFiles(mytrack); }
                    trackList.Add(mytrack);
                }
                if (tagstrV2 == "V2")
                {
                    var id3 = new ID3v2Tag(fileList[i].FullName);
                    if (id3.Genre == null)
                    {
                        id3.Genre = "none";
                    }

                    try
                    {
                        var mytrack = new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber, id3.Genre, fileList[i].FullName, tagstrV1 + "/" + tagstrV2);
                        if (OnListFiles != null) { OnListFiles(mytrack); }
                        trackList.Add(mytrack);
                    }
                    catch (Exception)
                    {
                       trackList.RemoveAt(trackList.Count - 1);
                       trackList.Add(new Track("", "", "", "", "", "", fileList[i].FullName, "Bad Tag"));
                    }
                }

                if (tagstrV2 == "" & tagstrV1 == "")
                {
                    var mytrack = new Track("", "", "", "", "", "", fileList[i].FullName, "No Tag");
                    if (OnListFiles != null) { OnListFiles(mytrack); }
                    trackList.Add(mytrack);
                }

                if ((i % 100) == 0)
                {
                    if (UpdateProgress != null) { UpdateProgress(i * 100 / totalFiles); }

                }

            }
        }
Ejemplo n.º 12
0
        private void ScanDirectory(object basePathObject)
        {
            int totalFiles = 0;
            BindingList<Track> trackList = new BindingList<Track>();
            try
            {
                string basePath = (string)basePathObject;

                DirectoryInfo di = new DirectoryInfo(basePath);
                FileInfo[] fileList = di.GetFiles("*.mp3", SearchOption.AllDirectories);

                EnableCancelButton();

                totalFiles = fileList.Length;

                for (int i = 0; i < totalFiles; i++)
                {
                    if (m_CancelScanning)
                    {
                        totalFiles = i;
                        break;
                    }

                    IID3v2Tag id3 = new ID3v2Tag(fileList[i].FullName);

                    trackList.Add(new Track
                    {
                        Artist = id3.Artist,
                        Title = id3.Title,
                        Album = id3.Album,
                        Year = id3.Year,
                        Genre = id3.Genre,
                        FileName = fileList[i].Name
                    });

                    if ((i % 100) == 0)
                    {
                        UpdateProgress(i * 100 / totalFiles);
                    }
                }
            }
            finally
            {
                EndRecursiveScanning(totalFiles, trackList);
            }
        }
Ejemplo n.º 13
0
Archivo: Form1.cs Proyecto: nowen3/Ntag
        private void BTNcopy_Click(object sender, EventArgs e)
        {
            if (musicListStore.SelectedItems.Count > 0)
            {
                var copywin = new FRMcopy();
                string temp = "";
                ListView.SelectedListViewItemCollection filename = this.musicListStore.SelectedItems;
                copywin.GetGenre = musicListStore.SelectedItems[0].SubItems[8].Text;
                if (copywin.ShowDialog(this) == DialogResult.OK)
                {
                    if (copywin.CopyV1)
                    {
                        foreach (ListViewItem item in filename)
                        {
                            temp = item.SubItems[1].Text + "\\" + item.SubItems[0].Text;
                            if (File.Exists(temp) & ID3v1Tag.DoesTagExist(temp))
                            {
                                var id3 = new ID3v1Tag(temp);
                                Miscutils.Savev2tag(new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber.ToString(), GenreHelper.GenreByIndex[id3.GenreIndex], temp, "V1/V2"));
                                ReloadlistviewV2(item);
                            }
                        }
                    }

                    if (copywin.CopyV2)
                    {
                        foreach (ListViewItem item in filename)
                        {
                            temp = item.SubItems[1].Text + "\\" + item.SubItems[0].Text;
                            if (File.Exists(temp) & ID3v2Tag.DoesTagExist(temp))
                            {
                                var id3 = new ID3v2Tag(temp);
                                string gen = copywin.GetGenre;
                                Miscutils.Savev1tag(new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber.ToString(), gen, temp, "V1/V2"));
                                ReloadlistviewV1(item);
                            }
                        }
                    }
                }
            }//end musicstore setected
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets the bytes of the current ID3v2 tag.
        /// </summary>
        /// <param name="minimumSize">The minimum size of the new tag, including the header and footer.</param>
        /// <returns>The bytes of the current ID3v2 tag.</returns>
        public byte[] GetBytes(int minimumSize)
        {
            ID3v2TagVersion tagVersion = _id3v2Header.TagVersion;

            using (MemoryStream tag = new MemoryStream())
            {
                byte[] framesByteArray = GetBytes(tagVersion);

                int tagSize = framesByteArray.Length;

                _id3v2Header.UsesUnsynchronization = false; // hack
                _id3v2Header.IsExperimental        = true;  // hack
                //_id3v2ExtendedHeader.IsCRCDataPresent = true; // hack: for testing
                //_id3v2Header.HasExtendedHeader = true; // hack: for testing

                if (_id3v2Header.HasExtendedHeader)
                {
                    // Add total size of extended header
                    tagSize += _id3v2ExtendedHeader.SizeExcludingSizeBytes + 4;
                }

                int paddingSize = minimumSize - (tagSize + 10);
                if (paddingSize < 0)
                {
                    paddingSize = 2000;
                }

                tagSize += paddingSize;

                // Set tag size in ID3v2 header
                _id3v2Header.TagSize = tagSize;

                byte[] id3v2Header = _id3v2Header.GetBytes();
                tag.Write(id3v2Header, 0, id3v2Header.Length);
                if (_id3v2Header.HasExtendedHeader)
                {
                    if (_id3v2ExtendedHeader.IsCRCDataPresent)
                    {
                        // TODO: Calculate total frame CRC (before or after unsync? compression? encr?)
                        _id3v2ExtendedHeader.CRC32 = CRC32.CalculateInt32(framesByteArray);
                    }

                    // Set padding size
                    _id3v2ExtendedHeader.PaddingSize = paddingSize; // todo: check

                    byte[] id3v2ExtendedHeader = _id3v2ExtendedHeader.GetBytes(tagVersion);
                    tag.Write(id3v2ExtendedHeader, 0, id3v2ExtendedHeader.Length);
                }

                tag.Write(framesByteArray, 0, framesByteArray.Length);
                byte[] padding = new byte[paddingSize];
                tag.Write(padding, 0, paddingSize);

                // Make sure WE can read it without throwing errors
                // TODO: Take this out eventually, this is just a precaution.
                tag.Position = 0;
                ID3v2Tag newID3v2 = new ID3v2Tag();
                newID3v2.Read(tag);

                return(tag.ToArray());
            }
        }
        /// <summary>
        ///     Sets the track album cover.
        /// </summary>
        /// <param name="track">The track.</param>
        /// <param name="image">The image.</param>
        public static void SetTrackAlbumCover(Track track, Image image)
        {
            if (track == null) return;
            if (image == null) return;
            if (!ID3v2Tag.DoesTagExist(track.Filename)) return;

            var tags = new ID3v2Tag(track.Filename);
            if (tags.PictureList.Count > 0) tags.PictureList.Clear();

            var picture = tags.PictureList.AddNew();

            if (picture != null)
            {
                picture.PictureType = PictureType.CoverFront;
                picture.MimeType = "image/jpeg";

                using (var stream = new MemoryStream())
                {
                    ImageHelper.SaveJpg(stream, image);
                    picture.PictureData = stream.ToArray();
                }
            }
            tags.Save(track.Filename);
        }
Ejemplo n.º 16
0
        public static Boolean Savev2tag(Track mytrack)
        {
            if (!File.Exists(mytrack.Filename))
            {
                MessageBox.Show("File Does not exist " + mytrack.Filename);
                return false;
            }
            var trackxml = new XMLutils(appPath + "\\trackxml.xml");
            removeID3v2(mytrack.Filename);
            var id3 = new ID3v2Tag(mytrack.Filename);
            if (!String.IsNullOrEmpty(mytrack.Filename) && File.Exists(mytrack.Filename))
            {
                id3.Album = mytrack.Album;
                id3.Artist = mytrack.Artist;
                id3.Title = mytrack.Title;
                id3.TrackNumber = mytrack.Trackno;
                id3.Year = mytrack.Year;
                id3.Genre = mytrack.Genre;

                if (mytrack.coverimage !=null)
                {
                    id3.PictureList.Clear();
                    IAttachedPicture picture = id3.PictureList.AddNew();

                    picture.PictureData = ConvertBitMapToByteArray(mytrack.coverimage);
                    picture.PictureType = PictureType.CoverFront;

                }
                id3.Save(mytrack.Filename);
                trackxml.ModifyRecord(mytrack);
            }
            if (ID3v2Tag.DoesTagExist(mytrack.Filename))
            {
                trackxml.Updaterecord(mytrack.Filename);
                return (true);
            }
            else return (false);
        }
Ejemplo n.º 17
0
 public void Updaterecord(string filename)
 {
     string tagstring = "";
     if (ID3v2Tag.DoesTagExist(filename))
     {
         tagstring = "/V2";
         if (ID3v1Tag.DoesTagExist(filename))
         {
             tagstring = "V1" + tagstring;
         }
         var id3 = new ID3v2Tag(filename);
         var mytrack = new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber, id3.Genre, filename, tagstring);
         ModifyRecord(mytrack);
     }
     if (ID3v1Tag.DoesTagExist(filename) && tagstring == "")
     {
         tagstring = "V1";
         var id3 = new ID3v1Tag(filename);
         var mytrack = new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber.ToString(), GenreHelper.GenreByIndex[id3.GenreIndex], filename, tagstring);
         ModifyRecord(mytrack);
     }
     if (tagstring == "No Tag")
     {
         var mytrack = new Track("", "", "", "", "", "", filename, "No Tag");
         ModifyRecord(mytrack);
     }
 }
Ejemplo n.º 18
0
Archivo: Form1.cs Proyecto: nowen3/Ntag
 public void ReloadlistviewV2(ListViewItem item)
 {
     string tagstring = "No Tag";
     if (ID3v1Tag.DoesTagExist(item.SubItems[1].Text + "\\" + item.SubItems[0].Text))
     {
         tagstring = "V1/";
     }
     if (ID3v2Tag.DoesTagExist(item.SubItems[1].Text + "\\" + item.SubItems[0].Text))
     {
         var id3 = new ID3v2Tag(item.SubItems[1].Text + "\\" + item.SubItems[0].Text);
         item.SubItems[2].Text = tagstring + "V2";
         item.SubItems[3].Text = id3.Title;
         item.SubItems[4].Text = id3.Artist;
         item.SubItems[5].Text = id3.Album;
         item.SubItems[7].Text = id3.Year;
         item.SubItems[6].Text = id3.TrackNumber;
         item.SubItems[8].Text = id3.Genre;
         //  Miscutils.Updaterecord(item.SubItems[1].Text + "\\" + item.SubItems[0].Text, id3.Album,
         //                         id3.Artist, id3.Genre, id3.Title, id3.TrackNumber, id3.Year);
     }
     else
     {
         item.SubItems[2].Text = tagstring;
         item.SubItems[3].Text = "";
         item.SubItems[4].Text = "";
         item.SubItems[5].Text = "";
         item.SubItems[7].Text = "";
         item.SubItems[6].Text = "";
         item.SubItems[8].Text = "";
         if (tagstring == "No Tag")
         {
             //    Miscutils.Updaterecord(item.SubItems[1].Text + "\\" + item.SubItems[0].Text, item.SubItems[1].Text,
             //                           "No Tag", "", "", "", "");
         }
     }
 }
Ejemplo n.º 19
0
Archivo: Form1.cs Proyecto: nowen3/Ntag
        private void poptextboxV2(string fdir)
        {
            TXTfilename.Text = fdir;
            pictureBox.Image = null;
            LABimage.Text = "";
            if (ID3v2Tag.DoesTagExist(fdir))
            {
                RDOver2.Checked = true;

                var id3v2 = new ID3v2Tag(fdir);
                CMBartist.Text = id3v2.Artist;
                CMBtitle.Text = id3v2.Title;
                CMBalbum.Text = id3v2.Album;
                CMBgenre.Text = id3v2.Genre;
                CMBtrack.Text = id3v2.TrackNumber;
                CMByear.Text = id3v2.Year;
                CMBcomment.Text = id3v2.CommentsList.ToString();
                if (id3v2.CommentsList.Count > 0)
                    CMBcomment.Text = id3v2.CommentsList[0].Value;
                if (id3v2.PictureList.Count > 0)
                {
                    pictureBox.Image = id3v2.PictureList[0].Picture;
                    LABimage.Text = id3v2.PictureList[0].Description.ToString() + "\r\n" +id3v2.PictureList[0].Picture.Size.ToString() + "\r\n" + id3v2.PictureList[0].PictureExtension.ToString();

                }
            }
        }
Ejemplo n.º 20
0
Archivo: Form1.cs Proyecto: nowen3/Ntag
        private Track Getkeepv2(string fname)
        {
            var mytrack = new Track();
            string tagstrV1 = "";
            if (ID3v1Tag.DoesTagExist(fname))
                tagstrV1 = "V1";
            var id3v2 = new ID3v2Tag(fname);
            mytrack.Filename = fname;
            if (CMBartist.Text == "#Keep#")
            { mytrack.Artist = id3v2.Artist; }
            else mytrack.Artist = CMBartist.Text;

            if (CMBtitle.Text == "#Keep#")
            { mytrack.Title = id3v2.Title; }
            else mytrack.Title = CMBtitle.Text;

            if (CMBalbum.Text == "#Keep#")
            { mytrack.Album = id3v2.Album; }
            else mytrack.Album = CMBalbum.Text;

            if (CMBgenre.Text == "#Keep#")
            { mytrack.Genre = id3v2.Genre; }
            else mytrack.Genre = CMBgenre.Text;

            if (CMBtrack.Text == "#Keep#")
            { mytrack.Trackno = id3v2.TrackNumber.ToString(); }
            else mytrack.Trackno = CMBtrack.Text;
            if (CMByear.Text == "#Keep#")

            { mytrack.Year = id3v2.Year; }
            else mytrack.Year = CMByear.Text;

            if (pictureBox.Image != null)
            {
                mytrack.coverimage = (Bitmap)pictureBox.Image;

            }

            mytrack.Tagtype = tagstrV1 + "/" + "V2";
            //CMBcomment.Text = id3v2.CommentsList[0].Value;
            return mytrack;
            //  }
            //  else return mytrack = null;
        }
Ejemplo n.º 21
0
        /// <summary>
        ///     Loads the track details from the tags in the associate mp3
        /// </summary>
        /// <param name="track">The track to load the details of.</param>
        public static void LoadTrack(Track track)
        {
            if (!File.Exists(track.Filename)) return;
            if (!track.Filename.ToLower().EndsWith(".mp3")) return;

            DebugHelper.WriteLine("Library - LoadTrack - " + track.Description);

            GuessTrackDetailsFromFileName(track);

            var dateLastModified = GetTrackLastModified(track.Filename);
            track.LastModified = dateLastModified;

            if (ID3v2Tag.DoesTagExist(track.Filename))
            {
                var tags = new ID3v2Tag(track.Filename);

                if (!string.IsNullOrEmpty(tags.Artist)) track.Artist = tags.Artist.Trim();
                if (!string.IsNullOrEmpty(tags.Artist)) track.AlbumArtist = tags.Artist.Trim();
                if (!string.IsNullOrEmpty(tags.Title)) track.Title = tags.Title.Trim();
                if (!string.IsNullOrEmpty(tags.Album)) track.Album = tags.Album.Trim();
                if (!string.IsNullOrEmpty(tags.Genre)) track.Genre = tags.Genre.Trim();
                if (!string.IsNullOrEmpty(tags.InitialKey))
                {
                    var tagKey = tags.InitialKey.Trim();
                    track.Key = tagKey;
                }

                LoadArtistAndAlbumArtist(track);

                if (tags.LengthMilliseconds.HasValue) track.Length = (decimal) tags.LengthMilliseconds/1000M;

                decimal bpm;
                if (decimal.TryParse(tags.BPM, out bpm)) track.Bpm = bpm;

                track.Bpm = BpmHelper.NormaliseBpm(track.Bpm);
                track.EndBpm = track.Bpm;
                track.StartBpm = track.Bpm;
                track.Bpm = BpmHelper.GetAdjustedBpmAverage(track.StartBpm, track.EndBpm);

                int trackNumber;
                var trackNumberTag = (tags.TrackNumber + "/").Split('/')[0].Trim();
                if (int.TryParse(trackNumberTag, out trackNumber)) track.TrackNumber = trackNumber;

                if (GenreCode.IsGenreCode(track.Genre)) track.Genre = GenreCode.GetGenre(track.Genre);
                if (track.Artist == "") track.Artist = NoValue;
                if (track.AlbumArtist == "") track.AlbumArtist = NoValue;
                if (track.Title == "") track.Title = NoValue;
                if (track.Album == "") track.Album = NoValue;
                if (track.Genre == "") track.Genre = NoValue;
            }

            track.OriginalDescription = track.Description;
            track.FullLength = track.Length;

            UpdateLength(track);
            UpdateKey(track);

            track.Bpm = BpmHelper.GetAdjustedBpmAverage(track.StartBpm, track.EndBpm);

            track.OriginalDescription = track.Description;

            if (track.EndBpm == 0 || track.EndBpm == 100) track.EndBpm = track.Bpm;
            if (track.StartBpm == 0 || track.StartBpm == 100) track.StartBpm = track.Bpm;
        }
Ejemplo n.º 22
0
 public static Boolean removeID3v2(string fname)
 {
     Boolean success = false;
     var trackxml = new XMLutils(appPath + "\\trackxml.xml");
     if (!String.IsNullOrEmpty(fname) && File.Exists(fname))
     {
         var id3 = new ID3v2Tag(fname);
         if (id3.PictureList.Count > 0)
         {
             id3.PictureList.Clear();
         }
             success = ID3v2Tag.RemoveTag(fname);
     }
     if (success)
     {
         trackxml.Updaterecord(fname);
     }
     return (success);
 }
Ejemplo n.º 23
0
        /// <summary>Saves the tag to the specified path.</summary>
        /// <param name="path">The full path of the file.</param>
        private void Save(string path)
        {
            if (string.IsNullOrEmpty(path))
                throw new ArgumentNullException("path");

            if (VorbisComment.VorbisComment.IsFlac(path))
            {
                VorbisComment.VorbisComment vc = new VorbisComment.VorbisComment(path);
                vc.Title = Title;
                vc.Artist = Artist;
                vc.Album = Album;
                vc.Year = Year;
                vc.Genre = Genre;
                vc.TrackNumber = TrackNumber;
                vc.Comment = Comment;
                vc.Save(path);

                ID3v2Tag.RemoveTag(path);
                ID3v1Tag.RemoveTag(path);
            }
            else
            {
                ID3v2Tag id3v2 = new ID3v2Tag(path);
                id3v2.Title = Title;
                id3v2.Artist = Artist;
                id3v2.Album = Album;
                id3v2.Year = Year;
                id3v2.Genre = Genre;
                id3v2.TrackNumber = TrackNumber;

                if (id3v2.CommentsList.Count > 0)
                {
                    id3v2.CommentsList[0].Description = Comment;
                }
                else
                {
                    if (!string.IsNullOrEmpty(Comment))
                        id3v2.CommentsList.AddNew().Description = Comment;
                }

                ID3v1Tag id3v1 = new ID3v1Tag(path);
                id3v1.Title = Title;
                id3v1.Artist = Artist;
                id3v1.Album = Album;
                id3v1.Year = Year;
                id3v1.GenreIndex = GenreHelper.GetGenreIndex(Genre);
                id3v1.Comment = Comment;
                int trackNumber;
                if (int.TryParse(TrackNumber, out trackNumber))
                {
                    id3v1.TrackNumber = trackNumber;
                }
                else
                {
                    // Handle ##/## format
                    if (TrackNumber.Contains("/"))
                    {
                        if (int.TryParse(TrackNumber.Split('/')[0], out trackNumber))
                            id3v1.TrackNumber = trackNumber;
                        else
                            id3v1.TrackNumber = 0;
                    }
                    else
                    {
                        id3v1.TrackNumber = 0;
                    }
                }

                id3v2.Save(path);
                id3v1.Save(path);
            }

            Read(path);
        }
Ejemplo n.º 24
0
        /// <summary>Reads the tag from the specified stream.</summary>
        /// <param name="stream">The stream.</param>
        private void Read(Stream stream)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");

            bool id3v2Found = false;
            string tagVersion = string.Empty;

            // ID3v2
            if (ID3v2Tag.DoesTagExist(stream))
            {
                ID3v2Tag id3v2 = new ID3v2Tag(stream);
                Title = id3v2.Title;
                Artist = id3v2.Artist;
                Album = id3v2.Album;
                Year = id3v2.Year;
                Genre = id3v2.Genre;
                TrackNumber = id3v2.TrackNumber;

                if (id3v2.CommentsList.Count > 0)
                    Comment = id3v2.CommentsList[0].Description;
                else
                    Comment = null;

                tagVersion = EnumUtils.GetDescription(id3v2.Header.TagVersion);

                id3v2Found = true;
            }

            // ID3v1
            if (ID3v1Tag.DoesTagExist(stream))
            {
                ID3v1Tag id3v1 = new ID3v1Tag(stream);

                // Use ID3v1 fields if ID3v2 doesn't exist or field is blank
                if (!id3v2Found || string.IsNullOrEmpty(Title)) Title = id3v1.Title;
                if (!id3v2Found || string.IsNullOrEmpty(Artist)) Artist = id3v1.Artist;
                if (!id3v2Found || string.IsNullOrEmpty(Album)) Album = id3v1.Album;
                if (!id3v2Found || string.IsNullOrEmpty(Year)) Year = id3v1.Year;
                if (!id3v2Found || string.IsNullOrEmpty(Genre)) Genre = GenreHelper.GenreByIndex[id3v1.GenreIndex];
                if (!id3v2Found || string.IsNullOrEmpty(TrackNumber)) TrackNumber = id3v1.TrackNumber.ToString();
                if (!id3v2Found || string.IsNullOrEmpty(Comment)) Comment = id3v1.Comment;

                tagVersion += (!string.IsNullOrEmpty(tagVersion) ? ", " : "") + EnumUtils.GetDescription(id3v1.TagVersion);
            }

            // Vorbis Comment
            if (VorbisComment.VorbisComment.IsFlac(stream))
            {
                VorbisComment.VorbisComment vc = new VorbisComment.VorbisComment(stream);
                Title = vc.Title;
                Artist = vc.Artist;
                Album = vc.Album;
                Year = vc.Year;
                Genre = vc.Genre;
                TrackNumber = vc.TrackNumber;
                Comment = vc.Comment;
                tagVersion = (!string.IsNullOrEmpty(tagVersion) ? ", " : "") + "Vorbis Comment";
            }

            // No tag found
            if (string.IsNullOrEmpty(tagVersion))
            {
                Title = null;
                Artist = null;
                Album = null;
                Year = null;
                Genre = null;
                TrackNumber = null;
                Comment = null;
                tagVersion = "None";
            }

            // Set TagVersion
            TagVersion = tagVersion;
        }
Ejemplo n.º 25
0
Archivo: Form1.cs Proyecto: nowen3/Ntag
        private void addImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FRMImage addimage = new FRMImage();

            ListView.SelectedListViewItemCollection filename = this.musicListStore.SelectedItems;
            var trackxml = new XMLutils(appPath + "\\trackxml.xml");
            addimage.Artist = filename[0].SubItems[4].Text;
            addimage.Album = filename[0].SubItems[5].Text;

            if (addimage.ShowDialog(this) == DialogResult.OK)
            {

                foreach (ListViewItem item in filename)
                {
                    string fname = item.SubItems[1].Text + "\\" + item.SubItems[0].Text;
                    var id3v2 = new ID3v2Tag(fname);
                    var mytrack = new Track();
                    mytrack.Filename = fname;
                    mytrack.Artist = id3v2.Artist;
                    mytrack.Title = id3v2.Title;
                    mytrack.Album = id3v2.Album;
                    mytrack.Genre = id3v2.Genre;
                    mytrack.Trackno = id3v2.TrackNumber.ToString();
                    mytrack.Year = id3v2.Year;
                    if (addimage.Getimage() != null)
                    {
                        mytrack.coverimage = addimage.Getimage();

                    }
                    Miscutils.Savev2tag(mytrack);
                    //ReloadlistviewV2(fname);

                }

            }
        }