コード例 #1
0
        /// <inheritdoc />
        public virtual TStream Build()
        {
            // Check for video stereo stream
            var idString = Get("ID");

            if (!TagBuilderHelper.TryGetInt(idString, out object id))
            {
                var idValues = idString.Split('/').Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToArray();
                if (idValues.Length >= 1)
                {
                    if (!TagBuilderHelper.TryGetInt(idValues.First(), out id))
                    {
                        id = 0;
                    }
                }
            }

            return(new TStream
            {
                Id = (int)id,
                Name = Get("Title"),
                StreamPosition = this.StreamPosition,
                StreamNumber = this.StreamNumber,
            });
        }
コード例 #2
0
        public virtual T Build()
        {
            var result = new T();

            foreach (var tagItem in GeneralTagItems)
            {
                var value = MediaInfo.Get(StreamKind.General, StreamPosition, (int)tagItem.Item1);
                if (!string.IsNullOrEmpty(value) && tagItem.Item2(value, out var tagValue))
                {
                    result.GeneralTags.Add(tagItem.Item1, tagValue);
                }
            }

            // parse covers
            result.GeneralTags.TryGetValue(NativeMethods.General.General_Cover_Type, out var coverType);
            result.GeneralTags.TryGetValue(NativeMethods.General.General_Cover_Mime, out var coverMime);
            result.GeneralTags.TryGetValue(NativeMethods.General.General_Cover_Description, out var coverDescription);
            result.GeneralTags.TryGetValue(NativeMethods.General.General_Cover, out var cover);

            if (result.GeneralTags.TryGetValue(NativeMethods.General.General_Cover_Data, out var coverData) ||
                coverType != null ||
                coverMime != null ||
                coverDescription != null ||
                cover != null)
            {
                var coverDataItems        = ((string)coverData)?.Split(new[] { " / " }, StringSplitOptions.RemoveEmptyEntries);
                var coverTypeItems        = ((string)coverType)?.Split(new[] { " / " }, StringSplitOptions.RemoveEmptyEntries);
                var coverMimeItems        = ((string)coverMime)?.Split(new[] { " / " }, StringSplitOptions.RemoveEmptyEntries);
                var coverItems            = ((string)cover)?.Split(new[] { " / " }, StringSplitOptions.RemoveEmptyEntries);
                var coverDescriptionItems = ((string)coverDescription)?.Split(new[] { " / " }, StringSplitOptions.RemoveEmptyEntries);
                var itemCount             = new[] { coverDataItems?.Length ?? 0, coverTypeItems?.Length ?? 0, coverMimeItems?.Length ?? 0, coverDescriptionItems?.Length ?? 0, coverItems?.Length ?? 0 }.Max();
                if (itemCount > 0)
                {
                    var covers = new List <CoverInfo>(itemCount);
                    for (var i = 0; i < itemCount; ++i)
                    {
                        var data = coverDataItems.TryGet(i, string.Empty) ?? string.Empty;
                        covers.Add(new CoverInfo
                        {
                            Exists      = ToBool(coverItems.TryGet(i, string.Empty)),
                            Description = coverDescriptionItems?.TryGet(i, string.Empty) ?? string.Empty,
                            Type        = coverTypeItems?.TryGet(i, string.Empty) ?? string.Empty,
                            Mime        = coverMimeItems?.TryGet(i, string.Empty) ?? string.Empty,
                            Data        = string.IsNullOrEmpty(data) ? null : Convert.FromBase64String(data)
                        });
                    }

                    result.Covers = covers;
                }
                else
                {
                    result.Covers = Enumerable.Empty <CoverInfo>();
                }
            }
            else
            {
                result.Covers = Enumerable.Empty <CoverInfo>();
            }

            if (!result.GeneralTags.ContainsKey(NativeMethods.General.General_Album_Performer))
            {
                var value = MediaInfo.Get(StreamKind.Audio, StreamPosition, "ARTIST");
                if (!string.IsNullOrEmpty(value))
                {
                    result.GeneralTags.Add(NativeMethods.General.General_Album_Performer, value);
                }
            }

            if (!result.GeneralTags.ContainsKey(NativeMethods.General.General_Title))
            {
                var value = MediaInfo.Get(StreamKind.Audio, StreamPosition, "Title");
                if (!string.IsNullOrEmpty(value))
                {
                    result.GeneralTags.Add(NativeMethods.General.General_Title, value);
                }
            }

            if (!result.GeneralTags.ContainsKey(NativeMethods.General.General_Tagged_Date))
            {
                var value = TagBuilderHelper.TryGetDate(MediaInfo.Get(StreamKind.Audio, StreamPosition, "DATE_TAGGED"), out DateTime res) ? (DateTime?)res : null;
                if (value != null)
                {
                    result.GeneralTags.Add(NativeMethods.General.General_Tagged_Date, value);
                }
            }

            if (!result.GeneralTags.ContainsKey(NativeMethods.General.General_Genre))
            {
                var value = MediaInfo.Get(StreamKind.Audio, StreamPosition, "GENRE");
                if (!string.IsNullOrEmpty(value))
                {
                    result.GeneralTags.Add(NativeMethods.General.General_Genre, value);
                }
            }

            if (!result.GeneralTags.ContainsKey(NativeMethods.General.General_Rating))
            {
                var value = TagBuilderHelper.TryGetDouble(MediaInfo.Get(StreamKind.Audio, StreamPosition, "RATING"), out double res) ? (double?)res : null;
                if (value != null)
                {
                    result.GeneralTags.Add(NativeMethods.General.General_Rating, value);
                }
            }

            if (!result.GeneralTags.ContainsKey(NativeMethods.General.General_Released_Date))
            {
                var value = TagBuilderHelper.TryGetDate(MediaInfo.Get(StreamKind.Audio, StreamPosition, "Released_Date"), out DateTime res) ? (DateTime?)res : null;
                if (value != null)
                {
                    result.GeneralTags.Add(NativeMethods.General.General_Released_Date, value);
                }
            }

            if (!result.GeneralTags.ContainsKey(NativeMethods.General.General_Encoded_Library))
            {
                var value = MediaInfo.Get(StreamKind.Audio, StreamPosition, "Encoded_Library");
                if (!string.IsNullOrEmpty(value))
                {
                    result.GeneralTags.Add(NativeMethods.General.General_Encoded_Library, value);
                }
            }

            if (!result.GeneralTags.ContainsKey((NativeMethods.General) 1000))
            {
                if (TagBuilderHelper.TryGetBool(MediaInfo.Get(StreamKind.General, StreamPosition, "Stereoscopic"), out var value))
                {
                    result.GeneralTags.Add((NativeMethods.General) 1000, value);
                }
            }

            if (!result.GeneralTags.ContainsKey((NativeMethods.General) 1001))
            {
                if (TagBuilderHelper.TryGetStereoMode(MediaInfo.Get(StreamKind.General, StreamPosition, "StereoscopicLayout"), out var value))
                {
                    result.GeneralTags.Add((NativeMethods.General) 1001, value);
                }
            }

            if (!result.GeneralTags.ContainsKey((NativeMethods.General) 1002))
            {
                if (TagBuilderHelper.TryGetInt(MediaInfo.Get(StreamKind.General, StreamPosition, "StereoscopicSkip"), out int value))
                {
                    result.GeneralTags.Add((NativeMethods.General) 1002, value);
                }
            }

            return(result);
        }