예제 #1
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);
        }
예제 #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);
        }
예제 #3
0
파일: Music.cs 프로젝트: Livila/stuffa
        public bool setTitle(string n)
        {
            bool ret = true;

            try
            {
                IID3v2Tag fileInfo = new ID3v2Tag(getFullPath());
                fileInfo.Title = n;
                fileInfo.Save(getFullPath());
                this.title = n;
            }
            catch
            {
                Console.WriteLine("did not save Title to ID3 tag\n" + getFullPath() + "\nif file is open, close it and try again");
                ret = false;
            }
            return(ret);
        }
예제 #4
0
파일: Music.cs 프로젝트: Livila/stuffa
        public bool setBPM(string n)
        {
            bool ret = true;


            try
            {
                IID3v2Tag fileInfo = new ID3v2Tag(getFullPath());
                fileInfo.BPM = n;
                fileInfo.Save(getFullPath());
                this.BPM = Int32.Parse(n);
            }
            catch
            {
                Console.WriteLine("did not save BPM to ID3 tag\n" + getFullPath() + "\n* if file is open, close it and try again\n* check that you enterd an integer");
                ret = false;
            }
            return(ret);
        }
예제 #5
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);
            }
        }
        /// <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);
        }
예제 #7
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);
        }
예제 #8
0
        public bool WriteTags(AudioMetaData metaData, string filename, bool force = false)
        {
            try
            {
                if (!metaData.IsValid)
                {
                    this.Logger.LogWarning($"Invalid MetaData `{ metaData }` to save to file [{ filename }]");
                    return(false);
                }
                ID3v1Tag.RemoveTag(filename);

                var trackNumber      = metaData.TrackNumber ?? 1;
                var totalTrackNumber = metaData.TotalTrackNumbers ?? trackNumber;

                var disc      = metaData.Disk ?? 1;
                var discCount = metaData.TotalDiscCount ?? disc;

                IID3v2Tag id3v2 = new ID3v2Tag(filename)
                {
                    Artist      = metaData.Artist,
                    Album       = metaData.Release,
                    Title       = metaData.Title,
                    Year        = metaData.Year.Value.ToString(),
                    TrackNumber = totalTrackNumber < 99 ? $"{trackNumber.ToString("00")}/{totalTrackNumber.ToString("00")}" : $"{trackNumber.ToString()}/{totalTrackNumber.ToString()}",
                    DiscNumber  = discCount < 99 ? $"{disc.ToString("00")}/{discCount.ToString("00")}" : $"{disc.ToString()}/{discCount.ToString()}"
                };
                if (metaData.TrackArtists.Any())
                {
                    id3v2.OriginalArtist = string.Join("/", metaData.TrackArtists);
                }
                if (this.Configuration.Processing.DoClearComments)
                {
                    if (id3v2.CommentsList.Any())
                    {
                        for (var i = 0; i < id3v2.CommentsList.Count; i++)
                        {
                            id3v2.CommentsList[i].Description = null;
                            id3v2.CommentsList[i].Value       = null;
                        }
                    }
                }
                id3v2.Save(filename);

                //// Delete first embedded picture (let's say it exists)
                //theTrack.EmbeddedPictures.RemoveAt(0);

                //// Add 'CD' embedded picture
                //PictureInfo newPicture = new PictureInfo(Commons.ImageFormat.Gif, PictureInfo.PIC_TYPE.CD);
                //newPicture.PictureData = System.IO.File.ReadAllBytes("E:/temp/_Images/pic1.gif");
                //theTrack.EmbeddedPictures.Add(newPicture);

                //// Save modifications on the disc
                //theTrack.Save();


                //tagFile.Tag.Pictures = metaData.Images == null ? null : metaData.Images.Select(x => new TagLib.Picture
                //{
                //    Data = new TagLib.ByteVector(x.Data),
                //    Description = x.Description,
                //    MimeType = x.MimeType,
                //    Type = (TagLib.PictureType)x.Type
                //}).ToArray();
                //tagFile.Save();
                return(true);
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ex, string.Format("MetaData [{0}], Filename [{1}]", metaData.ToString(), filename));
            }
            return(false);
        }
예제 #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));
            }
        }
예제 #10
0
        private void CopyAndSplitMP3s(bool p_bIsReSpliting = false)
        {
            // Get the Split size in bytes (from megabytes)
            Int64 iSplitSize = ((Convert.ToInt64(numSplitSize.Value /* Megabytes */) * 1024 /* Kilobytes */) * 1024 /* Bytes */);

            if (!p_bIsReSpliting)
            {
                if (chkSplitRandomly.Checked)
                {
                    if (!bCopyCompletedOnce)
                    {
                        iaRandOrder = new int[finalTrackList.Count];
                        for (int i = 0; i < iaRandOrder.Length; i++)
                        {
                            iaRandOrder[i] = i;
                        }
                        Shuffle(iaRandOrder);
                    }

                    orderedTrackList = new List <Track>();
                    foreach (int iIndx in iaRandOrder)
                    {
                        orderedTrackList.Add(finalTrackList[iIndx]);
                    }

                    iaRandOrder = null;
                }
                else
                {
                    orderedTrackList = finalTrackList;
                }
            }

            // Split the MP3s into Size folders
            Int64 iCurrentTotalSize = 0;
            int   iSplitCount       = 1;
            int   iTrackCount       = 0;

            foreach (Track rwTrack in orderedTrackList)
            {
                if (chkSplitSize.Checked && (iCurrentTotalSize + rwTrack.FileSize) > iSplitSize)
                {
                    iCurrentTotalSize = 0;
                    iSplitCount++;
                }

                // Copy MP3s into Folder
                FileInfo oFile       = new FileInfo(rwTrack.FileName);
                string   sDestFolder = Path.Combine(txtDestFolder.Text, (chkSplitSize.Checked ? "Disc_" + iSplitCount.ToString("D2") : ""));
                if (!Directory.Exists(sDestFolder))
                {
                    Directory.CreateDirectory(sDestFolder);
                }
                string sDestPath = Path.Combine(sDestFolder, rwTrack.DestFileName);
                if (!File.Exists(sDestPath))
                {
                    oFile.CopyTo(sDestPath);

                    // Now that we have a copy of the MP3 file we should re-tag it to match the tags retrieved from Rainwave.
                    // The Rainwave tags are much better than the OCRemix tags!!
                    IID3v1Tag id3v1 = new ID3v1Tag(sDestPath);
                    id3v1.Album  = rwTrack.Album;
                    id3v1.Artist = rwTrack.Artist;
                    id3v1.Title  = rwTrack.Title;
                    id3v1.Save(sDestPath);

                    IID3v2Tag id3v2 = new ID3v2Tag(sDestPath);
                    id3v2.Album  = rwTrack.Album;
                    id3v2.Artist = rwTrack.Artist;
                    id3v2.Title  = rwTrack.Title;
                    id3v2.Save(sDestPath);

                    if (chkSplitSize.Checked)
                    {
                        iCurrentTotalSize += rwTrack.FileSize;
                    }

                    iTrackCount++;
                    UpdateFolderProgress(iTrackCount, orderedTrackList.Count);
                }
            }

            bCopyCompletedOnce = true;
        }