Пример #1
0
        public static void Build(FetcherTaskToken token)
        {
            var jsonVideoInfo = NetworkHelper.GetTextFromUri(token.ToUri());

            if (jsonVideoInfo.Length > 100)
            {
                var       videoInfo = JsonConvert.DeserializeObject <VideoInfo>(jsonVideoInfo);
                VideoTask newTask   = GetVideoTask(token, videoInfo);

                var settings = Data.ApplicationSettings.GetInstance();

                settings.Dispatcher.Invoke(delegate
                {
                    Data.FetchingTasks.AddTask(newTask);
                });

                var task = new Task(() => { GetDownloadUrl(newTask); });

                // TODO: 改用后台进程/进程池实现
                task.Start();
            }
            else
            {
                var errorMsg = JsonConvert.DeserializeObject <ServerSideException>(jsonVideoInfo);
                Data.NotificationData.AddErrorNotifiction(errorMsg);
            }
        }
Пример #2
0
        /// <summary>
        /// 由av号和起始,结束分段号建立批量任务
        /// </summary>
        /// <param name="aid">av号</param>
        /// <param name="start">开始分段,从1开始,小于1时,将会从第一个分段开始</param>
        /// <param name="end">结束分段,大于总分段数时,将从start一直下载到最后一个分段</param>
        /// <exception cref="ArgumentOutOfRangeException">分段数不合理时,将引发ArgumentOutOfRangeException</exception>
        public static void Build(string aid, int start = 1, int end = int.MaxValue)
        {
            string json = NetworkHelper.GetTextFromUri(VIDEO_INFO_API + aid + "&page=" + 1);

            if (json.Length > 100)
            {
                var videoInfo = JsonConvert.DeserializeObject <VideoInfo>(json);

                if (start > videoInfo.pages)
                {
                    throw new ArgumentOutOfRangeException("页面范围无效");
                    //Data.NotificationData.AddErrorNotifiction("页面范围无效!");
                    //return;
                }
                // 当start小于1时,取1作为起始分段
                start = Math.Max(start, 1);
                // 当end大于总分段数时,取总分段数作为结束分段
                end = Math.Min(end, videoInfo.pages);
                var aids = new FetcherTaskToken[end - start + 1];
                int j    = 0;
                for (int i = start; i <= end; i++)
                {
                    aids[j++] = new FetcherTaskToken(aid, i);
                }
                Parallel.ForEach(aids, (i) => { Build(i); });
            }
            else
            {
                var errorMsg = JsonConvert.DeserializeObject <ServerSideException>(json);
                throw errorMsg;
                //Data.NotificationData.AddErrorNotifiction(errorMsg);
            }
        }
 public static void CreateTask(FetcherTaskToken token)
 {
     Task.Run(() => TaskBuilder.Build(token));
     Data.NotificationData.AddNotifiction(NotificationLevel.Info, $"任务aid{token.Aid}已开始解析! 请稍等.");
     //new Thread(delegate ()
     //{
     //    TaskBuilder.Build(token);
     //}).Start();
 }
Пример #4
0
        private static VideoTask GetVideoTask(FetcherTaskToken token, VideoInfo videoInfo)
        {
            var newTask = new VideoTask(token)
            {
                VideoInfo = videoInfo,
                State     = FetchState.Waiting,

                Name     = videoInfo.title,
                Partname = videoInfo.partname,

                DownloadUrl = new List <string>(),
                Danmu       = "http://comment.bilibili.com/" + videoInfo.cid + ".xml"
            };

            return(newTask);
        }
 public NewTaskRequestEventArgs(FetcherTaskToken token)
 {
     this.Token = token;
 }
 public bool Equals(FetcherTaskToken other)
 {
     return(this.Aid.Equals(other.Aid) && this.PartIndex.Equals(other.PartIndex));
 }