Ejemplo n.º 1
0
        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
            });
        }
Ejemplo n.º 2
0
        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;
                    HttpResult streamResult = await new MyNet().DownLoadFile(url);
                    if (streamResult != null)
                    {
                        ImageProcess.SaveImage(actress.name, streamResult.FileByte, ImageType.ActorImage, url);
                        actress.smallimage = ImageProcess.GetBitmapImage(actress.name, "Actresses");
                    }
                }
                //下载信息
                bool success = false;
                success = await Task.Run(() =>
                {
                    Task.Delay(300).Wait();
                    return(MyNet.DownLoadActress(actress.id, actress.name, callback: (message) => { MessageCallBack?.Invoke(this, new MessageCallBackEventArgs(message)); }));
                });

                if (success)
                {
                    actress = DataBase.SelectInfoByActress(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();
            }
        }
Ejemplo n.º 3
0
        public async void DownLoad()
        {
            IsDownLoading = true;
            //下载信息
            if (DetailMovie.IsToDownLoadInfo())
            {
                HttpResult httpResult = await MyNet.DownLoadFromNet(DetailMovie);

                if (httpResult != null && !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 = DataBase.SelectDetailMovieById(DetailMovie.id);

            if (dm == null || 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);//下载预览图
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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}"));
                }
            }
        }
Ejemplo n.º 6
0
        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();
            }
        }