private async void DownLoadBigPic(DetailMovie dm) { HttpStatusCode sc = HttpStatusCode.Forbidden; if (dm.bigimageurl != "") { (bool success, string cookie) = await Task.Run(() => { return(MyNet.DownLoadImage(dm.bigimageurl, ImageType.BigImage, dm.id, callback: (statuscode) => { sc = (HttpStatusCode)statuscode; })); }); if (success) { BigImageDownLoadCompleted?.Invoke(this, new MessageCallBackEventArgs(dm.id)); } else { MessageCallBack?.Invoke(this, new MessageCallBackEventArgs($"{Jvedio.Language.Resources.DownloadBPicFailFor} {sc.ToStatusMessage()} {Jvedio.Language.Resources.Message_ViewLog}")); } } InfoUpdate?.Invoke(this, new DetailMovieEventArgs() { DetailMovie = dm, value = Value, maximum = Maximum }); }
private async void DownLoadExtraPic(DetailMovie dm) { List <string> urlList = dm.extraimageurl?.Split(';').Where(arg => arg.IsProperUrl()).ToList(); bool dlimageSuccess = false; string cookies = ""; for (int i = 0; i < urlList.Count(); i++) { HttpStatusCode sc = HttpStatusCode.Forbidden; if (cts.IsCancellationRequested) { CancelEvent?.Invoke(this, EventArgs.Empty); break; } string filepath = ""; filepath = BasePicPath + "ExtraPic\\" + dm.id + "\\" + Path.GetFileName(new Uri(urlList[i]).LocalPath); if (!File.Exists(filepath)) { (dlimageSuccess, cookies) = await Task.Run(() => { return(MyNet.DownLoadImage(urlList[i], ImageType.ExtraImage, dm.id, Cookie: cookies, callback: (statuscode) => { sc = (HttpStatusCode)statuscode; })); }); if (dlimageSuccess) { ExtraImageDownLoadCompleted?.Invoke(this, new MessageCallBackEventArgs(filepath)); if (urlList[i].IndexOf("dmm") > 0) { Thread.Sleep(Delay.MEDIUM); } else { Thread.Sleep(Delay.SHORT_3); } } else { Logger.LogN($" {Jvedio.Language.Resources.Preview} {i + 1} {Jvedio.Language.Resources.Message_Fail}:{urlList[i]}, {Jvedio.Language.Resources.Reason} : {sc.ToStatusMessage()}"); MessageCallBack?.Invoke(this, new MessageCallBackEventArgs($" {Jvedio.Language.Resources.Preview} {i + 1} {Jvedio.Language.Resources.Message_Fail},{Jvedio.Language.Resources.Reason} :{sc.ToStatusMessage()} ,{Jvedio.Language.Resources.Message_ViewLog}")); } } lock (lockobject) Value += 1; InfoUpdate?.Invoke(this, new DetailMovieEventArgs() { DetailMovie = dm, value = Value, maximum = Maximum }); } lock (lockobject) Value = Maximum; InfoUpdate?.Invoke(this, new DetailMovieEventArgs() { DetailMovie = dm, value = Value, maximum = Maximum }); IsDownLoading = false; }
private async void DownLoadSmallPic(DetailMovie dm) { HttpStatusCode sc = HttpStatusCode.Forbidden; if (dm.smallimageurl != "") { (bool success, string cookie) = await Task.Run(() => { return(MyNet.DownLoadImage(dm.smallimageurl, ImageType.SmallImage, dm.id, callback: (statuscode) => { sc = (HttpStatusCode)statuscode; })); }); if (success) { SmallImageDownLoadCompleted?.Invoke(this, new MessageCallBackEventArgs(dm.id)); } else { MessageCallBack?.Invoke(this, new MessageCallBackEventArgs($"{Jvedio.Language.Resources.DownloadSPicFailFor} {sc.ToStatusMessage()} {Jvedio.Language.Resources.Message_ViewLog}")); } } }
private async void DownLoad(object o) { //下载信息 Movie movie = o as Movie; if (movie.id.ToUpper().StartsWith("FC2")) { SemaphoreFC2.WaitOne(); } else { Semaphore.WaitOne();//阻塞 } if (Cancel || string.IsNullOrEmpty(movie.id)) { if (movie.id.ToUpper().StartsWith("FC2")) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } return; } //下载信息 State = DownLoadState.DownLoading; if (movie.IsToDownLoadInfo() || enforce) { //满足一定条件才下载信息 HttpResult httpResult = await MyNet.DownLoadFromNet(movie); if (httpResult != null) { if (httpResult.Success) { InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = movie, progress = downLoadProgress.value, Success = httpResult.Success }); //委托到主界面显示 } else { string error = httpResult.Error != "" ? httpResult.Error : httpResult.StatusCode.ToStatusMessage(); MessageCallBack?.Invoke(this, new MessageCallBackEventArgs($" {movie.id} {Jvedio.Language.Resources.DownloadMessageFailFor}:{error}")); } } } DetailMovie dm = DataBase.SelectDetailMovieById(movie.id); if (dm == null) { if (movie.id.ToUpper().StartsWith("FC2")) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } return; } if (!File.Exists(BasePicPath + $"BigPic\\{dm.id}.jpg") || enforce) { await MyNet.DownLoadImage(dm.bigimageurl, ImageType.BigImage, dm.id);//下载大图 } //fc2 没有缩略图 if (dm.id.IndexOf("FC2") >= 0) { //复制海报图作为缩略图 if (File.Exists(BasePicPath + $"BigPic\\{dm.id}.jpg") && !File.Exists(BasePicPath + $"SmallPic\\{dm.id}.jpg")) { FileHelper.TryCopyFile(BasePicPath + $"BigPic\\{dm.id}.jpg", BasePicPath + $"SmallPic\\{dm.id}.jpg"); } } else { if (!File.Exists(BasePicPath + $"SmallPic\\{dm.id}.jpg") || enforce) { await MyNet.DownLoadImage(dm.smallimageurl, ImageType.SmallImage, dm.id); //下载小图 } } dm.smallimage = ImageProcess.GetBitmapImage(dm.id, "SmallPic"); InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = dm, progress = downLoadProgress.value, state = State }); //委托到主界面显示 dm.bigimage = ImageProcess.GetBitmapImage(dm.id, "BigPic"); lock (downLoadProgress.lockobject) downLoadProgress.value += 1; //完全下载完一个影片 InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = dm, progress = downLoadProgress.value, state = State, Success = true }); //委托到主界面显示 Task.Delay(Delay.MEDIUM).Wait(); //每个线程之间暂停 //取消阻塞 if (movie.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } }