Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (currentAv != null)
            {
                currentAv.Actress     = txtActress.Text.Replace("[", "").Replace("]", "");
                currentAv.Category    = txtCategory.Text.Replace("[", "").Replace("]", "");
                currentAv.Company     = txtCompany.Text.Replace("[", "").Replace("]", "");
                currentAv.Publisher   = txtPublisher.Text.Replace("[", "").Replace("]", "");
                currentAv.ReleaseDate = DateTime.Parse(txtDate.Text);

                if (currentAv.ReleaseDate == DateTime.MinValue)
                {
                    currentAv.ReleaseDate = new DateTime(2050, 1, 1);
                }

                if (!File.Exists(imgFolder + currentAv.ID + currentAv.Name + ".jpg"))
                {
                    DownloadHelper.DownloadFile(currentAv.PictureURL, imgFolder + currentAv.ID + currentAv.Name + ".jpg");
                }

                if (!JavDataBaseManager.HasAv(currentAv.ID, currentAv.Name))
                {
                    JavDataBaseManager.InsertAV(currentAv);
                }

                tx.Text           = currentAv.ID.ToUpper();
                this.DialogResult = DialogResult.Yes;
                this.Close();
            }
        }
Ejemplo n.º 2
0
        private static void ScanEachAv(ScanURL url, string status, bool force = false)
        {
            AV av = new AV();

            if (!JavDataBaseManager.HasAv(url.URL) || force)
            {
                var htmlRes = JavCookieContanierHelper(url.URL);

                if (htmlRes.Success)
                {
                    HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
                    htmlDocument.LoadHtml(htmlRes.Content);

                    av = GenerateAVModel(htmlRes.Content, url.URL);

                    if (!force)
                    {
                        JavDataBaseManager.InsertAV(av);

                        Console.WriteLine("线程 " + Thread.CurrentThread.ManagedThreadId.ToString() + " => 插入AV => " + av.ID + " - " + av.Name + " " + status);
                        JavDataBaseManager.UpdateScanURL(url.URL);

                        Console.WriteLine("AV:" + JsonConvert.SerializeObject(new RefreshModel
                        {
                            Id   = av.ID,
                            Name = av.Name,
                            Url  = av.PictureURL
                        })
                                          );
                    }

                    string result = "";
                    if (!File.Exists(ImgFolder + av.ID + av.Name + ".jpg"))
                    {
                        result = DownloadHelper.DownloadHttps(av.PictureURL, ImgFolder + av.ID + av.Name + ".jpg", "");

                        if (string.IsNullOrEmpty(result))
                        {
                            Console.WriteLine("线程 " + Thread.CurrentThread.ManagedThreadId.ToString() + " => 下载AV图片成功 => " + av.ID + " - " + av.Name);
                        }
                        else
                        {
                            Console.WriteLine(result);
                        }
                    }
                    else
                    {
                        Console.WriteLine("已存在图片不下载");
                    }
                }
            }
            else
            {
                Console.WriteLine("已存在 => " + url.URL + " " + status);
                JavDataBaseManager.UpdateScanURL(url.URL);
            }
        }
Ejemplo n.º 3
0
        private void saveBtn_Click(object sender, EventArgs e)
        {
            if (av != null)
            {
                if (!JavDataBaseManager.HasAv(av.URL))
                {
                    JavDataBaseManager.InsertAV(av);
                }

                string result = "";
                if (!File.Exists(imgFolder + av.ID + av.Name + ".jpg"))
                {
                    result = DownloadHelper.DownloadFile(av.PictureURL, imgFolder + av.ID + av.Name + ".jpg");
                }

                this.DialogResult = DialogResult.Yes;
                this.Close();
            }
        }
