示例#1
0
        //Collects the stacks saved in the mp3 file. saves them in the printouts folder.
        public static string ReturnCloudCoinStack(TagLib.File Mp3File)
        {
            TagLib.Ape.Tag  ApeTag = Mp3Methods.CheckApeTag(Mp3File);
            TagLib.Ape.Item CCS    = ApeTag.GetItem("CloudCoinStack");
            TagLib.Ape.Item StackN = ApeTag.GetItem("StackName");

            if (CCS != null)
            {
                string filename = StackN.ToString();
                string message  = "Press enter to extract the Cloudcoin stack from " + filename + ".";

                if (getEnter(message))
                {
                    Console.Out.WriteLine("Stack: " + filename + " has been found");
                    string CloudCoinAreaValues = CCS.ToString();
                    string path = "./Printouts/" + filename;
                    try
                    {
                        System.IO.File.WriteAllText(path, CloudCoinAreaValues);     //Create a document containing Mp3 ByteFile (debugging).
                    }
                    catch (Exception e)
                    {
                        Console.Out.WriteLine("Failed to save CloudCoin data {0}", e);
                    }
                    Console.Out.WriteLine("CCS: " + CloudCoinAreaValues);
                    return(path);
                }
                return("null");
            }
            else
            {
                Console.Out.WriteLine("no stack in file" + CCS);
                return("no .stack in file");
            }
        }
示例#2
0
        //Used for debugging.
        // public static void ReadBytes(string Mp3Path, Encoding FileEncoding){
        //     Console.OutputEncoding = FileEncoding; //set the console output.
        //     byte[] MyMp3 = System.IO.File.ReadAllBytes(Mp3Path);
        //     string ByteFile = Hex.Dump(MyMp3); //Store Hex the Hex data from the Mp3 file.
        //     System.IO.File.WriteAllText("./Printouts/Mp3HexPrintout.txt", ByteFile); //Create a document containing Mp3 ByteFile (debugging).
        // }

        ///Method ensures the mp3 file is encapsulated with the appropriate data.
        ///Does not alter existing meta data.
        ///Ensures the existence of an ApeTag item with the key: CloudCoinStack.
        ///Correct Apetag has a CloudCoinStack and StackName container.
        public static TagLib.Ape.Tag CheckApeTag(TagLib.File Mp3File)
        {
            TagLib.Ape.Tag ApeTag;
            bool           hasCCS       = false;
            bool           hasStackName = false;

            // Pass a true parameter to the GetTag function in order to add one if the Mp3File doesn't already have a Mp3Tag.
            // By passing a the parameter 'TagTypes.Ape' we ensure the type is of Ape.

            try{
                ApeTag       = (TagLib.Ape.Tag)Mp3File.GetTag(TagLib.TagTypes.Ape, true);
                hasCCS       = ApeTag.HasItem("CloudCoinStack");
                hasStackName = ApeTag.HasItem("StackName");
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("The process failed: {0}", e.ToString());
                ApeTag = (TagLib.Ape.Tag)Mp3File.GetTag(TagLib.TagTypes.Ape, false);
            }
            if (!hasCCS)
            {
                TagLib.Ape.Item item = new TagLib.Ape.Item("CloudCoinStack", "");
                ApeTag.SetItem(item);
            }
            if (!hasStackName)
            {
                TagLib.Ape.Item itemName = new TagLib.Ape.Item("StackName", "");
                ApeTag.SetItem(itemName);
            }
            return(ApeTag);
        }
示例#3
0
 ///Stores the CloudCoin.stack file as the value tied to the CloudCoinStack key.
 public static TagLib.Ape.Tag SetApeTagValue(TagLib.Ape.Tag ApeTag, string MyCloudCoin, string stackName)
 {
     // Get the APEv2 tag if it exists.
     try{
         TagLib.Ape.Item currentStacks = ApeTag.GetItem("CloudCoinStack");
         ApeTag.SetValue("CloudCoinStack", MyCloudCoin);
         ApeTag.SetValue("StackName", stackName);
         return(ApeTag);
     }
     catch (Exception e)
     {
         Console.Out.WriteLine("The process failed: {0}", e.ToString());
         return(ApeTag);
     }
 }
示例#4
0
        public static string[] GetMiscTag(TagLib.File file, string name)
        {
            //TagLib.Mpeg4.AppleTag apple = (TagLib.Mpeg4.AppleTag)file.GetTag(TagLib.TagTypes.Apple);
            //TagLib.Id3v2.Tag id3v2 = (TagLib.Id3v2.Tag)file.GetTag(TagLib.TagTypes.Id3v2);
            TagLib.Ogg.XiphComment xiph = (TagLib.Ogg.XiphComment)file.GetTag(TagLib.TagTypes.Xiph);
            TagLib.Ape.Tag         ape  = (TagLib.Ape.Tag)file.GetTag(TagLib.TagTypes.Ape);

            //if (apple != null)
            //{
            //    string[] text = apple.GetText(name);
            //    if (text.Length != 0)
            //        return text;
            //}

            //if (id3v2 != null)
            //    foreach (TagLib.Id3v2.Frame f in id3v2.GetFrames())
            //        if (f is TagLib.Id3v2.TextInformationFrame && ((TagLib.Id3v2.TextInformationFrame)f).Text != null)
            //            return ((TagLib.Id3v2.TextInformationFrame)f).Text;

            if (xiph != null)
            {
                string[] l = xiph.GetField(name);
                if (l != null && l.Length != 0)
                {
                    return(l);
                }
            }

            if (ape != null)
            {
                TagLib.Ape.Item item = ape.GetItem(name);
                if (item != null)
                {
                    return(item.ToStringArray());
                }
            }

            return(null);
        }
