Exemplo n.º 1
0
        private List <ChannelMediaInfo> GetMediaInfo(IEnumerable <HtmlNode> nodes, string html)
        {
            var links = nodes.Select(i => i.GetAttributeValue("href", ""))
                        .Where(i => !string.IsNullOrWhiteSpace(i))
                        .ToList();

            var list = new List <ChannelMediaInfo>();

            foreach (var link in links)
            {
                if (ValidContainers.Any(i => link.EndsWith(i, StringComparison.OrdinalIgnoreCase)))
                {
                    //_logger.Debug("Found url: " + link);

                    var url = link;

                    if (!url.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                    {
                        url = BaseUrl + url.TrimStart('/');
                    }

                    list.Add(new ChannelMediaInfo
                    {
                        Container           = Path.GetExtension(link).TrimStart('.'),
                        Path                = url,
                        Protocol            = MediaProtocol.Http,
                        RequiredHttpHeaders = GetRequiredHttpHeaders(url),
                        SupportsDirectPlay  = false
                    });
                }
            }

            return(list
                   .Where(i => IsValidDomain(i.Path))
                   .Select(SetValues)
                   .ToList());
        }
Exemplo n.º 2
0
        private List <ChannelMediaInfo> GetMediaInfo(IEnumerable <HtmlNode> nodes, string html)
        {
            var links = nodes.Select(i => i.GetAttributeValue("href", ""))
                        .Where(i => !string.IsNullOrWhiteSpace(i))
                        .ToList();

            var list = new List <ChannelMediaInfo>();

            foreach (var link in links)
            {
                if (ValidContainers.Any(i => link.EndsWith(i, StringComparison.OrdinalIgnoreCase)))
                {
                    //_logger.Debug("Found url: " + link);

                    var url = link;

                    if (!url.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                    {
                        url = BaseUrl + url.TrimStart('/');
                    }

                    list.Add(new ChannelMediaInfo
                    {
                        Container           = Path.GetExtension(link).TrimStart('.'),
                        Path                = url,
                        Protocol            = MediaProtocol.Http,
                        RequiredHttpHeaders = GetRequiredHttpHeaders(url),
                        SupportsDirectPlay  = false
                    });
                }
            }

            const string srch  = "file: \"";
            var          start = 0;
            var          index = html.IndexOf(srch, start, StringComparison.OrdinalIgnoreCase);

            while (index != -1)
            {
                var subString = html.Substring(index + srch.Length);
                var endIndex  = subString.IndexOf("\"", StringComparison.OrdinalIgnoreCase);

                if (endIndex == -1)
                {
                    break;
                }

                var url = subString.Substring(0, endIndex);

                //_logger.Debug("Found url: " + url);

                list.Add(new ChannelMediaInfo
                {
                    Container           = Path.GetExtension(url).TrimStart('.'),
                    Path                = url,
                    Protocol            = MediaProtocol.Http,
                    RequiredHttpHeaders = GetRequiredHttpHeaders(url),
                    SupportsDirectPlay  = false
                });

                start = index + srch.Length;
                index = html.IndexOf(srch, start, StringComparison.OrdinalIgnoreCase);
            }

            return(list
                   .Where(i => IsValidDomain(i.Path))
                   .Select(SetValues)
                   .ToList());
        }