Example #1
0
        /// <summary>
        /// Read MP4 audio meta data.
        /// </summary>
        /// <param name="strm">MP4 input data stream</param>
        /// <param name="createImageObject">Read embedded Cover Art(=true) or not(=false)</param>
        /// <returns>List of meta data or null</returns>
        public static List <KeyValuePair <string, object> > Read(Stream strm, bool createImageObject = true)
        {
            var parser = new MP4(strm, createImageObject);

            try
            {
                parser.ReadRecurse(strm.Length);
            }
            catch (ArgumentException) { }
            catch (IOException) { }
            catch (FormatException) { }

            return(parser.tags);
        }
Example #2
0
        public static List <KeyValuePair <string, object> > readTagByFilename(string filename, bool createImageObject)
        {
            List <KeyValuePair <string, object> > tag = null;

            try
            {
                using (System.IO.FileStream fs = System.IO.File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
                {
                    switch (System.IO.Path.GetExtension(filename).ToLower())
                    {
                    case ".flac":
                        tag = FlacTag.Read(fs, createImageObject);
                        break;

                    case ".ogg":
                        tag = Ogg.Read(fs);
                        break;

                    case ".m4a":
                    case ".m4v":
                    case ".mp4":
                    case ".aac":
                        tag = MP4.Read(fs, createImageObject);
                        break;

                    case ".wma":
                    case ".asf":
                    case ".wmv":
                        tag = ASF.Read(fs, createImageObject);
                        break;

                    case ".ape":
                    case ".tak":
                    case ".wv":
                        tag = ApeTag.Read(fs, createImageObject);
                        break;

                    case ".tta":
                    case ".mp3":
                    case ".mp2":
                        try
                        {
                            tag = ApeTag.Read(fs, createImageObject);
                            if (tag == null)
                            {
                                tag = new List <KeyValuePair <string, object> >();
                            }
                        }
                        catch (IOException) { }
                        try
                        {
                            fs.Seek(0, System.IO.SeekOrigin.Begin);
                            var tag_id3v2 = ID3ToTag(ID3V2Tag.readID3tag(fs, createImageObject));
                            if (tag_id3v2 != null)
                            {
                                tag.AddRange(tag_id3v2);
                            }
                        }
                        catch (IOException ex) { Logger.Error(ex); }
                        try
                        {
                            fs.Seek(0, System.IO.SeekOrigin.Begin);
                            var tag_id3v1 = ID3.Read(fs);
                            if (tag_id3v1 != null)
                            {
                                foreach (var v1tag in tag_id3v1)
                                {
                                    if (tag.Find((e) => e.Key == v1tag.Key).Key == null)
                                    {
                                        tag.Add(v1tag);
                                    }
                                }
                            }
                        }
                        catch (IOException) { }
                        break;

                    default:
                        return(null);
                    }
                }
            }
            catch (IOException) { }

            if (tag == null)
            {
                return(null);
            }

            // BANDをALBUM ARTISTとして扱う
            var band = tag.Find((e) => { return(e.Key == "BAND"); });

            if (band.Value != null)
            {
                tag.Add(new KeyValuePair <string, object>("ALBUM ARTIST", band.Value));
            }

            // TRACKNUMBERをTRACKとして扱う
            var tracknumber = tag.Find((e) => { return(e.Key == "TRACKNUMBER"); });

            if (tracknumber.Value != null)
            {
                tag.Add(new KeyValuePair <string, object>("TRACK", tracknumber.Value));
            }

            // ARTISTがないとき、ALBUM ARTISTをARTISTとして扱う
            if (tag.Find((e) => { return(e.Key == "ARTIST"); }).Value == null)
            {
                var albumartist = tag.Find((e) => { return(e.Key == "ALBUM ARTIST"); });
                if (albumartist.Value != null)
                {
                    tag.Add(new KeyValuePair <string, object>("ARTIST", albumartist.Value));
                }
            }
            return(tag);
        }