public static TValue?AttributeValue <TValue>(this M3U8TagInstance tagInstance, M3U8ValueAttribute <TValue> attribute) where TValue : struct
        {
            M3U8AttributeValueInstance <TValue> attributeValueInstance = M3U8TagInstanceExtensions.Attribute <TValue>(tagInstance, attribute);

            if (null == attributeValueInstance)
            {
                return(new TValue?());
            }
            return(new TValue?(attributeValueInstance.Value));
        }
        public static TValue AttributeObject <TValue>(this M3U8TagInstance tagInstance, M3U8ValueAttribute <TValue> attribute) where TValue : class
        {
            M3U8AttributeValueInstance <TValue> attributeValueInstance = M3U8TagInstanceExtensions.Attribute <TValue>(tagInstance, attribute);

            if (null == attributeValueInstance)
            {
                return(default(TValue));
            }
            return(attributeValueInstance.Value);
        }
        public static IEnumerable <M3U8AttributeInstance> Attributes(this M3U8TagInstance tagInstance)
        {
            AttributesTagInstance attributesTagInstance = tagInstance as AttributesTagInstance;

            if (null == attributesTagInstance)
            {
                return(M3U8TagInstanceExtensions.NoAttributeInstances);
            }
            return(attributesTagInstance.Attributes);
        }
Example #4
0
        private void HandleExt(string line)
        {
            int    length  = line.IndexOf(':');
            string tagName = line;
            string str     = (string)null;

            if (length > 3)
            {
                tagName = line.Substring(0, length);
                if (length + 1 < line.Length)
                {
                    str = line.Substring(length + 1);
                }
            }
            M3U8TagInstance tagInstance = M3U8Tags.Default.Create(tagName, str);

            if (null == tagInstance)
            {
                return;
            }
            switch (tagInstance.Tag.Scope)
            {
            case M3U8TagScope.Global:
                if (1 == this._lineNumber && tagInstance.Tag == M3U8Tags.ExtM3UMarker)
                {
                    this._hasMarker = true;
                }
                this._globalTags.Add(tagInstance);
                break;

            case M3U8TagScope.Shared:
                this.ResolveShared(tagInstance);
                break;

            case M3U8TagScope.Segment:
                this._tags.Add(tagInstance);
                break;
            }
        }
Example #5
0
 void ResolveShared(M3U8TagInstance tagInstance)
 {
     // TODO: Shared tags needs a conflict/update policy (e.g., a new key of the same type should remove the old one)
     _sharedTags.Add(tagInstance);
 }
Example #6
0
 private void ResolveShared(M3U8TagInstance tagInstance)
 {
     this._sharedTags.Add(tagInstance);
 }
Example #7
0
        static bool IsYesNo(M3U8TagInstance tag, M3U8ValueAttribute<string> attribute, bool defaultValue = false)
        {
            var attr = tag.Attribute(attribute);

            if (null == attr || string.IsNullOrWhiteSpace(attr.Value))
                return defaultValue;

            return 0 == string.CompareOrdinal("YES", attr.Value.ToUpperInvariant());
        }
Example #8
0
        static void AddMedia(Uri playlist, M3U8TagInstance gt, Dictionary<string, MediaGroup> audioStreams)
        {
            var groupId = gt.Attribute(ExtMediaSupport.AttrGroupId).Value;

            var urlAttribute = gt.AttributeObject(ExtMediaSupport.AttrUri);

            Uri playlistUrl = null;

            if (null != urlAttribute)
                playlistUrl = new Uri(playlist, new Uri(urlAttribute, UriKind.RelativeOrAbsolute));

            var language = gt.AttributeObject(ExtMediaSupport.AttrLanguage);

            var audioStream = new PlaylistSubStream
            {
                Type = gt.AttributeObject(ExtMediaSupport.AttrType),
                Name = groupId,
                Playlist = playlistUrl,
                IsAutoselect = IsYesNo(gt, ExtMediaSupport.AttrAutoselect),
                Language = null == language ? null : language.Trim().ToLower()
            };

            MediaGroup mediaGroup;
            if (!audioStreams.TryGetValue(groupId, out mediaGroup))
            {
                mediaGroup = new MediaGroup
                {
                    Default = audioStream
                };

                audioStreams[groupId] = mediaGroup;
            }

            var isDefault = IsYesNo(gt, ExtMediaSupport.AttrDefault);

            if (isDefault)
                mediaGroup.Default = audioStream;

            var name = gt.Attribute(ExtMediaSupport.AttrName).Value;

            mediaGroup.Streams[name] = audioStream;
        }
 public static M3U8AttributeValueInstance <TValue> Attribute <TValue>(this M3U8TagInstance tagInstance, M3U8ValueAttribute <TValue> attribute, TValue value) where TValue : IEquatable <TValue>
 {
     return(Enumerable.FirstOrDefault <M3U8AttributeValueInstance <TValue> >(Enumerable.OfType <M3U8AttributeValueInstance <TValue> >((IEnumerable)M3U8TagInstanceExtensions.Attributes(tagInstance)), (Func <M3U8AttributeValueInstance <TValue>, bool>)(a => a.Attribute == (M3U8Attribute)attribute && a.Value.Equals(value))));
 }
 public static IEnumerable <M3U8AttributeValueInstance <TValue> > Attributes <TValue>(this M3U8TagInstance tagInstance, M3U8ValueAttribute <TValue> attribute)
 {
     return(Enumerable.Where <M3U8AttributeValueInstance <TValue> >(Enumerable.OfType <M3U8AttributeValueInstance <TValue> >((IEnumerable)M3U8TagInstanceExtensions.Attributes(tagInstance)), (Func <M3U8AttributeValueInstance <TValue>, bool>)(a => a.Attribute == (M3U8Attribute)attribute)));
 }
 public static TInstance AttributeInstance <TInstance>(this M3U8TagInstance tagInstance, M3U8Attribute attribute) where TInstance : M3U8AttributeInstance
 {
     return(Enumerable.FirstOrDefault <M3U8AttributeInstance>(M3U8TagInstanceExtensions.Attributes(tagInstance), (Func <M3U8AttributeInstance, bool>)(a => a.Attribute == attribute)) as TInstance);
 }
 public static IEnumerable <M3U8AttributeInstance> Attributes(this M3U8TagInstance tagInstance, M3U8Attribute attribute)
 {
     return(Enumerable.Where <M3U8AttributeInstance>(M3U8TagInstanceExtensions.Attributes(tagInstance), (Func <M3U8AttributeInstance, bool>)(a => a.Attribute == attribute)));
 }