Ejemplo n.º 4
0
        public static void ReFormatName(string folder)
        {
            if (Directory.Exists(folder))
            {
                foreach (var file in new DirectoryInfo(folder).GetFiles())
                {
                    if (AVFileHelper.IsReformated(file))
                    {
                        var ret = AVFileHelper.ParseAvFile(file.FullName);
                        var has = JavDataBaseManager.HasAv(ret.AvId, ret.AvName);

                        Console.WriteLine(file + (has ? " 数据库存在" : " 数据库不存在"));
                    }
                    else
                    {
                        var reName = AVFileHelper.GetAvName(file);
                        file.MoveTo(reName);
                        AVFileHelper.ParseAvFile(reName);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static CookieContainer StartDownload(string url, string oriURL, int currentItem, int totalItem, CookieContainer cc)
        {
            var ret = InitHelper.InitManager.UpdateCookie(cc, url);

            cc = ret.CC;
            var res = ret.Content;

            try
            {
                if (res.Success)
                {
                    _logger.WriteLog(url, string.IsNullOrWhiteSpace(res.Content) ? "空" : res.Content);

                    Console.WriteLine(string.Format("Start to download {0}, {1}/{2}", oriURL, currentItem, totalItem));

                    AV av = new AV();

                    var m = Regex.Matches(res.Content, detailIDPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                    foreach (Match item in m)
                    {
                        var data = item.Groups[1].Value;
                        Console.WriteLine(string.Format("Get AV {0}, ID -> {1}", url, data));
                        av.ID = data;
                    }

                    m = Regex.Matches(res.Content, detailTitlePattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                    foreach (Match item in m)
                    {
                        var data = item.Groups[2].Value.Replace(av.ID + " ", "");
                        Console.WriteLine(string.Format("Get AV {0}, Title -> {1}", url, data));
                        av.Name = FileUtility.ReplaceInvalidChar(data);
                    }

                    m = Regex.Matches(res.Content, detailImgPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                    foreach (Match item in m)
                    {
                        var data = item.Groups[1].Value.StartsWith("http") ? item.Groups[1].Value : "http:" + item.Groups[1].Value;
                        Console.WriteLine(string.Format("Get AV {0}, IMG -> {1}", url, data));
                        av.PictureURL = data;
                    }

                    m = Regex.Matches(res.Content, detailDatePattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                    foreach (Match item in m)
                    {
                        var data = item.Groups[1].Value;
                        Console.WriteLine(string.Format("Get AV {0}, Date -> {1}", url, data));
                        av.ReleaseDate = DateTime.Parse(data);
                    }

                    m = Regex.Matches(res.Content, detailLengthPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                    foreach (Match item in m)
                    {
                        var data = item.Groups[1].Value;
                        Console.WriteLine(string.Format("Get AV {0}, Length -> {1}", url, data));
                        av.AvLength = int.Parse(data);
                    }

                    m = Regex.Matches(res.Content, detailDirectorPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                    foreach (Match item in m)
                    {
                        var u    = item.Groups[1].Value;
                        var data = item.Groups[2].Value;
                        Console.WriteLine(string.Format("Get AV {0}, Director -> {1}", url, data));
                        av.Director += data + ",";
                        Director d = new Director
                        {
                            CreateTime = DateTime.Now,
                            Name       = data,
                            URL        = prefix + directorPrefix + u
                        };

                        if (!JavDataBaseManager.HasDirector(d.URL))
                        {
                            JavDataBaseManager.InsertDirector(d);
                        }
                    }

                    m = Regex.Matches(res.Content, detailCompanyPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                    foreach (Match item in m)
                    {
                        var u    = item.Groups[1].Value;
                        var data = item.Groups[2].Value;
                        Console.WriteLine(string.Format("Get AV {0}, Company -> {1}", url, data));
                        av.Company += data + ",";
                        Company c = new Company
                        {
                            CreateTime = DateTime.Now,
                            Name       = data,
                            URL        = prefix + companyPrefix + u
                        };

                        if (!JavDataBaseManager.HasCompany(c.URL))
                        {
                            JavDataBaseManager.InsertCompany(c);
                        }
                    }

                    m = Regex.Matches(res.Content, detailPublisherPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                    foreach (Match item in m)
                    {
                        var u    = item.Groups[1].Value;
                        var data = item.Groups[2].Value;
                        Console.WriteLine(string.Format("Get AV {0}, Publisher -> {1}", url, data));
                        av.Publisher += data + ",";
                        Publisher p = new Publisher
                        {
                            CreateTime = DateTime.Now,
                            Name       = data,
                            URL        = prefix + publisherPrefix + u
                        };

                        if (!JavDataBaseManager.HasPublisher(p.URL))
                        {
                            JavDataBaseManager.InsertPublisher(p);
                        }
                    }

                    m = Regex.Matches(res.Content, detailCategoryPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                    foreach (Match item in m)
                    {
                        var data = item.Groups[2].Value;
                        Console.WriteLine(string.Format("Get AV {0}, Category -> {1}", url, data));
                        av.Category += data + ",";
                    }

                    m = Regex.Matches(res.Content, detailActressPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                    foreach (Match item in m)
                    {
                        var u    = item.Groups[1].Value;
                        var data = item.Groups[2].Value;
                        Console.WriteLine(string.Format("Get AV {0}, Actress -> {1}", url, data));
                        av.Actress += data + ",";
                        Actress a = new Actress
                        {
                            CreateTime = DateTime.Now,
                            Name       = data,
                            URL        = prefix + actressPrefix + u
                        };

                        if (!JavDataBaseManager.HasActress(a.URL))
                        {
                            JavDataBaseManager.InsertActress(a);
                        }
                    }

                    //m = Regex.Matches(res.Content, detailCommentPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                    //foreach (Match item in m)
                    //{
                    //    var data = item.Groups[1].Value;
                    //    Console.WriteLine(string.Format("Get AV {0}, Comments -> {1}", url, data));
                    //    Comments c = new Comments
                    //    {
                    //        Comment = data,
                    //        AvID = av.ID,
                    //        AvTitle = av.Name,
                    //        CreateTime = DateTime.Now
                    //    };
                    //    if (!JavDataBaseManager.HasComment(c))
                    //    {
                    //        JavDataBaseManager.InsertComment(c);
                    //    }
                    //}
                    av.URL = url;

                    if (!JavDataBaseManager.HasAv(av.URL))
                    {
                        JavDataBaseManager.InsertAV(av);
                    }

                    string result = "";
                    if (!File.Exists(imgFolder + av.ID + av.Name + ".jpg"))
                    {
                        result = Utils.DownloadHelper.DownloadFile(av.PictureURL, imgFolder + av.ID + av.Name + ".jpg");
                    }
                    JavDataBaseManager.UpdateScanURL(oriURL);

                    if (!string.IsNullOrEmpty(result))
                    {
                        _logger.WriteExceptionLog(url, string.Format("Download picture failed {0}", imgFolder + av.ID + av.Name + ".jpg"));
                    }
                }
                else
                {
                    _logger.WriteExceptionLog(url, string.Format("Download failed {0}", url));
                }
            }
            catch (Exception e)
            {
                _logger.WriteExceptionLog(url, string.Format("Download failed {0}", e.ToString()));
            }

            return(cc);
        }
Ejemplo n.º 6
0
        private static void ScanEachAvSingleThread()
        {
            List <ScanURL> urls  = JavDataBaseManager.GetScanURL().Where(x => x.IsDownload == false).ToList();
            int            index = 0;

            foreach (var url in urls)
            {
                int retry = 1;
                //二次确认
                if (!JavDataBaseManager.HasAv(url.URL))
                {
                    var htmlRes = new Utils.HtmlResponse();

                    //最多重试5次
                    while (retry <= 5)
                    {
                        htmlRes = HtmlManager.GetHtmlWebClientWithRenewCC("http://www.javlibrary.com/cn/", url.URL, cc);

                        if (htmlRes.IsExpire)
                        {
                            GetJavCookie();
                            retry++;
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (htmlRes.Success)
                    {
                        index++;
                        HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
                        htmlDocument.LoadHtml(htmlRes.Content);

                        var av = GenerateAVModel(htmlRes.Content, url.URL);

                        JavDataBaseManager.InsertAV(av);
                        Console.WriteLine("线程 " + Thread.CurrentThread.ManagedThreadId.ToString() + " => 插入AV => " + av.ID + " - " + av.Name);
                        JavDataBaseManager.UpdateScanURL(url.URL);

                        string result = "";
                        if (!File.Exists(ImgFolder + av.ID + av.Name + ".jpg"))
                        {
                            result = DownloadHelper.DownloadHttps(av.PictureURL, ImgFolder + av.ID + av.Name + ".jpg", "");

                            if (string.IsNullOrEmpty(result))
                            {
                                Console.WriteLine("线程 " + Thread.CurrentThread.ManagedThreadId.ToString() + " => 下载AV图片成功 => " + av.ID + " - " + av.Name);
                            }
                            else
                            {
                                Console.WriteLine(result);
                            }
                        }
                        else
                        {
                            Console.WriteLine("已存在图片不下载");
                        }

                        Console.WriteLine("完成" + index + " / " + urls.Count);
                    }
                }
                else
                {
                    JavDataBaseManager.UpdateScanURL(url.URL);
                    Console.WriteLine("详情页已下载 => " + url.URL + " 完成" + index + " / " + urls.Count);
                }
            }
        }