Пример #1
0
        private async Task <ChannelItemResult> GetChannelItemsInternal(InternalChannelItemQuery query, CancellationToken cancellationToken)
        {
            var offset     = query.StartIndex.GetValueOrDefault();
            var downloader = new TwitChannelItemsDownloader(_logger, _xmlSerializer, _httpClient);

            var baseurl = "http://feeds.twit.tv/" + query.FolderId + "_video_hd.xml";

            var videos = await downloader.GetStreamList(baseurl, offset, cancellationToken)
                         .ConfigureAwait(false);

            var itemslist = videos.channel.item;

            var items = new List <ChannelItemInfo>();

            foreach (var i in itemslist)
            {
                var mediaInfo = new List <ChannelMediaInfo>
                {
                    new ChannelMediaInfo
                    {
                        Protocol = MediaProtocol.Http,
                        Path     = i.link,
                        Width    = 1280,
                        Height   = 720,
                    }
                };

                var runtimeArray = i.duration.Split(':');
                int hours;
                int minutes;
                int.TryParse(runtimeArray[0], out hours);
                int.TryParse(runtimeArray[1], out minutes);
                long runtime = (hours * 60) + minutes;
                runtime = TimeSpan.FromMinutes(runtime).Ticks;

                items.Add(new ChannelItemInfo
                {
                    ContentType      = ChannelMediaContentType.Podcast,
                    ImageUrl         = "http://feeds.twit.tv/coverart/" + query.FolderId + "600.jpg",
                    IsInfiniteStream = true,
                    MediaType        = ChannelMediaType.Video,
                    MediaSources     = mediaInfo,
                    RunTimeTicks     = runtime,
                    Name             = i.title,
                    Id          = i.link,
                    Type        = ChannelItemType.Media,
                    DateCreated = !String.IsNullOrEmpty(i.pubDate) ?
                                  Convert.ToDateTime(i.pubDate) : (DateTime?)null,
                    PremiereDate = !String.IsNullOrEmpty(i.pubDate) ?
                                   Convert.ToDateTime(i.pubDate) : (DateTime?)null,
                    Overview = i.summary,
                });
            }

            return(new ChannelItemResult
            {
                Items = items,
                TotalRecordCount = items.Count,
            });
        }
Пример #2
0
        private async Task <ChannelItemResult> GetChannelItemsInternal(InternalChannelItemQuery query, CancellationToken cancellationToken)
        {
            var offset     = query.StartIndex.GetValueOrDefault();
            var downloader = new TwitChannelItemsDownloader(_logger, _xmlSerializer, _httpClient);

            var baseurl = "http://feeds.twit.tv/" + query.FolderId + "_video_hd.xml";

            var videos = await downloader.GetStreamList(baseurl, offset, cancellationToken)
                         .ConfigureAwait(false);

            var itemslist = videos.channel.item;

            var items = new List <ChannelItemInfo>();

            _logger.Info("Twit found {0} items under folder {1}", itemslist.Length, query.FolderId);

            foreach (var i in itemslist)
            {
                var mediaInfo = new List <MediaSourceInfo>
                {
                    new ChannelMediaInfo
                    {
                        Protocol  = MediaProtocol.Http,
                        Path      = i.enclosure.url,
                        Width     = 1280,
                        Height    = 720,
                        Container = Container.MP4,
                    }.ToMediaSource()
                };

                if (!long.TryParse(i.duration, out long runtime))
                {
                    var runtimeArray = i.duration.Split(':');
                    int hours        = 0;
                    int minutes      = 0;
                    int seconds      = 0;

                    if (runtimeArray.Length == 3)
                    {
                        int.TryParse(runtimeArray[0], out hours);
                        int.TryParse(runtimeArray[1], out minutes);
                        int.TryParse(runtimeArray[2], out seconds);
                    }
                    else if (runtimeArray.Length == 2)
                    {
                        int.TryParse(runtimeArray[0], out minutes);
                        int.TryParse(runtimeArray[1], out seconds);
                    }
                    runtime = (hours * 3600) + (minutes * 60) + seconds;
                }
                runtime = TimeSpan.FromSeconds(runtime).Ticks;


                try
                {
                    items.Add(new ChannelItemInfo
                    {
                        ContentType = ChannelMediaContentType.Podcast,
                        ImageUrl    = (i.content != null && !String.IsNullOrEmpty(i.content.thumbnail.FirstOrDefault().url)) ?
                                      i.content.thumbnail.FirstOrDefault().url : "http://feeds.twit.tv/coverart/" + query.FolderId + "600.jpg",
                        MediaType    = ChannelMediaType.Video,
                        MediaSources = mediaInfo,
                        RunTimeTicks = runtime,
                        Name         = i.title,
                        Id           = i.link,
                        Type         = ChannelItemType.Media,
                        DateCreated  = !String.IsNullOrEmpty(i.pubDate) ?
                                       Convert.ToDateTime(i.pubDate.Substring(0, 25)) : (DateTime?)null,
                        PremiereDate = !String.IsNullOrEmpty(i.pubDate) ?
                                       Convert.ToDateTime(i.pubDate.Substring(0, 25)) : (DateTime?)null,
                        Overview = StripTags(i.summary),
                    });
                }
                catch (Exception x)
                {
                    _logger.Debug("TWiT caught exception {0} when adding ChannelItemInfo for {1}", x.Message, i.title);
                }
            }
            return(new ChannelItemResult
            {
                Items = items,
                TotalRecordCount = items.Count,
            });
        }