示例#1
0
        public static IVideoItem CreateVideoItem(VideoItemPOCO poco,
                                                 SiteType site,
                                                 bool isJoinName  = false,
                                                 SyncState sstate = SyncState.Notset)
        {
            IVideoItem vi;

            switch (site)
            {
            case SiteType.YouTube:
                vi = new YouTubeItem
                {
                    ID             = poco.ID,
                    Title          = poco.Title,
                    ParentID       = poco.ParentID,
                    Description    = poco.Description,  // .WordWrap(80);
                    ViewCount      = poco.ViewCount,
                    Duration       = poco.Duration,
                    Comments       = poco.Comments,
                    Thumbnail      = poco.Thumbnail,
                    Timestamp      = poco.Timestamp,
                    LikeCount      = poco.LikeCount,
                    DislikeCount   = poco.DislikeCount,
                    ViewDiff       = poco.ViewDiff,
                    SyncState      = sstate == SyncState.Notset ? (SyncState)poco.SyncState : sstate,
                    WatchState     = (WatchState)poco.WatchState,
                    DurationString = StringExtensions.IntTostrTime(poco.Duration),
                    DateTimeAgo    = StringExtensions.TimeAgo(poco.Timestamp),
                    Subtitles      = new ObservableCollection <ISubtitle>(),
                    ParentTitle    = isJoinName ? poco.ParentName : string.Empty
                };
                break;

            case SiteType.Tapochek:
                vi = new TapochekItem();
                break;

            case SiteType.RuTracker:
                vi = new RuTrackerItem();
                break;

            default:
                vi = null;
                break;
            }
            return(vi);
        }
示例#2
0
        public static async Task <IVideoItem> GetVideoItemNetAsync(string id, SiteType site)
        {
            try
            {
                VideoItemPOCO poco = null;
                switch (site)
                {
                case SiteType.YouTube:
                    poco = await YouTubeSite.GetVideoItemNetAsync(id).ConfigureAwait(false);

                    break;
                }
                IVideoItem vi = CreateVideoItem(poco, site);
                return(vi);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public async Task GetVideoItemNetAsync()
        {
            VideoItemPOCO res = await YouTubeSite.GetVideoItemNetAsync("lHgIpxQac3w").ConfigureAwait(false); //

            Assert.AreEqual(res.Title, "Metallica — Unforgiven (FDM edition)");
        }
示例#4
0
        private static void FillVideoItemPOCO(VideoItemPOCO item, HtmlNode node, string site)
        {
            IEnumerable <HtmlNode> dl =
                node.Descendants("a").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Equals("small tr-dl"));

            foreach (HtmlNode htmlNode in dl)
            {
                string   videoLink = string.Format("{0}{1}", site, htmlNode.Attributes["href"].Value.TrimStart('.'));
                string[] sp        = videoLink.Split('=');
                if (sp.Length == 2)
                {
                    item.ID = sp[1];
                }

                // Duration = GetTorrentSize(ScrubHtml(htmlNode.InnerText));
                break;
            }

            IEnumerable <HtmlNode> counts =
                node.Descendants("a").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Equals("genmed"));

            foreach (HtmlNode htmlNode in counts)
            {
                item.Title = HttpUtility.HtmlDecode(htmlNode.InnerText).Trim();
                break;
            }

            IEnumerable <HtmlNode> prov =
                node.Descendants("td")
                .Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Equals("row4 small nowrap"));

            foreach (HtmlNode htmlNode in prov)
            {
                List <HtmlNode> pdate = htmlNode.Descendants("p").ToList();
                if (pdate.Count == 2)
                {
                    item.Timestamp = Convert.ToDateTime(pdate[1].InnerText);
                    break;
                }
            }

            IEnumerable <HtmlNode> seemed =
                node.Descendants("td").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Equals("row4 seedmed"));

            foreach (HtmlNode htmlNode in seemed)
            {
                item.ViewCount = Convert.ToInt32(htmlNode.InnerText);
                break;
            }

            IEnumerable <HtmlNode> med =
                node.Descendants("td").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Equals("row4 small"));

            foreach (HtmlNode htmlNode in med)
            {
                item.Comments = Convert.ToInt32(htmlNode.InnerText);
                break;
            }

            IEnumerable <HtmlNode> user =
                node.Descendants("a").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Equals("med"));

            foreach (HtmlNode htmlNode in user)
            {
                string   uid = htmlNode.Attributes["href"].Value;
                string[] sp  = uid.Split('=');
                if (sp.Length == 2)
                {
                    item.ParentID = sp[1];
                }

                // VideoOwnerName = htmlNode.InnerText;
                break;
            }

            IEnumerable <HtmlNode> forum =
                node.Descendants("a").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Equals("gen"));

            foreach (HtmlNode htmlNode in forum)
            {
                item.Description = htmlNode.InnerText;
                break;
            }

            // var topic = node.Descendants("a").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Equals("genmed"));
            // foreach (HtmlNode htmlNode in topic)
            // {
            // PlaylistID = string.Format("http://{0}/forum{1}", site, htmlNode.Attributes["href"].Value.TrimStart('.'));
            // break;
            // }
        }
示例#5
0
        /// <summary>
        ///     Get user releases. 0 - all
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="maxresult"></param>
        /// <returns></returns>
        public async Task <IEnumerable <VideoItemPOCO> > GetChannelItemsAsync(IChannel channel, int maxresult)
        {
            var    lst = new List <VideoItemPOCO>();
            string zap = string.Format("{0}={1}", userUrl, channel.ID);

            string page = await SiteHelper.DownloadStringWithCookieAsync(new Uri(zap), channel.ChannelCookies);

            var doc = new HtmlDocument();

            doc.LoadHtml(page);

            List <HtmlNode> links =
                doc.DocumentNode.Descendants("tr")
                .Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Equals("tCenter"))
                .ToList();

            foreach (HtmlNode node in links)
            {
                var item = new VideoItemPOCO();
                FillVideoItemPOCO(item, node, hostUrl);
                if (!string.IsNullOrEmpty(item.ID))
                {
                    lst.Add(item);
                }
            }

            if (maxresult == 0)
            {
                Thread.Sleep(500);

                IEnumerable <string> searchlinks = GetAllSearchLinks(doc);

                foreach (string link in searchlinks)
                {
                    page = await SiteHelper.DownloadStringWithCookieAsync(new Uri(link), channel.ChannelCookies);

                    doc = new HtmlDocument();

                    doc.LoadHtml(page);

                    links =
                        doc.DocumentNode.Descendants("tr")
                        .Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Equals("tCenter"))
                        .ToList();

                    foreach (HtmlNode node in links)
                    {
                        var item = new VideoItemPOCO();
                        FillVideoItemPOCO(item, node, hostUrl);
                        if (!string.IsNullOrEmpty(item.ID))
                        {
                            lst.Add(item);
                        }
                    }
                }

                Thread.Sleep(500);
            }

            return(lst);
        }