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 }); }
public void UpdateInfo(int timeout) { Info info = GetInfo(timeout); if (info != null && info.GetHashCode() != CurrentInfo.GetHashCode()) { CurrentInfo = info; InfoUpdate?.Invoke(CurrentInfo); } }
public async void DownLoad() { IsDownLoading = true; //下载信息 if (DetailMovie.IsToDownLoadInfo()) { HttpResult httpResult = await Net.DownLoadFromNet(DetailMovie); if (httpResult != null) { if (!httpResult.Success) { string error = httpResult.Error != "" ? httpResult.Error : httpResult.StatusCode.ToStatusMessage(); MessageCallBack?.Invoke(this, new MessageCallBackEventArgs($" {DetailMovie.id} {Jvedio.Language.Resources.DownloadMessageFailFor}:{error}")); } } } DetailMovie dm = new DetailMovie(); dm = DataBase.SelectDetailMovieById(DetailMovie.id); if (string.IsNullOrEmpty(dm.title)) { InfoUpdate?.Invoke(this, new DetailMovieEventArgs() { DetailMovie = dm, value = 1, maximum = 1 }); return; } InfoUpdate?.Invoke(this, new DetailMovieEventArgs() { DetailMovie = dm, value = Value, maximum = Maximum }); InfoDownloadCompleted?.Invoke(this, new MessageCallBackEventArgs(DetailMovie.id)); if (!File.Exists(BasePicPath + $"BigPic\\{dm.id}.jpg")) { DownLoadBigPic(dm); //下载大图 } if (!File.Exists(BasePicPath + $"SmallPic\\{dm.id}.jpg")) { DownLoadSmallPic(dm); //下载小图 } List <string> urlList = new List <string>(); foreach (var item in dm.extraimageurl?.Split(';')) { if (!string.IsNullOrEmpty(item)) { urlList.Add(item); } } Maximum = urlList.Count() == 0 ? 1 : urlList.Count; DownLoadExtraPic(dm);//下载预览图 }
private async void DownLoad(object o) { Semaphore.WaitOne(); Actress actress = o as Actress; if (Cancel | actress.id == "") { Semaphore.Release(); return; } try { this.State = DownLoadState.DownLoading; //下载头像 if (!string.IsNullOrEmpty(actress.imageurl)) { string url = actress.imageurl; byte[] imageBytes = null; imageBytes = await Task.Run(() => { return(Net.DownLoadFile(url).filebytes); }); if (imageBytes != null) { ImageProcess.SaveImage(actress.name, imageBytes, ImageType.ActorImage, url); actress.smallimage = ImageProcess.GetBitmapImage(actress.name, "Actresses"); } } //下载信息 bool success = false; success = await Task.Run(() => { Task.Delay(300).Wait(); return(Net.DownActress(actress.id, actress.name, callback: (message) => { MessageCallBack?.Invoke(this, new MessageCallBackEventArgs(message)); })); }); if (success) { actress = DataBase.SelectInfoFromActress(actress); } ProgressBarUpdate.value += 1; InfoUpdate?.Invoke(this, new ActressUpdateEventArgs() { Actress = actress, progressBarUpdate = ProgressBarUpdate, state = State }); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Semaphore.Release(); } }
private async void DownLoadBigPic(DetailMovie dm) { if (dm.bigimageurl != "") { await Task.Run(() => { return(Net.DownLoadImage(dm.bigimageurl, ImageType.BigImage, dm.id)); }); } 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; }
public async void DownLoad() { IsDownLoading = true; //下载信息 if (DetailMovie.title == "" | DetailMovie.bigimageurl == "" | DetailMovie.extraimageurl == "" | DetailMovie.sourceurl == "") { string[] url = new string[] { Properties.Settings.Default.Bus, Properties.Settings.Default.BusEurope, Properties.Settings.Default.DB, Properties.Settings.Default.Library }; bool[] enableurl = new bool[] { Properties.Settings.Default.EnableBus, Properties.Settings.Default.EnableBusEu, Properties.Settings.Default.EnableDB, Properties.Settings.Default.EnableLibrary, Properties.Settings.Default.EnableFC2 }; string[] cookies = new string[] { Properties.Settings.Default.DBCookie }; bool success; string resultMessage; (success, resultMessage) = await Task.Run(() => { return(Net.DownLoadFromNet((Movie)DetailMovie)); }); } DetailMovie dm = new DetailMovie(); DataBase cdb = new DataBase(""); dm = cdb.SelectDetailMovieById(DetailMovie.id); cdb.CloseDB(); InfoUpdate?.Invoke(this, new DetailMovieEventArgs() { DetailMovie = dm, value = Value, maximum = Maximum }); if (!File.Exists(StaticVariable.BasePicPath + $"BigPic\\{dm.id}.jpg")) { DownLoadBigPic(dm); //下载大图 } if (!File.Exists(StaticVariable.BasePicPath + $"SmallPic\\{dm.id}.jpg")) { DownLoadSmallPic(dm); //下载小图 } List <string> urlList = new List <string>(); foreach (var item in dm.extraimageurl?.Split(';')) { if (!string.IsNullOrEmpty(item)) { urlList.Add(item); } } Maximum = urlList.Count() == 0 ? 1 : urlList.Count(); //下载预览图 DownLoadExtraPic(dm); }
private async void DownLoadExtraPic(DetailMovie dm) { List <string> urlList = new List <string>(); foreach (var item in dm.extraimageurl?.Split(';')) { if (!string.IsNullOrEmpty(item)) { urlList.Add(item); } } bool dlimageSuccess = false; string cookies = ""; for (int i = 0; i < urlList.Count(); i++) { if (cts.IsCancellationRequested) { CancelEvent?.Invoke(this, EventArgs.Empty); break; } string filepath = ""; if (urlList[i].Length > 0) { filepath = StaticVariable.BasePicPath + "ExtraPic\\" + dm.id + "\\" + Path.GetFileName(new Uri(urlList[i]).LocalPath); if (!File.Exists(filepath)) { (dlimageSuccess, cookies) = await Task.Run(() => { return(Net.DownLoadImage(urlList[i], ImageType.ExtraImage, dm.id, Cookie: cookies)); }); if (dlimageSuccess) { Thread.Sleep(1500); } } } 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 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 Net.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 Net.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")) { try { File.Copy(BasePicPath + $"BigPic\\{dm.id}.jpg", BasePicPath + $"SmallPic\\{dm.id}.jpg"); } catch (Exception ex) { Logger.LogF(ex); } } } else { if (!File.Exists(BasePicPath + $"SmallPic\\{dm.id}.jpg") || enforce) { await Net.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(DelayInvterval).Wait(); //每个线程之间暂停 //取消阻塞 if (movie.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } }
private async void DownLoad(object o) { //下载信息=>下载图片 Movie movie = o as Movie; try { if (movie.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.WaitOne(); } else { Semaphore.WaitOne(); } if (Cancel | movie.id == "") { return; } bool success; string resultMessage; //下载信息 State = DownLoadState.DownLoading; if (movie.title == "" | movie.smallimageurl == "" | movie.bigimageurl == "" | movie.sourceurl == "") { (success, resultMessage) = await Task.Run(() => { return(Net.DownLoadFromNet(movie)); }); if (success) { InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = movie, progress = downLoadProgress.value }); //委托到主界面显示 } } DetailMovie dm = new DetailMovie(); dm = DataBase.SelectDetailMovieById(movie.id); //下载小图 await DownLoadSmallPic(dm); dm.smallimage = StaticClass.GetBitmapImage(dm.id, "SmallPic"); InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = dm, progress = downLoadProgress.value, state = State }); //委托到主界面显示 if (dm.sourceurl?.IndexOf("fc2club") >= 0) { //复制大图 if (File.Exists(StaticVariable.BasePicPath + $"SmallPic\\{dm.id}.jpg") & !File.Exists(StaticVariable.BasePicPath + $"BigPic\\{dm.id}.jpg")) { File.Copy(StaticVariable.BasePicPath + $"SmallPic\\{dm.id}.jpg", StaticVariable.BasePicPath + $"BigPic\\{dm.id}.jpg"); } } else { //下载大图 await DownLoadBigPic(dm); } dm.bigimage = StaticClass.GetBitmapImage(dm.id, "BigPic"); lock (downLoadProgress.lockobject) downLoadProgress.value += 1; InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = dm, progress = downLoadProgress.value, state = State }); //委托到主界面显示 Task.Delay(1000).Wait(); } catch (Exception e) { Logger.LogE(e); } finally { if (movie.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } } }
private async void DownLoad(object o) { DownLoadInfo downLoadInfo = o as DownLoadInfo; try { if (downLoadInfo.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.WaitOne(); } else { Semaphore.WaitOne(); } if (Cancel) { return; } while (Pause & !Cancel) { Task.Delay(300).Wait(); } this.State = DownLoadState.DownLoading; DataBase cdb = new DataBase(""); Movie movie = await cdb.SelectMovieByID(downLoadInfo.id); cdb.CloseDB(); string[] url = new string[] { Properties.Settings.Default.Bus, Properties.Settings.Default.BusEurope, Properties.Settings.Default.DB, Properties.Settings.Default.Library }; bool[] enableurl = new bool[] { Properties.Settings.Default.EnableBus, Properties.Settings.Default.EnableBusEu, Properties.Settings.Default.EnableDB, Properties.Settings.Default.EnableLibrary, Properties.Settings.Default.EnableFC2 }; string[] cookies = new string[] { Properties.Settings.Default.DBCookie }; if (movie.title == "" | movie.smallimageurl == "" | movie.bigimageurl == "" | movie.sourceurl == "") { await Task.Run(() => { return(Net.DownLoadFromNet(movie)); }); } //写入NFO //if (Properties.Settings.Default.DLNFO) // SaveToNFO(dm, GetNfoPath(dm)); cdb = new DataBase(""); movie = await cdb.SelectMovieByID(downLoadInfo.id); cdb.CloseDB(); //更新总进度 List <string> extrapicurlList = new List <string>(); var list = movie.extraimageurl.Split(';'); foreach (var item in list) { if (!string.IsNullOrEmpty(item)) { extrapicurlList.Add(item); } } downLoadInfo.maximum = extrapicurlList.Count; downLoadInfo.maximum += 2; //小图 await DownLoadSmallPic(movie); downLoadInfo.progress += 1; InfoUpdate?.Invoke(this, new DownloadUpdateEventArgs() { DownLoadInfo = downLoadInfo }); //更新进度 //大图 await DownLoadBigPic(movie); downLoadInfo.progress += 1; InfoUpdate?.Invoke(this, new DownloadUpdateEventArgs() { DownLoadInfo = downLoadInfo }); //更新进度 //预览图 bool dlimageSuccess; string cookie = ""; for (int i = 0; i < extrapicurlList.Count(); i++) { if (!File.Exists(StaticVariable.BasePicPath + $"Extrapic\\{movie.id.ToUpper()}\\{movie.id.ToUpper()}.jpg")) { if (Cancel) { return; } while (Pause & !Cancel) { Task.Delay(300).Wait(); } if (extrapicurlList[i].Length > 0) { (dlimageSuccess, cookie) = await DownLoadExtraPic(movie.id, extrapicurlList[i], cookie); if (dlimageSuccess) { Task.Delay(1000).Wait(); } } } downLoadInfo.progress += 1; InfoUpdate?.Invoke(this, new DownloadUpdateEventArgs() { DownLoadInfo = downLoadInfo }); //更新进度 } } finally { if (downLoadInfo.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } } }
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; } bool success; string resultMessage; //下载信息 State = DownLoadState.DownLoading; if (Net.IsToDownLoadInfo(movie) || enforce) { //满足一定条件才下载信息 (success, resultMessage) = await Task.Run(() => { return(Net.DownLoadFromNet(movie)); }); InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = movie, progress = downLoadProgress.value, Success = success }); //委托到主界面显示 if (!success) { MessageCallBack?.Invoke(this, new MessageCallBackEventArgs($" {movie.id} {Jvedio.Language.Resources.DownloadMessageFailFor}:{(resultMessage.ToStatusMessage())}")); } } DetailMovie dm = new DetailMovie(); dm = DataBase.SelectDetailMovieById(movie.id); if (!File.Exists(BasePicPath + $"BigPic\\{dm.id}.jpg") || enforce) { string message2 = ""; (bool success2, string cookie2) = await Net.DownLoadImage(dm.bigimageurl, ImageType.BigImage, dm.id, callback : (sc) => { message2 = sc.ToString(); });//下载大图 //if (!success2) MessageCallBack?.Invoke(this, new MessageCallBackEventArgs($" {dm.id} 海报图下载失败,原因:{message2.ToStatusMessage()}")); } //fc2 没有缩略图 if (dm.id.IndexOf("FC2") >= 0) { //复制海报图作为缩略图 if (File.Exists(BasePicPath + $"BigPic\\{dm.id}.jpg") && !File.Exists(BasePicPath + $"SmallPic\\{dm.id}.jpg")) { File.Copy(BasePicPath + $"BigPic\\{dm.id}.jpg", BasePicPath + $"SmallPic\\{dm.id}.jpg"); } } else { if (!File.Exists(BasePicPath + $"SmallPic\\{dm.id}.jpg") || enforce) { string message = ""; (bool success1, string cookie) = await Net.DownLoadImage(dm.smallimageurl, ImageType.SmallImage, dm.id, callback : (sc) => { message = sc.ToString(); }); //下载小图 //if (!success1) MessageCallBack?.Invoke(this, new MessageCallBackEventArgs($" {dm.id} 缩略图下载失败,原因:{message.ToStatusMessage()}")); } } 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(DelayInvterval).Wait(); //每个线程之间暂停 //取消阻塞 if (movie.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } }
private async void DownLoad(object o) { DownLoadInfo downLoadInfo = o as DownLoadInfo; try { if (downLoadInfo.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.WaitOne(); } else { Semaphore.WaitOne(); } if (Cancel) { return; } while (Pause & !Cancel) { Task.Delay(300).Wait(); } this.State = DownLoadState.DownLoading; Movie movie = DataBase.SelectMovieByID(downLoadInfo.id); if (movie.title == "" | movie.smallimageurl == "" | movie.bigimageurl == "" | movie.sourceurl == "") { await Task.Run(() => { return(Net.DownLoadFromNet(movie)); }); } movie = DataBase.SelectMovieByID(downLoadInfo.id); //更新总进度 List <string> extrapicurlList = new List <string>(); var list = movie.extraimageurl.Split(';'); foreach (var item in list) { if (!string.IsNullOrEmpty(item)) { extrapicurlList.Add(item); } } downLoadInfo.maximum = extrapicurlList.Count; downLoadInfo.maximum += 2; //小图 await DownLoadSmallPic(movie); downLoadInfo.progress += 1; InfoUpdate?.Invoke(this, new DownloadUpdateEventArgs() { DownLoadInfo = downLoadInfo }); //更新进度 //大图 await DownLoadBigPic(movie); downLoadInfo.progress += 1; InfoUpdate?.Invoke(this, new DownloadUpdateEventArgs() { DownLoadInfo = downLoadInfo }); //更新进度 //预览图 bool dlimageSuccess; string cookie = ""; for (int i = 0; i < extrapicurlList.Count(); i++) { if (!File.Exists(GlobalVariable.BasePicPath + $"Extrapic\\{movie.id.ToUpper()}\\{movie.id.ToUpper()}.jpg")) { if (Cancel) { return; } while (Pause & !Cancel) { Task.Delay(300).Wait(); } if (extrapicurlList[i].Length > 0) { (dlimageSuccess, cookie) = await DownLoadExtraPic(movie.id, extrapicurlList[i], cookie); if (dlimageSuccess) { Task.Delay(1000).Wait(); } } } downLoadInfo.progress += 1; InfoUpdate?.Invoke(this, new DownloadUpdateEventArgs() { DownLoadInfo = downLoadInfo }); //更新进度 } } finally { if (downLoadInfo.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } } }