예제 #1
0
        /// <summary>
        ///     Generate video links for all videos from a certain user.
        ///     This method may costs quite a long time. As a result, a IProgess is implemented to retrieve the status
        ///     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)
        ///     3. Status reporting example is here:
        ///     https://stackoverflow.com/questions/19980112/how-to-do-progress-reporting-using-async-await/19980151#19980151
        ///     It's a two-element double array. The first is the page status and the second is the video status
        /// </summary>
        /// <param name="contentUrl"></param>
        /// <param name="progressStatus"></param>
        /// <returns></returns>
        private async Task <List <string> > GenerateUserVideoLink(string contentUrl, IProgress <double[]> progressStatus)
        {
            // BGet library related stuff
            var userVideoGrabber = new UserVideoGrabber();
            var userVideoResult  = await userVideoGrabber.GetAllVideoFromUser(contentUrl);

            // Create a list to get all video links
            var urlList = new List <string>();

            for (var currentVideoPage = 0; currentVideoPage < userVideoResult.Count; currentVideoPage++)
            {
                for (var currentVideo = 0;
                     currentVideo < userVideoResult[currentVideoPage].UploadedVideo.VideoList.Count;
                     currentVideo++)
                {
                    var video = userVideoResult[currentVideoPage].UploadedVideo.VideoList[currentVideo];
                    urlList.AddRange(await GenerateGeneralVideoLink(video.ContentId));

                    // Report the status
                    progressStatus.Report(
                        new[]
                    {
                        currentVideoPage / (double)userVideoResult.Count,
                        currentVideo / (double)userVideoResult[currentVideoPage].UploadedVideo.VideoList.Count
                    });
                }
            }

            return(urlList);
        }
예제 #2
0
 public BgetUserVideoTest()
 {
     _userVideoGrabber = new UserVideoGrabber();
 }