Пример #1
0
        public async Task GetVideoUrlForFeelAgain()
        {
            var result = await _videoUrlCrawler.GetUrlBySingleContentId(
                await _videoInfoCrawler.GetVideoInfo("av349183"));

            Assert.NotNull(result);
            Assert.NotEqual(0, result.Durl.Count);

            _PrintUrl(result);
        }
Пример #2
0
        public async Task WhatMakesYouBeautifulMvTest()
        {
            // Video URL: http://www.bilibili.com/video/av3355175/
            // Video is "What makes ou beautiful", Content ID 5309628
            Console.WriteLine("[TEST] Running test for av3355175...");
            var videoInfoForAv3355175 = await videoInfoCrawler.GetVideoInfo("av3355175");

            // Validate the beautiful result and see if it correct content ID
            Assert.NotNull(videoInfoForAv3355175);
            Assert.True(videoInfoForAv3355175.ContentId.Equals("5309628"));
        }
Пример #3
0
        /// <summary>
        ///     Generate video link
        ///     Note:
        ///     1. UserAgent (MSIE10) and Referrer must be set to the downloader, otherwise server will return 500
        ///     2. Exception may be raised if something goes wrong (e.g. no video found)
        /// </summary>
        /// <param name="contentUrl"></param>
        /// <returns></returns>
        private async Task <List <string> > GenerateGeneralVideoLink(string contentUrl)
        {
            // BGetCore library related stuff
            var videoInfoCrawler = new VideoInfoCrawler();
            var videoInfo        = await videoInfoCrawler.GetVideoInfo(contentUrl);

            var videoUrlGrabber = new VideoUrlCrawler();
            var videoUrl        = await videoUrlGrabber.GetUrlBySingleContentId(videoInfo);

            var urlList = new List <string>();

            // Just a practice of LINQ...
            if (Settings.Default.PreferFlv)
            {
                videoUrl.Durl.ForEach(url => urlList.Add(url.Url));
            }
            else
            {
                urlList.AddRange(
                    videoUrl.Durl.Where(url => url.BackupUrl != null && url.BackupUrl.Url.Count != 0)
                    .SelectMany(url => url.BackupUrl.Url));
            }

            return(urlList);
        }
Пример #4
0
        private static void Main(string[] args)
        {
            Console.Write("[INFO] Enter your video ID, e.g. av349183: ");
            var inputVideo = Console.ReadLine();

            Console.WriteLine("[INFO] Please wait...");

            var videoInfoCrawler = new VideoInfoCrawler();
            var videoInfo        = videoInfoCrawler.GetVideoInfo(inputVideo).Result;
            var cid = videoInfo.ContentId;

            Console.WriteLine("[DEBUG] CID is " + cid);
            Console.WriteLine("[INFO] Title: " + videoInfo.Title);
            Console.WriteLine("[INFO] Author: " + videoInfo.Author);
            Console.WriteLine("[INFO] Description: " + videoInfo.Description + "\n\n\n");

            var videoUrlGrabber = new VideoUrlCrawler();
            var videoUrl        = videoUrlGrabber.GetUrlBySingleContentId(videoInfo).Result;

            Console.WriteLine("[INFO] Got {0} video sections.", videoUrl.Durl.Count);


            foreach (var url in videoUrl.Durl)
            {
                Console.WriteLine("[INFO] Flash video URL: {0}", url.Url);

                if (url.BackupUrl != null && url.BackupUrl.Url.Count != 0)
                {
                    foreach (var mp4Url in url.BackupUrl.Url)
                    {
                        Console.WriteLine("[INFO] MP4 backup video URL: {0}", mp4Url);
                    }
                }
            }


            Console.Read();
        }
Пример #5
0
        public async Task <List <VideoInfo> > GetAllVideoInfoByKeyword(string keyword, bool deepSearch = false)
        {
            // Set initial page from page 1
            var pageCount     = 1;
            var videoInfoList = new List <VideoInfo>();
            var searchResult  = await SearchByKeyword(keyword, SearchType.Video, pageCount);

            // "Iterate" the pages
            while (searchResult.IsSuccessful)
            {
                // Parse HTML content
                var htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(searchResult.RawHtml);

                // Get Video URLs and titles
                var videoTitleAndUrlNodes = htmlDoc.DocumentNode.SelectNodes("//a[@class=\"title\"]");

                // Deep search will (wayyyyyyy much) slower the fetching speed, so it's not recommend unless tag is required.
                if (deepSearch)
                {
                    var videoInfoCrawler = new VideoInfoCrawler();

                    // The URL does not have its initial "https:", instead it starts with "//www.bilibili.com".
                    // As a result, append a "https:" before it before further crawling.
                    foreach (var singleNode in videoTitleAndUrlNodes)
                    {
                        var url = string.Format("https:{0}", singleNode.Attributes["href"].Value);
                        videoInfoList.Add(await videoInfoCrawler.GetVideoInfo(url));
                    }
                }
                else
                {
                    // Get video descriptions
                    var videoDescriptionNodes = htmlDoc.DocumentNode.SelectNodes("//div[@class=\"des hide\"]");

                    // Get video uploaders
                    var videoUploaderNodes = htmlDoc.DocumentNode.SelectNodes("//a[@class=\"up-name\"]");

                    // Iterate all video info from result (without tags)
                    videoInfoList.AddRange(videoDescriptionNodes.Select((t, videoCountIndex) => new VideoInfo
                    {
                        // Extract author ID from URL
                        Author = Regex.Match(videoUploaderNodes[videoCountIndex].Attributes["href"].Value,
                                             @"\/(\d+)\?").Groups[1].Value,

                        // Extract description, new lines and tabs are removed
                        Description = Regex.Match(t.InnerText, "[^\t|\n|\r]+").Value,

                        // Extract video URL
                        VideoPage = string.Format("https:{0}",
                                                  videoTitleAndUrlNodes[videoCountIndex].Attributes["href"].Value),

                        // Extract video ID
                        ContentId = Regex.Match(videoTitleAndUrlNodes[videoCountIndex].Attributes["href"].Value,
                                                @"\/av(\d+)\?").Groups[1].Value,

                        // Extract title
                        Title = videoTitleAndUrlNodes[videoCountIndex].Attributes["title"].Value
                    }));
                }

                // Update page count and move to next page...
                searchResult = await SearchByKeyword(keyword, SearchType.Video, ++pageCount);
            }

            return(videoInfoList);
        }