示例#5
0
        /// <summary>
        /// Read the Tags from the File
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static TrackData Create(string fileName)
        {
            TrackData track = new TrackData();

            TagLib.File file  = null;
            bool        error = false;

            try
            {
                TagLib.ByteVector.UseBrokenLatin1Behavior = true;
                file = TagLib.File.Create(fileName);
            }
            catch (CorruptFileException)
            {
                log.Warn("File Read: Ignoring track {0} - Corrupt File!", fileName);
                error = true;
            }
            catch (UnsupportedFormatException)
            {
                log.Warn("File Read: Ignoring track {0} - Unsupported format!", fileName);
                error = true;
            }
            catch (FileNotFoundException)
            {
                log.Warn("File Read: Ignoring track {0} - Physical file no longer existing!", fileName);
                error = true;
            }
            catch (Exception ex)
            {
                log.Error("File Read: Error processing file: {0} {1}", fileName, ex.Message);
                error = true;
            }

            if (error)
            {
                return(null);
            }

            TagLib.Id3v2.Tag id3v2tag = null;
            try
            {
                if (file.MimeType.Substring(file.MimeType.IndexOf("/") + 1) == "mp3")
                {
                    id3v2tag = file.GetTag(TagTypes.Id3v2, false) as TagLib.Id3v2.Tag;
                }
            }
            catch (Exception ex)
            {
                log.Error("File Read: Error retrieving id3tag: {0} {1}", fileName, ex.Message);
                return(null);
            }

            #region Set Common Values

            FileInfo fi = new FileInfo(fileName);
            try
            {
                track.Id           = Guid.NewGuid();
                track.FullFileName = fileName;
                track.FileName     = Path.GetFileName(fileName);
                track.Readonly     = fi.IsReadOnly;
                track.TagType      = file.MimeType.Substring(file.MimeType.IndexOf("/") + 1);
            }
            catch (Exception ex)
            {
                log.Error("File Read: Error setting Common tags: {0} {1}", fileName, ex.Message);
                return(null);
            }
            #endregion

            #region Set Tags

            try
            {
                // Artist
                track.Artist = String.Join(";", file.Tag.Performers);
                if (track.Artist.Contains("AC;DC"))
                {
                    track.Artist = track.Artist.Replace("AC;DC", "AC/DC");
                }

                track.ArtistSortName = String.Join(";", file.Tag.PerformersSort);
                if (track.ArtistSortName.Contains("AC;DC"))
                {
                    track.ArtistSortName = track.ArtistSortName.Replace("AC;DC", "AC/DC");
                }

                track.AlbumArtist = String.Join(";", file.Tag.AlbumArtists);
                if (track.AlbumArtist.Contains("AC;DC"))
                {
                    track.AlbumArtist = track.AlbumArtist.Replace("AC;DC", "AC/DC");
                }

                track.AlbumArtistSortName = String.Join(";", file.Tag.AlbumArtistsSort);
                if (track.AlbumArtistSortName.Contains("AC;DC"))
                {
                    track.AlbumArtistSortName = track.AlbumArtistSortName.Replace("AC;DC", "AC/DC");
                }

                track.Album         = file.Tag.Album ?? "";
                track.AlbumSortName = file.Tag.AlbumSort ?? "";

                track.BPM         = (int)file.Tag.BeatsPerMinute;
                track.Compilation = id3v2tag == null ? false : id3v2tag.IsCompilation;
                track.Composer    = string.Join(";", file.Tag.Composers);
                track.Conductor   = file.Tag.Conductor ?? "";
                track.Copyright   = file.Tag.Copyright ?? "";

                track.DiscNumber = file.Tag.Disc;
                track.DiscCount  = file.Tag.DiscCount;

                track.Genre         = string.Join(";", file.Tag.Genres);
                track.Grouping      = file.Tag.Grouping ?? "";
                track.Title         = file.Tag.Title ?? "";
                track.TitleSortName = file.Tag.TitleSort ?? "";

                track.ReplayGainTrack     = file.Tag.ReplayGainTrack ?? "";
                track.ReplayGainTrackPeak = file.Tag.ReplayGainTrackPeak ?? "";
                track.ReplayGainAlbum     = file.Tag.ReplayGainAlbum ?? "";
                track.ReplayGainAlbumPeak = file.Tag.ReplayGainAlbumPeak ?? "";

                track.TrackNumber = file.Tag.Track;
                track.TrackCount  = file.Tag.TrackCount;
                track.Year        = (int)file.Tag.Year;

                // Pictures
                foreach (IPicture picture in file.Tag.Pictures)
                {
                    MPTagThat.Core.Common.Picture pic = new MPTagThat.Core.Common.Picture
                    {
                        Type        = picture.Type,
                        MimeType    = picture.MimeType,
                        Description = picture.Description
                    };

                    pic.Data = picture.Data.Data;
                    track.Pictures.Add(pic);
                }

                // Comments
                if (track.IsMp3 && id3v2tag != null)
                {
                    foreach (CommentsFrame commentsframe in id3v2tag.GetFrames <CommentsFrame>())
                    {
                        track.ID3Comments.Add(new Comment(commentsframe.Description, commentsframe.Language, commentsframe.Text));
                    }
                }
                else
                {
                    track.Comment = file.Tag.Comment;
                }

                // Lyrics
                track.Lyrics = file.Tag.Lyrics;
                if (track.IsMp3 && id3v2tag != null)
                {
                    foreach (UnsynchronisedLyricsFrame lyricsframe in id3v2tag.GetFrames <UnsynchronisedLyricsFrame>())
                    {
                        // Only add non-empty Frames
                        if (lyricsframe.Text != "")
                        {
                            track.LyricsFrames.Add(new Lyric(lyricsframe.Description, lyricsframe.Language, lyricsframe.Text));
                        }
                    }
                }

                // Rating
                if (track.IsMp3)
                {
                    TagLib.Id3v2.PopularimeterFrame popmFrame = null;
                    // First read in all POPM Frames found
                    if (id3v2tag != null)
                    {
                        foreach (PopularimeterFrame popmframe in id3v2tag.GetFrames <PopularimeterFrame>())
                        {
                            // Only add valid POPM Frames
                            if (popmframe.User != "" && popmframe.Rating > 0)
                            {
                                track.Ratings.Add(new PopmFrame(popmframe.User, (int)popmframe.Rating, (int)popmframe.PlayCount));
                            }
                        }

                        popmFrame = TagLib.Id3v2.PopularimeterFrame.Get(id3v2tag, "MPTagThat", false);
                        if (popmFrame != null)
                        {
                            track.Rating = popmFrame.Rating;
                        }
                    }

                    if (popmFrame == null)
                    {
                        // Now check for Ape Rating
                        TagLib.Ape.Tag  apetag  = file.GetTag(TagTypes.Ape, true) as TagLib.Ape.Tag;
                        TagLib.Ape.Item apeItem = apetag.GetItem("RATING");
                        if (apeItem != null)
                        {
                            string rating = apeItem.ToString();
                            try
                            {
                                track.Rating = Convert.ToInt32(rating);
                            }
                            catch (Exception)
                            { }
                        }
                    }
                }
                else if (track.TagType == "ape")
                {
                    TagLib.Ape.Tag  apetag  = file.GetTag(TagTypes.Ape, true) as TagLib.Ape.Tag;
                    TagLib.Ape.Item apeItem = apetag.GetItem("RATING");
                    if (apeItem != null)
                    {
                        string rating = apeItem.ToString();
                        try
                        {
                            track.Rating = Convert.ToInt32(rating);
                        }
                        catch (Exception)
                        { }
                    }
                }
                else if (track.TagType == "ogg" || track.TagType == "flac")
                {
                    XiphComment xiph   = file.GetTag(TagLib.TagTypes.Xiph, false) as XiphComment;
                    string[]    rating = xiph.GetField("RATING");
                    if (rating.Length > 0)
                    {
                        try
                        {
                            track.Rating = Convert.ToInt32(rating[0]);
                        }
                        catch (Exception)
                        { }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Exception setting Tags for file: {0}. {1}", fileName, ex.Message);
            }

            #endregion

            #region Set Properties

            try
            {
                track.DurationTimespan = file.Properties.Duration;

                int fileLength = (int)(fi.Length / 1024);
                track.FileSize = fileLength.ToString();

                track.BitRate       = file.Properties.AudioBitrate.ToString();
                track.SampleRate    = file.Properties.AudioSampleRate.ToString();
                track.Channels      = file.Properties.AudioChannels.ToString();
                track.Version       = file.Properties.Description;
                track.CreationTime  = string.Format("{0:yyyy-MM-dd HH:mm:ss}", fi.CreationTime);
                track.LastWriteTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", fi.LastWriteTime);
            }
            catch (Exception ex)
            {
                log.Error("Exception setting Properties for file: {0}. {1}", fileName, ex.Message);
            }

            #endregion

            // Now copy all Text frames of an ID3 V2
            try
            {
                if (track.IsMp3 && id3v2tag != null)
                {
                    foreach (TagLib.Id3v2.Frame frame in id3v2tag.GetFrames())
                    {
                        string id = frame.FrameId.ToString();
                        if (!Util.StandardFrames.Contains(id) && Util.ExtendedFrames.Contains(id))
                        {
                            track.Frames.Add(new Frame(id, "", frame.ToString()));
                        }
                        else if (!Util.StandardFrames.Contains(id) && !Util.ExtendedFrames.Contains(id))
                        {
                            if ((Type)frame.GetType() == typeof(UserTextInformationFrame))
                            {
                                // Don't add Replaygain frames, as they are handled in taglib tags
                                if (!Util.IsReplayGain((frame as UserTextInformationFrame).Description))
                                {
                                    track.UserFrames.Add(new Frame(id, (frame as UserTextInformationFrame).Description ?? "",
                                                                   (frame as UserTextInformationFrame).Text.Length == 0
                                                 ? ""
                                                 : (frame as UserTextInformationFrame).Text[0]));
                                }
                            }
                            else if ((Type)frame.GetType() == typeof(PrivateFrame))
                            {
                                track.UserFrames.Add(new Frame(id, (frame as PrivateFrame).Owner ?? "",
                                                               (frame as PrivateFrame).PrivateData == null
                                                 ? ""
                                                 : (frame as PrivateFrame).PrivateData.ToString()));
                            }
                            else if ((Type)frame.GetType() == typeof(UniqueFileIdentifierFrame))
                            {
                                track.UserFrames.Add(new Frame(id, (frame as UniqueFileIdentifierFrame).Owner ?? "",
                                                               (frame as UniqueFileIdentifierFrame).Identifier == null
                                                 ? ""
                                                 : (frame as UniqueFileIdentifierFrame).Identifier.ToString()));
                            }
                            else if ((Type)frame.GetType() == typeof(UnknownFrame))
                            {
                                track.UserFrames.Add(new Frame(id, "",
                                                               (frame as UnknownFrame).Data == null
                                                 ? ""
                                                 : (frame as UnknownFrame).Data.ToString()));
                            }
                            else
                            {
                                track.UserFrames.Add(new Frame(id, "", frame.ToString()));
                            }
                        }
                    }

                    track.ID3Version = id3v2tag.Version;
                }
            }
            catch (Exception ex)
            {
                log.Error("Exception getting User Defined frames for file: {0}. {1}", fileName, ex.Message);
            }

            return(track);
        }
示例#6
0
        /// <summary>
        /// This method is called by mediaportal when it wants information for a music file
        /// The method will check which tagreader supports the file and ask it to extract the information from it
        /// </summary>
        /// <param name="strFile">filename of the music file</param>
        /// <returns>
        /// MusicTag instance when file has been read
        /// null when file type is not supported or if the file does not contain any information
        /// </returns>
        public static MusicTag ReadTag(string strFile)
        {
            // Read Cue info
            if (CueUtil.isCueFakeTrackFile(strFile))
            {
                try
                {
                    return(CueUtil.CueFakeTrackFile2MusicTag(strFile));
                }
                catch (Exception ex)
                {
                    Log.Warn("TagReader: Exception reading file {0}. {1}", strFile, ex.Message);
                }
            }

            if (!IsAudio(strFile))
            {
                return(null);
            }

            char[] trimChars = { ' ', '\x00' };

            try
            {
                // Set the flag to use the standard System Encoding set by the user
                // Otherwise Latin1 is used as default, which causes characters in various languages being displayed wrong
                TagLib.ByteVector.UseBrokenLatin1Behavior = true;
                TagLib.File tag = TagLib.File.Create(strFile);
                if (tag == null)
                {
                    Log.Warn("Tagreader: No tag in file - {0}", strFile);
                    return(null);
                }

                MusicTag musictag = new MusicTag();
                string[] artists  = tag.Tag.Performers;
                if (artists.Length > 0)
                {
                    musictag.Artist = String.Join(";", artists).Trim(trimChars);
                    // The AC/DC exception
                    if (musictag.Artist.Contains("AC;DC"))
                    {
                        musictag.Artist = musictag.Artist.Replace("AC;DC", "AC/DC");
                    }
                }

                musictag.Album          = tag.Tag.Album == null ? "" : tag.Tag.Album.Trim(trimChars);
                musictag.HasAlbumArtist = false;
                string[] albumartists = tag.Tag.AlbumArtists;
                if (albumartists.Length > 0)
                {
                    musictag.AlbumArtist    = String.Join(";", albumartists).Trim(trimChars);
                    musictag.HasAlbumArtist = true;
                    // The AC/DC exception
                    if (musictag.AlbumArtist.Contains("AC;DC"))
                    {
                        musictag.AlbumArtist = musictag.AlbumArtist.Replace("AC;DC", "AC/DC");
                    }
                }
                musictag.BitRate = tag.Properties.AudioBitrate;
                musictag.Comment = tag.Tag.Comment == null ? "" : tag.Tag.Comment.Trim(trimChars);
                string[] composer = tag.Tag.Composers;
                if (composer.Length > 0)
                {
                    musictag.Composer = string.Join(";", composer).Trim(trimChars);
                }
                musictag.Conductor = tag.Tag.Conductor == null ? "" : tag.Tag.Conductor.Trim(trimChars);
                IPicture[] pics = new IPicture[] { };
                pics = tag.Tag.Pictures;
                if (pics.Length > 0)
                {
                    musictag.CoverArtImageBytes = pics[0].Data.Data;
                }
                musictag.Duration = (int)tag.Properties.Duration.TotalSeconds;
                musictag.FileName = strFile;
                musictag.FileType = tag.MimeType.Substring(tag.MimeType.IndexOf("/") + 1);
                string[] genre = tag.Tag.Genres;
                if (genre.Length > 0)
                {
                    musictag.Genre = String.Join(";", genre).Trim(trimChars);
                }
                string lyrics = tag.Tag.Lyrics == null ? "" : tag.Tag.Lyrics.Trim(trimChars);
                musictag.Title = tag.Tag.Title == null ? "" : tag.Tag.Title.Trim(trimChars);
                // Prevent Null Ref execption, when Title is not set
                musictag.Track      = (int)tag.Tag.Track;
                musictag.TrackTotal = (int)tag.Tag.TrackCount;
                musictag.DiscID     = (int)tag.Tag.Disc;
                musictag.DiscTotal  = (int)tag.Tag.DiscCount;
                musictag.Codec      = tag.Properties.Description;
                if (tag.MimeType == "taglib/mp3")
                {
                    musictag.BitRateMode = tag.Properties.Description.IndexOf("VBR") > -1 ? "VBR" : "CBR";
                }
                else
                {
                    musictag.BitRateMode = "";
                }
                musictag.BPM                 = (int)tag.Tag.BeatsPerMinute;
                musictag.Channels            = tag.Properties.AudioChannels;
                musictag.SampleRate          = tag.Properties.AudioSampleRate;
                musictag.Year                = (int)tag.Tag.Year;
                musictag.ReplayGainTrack     = tag.Tag.ReplayGainTrack ?? "";
                musictag.ReplayGainTrackPeak = tag.Tag.ReplayGainTrackPeak ?? "";
                musictag.ReplayGainAlbum     = tag.Tag.ReplayGainAlbum ?? "";
                musictag.ReplayGainAlbumPeak = tag.Tag.ReplayGainAlbumPeak ?? "";

                if (tag.MimeType == "taglib/mp3")
                {
                    bool foundPopm = false;
                    // Handle the Rating, which comes from the POPM frame
                    TagLib.Id3v2.Tag id32_tag = tag.GetTag(TagLib.TagTypes.Id3v2) as TagLib.Id3v2.Tag;
                    if (id32_tag != null)
                    {
                        // Do we have a POPM frame written by MediaPortal or MPTagThat?
                        TagLib.Id3v2.PopularimeterFrame popmFrame = TagLib.Id3v2.PopularimeterFrame.Get(id32_tag, "MediaPortal",
                                                                                                        false);
                        if (popmFrame == null)
                        {
                            popmFrame = TagLib.Id3v2.PopularimeterFrame.Get(id32_tag, "MPTagThat", false);
                        }
                        if (popmFrame != null)
                        {
                            musictag.Rating = popmFrame.Rating;
                            foundPopm       = true;
                        }

                        // Now look for a POPM frame written by WMP
                        if (!foundPopm)
                        {
                            TagLib.Id3v2.PopularimeterFrame popm = TagLib.Id3v2.PopularimeterFrame.Get(id32_tag,
                                                                                                       "Windows Media Player 9 Series",
                                                                                                       false);
                            if (popm != null)
                            {
                                // Get the rating stored in the WMP POPM frame
                                int rating = popm.Rating;
                                int i      = 0;
                                if (rating == 255)
                                {
                                    i = 5;
                                }
                                else if (rating == 196)
                                {
                                    i = 4;
                                }
                                else if (rating == 128)
                                {
                                    i = 3;
                                }
                                else if (rating == 64)
                                {
                                    i = 2;
                                }
                                else if (rating == 1)
                                {
                                    i = 1;
                                }

                                musictag.Rating = i;
                                foundPopm       = true;
                            }
                        }

                        if (!foundPopm)
                        {
                            // Now look for any other POPM frame that might exist
                            foreach (TagLib.Id3v2.PopularimeterFrame popm in id32_tag.GetFrames <TagLib.Id3v2.PopularimeterFrame>())
                            {
                                int rating = popm.Rating;
                                int i      = 0;
                                if (rating > 205 || rating == 5)
                                {
                                    i = 5;
                                }
                                else if (rating > 154 || rating == 4)
                                {
                                    i = 4;
                                }
                                else if (rating > 104 || rating == 3)
                                {
                                    i = 3;
                                }
                                else if (rating > 53 || rating == 2)
                                {
                                    i = 2;
                                }
                                else if (rating > 0 || rating == 1)
                                {
                                    i = 1;
                                }

                                musictag.Rating = i;
                                foundPopm       = true;
                                break; // we only take the first popm frame
                            }
                        }

                        if (!foundPopm)
                        {
                            // If we don't have any POPM frame, we might have an APE Tag embedded in the mp3 file
                            TagLib.Ape.Tag apetag = tag.GetTag(TagTypes.Ape, false) as TagLib.Ape.Tag;
                            if (apetag != null)
                            {
                                TagLib.Ape.Item apeItem = apetag.GetItem("RATING");
                                if (apeItem != null)
                                {
                                    string rating = apeItem.ToString();
                                    try
                                    {
                                        musictag.Rating = Convert.ToInt32(rating);
                                    }
                                    catch (Exception ex)
                                    {
                                        musictag.Rating = 0;
                                        Log.Warn("Tagreader: Unsupported APE rating format - {0} in {1} {2}", rating, strFile, ex.Message);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (tag.MimeType == "taglib/ape")
                    {
                        TagLib.Ape.Tag apetag = tag.GetTag(TagTypes.Ape, false) as TagLib.Ape.Tag;
                        if (apetag != null)
                        {
                            TagLib.Ape.Item apeItem = apetag.GetItem("RATING");
                            if (apeItem != null)
                            {
                                string rating = apeItem.ToString();
                                try
                                {
                                    musictag.Rating = Convert.ToInt32(rating);
                                }
                                catch (Exception ex)
                                {
                                    musictag.Rating = 0;
                                    Log.Warn("Tagreader: Unsupported APE rating format - {0} in {1} {2}", rating, strFile, ex.Message);
                                }
                            }
                        }
                    }
                }

                // if we didn't get a title, use the Filename without extension to prevent the file to appear as "unknown"
                if (musictag.Title == "")
                {
                    Log.Warn("TagReader: Empty Title found in file: {0}. Please retag.", strFile);
                    musictag.Title = System.IO.Path.GetFileNameWithoutExtension(strFile);
                }

                return(musictag);
            }
            catch (UnsupportedFormatException)
            {
                Log.Warn("Tagreader: Unsupported File Format {0}", strFile);
            }
            catch (Exception ex)
            {
                Log.Warn("TagReader: Exception reading file {0}. {1}", strFile, ex.Message);
            }
            return(null);
        }
示例#7
0
        public static bool mp3_application(int m1, int m5, int m25, int m100, int m250, String nametag)
        {
            Console.WriteLine("1: ", m1);
            Console.WriteLine("5: ", m5);
            Console.WriteLine("25: ", m25);
            Console.WriteLine("100: ", m100);
            Console.WriteLine("250: ", m250);
            Console.WriteLine("String ", nametag);
            Encoding FileEncoding = Encoding.ASCII; //Define the encoding.

            TagLib.File    Mp3File = null;          // = TagLib.File.Create(Mp3Path); //Create TagLib file... ensures a Id3v2 header.;
            TagLib.Ape.Tag ApeTag  = null;          // = Mp3Methods.CheckApeTag(Mp3File); //return existing tag. create one if none.
            string[]       collectCloudCoinStack = new string[3];
            //State 1:endState[0] = MP3 filename
            //State 2:endState[1] = Name of external CloudCoinStack to be inserted.
            //State 3:endState[2] = Name of the CloudCoinStack currently found in the MP3.
            //State 4:endState[3] =
            //State 5:endState[4] =
            //State 6:endState[5] =
            string[] endState      = new string[6]; //Keeps the current state of each case
            bool     menuStyle     = true;          // Discriptive / Standard
            bool     makingChanges = true;          //Keeps the session runnning.
            string   Mp3Path       = null;

            Mp3Methods.printWelcome();
            int userChoice = Mp3Methods.printOptions() + 1;

            Console.WriteLine("");

            while (makingChanges)
            {
                switch (userChoice)
                {
                case 1:                                       //Select .mp3 file.
                    Mp3Path = Mp3Methods.ReturnMp3FilePath(); //Save file path.
                    selectMp3(Mp3Path);
                    break;

                case 2:    //Select .stack file from Bank folder
                    selectStack();
                    break;

                case 3:    //Insert the .stack file into the .mp3 file
                    stackToMp3();
                    break;

                case 4:    //Return .stack from .mp3
                    stackFromMp3();
                    break;

                case 5:    //Delete .stack from .mp3
                    deleteFromMp3(Mp3Path);
                    break;

                case 6:    //Save .mp3's current state
                    saveMp3();
                    break;

                case 7:    //Quit
                    makingChanges = false;
                    break;

                case 8:    //Descriptions
                    menuStyle = !menuStyle;
                    break;

                default:
                    Console.Out.WriteLine("No matches for input!");
                    break;
                }
                Console.Clear();
                ///Switch bestween discriptive and standard menus options.
                switch (menuStyle)
                {
                case true:
                    Mp3Methods.consoleGap(1);
                    Mp3Methods.printStates(endState);
                    userChoice = Mp3Methods.printOptions() + 1;
                    break;

                case false:
                    Mp3Methods.consoleGap(1);
                    Mp3Methods.printStates(endState);
                    userChoice = Mp3Methods.printHelp() + 1;
                    break;
                } //end switch
            }     //end while loop.
            Console.Out.WriteLine("Goodbye");

            void selectMp3(string filePath)
            {
                if (filePath != "null")
                {
                    Mp3File = TagLib.File.Create(filePath);    //Create TagLib file... ensures a Id3v2 header.
                    ApeTag  = Mp3Methods.CheckApeTag(Mp3File); //return existing tag. create one if none.
                    string fileName = Mp3File.Name;
                    resetEndStates(fileName, ApeTag);
                    endState[0] = "MP3 file: " + fileName + " has been selected. ";
                }// end if.
                else
                {
                    endState[0] = "No file chosen.";
                } // end else.
            }     // end selectMp3

            void selectStack()//External souce to be inserted in the mp3 file.
            {
                try
                {
                    collectCloudCoinStack = Mp3Methods.collectBankStacks(); //Select stacks to insert.
                    if (collectCloudCoinStack[0] != "null")
                    {
                        endState[1] = "External Stack: " + collectCloudCoinStack[0];
                    }    //end if
                    else
                    {
                        endState[1] = "No stack file chose.";
                    } //end else.
                }     //end try
                catch
                {
                    endState[1] = ".stack error ";
                }    //end catch
                Console.Out.WriteLine(endState[1]);
            }// end selectStack

            void stackToMp3()//the process of inserting the selected stack into the file.
            {
                string cloudCoinStack = collectCloudCoinStack[1];
                string stackName      = collectCloudCoinStack[2];

                Console.Out.WriteLine("Existing Stacks in the mp3 will be overwritten");
                Console.Out.WriteLine("Enter/Return to continue, Any other key to go back.");
                if (Console.ReadKey(true).Key == ConsoleKey.Enter)   //prompt user to continue.
                {
                    if (cloudCoinStack != null && ApeTag != null)
                    {
                        Console.Out.WriteLine("Existing Stacks in the mp3 will be overwritten");
                        ApeTag = Mp3Methods.CheckApeTag(Mp3File);
                        Mp3Methods.SetApeTagValue(ApeTag, cloudCoinStack, stackName);
                        endState[2] = ".stack was successfully inserted in " + Mp3File.Name;
                        endState[4] = "Stacks in " + Mp3File.Name + " have been added.";
                    }    //end if
                    else
                    {
                        Mp3Methods.SetApeTagValue(ApeTag, cloudCoinStack, stackName);
                        endState[2] = "No saved cloud coin stack.";
                    } //end else
                    Console.Out.WriteLine(endState[2]);
                }     //end if
            }//end stackToMp3

            void stackFromMp3()//returning the stack from the mp3
            {
                Mp3File = TagLib.File.Create(Mp3Path);
                if (Mp3File != null)
                {
                    string mp3CurrentCoinStack = Mp3Methods.ReturnCloudCoinStack(Mp3File);    //The current stack from the mp3 gets saved.
                    if (mp3CurrentCoinStack != "null")
                    {
                        endState[3] = "A file was created:  " + mp3CurrentCoinStack;
                    }    //end if.
                    else
                    {
                        endState[3] = "Incorrect key press.";
                    } //end else.
                    Console.Out.WriteLine(endState[3]);
                }     //end if.
                else
                {
                    Console.Out.WriteLine("No mp3 file selected.");
                }    //end else.
            } //end stackFromMp3

            void deleteFromMp3(string filePath)
            {
                Console.Out.WriteLine("WARNING: you are about to permenantley delete any stack files found in " + Mp3File.Name);
                Console.Out.WriteLine("Enter/Return to continue, Any other key to go back.");

                if (Console.ReadKey(true).Key == ConsoleKey.Enter)
                {
                    bool isDeleted = Mp3Methods.RemoveExistingStacks(ApeTag);
                    Console.Out.WriteLine(isDeleted);
                    if (isDeleted)
                    {
                        Mp3File.Save();
                        selectMp3(filePath); // rerun code to update states.
                        endState[4] = "Any existing stacks in " + Mp3File.Name + " have been deleted.";
                    }                        //end if (is Deleted)
                    else
                    {
                        endState[4] = "Stacks in " + Mp3File.Name + " have not been properly deleted.";
                    }
                }    //end if.
                else
                {
                    endState[4] = "Stacks in " + Mp3File.Name + " have NOT been deleted.";
                }    //end else.
                Console.Out.WriteLine(endState[4]);
            } // end deleteFromMp3.

            void saveMp3()
            {
                Mp3File.Save();     // Save changes.
                endState[5] = Mp3File.Name + " has been saved with the changes made";
                Console.Out.WriteLine(endState[5]);
            }//end saveMp3

            //Endstates are the 6 messages that are displayed to the user between actions.
            void resetEndStates(string filename, TagLib.Ape.Tag tag)
            {
                int length = endState.Length;

                TagLib.Ape.Item StackN = tag.GetItem("StackName");

                //UPDATE endState[1]: remove current external cloudcoinstack.
                endState[1] = "No external CloudCoin stack selected.";
                for (int i = 0; i < 3; i++)
                {
                    collectCloudCoinStack[i] = "";
                }// end for

                //UPDATE endState[2]: Check for an existing CloudCoinStack in new file.
                if (StackN.Size <= 1)
                {
                    endState[2] = filename + " does not include a stack.";
                }//end if
                else
                {
                    Console.Out.WriteLine(StackN.Size);
                    endState[2] = filename + " includes cloudcoin stack: " + StackN + ".";
                }// end else

                endState[3] = "";
                endState[4] = "";
                endState[5] = "";
            }

            return(true);
        } //end Mp3Start.