Example #1
0
        /// <summary>
        /// 获取任务的大小和下载地址
        /// </summary>
        /// <param name="newTask"></param>
        private static void GetDownloadUrl(VideoTask newTask)
        {
            var cid = newTask.VideoInfo.cid;

            if (AdvanceSettings.UseNativeApi)
            {
                BilibiliVideoInfo info = GetVideoInfoFromNativeApi(cid);
                if (info.Code < 0)
                {
                    throw new ServerSideException(info.Code, info.Result);
                }
                AppendFileSystemInfo(newTask, info);
                return;
            }

            var settings = ApplicationSettings.GetInstance();
            var downJson = NetworkHelper.GetTextFromUri(
                DOWNLOAD_API + cid + "?quality=1&type=" + settings.FetchingOption.Format);

            if (downJson.Length < 100)
            {
                NotificationData.AddErrorNotifiction(
                    "无法获取cid:" + cid + "的下载地址, 可能是非bilibili源的缘故");
                newTask.State = FetchState.Error;
                return;
            }
            var jvd = JsonConvert.DeserializeObject <jsonVideoDownload>(downJson);

            if (settings.FetchingOption.Quality == "high")
            {
                var quality = jvd.accept_quality.OrderByDescending(t => t).First();
                downJson = NetworkHelper.GetTextFromUri(
                    DOWNLOAD_API + newTask.VideoInfo.cid + "?quality=" + quality);
                jvd = JsonConvert.DeserializeObject <jsonVideoDownload>(downJson);
            }

            if (jvd.durl.Count == 0)
            {
                NotificationData.AddErrorNotifiction(
                    "无法获取cid:" + cid + "的下载地址, durl.count = 0");
                newTask.State = FetchState.Error;
                return;
            }

            AppendFileSystemInfo(newTask, jvd);

            NotificationData.AddNotifiction(
                NotificationLevel.Info,
                "成功获取cid:" + cid + "的下载地址, 请复制下载地址到其它软件下载");
        }
 private void WaitForClose(Window dialog)
 {
     do
     {
         try
         {
             dialog.ShowDialog();
         }
         catch (ArgumentException ex)
         {
             NotificationData.AddErrorNotifiction(ex.Message);
         }
         catch (NotSupportedException ex)
         {
             NotificationData.AddErrorNotifiction(ex.Message);
         }
     } while (dialog.Visibility == Visibility.Visible);
 }
 private void Dialog_ErrorCaptured(object sender, string e)
 {
     NotificationData.AddErrorNotifiction(e);
 }