| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529 |
- package top.lvzhiqiang.service.impl;
- import lombok.extern.slf4j.Slf4j;
- import org.jsoup.Connection;
- import org.jsoup.HttpStatusException;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Propagation;
- import org.springframework.transaction.annotation.Transactional;
- import top.lvzhiqiang.config.WebAppConfig;
- import top.lvzhiqiang.dto.JavAllInfo;
- import top.lvzhiqiang.dto.JavAllInfo4Infantry;
- import top.lvzhiqiang.dto.JavAllInfo4Uncensored;
- import top.lvzhiqiang.entity.*;
- import top.lvzhiqiang.enumeration.ResultCodeEnum;
- import top.lvzhiqiang.exception.BusinessException;
- import top.lvzhiqiang.exception.ParameterException;
- import top.lvzhiqiang.mapper.*;
- import top.lvzhiqiang.service.BgService;
- import top.lvzhiqiang.service.Crawler4JavbusService;
- import top.lvzhiqiang.util.DateUtils;
- import top.lvzhiqiang.util.JsoupUtil;
- import top.lvzhiqiang.util.StringUtils;
- import javax.annotation.Resource;
- import java.io.*;
- import java.lang.reflect.Field;
- import java.math.BigDecimal;
- import java.net.InetSocketAddress;
- import java.net.Proxy;
- import java.nio.charset.StandardCharsets;
- import java.time.Instant;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.time.ZoneOffset;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * Bg ServiceImpl
- *
- * @author lvzhiqiang
- * 2022/4/16 16:10
- */
- @Service
- @Slf4j
- public class BgServiceImpl implements BgService {
- @Resource
- private VideoGenresMapper videoGenresMapper;
- @Resource
- private VideoCastMapper videoCastMapper;
- @Resource
- private VideoInfoCastMapper videoInfoCastMapper;
- @Resource
- private VideoInfoGenresMapper videoInfoGenresMapper;
- @Resource
- private VideoInfoMapper videoInfoMapper;
- @Resource
- private IcodePoolMapper icodePoolMapper;
- @Resource
- private VideoInfoPoolMapper videoInfoPoolMapper;
- @Resource
- private VideoSitePoolMapper videoSitePoolMapper;
- @Resource
- private DicCodeMapper dicCodeMapper;
- @Resource
- private VideoInfoOtherMapper videoInfoOtherMapper;
- @Resource
- private VideoInfoUncensoredMapper videoInfoUncensoredMapper;
- @Resource
- private VideoInfoInfantryMapper videoInfoInfantryMapper;
- @Resource
- private CrawlerLoveFootMapper crawlerLoveFootMapper;
- @Resource
- private Crawler4JavbusService crawler4JavbusService;
- @Value("${spring.profiles.active}")
- private String env;
- private String ignoreFileTypeSuffix = "";
- private Proxy proxy = null;
- private Proxy proxy2 = null;
- public void beforeProxy() {
- if (null == proxy) {
- if ("dev".equals(env)) {
- proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 1080));
- proxy2 = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 1080));
- } else {
- proxy = Proxy.NO_PROXY;
- //proxy2 = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 10808));
- proxy2 = Proxy.NO_PROXY;
- }
- }
- }
- /**
- * findDicCode
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @Override
- public String findDicCode(String codeDesc, String order) throws IllegalAccessException {
- List<DicCode> dicCodeList = dicCodeMapper.findByCodeDesc(codeDesc, order);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(dicCodeList.size())).concat("<br/>"));
- for (DicCode dicCode : dicCodeList) {
- sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
- Field[] fields = dicCode.getClass().getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- sb.append("<tr>");
- sb.append("<td>").append(field.getName()).append("</td>");
- sb.append("<td>").append(field.get(dicCode)).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- }
- return sb.toString();
- }
- /**
- * findIcodePool
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @Override
- public String findIcodePool(String identificationCode, Integer status, String order, String crudT) throws IllegalAccessException {
- if ("2".equals(crudT)) {
- //更新
- if (StringUtils.isEmpty(identificationCode) || null == status) {
- return "identificationCode和status不能为空";
- }
- icodePoolMapper.updateStatusByCode(identificationCode, status);
- return "success";
- }
- if ("3".equals(crudT)) {
- //删除
- if (StringUtils.isEmpty(identificationCode)) {
- return "dentificationCode不能为空";
- }
- icodePoolMapper.delByCode(identificationCode);
- return "success";
- }
- List<IcodePool> icodePoolList = icodePoolMapper.findByCodeAndStatus(identificationCode, status, order);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(icodePoolList.size())).concat("<br/>"));
- for (IcodePool icodePool : icodePoolList) {
- sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
- Field[] fields = icodePool.getClass().getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- sb.append("<tr>");
- sb.append("<td>").append(field.getName()).append("</td>");
- sb.append("<td>").append(field.get(icodePool)).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- }
- return sb.toString();
- }
- /**
- * findVideoSitePool
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @Override
- public String findVideoSitePool(String url, String order) throws IllegalAccessException {
- List<VideoSitePool> videoSitePoolList = videoSitePoolMapper.findByUrl(url, order);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoSitePoolList.size())).concat("<br/>"));
- for (VideoSitePool videoSitePool : videoSitePoolList) {
- sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
- Field[] fields = videoSitePool.getClass().getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- sb.append("<tr>");
- sb.append("<td>").append(field.getName()).append("</td>");
- sb.append("<td>").append(field.get(videoSitePool)).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- }
- return sb.toString();
- }
- /**
- * findVideoInfoPool
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @Override
- public String findVideoInfoPool(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
- if ("2".equals(crudT)) {
- //更新
- if (StringUtils.isEmpty(identificationCode) || null == type) {
- return "identificationCode和type不能为空";
- }
- videoInfoPoolMapper.updateTypeByCode(identificationCode, type);
- return "success";
- }
- if ("3".equals(crudT)) {
- //删除
- if (StringUtils.isEmpty(identificationCode)) {
- return "dentificationCode不能为空";
- }
- videoInfoPoolMapper.delByCode(identificationCode);
- return "success";
- }
- List<VideoInfoPool> videoInfoPoolList = videoInfoPoolMapper.findByCodeAndType(identificationCode, type, order);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoInfoPoolList.size())).concat("<br/>"));
- for (VideoInfoPool videoInfoPool : videoInfoPoolList) {
- sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
- Field[] fields = videoInfoPool.getClass().getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- sb.append("<tr>");
- sb.append("<td>").append(field.getName()).append("</td>");
- sb.append("<td>").append(field.get(videoInfoPool)).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- }
- return sb.toString();
- }
- /**
- * findVideoInfoLoveFoot
- *
- * @author lvzhiqiang
- * 2022/12/34 18:08
- */
- @Override
- public String findVideoInfoLoveFoot(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
- if ("2".equals(crudT)) {
- //更新
- if (StringUtils.isEmpty(identificationCode) || null == type) {
- return "identificationCode和type不能为空";
- }
- crawlerLoveFootMapper.updateTypeByCode(identificationCode, type);
- return "success";
- }
- if ("3".equals(crudT)) {
- //删除
- if (StringUtils.isEmpty(identificationCode)) {
- return "dentificationCode不能为空";
- }
- crawlerLoveFootMapper.delByCode(identificationCode);
- return "success";
- }
- List<CrawlerLoveFoot> crawlerLoveFootList = crawlerLoveFootMapper.findByCodeAndType(identificationCode, type, order);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(crawlerLoveFootList.size())).concat("<br/>"));
- for (CrawlerLoveFoot crawlerLoveFoot : crawlerLoveFootList) {
- sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
- Field[] fields = crawlerLoveFoot.getClass().getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- sb.append("<tr>");
- sb.append("<td>").append(field.getName()).append("</td>");
- sb.append("<td>").append(field.get(crawlerLoveFoot)).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- }
- return sb.toString();
- }
- /**
- * findVideoInfo
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @Override
- public String findVideoInfo(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
- if ("3".equals(crudT)) {
- //删除
- if (StringUtils.isEmpty(identificationCode)) {
- return "dentificationCode不能为空";
- }
- videoInfoMapper.delByCode(identificationCode);
- return "success";
- }
- List<VideoInfo> videoInfoList = videoInfoMapper.findByCodeAndType(identificationCode, type, order);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoInfoList.size())).concat("<br/>"));
- for (VideoInfo videoInfo : videoInfoList) {
- sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
- Field[] fields = videoInfo.getClass().getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- sb.append("<tr>");
- sb.append("<td>").append(field.getName()).append("</td>");
- sb.append("<td>").append(field.get(videoInfo)).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- }
- return sb.toString();
- }
- /**
- * updateScoreOrComment
- *
- * @author lvzhiqiang
- * 2022/5/4 9:54
- */
- @Override
- public String insertOrUpdateScoreOrComment(String identificationCode, String score, String comment) {
- BigDecimal scoreBD = null;
- if (StringUtils.isNotEmpty(score)) {
- scoreBD = new BigDecimal(score);
- }
- int num = videoInfoOtherMapper.findByCode(identificationCode);
- if (num == 0) {
- videoInfoOtherMapper.insertScoreOrComment(identificationCode, scoreBD, comment);
- return "insert success";
- }
- videoInfoOtherMapper.updateScoreOrComment(identificationCode, scoreBD, comment);
- return "update success";
- }
- /**
- * Jsoup VideoInfoUncensored
- *
- * @author lvzhiqiang
- * 2022/5/4 19:27
- */
- @Async
- @Override
- public void jsoupVideoInfoUncensored(Integer status) {
- log.warn("jsoupVideoInfoUncensored 开始:status={}", status);
- // 获取待抓取码列表
- List<String> icodeList = videoInfoUncensoredMapper.findIcodeByStatus(status);
- if (icodeList.size() == 0) {
- log.warn("status={}的icodeList为空", status);
- return;
- }
- // 获取javbus防屏蔽地址
- List<String> javbusUrlList = videoSitePoolMapper.findUrlByTypeAndDeleteFlag(1, 1);
- if (javbusUrlList.size() == 0) {
- log.warn("javbusUrlList为空");
- return;
- }
- // 获取码池图片保存路径
- String liuchuPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "liuchu_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
- // 遍历
- Document document;
- VideoInfoUncensored videoInfoUncensored;
- String javbusUrl;
- int j = 0;
- for (int i = 0; i < icodeList.size(); i++) {
- long start = System.currentTimeMillis();
- String identificationCode = icodeList.get(i);
- int retryCount = 0;
- while (retryCount <= 3) {
- javbusUrl = javbusUrlList.get((int) (0 + Math.random() * (javbusUrlList.size())));
- try {
- document = Jsoup.connect(javbusUrl.concat("/").concat(identificationCode))
- .timeout(50000)
- //.proxy()
- //.data()
- .ignoreContentType(true)
- .userAgent(getUserAgent())
- .header("referer", "https://www.javbus.com/".concat(identificationCode))
- .get();
- videoInfoUncensored = new VideoInfoUncensored();
- videoInfoUncensored.setIdentificationCode(identificationCode);
- parseDocument4Uncensored(document, identificationCode, liuchuPath, videoInfoUncensored);
- videoInfoUncensored.setStatus(2);
- videoInfoUncensoredMapper.updateJsoupInfoByCode(videoInfoUncensored);
- j++;
- log.warn("jsoupVideoInfoUncensored success:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCode);
- break;
- } catch (Exception e) {
- ++retryCount;
- if (retryCount < 4) {
- log.error("jsoupIcodePool error重试:i={},retryCount={},time={},identificationCode={}", i, retryCount, System.currentTimeMillis() - start, identificationCode, e);
- } else if (retryCount == 4) {
- videoInfoUncensoredMapper.updateStatus(identificationCode, 3);
- log.error("jsoupIcodePool error:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCode, e);
- }
- }
- }
- }
- log.warn("jsoupVideoInfoUncensored 统计:total={},success={}", icodeList.size(), j);
- }
- /**
- * Jsoup VideoInfo
- *
- * @author lvzhiqiang
- * 2022/5/5 18:21
- */
- @Async
- @Override
- public void jsoupVideoInfo(Integer status, String url, String identificationCodeP) {
- log.warn("jsoupVideoInfo 开始:status={}", status);
- // 获取待抓取码列表
- List<String> icodeList = new ArrayList<>();
- if (StringUtils.isEmpty(identificationCodeP)) {
- icodeList = videoInfoMapper.findIcodeByStatus(status);
- if (icodeList.size() == 0) {
- log.warn("status={}的icodeList为空", status);
- return;
- }
- } else {
- icodeList.add(identificationCodeP);
- }
- // 获取javbus防屏蔽地址
- List<String> javbusUrlList = new ArrayList<>();
- if (StringUtils.isEmpty(url)) {
- javbusUrlList = videoSitePoolMapper.findUrlByTypeAndDeleteFlag(1, 1);
- if (javbusUrlList.size() == 0) {
- log.warn("javbusUrlList为空");
- return;
- }
- } else {
- javbusUrlList.add(url);
- }
- beforeProxy();
- // 获取图片保存路径
- String qibingPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
- // 遍历
- Document document;
- VideoInfo videoInfo;
- String javbusUrl;
- int j = 0;
- for (int i = 0; i < icodeList.size(); i++) {
- long start = System.currentTimeMillis();
- String identificationCode = icodeList.get(i);
- int retryCount = 0;
- while (retryCount <= 3) {
- javbusUrl = javbusUrlList.get((int) (0 + Math.random() * (javbusUrlList.size())));
- try {
- document = Jsoup.connect(javbusUrl.concat("/").concat(identificationCode))
- .timeout(50000)
- .proxy(proxy)
- .userAgent(getUserAgent())
- .followRedirects(true)
- .ignoreContentType(true)
- .ignoreHttpErrors(true)
- .header("referer", "https://www.javbus.com/".concat(identificationCode))
- .get();
- videoInfo = new VideoInfo();
- videoInfo.setIdentificationCode(identificationCode);
- String picTime = parseDocument4QiBing(document, identificationCode, qibingPath, videoInfo);
- videoInfo.setStatus(2);
- // 获取男优
- getMaleCast(videoInfo);
- videoInfoMapper.updateJsoupInfoByCode(videoInfo);
- videoInfoOtherMapper.insertOrUpdate(identificationCode, 2);
- j++;
- log.warn("jsoupVideoInfo success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, identificationCode);
- break;
- } catch (Exception e) {
- ++retryCount;
- if (retryCount < 4) {
- log.error("jsoupVideoInfo error重试:i={},retryCount={},time={},identificationCode={},javbusUrl={}", i, retryCount, System.currentTimeMillis() - start, identificationCode, javbusUrl, e);
- } else if (retryCount == 4) {
- videoInfoMapper.updateStatus(identificationCode, 3);
- log.error("jsoupVideoInfo error:i={},time={},identificationCode={},javbusUrl={}", i, System.currentTimeMillis() - start, identificationCode, javbusUrl, e);
- }
- }
- }
- }
- log.warn("jsoupVideoInfo 统计:total={},success={}", icodeList.size(), j);
- }
- @Async
- @Override
- public void jsoupVideoInfo4javdb(Integer status, String url, String identificationCodeP) {
- log.warn("jsoupVideoInfo4javdb 开始:status={}", status);
- // 获取待抓取码列表
- List<String> icodeList = new ArrayList<>();
- if (StringUtils.isEmpty(identificationCodeP)) {
- icodeList = videoInfoMapper.findIcodeByStatus(status);
- if (icodeList.size() == 0) {
- log.warn("status={}的icodeList为空", status);
- return;
- }
- } else {
- icodeList.add(identificationCodeP);
- }
- beforeProxy();
- // 获取图片保存路径
- String qibingPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
- // 遍历
- Document document;
- VideoInfo videoInfo;
- int j = 0;
- for (int i = 0; i < icodeList.size(); i++) {
- long start = System.currentTimeMillis();
- String identificationCode = icodeList.get(i);
- int retryCount = 0;
- while (retryCount <= 3) {
- try {
- Map<String, String> headerMap = new HashMap<>();
- headerMap.put("referer", url);
- document = JsoupUtil.requestDocument(url, JsoupUtil.HTTP_GET, proxy2, null, headerMap, null);
- videoInfo = new VideoInfo();
- videoInfo.setIdentificationCode(identificationCode);
- String picTime = parseDocument4QiBing4Javdb(document, identificationCode, qibingPath, videoInfo);
- videoInfo.setStatus(2);
- // 获取男优
- getMaleCast(videoInfo);
- videoInfoMapper.updateJsoupInfoByCode(videoInfo);
- videoInfoOtherMapper.insertOrUpdate(identificationCode, 2);
- j++;
- log.warn("jsoupVideoInfo4javdb success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, identificationCode);
- break;
- } catch (Exception e) {
- ++retryCount;
- if (retryCount < 4) {
- log.error("jsoupVideoInfo4javdb error重试:i={},retryCount={},time={},identificationCode={},javbusUrl={}", i, retryCount, System.currentTimeMillis() - start, identificationCode, url, e);
- } else if (retryCount == 4) {
- videoInfoMapper.updateStatus(identificationCode, 3);
- log.error("jsoupVideoInfo4javdb error:i={},time={},identificationCode={},javbusUrl={}", i, System.currentTimeMillis() - start, identificationCode, url, e);
- }
- }
- }
- }
- log.warn("jsoupVideoInfo4javdb 统计:total={},success={}", icodeList.size(), j);
- }
- @Async
- @Override
- public void jsoupVideoInfoInfantry4javdb(String type, Integer status, String url, String identificationCodeP) {
- log.warn("jsoupVideoInfoInfantry4javdb 开始:status={}", status);
- // 获取待抓取码列表
- List<VideoInfoInfantry> videoInfoInfantryList;
- if (StringUtils.isEmpty(identificationCodeP)) {
- videoInfoInfantryList = videoInfoInfantryMapper.findInfoByTypeAndStatus(type, status);
- if (videoInfoInfantryList.size() == 0) {
- log.warn("status={}的videoInfoInfantryList为空", status);
- return;
- }
- } else {
- videoInfoInfantryList = videoInfoInfantryMapper.findByCodeAndType(identificationCodeP, type, status, null);
- videoInfoInfantryList.forEach(e -> {
- e.setJavdbUrl(url);
- });
- }
- List<DicCode> dicCodeList = dicCodeMapper.findAll();
- Map<String, String> javdbConstantMap = dicCodeList.stream()
- .filter(x -> x.getType() != null && 2 == x.getType() && x.getEnv().contains(env))
- .collect(Collectors.toMap(DicCode::getCodeKey, DicCode::getCodeValue, (key1, key2) -> key1));
- beforeProxy();
- // 获取图片保存路径
- String infantryPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
- // 遍历
- Document document;
- Document javdbSearchDocument;
- int j = 0;
- for (int i = 0; i < videoInfoInfantryList.size(); i++) {
- long start = System.currentTimeMillis();
- VideoInfoInfantry videoInfoInfantry = videoInfoInfantryList.get(i);
- int retryCount = 0;
- while (retryCount <= 3) {
- try {
- Thread.sleep(3000);
- String picTime;
- Elements itembSelects;
- if (StringUtils.isNotEmpty(videoInfoInfantry.getJavdbUrl())) {
- Map<String, String> headerMap = new HashMap<>();
- headerMap.put("referer", url);
- document = JsoupUtil.requestDocument(url, JsoupUtil.HTTP_GET, proxy2, null, headerMap, null);
- } else {
- String searchUrl = javdbConstantMap.get("javdb").concat("search?q=").concat(videoInfoInfantry.getIdentificationCode()).concat("&f=all");
- Map<String, String> header3Map = new HashMap<>();
- header3Map.put("referer", searchUrl);
- javdbSearchDocument = JsoupUtil.requestDocument(searchUrl, JsoupUtil.HTTP_GET, proxy2, null, header3Map, null);
- itembSelects = javdbSearchDocument.select("div.movie-list").select("div.item");
- if (itembSelects.size() == 0) {
- String newName = videoInfoInfantry.getName();
- searchUrl = javdbConstantMap.get("javdb").concat("search?q=").concat(newName).concat("&f=all");
- javdbSearchDocument = JsoupUtil.requestDocument(searchUrl, JsoupUtil.HTTP_GET, proxy2, null, header3Map, null);
- itembSelects = javdbSearchDocument.select("div.movie-list").select("div.item");
- }
- if (itembSelects.size() == 0) {
- throw new BusinessException(30000, "javdb search result null");
- }
- String title;
- String code;
- String codeUrl = null;
- for (Element itembSelect : itembSelects) {
- title = itembSelect.select("a.box").get(0).attr("title");
- code = itembSelect.select("a.box").get(0).select("div.video-title").select("strong").text();
- if (code.equalsIgnoreCase(videoInfoInfantry.getIdentificationCode())) {
- codeUrl = itembSelect.select("a.box").get(0).attr("abs:href");
- break;
- }
- String newName = videoInfoInfantry.getName().replace("●", "さ");
- if (title.contains(newName)) {
- codeUrl = itembSelect.select("a.box").get(0).attr("abs:href");
- videoInfoInfantry.setName(newName);
- break;
- }
- }
- if (StringUtils.isEmpty(codeUrl)) {
- throw new BusinessException(30000, "javdb search result mismatch");
- }
- document = JsoupUtil.requestDocument(codeUrl, JsoupUtil.HTTP_GET, proxy2, null, header3Map, null);
- videoInfoInfantry.setJavdbUrl(codeUrl);
- }
- picTime = parseDocument4Infantry4Javdb(document, infantryPath, videoInfoInfantry);
- videoInfoInfantry.setStatus(2);
- videoInfoInfantryMapper.updateJsoupInfoById(videoInfoInfantry);
- videoInfoOtherMapper.insertOrUpdate(videoInfoInfantry.getIdentificationCode(), 2);
- j++;
- log.warn("jsoupVideoInfoInfantry4javdb success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, videoInfoInfantry.getIdentificationCode());
- break;
- } catch (Exception e) {
- ++retryCount;
- if (retryCount < 4) {
- log.error("jsoupVideoInfoInfantry4javdb error重试:i={},retryCount={},time={},identificationCode={},javbusUrl={}", i, retryCount, System.currentTimeMillis() - start, videoInfoInfantry.getIdentificationCode(), url, e);
- } else if (retryCount == 4) {
- videoInfoInfantryMapper.updateStatus(videoInfoInfantry.getIdentificationCode(), 3);
- log.error("jsoupVideoInfoInfantry4javdb error:i={},time={},identificationCode={},javbusUrl={}", i, System.currentTimeMillis() - start, videoInfoInfantry.getIdentificationCode(), url, e);
- }
- }
- }
- }
- log.warn("jsoupVideoInfoInfantry4javdb 统计:total={},success={}", videoInfoInfantryList.size(), j);
- }
- @Async
- @Override
- public void jsoupVideoInfoUncensored4javdb(Integer status, String url, String identificationCodeP) {
- log.warn("jsoupVideoInfoUncensored4javdb 开始:status={}", status);
- // 获取待抓取码列表
- List<VideoInfoUncensored> videoInfoUncensoredList;
- if (StringUtils.isEmpty(identificationCodeP)) {
- videoInfoUncensoredList = videoInfoUncensoredMapper.findByCodeAndType(null, status, null);
- if (videoInfoUncensoredList.size() == 0) {
- log.warn("status={}的videoInfoUncensoredList为空", status);
- return;
- }
- } else {
- videoInfoUncensoredList = videoInfoUncensoredMapper.findByCodeAndType(identificationCodeP, status, null);
- videoInfoUncensoredList.forEach(e -> {
- e.setJavdbUrl(url);
- });
- }
- List<DicCode> dicCodeList = dicCodeMapper.findAll();
- Map<String, String> javdbConstantMap = dicCodeList.stream()
- .filter(x -> x.getType() != null && 2 == x.getType() && x.getEnv().contains(env))
- .collect(Collectors.toMap(DicCode::getCodeKey, DicCode::getCodeValue, (key1, key2) -> key1));
- beforeProxy();
- // 获取图片保存路径
- String uncensoredPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
- // 遍历
- Document document;
- Document javdbSearchDocument;
- int j = 0;
- for (int i = 0; i < videoInfoUncensoredList.size(); i++) {
- long start = System.currentTimeMillis();
- VideoInfoUncensored videoInfoUncensored = videoInfoUncensoredList.get(i);
- int retryCount = 0;
- while (retryCount <= 3) {
- try {
- Thread.sleep(3000);
- String picTime;
- Elements itembSelects;
- boolean ignoreCodeFlag = false;
- if (StringUtils.isNotEmpty(videoInfoUncensored.getJavdbUrl())) {
- Map<String, String> headerMap = new HashMap<>();
- headerMap.put("referer", url);
- document = JsoupUtil.requestDocument(url, JsoupUtil.HTTP_GET, proxy2, null, headerMap, null);
- } else {
- String searchUrl = javdbConstantMap.get("javdb").concat("search?q=").concat(videoInfoUncensored.getIdentificationCode()).concat("&f=all");
- Map<String, String> header3Map = new HashMap<>();
- header3Map.put("referer", searchUrl);
- javdbSearchDocument = JsoupUtil.requestDocument(searchUrl, JsoupUtil.HTTP_GET, proxy2, null, header3Map, null);
- itembSelects = javdbSearchDocument.select("div.movie-list").select("div.item");
- if (itembSelects.size() == 0) {
- String newName = videoInfoUncensored.getName();
- searchUrl = javdbConstantMap.get("javdb").concat("search?q=").concat(newName).concat("&f=all");
- javdbSearchDocument = JsoupUtil.requestDocument(searchUrl, JsoupUtil.HTTP_GET, proxy2, null, header3Map, null);
- itembSelects = javdbSearchDocument.select("div.movie-list").select("div.item");
- ignoreCodeFlag = true;
- }
- if (itembSelects.size() == 0) {
- throw new BusinessException(30000, "javdb search result null");
- }
- String title;
- String code;
- String codeUrl = null;
- for (Element itembSelect : itembSelects) {
- title = itembSelect.select("a.box").get(0).attr("title");
- code = itembSelect.select("a.box").get(0).select("div.video-title").select("strong").text();
- if (code.equalsIgnoreCase(videoInfoUncensored.getIdentificationCode())) {
- codeUrl = itembSelect.select("a.box").get(0).attr("abs:href");
- break;
- } else if (title.equalsIgnoreCase(videoInfoUncensored.getName()) && ignoreCodeFlag) {
- codeUrl = itembSelect.select("a.box").get(0).attr("abs:href");
- break;
- }
- String newName = videoInfoUncensored.getName().replace("●", "さ");
- if (title.contains(newName)) {
- codeUrl = itembSelect.select("a.box").get(0).attr("abs:href");
- videoInfoUncensored.setName(newName);
- break;
- }
- }
- if (StringUtils.isEmpty(codeUrl)) {
- throw new BusinessException(30000, "javdb search result mismatch");
- }
- document = JsoupUtil.requestDocument(codeUrl, JsoupUtil.HTTP_GET, proxy2, null, header3Map, null);
- videoInfoUncensored.setJavdbUrl(codeUrl);
- }
- picTime = parseDocument4Uncensored4Javdb(document, uncensoredPath, videoInfoUncensored);
- videoInfoUncensored.setStatus(2);
- videoInfoUncensoredMapper.updateJsoupInfoById(videoInfoUncensored);
- videoInfoOtherMapper.insertOrUpdate(videoInfoUncensored.getIdentificationCode(), 2);
- j++;
- log.warn("jsoupVideoInfoUncensored4javdb success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, videoInfoUncensored.getIdentificationCode());
- break;
- } catch (Exception e) {
- ++retryCount;
- if (retryCount < 4) {
- log.error("jsoupVideoInfoUncensored4javdb error重试:i={},retryCount={},time={},identificationCode={},javdbUrl={}", i, retryCount, System.currentTimeMillis() - start, videoInfoUncensored.getIdentificationCode(), videoInfoUncensored.getJavdbUrl(), e);
- } else if (retryCount == 4) {
- videoInfoUncensoredMapper.updateStatus(videoInfoUncensored.getIdentificationCode(), 3);
- log.error("jsoupVideoInfoUncensored4javdb error:i={},time={},identificationCode={},javdbsUrl={}", i, System.currentTimeMillis() - start, videoInfoUncensored.getIdentificationCode(), videoInfoUncensored.getJavdbUrl(), e);
- }
- }
- }
- }
- log.warn("jsoupVideoInfoUncensored4javdb 统计:total={},success={}", videoInfoUncensoredList.size(), j);
- }
- private String parseDocument4Uncensored4Javdb(Document document, String uncensoredPath, VideoInfoUncensored videoInfoUncensored) throws Exception {
- Elements container = document.select("section.section > div.container");
- if (container.size() == 0) {
- throw new BusinessException(30000, "番号无效!");
- }
- Elements videoDetail = container.select("div.video-detail");
- // 名称
- videoInfoUncensored.setName(videoDetail.select("h2.title").select("strong.current-title").text().trim());
- Elements moviePanelInfos = videoDetail.select("nav.movie-panel-info");
- Element pEle = moviePanelInfos.get(0);
- // 识别码
- String iCode = pEle.select("div:contains(番號)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
- if (!videoInfoUncensored.getIdentificationCode().equalsIgnoreCase(iCode)) {
- throw new Exception("番号与站点不一致");
- }
- // 发行日期
- String issueDate = pEle.select("div:contains(日期)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
- videoInfoUncensored.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- // 长度
- String length = pEle.select("div:contains(時長)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
- videoInfoUncensored.setLength(length);
- // 导演
- Elements directorEles = pEle.select("div:contains(導演)").select("span.value");
- if (directorEles.size() > 0) {
- videoInfoUncensored.setDirector(directorEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
- }
- // 制作商
- Elements markerEles = pEle.select("div:contains(片商)").select("span.value");
- if (markerEles.size() > 0) {
- videoInfoUncensored.setMaker(markerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
- }
- // 发行商
- Elements issuerEles = pEle.select("div:contains(發行)").select("span.value");
- if (issuerEles.size() > 0) {
- videoInfoUncensored.setIssuer(issuerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
- }
- // 类别
- Elements genresEles = pEle.select("div:contains(類別)").select("span.value");
- if (genresEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = genresEles.first().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoUncensored.setGenres(sb.toString());
- }
- // 演员
- Elements castEles = pEle.select("div:contains(演員)").select("span.value");
- if (castEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = castEles.first().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoUncensored.setCast(sb.toString());
- }
- // 图片 流出
- String liuchus = "流出/".concat(videoInfoUncensored.getMainWho()).concat("/").concat(iCode);
- StringBuffer picTime = new StringBuffer("{cover:");
- // 图片URL bigImage
- String liuchuCover = liuchus.concat("/cover/");
- String fileName = issueDate.concat(" ").concat(videoInfoUncensored.getIdentificationCode()).concat(" ").concat(StringUtils.escapeJavParam(videoInfoUncensored.getName()));
- byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
- if (imgUrlBytes.length > 251) {
- byte[] imgUrlDestBytes = new byte[251];
- System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
- fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
- }
- fileName = fileName.concat(".jpg");
- if (!new File(uncensoredPath.concat(liuchuCover), fileName).exists()) {
- Elements videoMetaPanel = videoDetail.select("div.column-video-cover");
- String href = videoMetaPanel.select("a > img").first().attr("src");
- long start = System.currentTimeMillis();
- Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- saveFile2(response.bodyStream(), uncensoredPath.concat(liuchuCover), fileName);
- picTime.append(System.currentTimeMillis() - start).append(",");
- }
- videoInfoUncensored.setImgUrl(iCode.concat("/cover/").concat(fileName));
- // 图片URL img_gf
- String liuchuImgGF = liuchus.concat("/img_gf/");
- File liuchuImgGFFile = new File(uncensoredPath.concat(liuchuImgGF));
- if (!liuchuImgGFFile.exists() || liuchuImgGFFile.listFiles().length == 0) {
- Elements sampleBoxEles = videoDetail.select("div.preview-images").select("a.tile-item");
- long start2 = System.currentTimeMillis();
- if (sampleBoxEles.size() > 0) {
- Connection.Response responseImg;
- for (Element sampleBoxEle : sampleBoxEles) {
- String sampleBoxHref = sampleBoxEle.attr("href");
- if (!sampleBoxHref.contains("http")) {
- sampleBoxHref = sampleBoxEle.attr("abs:href");
- }
- try {
- responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- } catch (HttpStatusException e) {
- sampleBoxHref = sampleBoxEle.select("img").attr("src");
- if (!sampleBoxHref.contains("http")) {
- sampleBoxHref = sampleBoxEle.select("img").attr("abs:src");
- }
- responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- }
- String sampleBoxFileName = sampleBoxHref.substring(sampleBoxHref.lastIndexOf("/") + 1);
- saveFile2(responseImg.bodyStream(), uncensoredPath.concat(liuchuImgGF), sampleBoxFileName);
- }
- } else {
- log.error("jsoupVideoInfoUncensored img_gf null,identificationCode={}", videoInfoUncensored.getIdentificationCode());
- }
- picTime.append("img_gf:").append(System.currentTimeMillis() - start2).append("}");
- }
- return picTime.toString();
- }
- private String parseDocument4Infantry4Javdb(Document document, String infantryPath, VideoInfoInfantry videoInfoInfantry) throws Exception {
- Elements container = document.select("section.section > div.container");
- if (container.size() == 0) {
- throw new BusinessException(30000, "番号无效!");
- }
- Elements videoDetail = container.select("div.video-detail");
- // 名称
- videoInfoInfantry.setName(videoDetail.select("h2.title").select("strong.current-title").text().trim());
- Elements moviePanelInfos = videoDetail.select("nav.movie-panel-info");
- Element pEle = moviePanelInfos.get(0);
- // 识别码
- String iCode = pEle.select("div:contains(番號)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
- if (!videoInfoInfantry.getIdentificationCode().equalsIgnoreCase(iCode)) {
- throw new Exception("番号与站点不一致");
- }
- // 发行日期
- String issueDate = pEle.select("div:contains(日期)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
- videoInfoInfantry.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- // 长度
- String length = pEle.select("div:contains(時長)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
- videoInfoInfantry.setLength(length);
- // 导演
- Elements directorEles = pEle.select("div:contains(導演)").select("span.value");
- if (directorEles.size() > 0) {
- videoInfoInfantry.setDirector(directorEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
- }
- // 制作商
- Elements markerEles = pEle.select("div:contains(片商)").select("span.value");
- if (markerEles.size() > 0) {
- videoInfoInfantry.setMaker(markerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
- }
- // 发行商
- Elements issuerEles = pEle.select("div:contains(發行)").select("span.value");
- if (issuerEles.size() > 0) {
- videoInfoInfantry.setIssuer(issuerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
- }
- // 类别
- Elements genresEles = pEle.select("div:contains(類別)").select("span.value");
- if (genresEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = genresEles.first().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoInfantry.setGenres(sb.toString());
- }
- // 演员
- Elements castEles = pEle.select("div:contains(演員)").select("span.value");
- if (castEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = castEles.first().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoInfantry.setCast(sb.toString());
- }
- // 图片 步兵
- String bubings = "步兵/".concat(videoInfoInfantry.getType()).concat("/").concat(iCode);
- StringBuffer picTime = new StringBuffer("{cover:");
- // 图片URL bigImage
- String bubingCover = bubings.concat("/cover/");
- String fileName = issueDate.concat(" ").concat(videoInfoInfantry.getIdentificationCode()).concat(" ").concat(videoInfoInfantry.getName()).replace("?", "?").replace("#","");
- byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
- if (imgUrlBytes.length > 251) {
- byte[] imgUrlDestBytes = new byte[251];
- System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
- fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
- }
- fileName = fileName.concat(".jpg");
- if (!new File(infantryPath.concat(bubingCover), fileName).exists()) {
- Elements videoMetaPanel = videoDetail.select("div.column-video-cover");
- String href = videoMetaPanel.select("a > img").first().attr("src");
- long start = System.currentTimeMillis();
- Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- saveFile2(response.bodyStream(), infantryPath.concat(bubingCover), fileName);
- picTime.append(System.currentTimeMillis() - start).append(",");
- }
- videoInfoInfantry.setImgUrl(iCode.concat("/cover/").concat(fileName));
- // 图片URL img_gf
- String bubingImgGF = bubings.concat("/img_gf/");
- File bubingImgGFFile = new File(infantryPath.concat(bubingImgGF));
- if (!bubingImgGFFile.exists() || bubingImgGFFile.listFiles().length == 0) {
- Elements sampleBoxEles = videoDetail.select("div.preview-images").select("a.tile-item");
- long start2 = System.currentTimeMillis();
- if (sampleBoxEles.size() > 0) {
- Connection.Response responseImg;
- for (Element sampleBoxEle : sampleBoxEles) {
- String sampleBoxHref = sampleBoxEle.attr("href");
- if (!sampleBoxHref.contains("http")) {
- sampleBoxHref = sampleBoxEle.attr("abs:href");
- }
- try {
- responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- } catch (HttpStatusException e) {
- sampleBoxHref = sampleBoxEle.select("img").attr("src");
- if (!sampleBoxHref.contains("http")) {
- sampleBoxHref = sampleBoxEle.select("img").attr("abs:src");
- }
- responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- }
- String sampleBoxFileName = sampleBoxHref.substring(sampleBoxHref.lastIndexOf("/") + 1);
- saveFile2(responseImg.bodyStream(), infantryPath.concat(bubingImgGF), sampleBoxFileName);
- }
- } else {
- log.error("jsoupVideoInfoInfantry img_gf null,identificationCode={}", videoInfoInfantry.getIdentificationCode());
- }
- picTime.append("img_gf:").append(System.currentTimeMillis() - start2).append("}");
- }
- return picTime.toString();
- }
- @Override
- public void getMaleCast(VideoInfo videoInfo) {
- Document document;
- try {
- Map<String, String> headerMap = new HashMap<>();
- headerMap.put("referer", "avdanyuwiki.com");
- document = JsoupUtil.requestDocument("https://avdanyuwiki.com/?s=".concat(videoInfo.getName()), JsoupUtil.HTTP_GET, Proxy.NO_PROXY, null, headerMap, null);
- Elements container = document.select("div#header-container-in");
- if (container.size() == 0) {
- return;
- }
- Elements alinks1 = container.select("h4").select("a[rel='bookmark']");
- if (alinks1 == null || alinks1.size() == 0) {
- return;
- }
- String alinkhref = alinks1.first().attr("abs:href");
- document = JsoupUtil.requestDocument(alinkhref, JsoupUtil.HTTP_GET, Proxy.NO_PROXY, null, headerMap, null);
- Elements entrycontent = document.select("div.entry-content");
- if (entrycontent.size() == 0) {
- return;
- }
- String[] entrycontentArr = entrycontent.html().split("<br>");
- for (String s : entrycontentArr) {
- if (s.contains("出演男優")) {
- String[] split = s.split(":");
- if (split.length < 2) {
- return;
- }
- String maleCasts = s.split(":")[1];
- List<String> sssss = new ArrayList<>();
- String[] split1 = maleCasts.split(",");
- for (String s1 : split1) {
- String[] split2 = s1.trim().split("\\s+");
- for (String s2 : split2) {
- sssss.add(s2.replaceAll(" ", "").trim());
- }
- }
- String maleCast = StringUtils.join(sssss, ",");
- videoInfo.setMaleCast(maleCast);
- break;
- }
- }
- } catch (Exception e) {
- log.error("getMaleCast error,icode={},name={}={}", videoInfo.getIdentificationCode(), videoInfo.getName(), e);
- }
- }
- /**
- * 删除影片
- *
- * @param identificationCode
- * @param parentTypeName
- * @author lvzhiqiang
- * 2022/5/29 12:59
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- public void delVideoInfo(String identificationCode, String parentTypeName, String allFlag) {
- if (StringUtils.isNotEmpty(parentTypeName) && StringUtils.isEmpty(allFlag)) {
- if (parentTypeName.contains("类别")) {
- String videoGenres = parentTypeName.replace("(类别)", "");
- VideoInfoGenres videoInfoGenres = videoInfoGenresMapper.findVideoInfoGenresByCodeAndName(identificationCode, videoGenres);
- if ("1".equals(videoInfoGenres.getType())) {
- // 主体
- throw new ParameterException("上级类型名称为主体,请选用allFlag参数");
- } else {
- // 链接
- videoInfoGenresMapper.deleteById(videoInfoGenres.getId());
- }
- } else if (parentTypeName.contains("优")) {
- String videoCast = "";
- if (parentTypeName.contains("(男")) {
- videoCast = parentTypeName.replace("(男优)", "");
- } else if (parentTypeName.contains("(女")) {
- videoCast = parentTypeName.replace("(女优)", "");
- }
- VideoInfoCast videoInfoCast = videoInfoCastMapper.findVideoInfoCastByCodeAndName(identificationCode, videoCast);
- if ("1".equals(videoInfoCast.getType())) {
- // 主体
- throw new ParameterException("上级类型名称为主体,请选用allFlag参数");
- } else {
- // 链接
- videoInfoCastMapper.deleteById(videoInfoCast.getId());
- }
- } else {
- throw new ParameterException("直属类型不存在");
- }
- } else if (StringUtils.isEmpty(parentTypeName) && StringUtils.isNotEmpty(allFlag)) {
- videoInfoMapper.delByIdentificationCode(identificationCode);
- videoInfoCastMapper.deleteByCode(identificationCode);
- videoInfoGenresMapper.deleteByCode(identificationCode);
- } else {
- throw new ParameterException("参数有误");
- }
- }
- /**
- * findVideoInfoOther
- *
- * @author lvzhiqiang
- * 2022/9/17 19:17
- */
- @Override
- public String findVideoInfoOther(String identificationCode, String resolutionRatio, Integer original, Integer subtitle, Integer recoding, String crudT) {
- if ("2".equals(crudT)) {
- identificationCode = identificationCode.trim();
- // 更新/新增
- int num = videoInfoOtherMapper.findByCode(identificationCode);
- if (num == 0) {
- videoInfoOtherMapper.insertVideoInfoOther(identificationCode, resolutionRatio, original, subtitle, recoding);
- return "insert success";
- }
- videoInfoOtherMapper.updateVideoInfoOther(identificationCode, resolutionRatio, original, subtitle, recoding);
- return "update success";
- }
- if ("3".equals(crudT)) {
- identificationCode = identificationCode.trim();
- //删除
- videoInfoOtherMapper.delByCode(identificationCode);
- return "delete success";
- }
- // 查询
- List<VideoInfoOther> videoInfoOtherList = videoInfoOtherMapper.findVideoInfoOther4MultipleParams(identificationCode, resolutionRatio, original, subtitle, recoding);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoInfoOtherList.size())).concat("<br/>"));
- sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>序号</th><th>识别码</th><th>评分</th><th>评语</th><th>评语first</th><th>分辨率</th><th>原档</th><th>字幕</th><th>重新编码</th><th>创建时间</th><th>最后修改时间</th></tr>");
- int i = 0;
- for (VideoInfoOther videoInfoOther : videoInfoOtherList) {
- i++;
- sb.append("<tr>");
- sb.append("<td>").append(i).append("</td>");
- sb.append("<td>").append(videoInfoOther.getIdentificationCode()).append("</td>");
- sb.append("<td>").append(videoInfoOther.getScore()).append("</td>");
- sb.append("<td>").append(videoInfoOther.getComment()).append("</td>");
- sb.append("<td>").append(videoInfoOther.getCommentFirst()).append("</td>");
- sb.append("<td>").append(videoInfoOther.getResolutionRatio()).append("</td>");
- sb.append("<td>").append(videoInfoOther.getOriginal() == null ? "?" : (videoInfoOther.getOriginal() == 1 ? "是" : "否")).append("</td>");
- sb.append("<td>").append(videoInfoOther.getSubtitle() == null ? "?" : (videoInfoOther.getSubtitle() == 1 ? "是" : "否")).append("</td>");
- sb.append("<td>").append(videoInfoOther.getRecoding() == null ? "?" : (videoInfoOther.getRecoding() == 1 ? "是" : "否")).append("</td>");
- sb.append("<td>").append(videoInfoOther.getCreateTime()).append("</td>");
- sb.append("<td>").append(videoInfoOther.getModifyTime()).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- return sb.toString();
- }
- /**
- * 增加影片
- *
- * @param identificationCode
- * @param videoName
- * @param parentType
- * @param parentName
- * @param type
- * @author lvzhiqiang
- * 2022/9/27 20:54
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- public void insertVideoInfo(String identificationCode, String videoName, Integer parentType, String parentName, Integer type) {
- String parentFullName;
- if (parentType == 1) {
- parentFullName = "(类别)" + parentName;
- VideoInfoGenres videoInfoGenres = new VideoInfoGenres();
- videoInfoGenres.setIdentificationCode(identificationCode);
- videoInfoGenres.setName(parentName);
- videoInfoGenres.setType(type);
- videoInfoGenresMapper.insert(videoInfoGenres);
- VideoGenres videoGenres = new VideoGenres();
- videoGenres.setName(parentName);
- videoGenresMapper.insertOrUpdate(videoGenres);
- } else if (parentType == 2) {
- parentFullName = "(男优)" + parentName;
- VideoInfoCast videoInfoCast = new VideoInfoCast();
- videoInfoCast.setIdentificationCode(identificationCode);
- videoInfoCast.setName(parentName);
- videoInfoCast.setType(type);
- videoInfoCastMapper.insert(videoInfoCast);
- VideoCast videoCast = new VideoCast();
- videoCast.setName(parentName);
- videoCast.setType(1);
- videoCastMapper.insertOrUpdate(videoCast);
- } else if (parentType == 3) {
- parentFullName = "(女优)" + parentName;
- VideoInfoCast videoInfoCast = new VideoInfoCast();
- videoInfoCast.setIdentificationCode(identificationCode);
- videoInfoCast.setName(parentName);
- videoInfoCast.setType(type);
- videoInfoCastMapper.insert(videoInfoCast);
- VideoCast videoCast = new VideoCast();
- videoCast.setName(parentName);
- videoCast.setType(2);
- videoCastMapper.insertOrUpdate(videoCast);
- } else {
- throw new RuntimeException("parentType类型错误");
- }
- // 主体
- if (type == 1) {
- VideoInfo videoInfo = new VideoInfo();
- videoInfo.setIdentificationCode(identificationCode);
- videoInfo.setType(1);
- // 视频URL
- videoInfo.setVideoUrl(parentFullName.concat("/").concat(videoName));
- // 修改时间
- videoInfo.setCreateTime(LocalDateTime.now());
- // 主体是谁
- videoInfo.setMainWho(parentFullName);
- videoInfoMapper.insertOrUpdate(videoInfo);
- }
- }
- /**
- * 初始化骑兵数据
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- @Async
- public void initVideoInfoData(Integer type, Integer isDel, String infantryType) {
- long startTime = System.currentTimeMillis();
- DicCode dicCode = null;
- if (type == 1) {
- dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "qibing_path".equals(x.getCodeKey())).findFirst().get();
- } else if (type == 3) {
- dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "liuchu_path".equals(x.getCodeKey())).findFirst().get();
- } else if (type == 2) {
- dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "bubing_path".equals(x.getCodeKey())).findFirst().get();
- }
- if (dicCode == null) {
- return;
- }
- String picPath = dicCode.getCodeValue();
- if (type == 1) {
- JavAllInfo javAllInfo = new JavAllInfo();
- // 删除所有
- if (isDel == 1) {
- videoGenresMapper.deleteAll();
- videoInfoMapper.deleteAll();
- videoCastMapper.deleteAll();
- videoInfoGenresMapper.deleteAll();
- videoInfoCastMapper.deleteAll();
- }
- ignoreFileTypeSuffix = dicCodeMapper.findByCodeKey("ignore_filetype_suffix", null).stream()
- .filter(x -> x.getEnv().contains(env)).findFirst().get().getCodeValue();
- List<String> allIcode = videoInfoMapper.findAllIcode();
- getAllFilePaths(picPath, javAllInfo, allIcode);
- saveInfo(javAllInfo, isDel);
- } else if (type == 3) {
- JavAllInfo4Uncensored javAllInfo4Uncensored = new JavAllInfo4Uncensored();
- getAllFilePaths4Uncensored(picPath, javAllInfo4Uncensored);
- saveInfo4Uncensored(javAllInfo4Uncensored, isDel);
- } else if (type == 2) {
- JavAllInfo4Infantry javAllInfo4Infantry = new JavAllInfo4Infantry();
- picPath = picPath.concat(infantryType);
- getAllFilePaths4Infantry(picPath, javAllInfo4Infantry, infantryType);
- saveInfo4Infantry(javAllInfo4Infantry, isDel, infantryType);
- }
- long endTime = System.currentTimeMillis();
- System.err.println((endTime - startTime) / 1000);
- }
- /**
- * 上传识别码文件
- *
- * @param is
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- @Async
- public void uploadFile4IdentificationCode(InputStream is, Integer isDel) {
- if (isDel == 1) {
- icodePoolMapper.deleteAll();
- }
- List<String> uploadIcodeList = readFromIcodeStream(is);
- List<String> icodePoolList = icodePoolMapper.findIcode();
- // 过滤库中已存在的
- Integer beforeUploadSize = uploadIcodeList.size();
- uploadIcodeList.removeAll(icodePoolList);
- log.warn("uploadFile4IdentificationCode:beforeUpload={},icodePool={},afterUpload={}", beforeUploadSize, icodePoolList.size(), uploadIcodeList.size());
- // 插入
- int num = 0;
- if (uploadIcodeList.size() > 0) {
- num = icodePoolMapper.insertList(uploadIcodeList);
- }
- log.warn("uploadFile4IdentificationCode:success={}", num);
- }
- /**
- * 单个识别码
- *
- * @param identificationCode
- */
- @Override
- public void single4IdentificationCode(String identificationCode, String url) {
- identificationCode = identificationCode.trim().toUpperCase();
- List<String> icodePoolList = icodePoolMapper.findIcodeByCode(identificationCode);
- if (icodePoolList.size() > 0) {
- throw new BusinessException(ResultCodeEnum.PARAM_DATA_EXIST_ERROR);
- }
- icodePoolMapper.insert(identificationCode, url);
- }
- /**
- * Jsoup IcodePool
- *
- * @param status
- */
- @Async
- @Override
- public String jsoupIcodePool(String website, Integer status, Integer isDel, Integer ignoreRetryCount) {
- log.warn("jsoupIcodePool 开始:website={},status={},isDel={},ignoreRetryCount={}", website, status, isDel, ignoreRetryCount);
- if (isDel == 1) {
- videoInfoPoolMapper.deleteAll();
- }
- // 获取待抓取码列表
- List<String> icodePoolList;
- if (1 == ignoreRetryCount) {
- icodePoolList = icodePoolMapper.findIcodeByStatus4IgnoreRetryCount(status);
- } else {
- icodePoolList = icodePoolMapper.findIcodeByStatus(status);
- }
- if (icodePoolList.size() == 0) {
- log.warn("status={}的icodePoolList为空", status);
- return "size:0";
- }
- // 获取javbus防屏蔽地址
- List<String> javbusUrlList = videoSitePoolMapper.findUrlByTypeAndDeleteFlag(1, 1);
- if (javbusUrlList.size() == 0) {
- log.warn("javbusUrlList为空");
- return "javbusUrlList为空";
- }
- // 获取主表所有识别码
- List<String> allIcode = videoInfoMapper.findAllIcode();
- // 获取码池图片保存路径
- String machiPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
- // 遍历
- Document document;
- VideoInfoPool videoInfoPool;
- String javbusUrl;
- int j = 0;
- for (int i = 0; i < icodePoolList.size(); i++) {
- long start = System.currentTimeMillis();
- String[] identificationCodeArr = icodePoolList.get(i).split("\\|");
- IcodePool icodePool = new IcodePool();
- icodePool.setIdentificationCode(identificationCodeArr[0]);
- if (allIcode.contains(identificationCodeArr[0])) {
- icodePool.setStatus(4);
- icodePool.setRetryCount(0);
- icodePoolMapper.updateStatus(icodePool);
- log.warn("jsoupIcodePool exists:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCodeArr[0]);
- continue;
- }
- int retryCount = 0;
- while (retryCount <= 3) {
- javbusUrl = javbusUrlList.get((int) (0 + Math.random() * (javbusUrlList.size())));
- try {
- videoInfoPool = new VideoInfoPool();
- long picTime = 0;
- if ("javbus".equalsIgnoreCase(website)) {
- document = Jsoup.connect(javbusUrl.concat("/").concat(identificationCodeArr[0]))
- .timeout(50000)
- //.proxy()
- //.data()
- .ignoreContentType(true)
- .userAgent(getUserAgent())
- .header("referer", javbusUrl.concat("/").concat(identificationCodeArr[0]))
- .get();
- picTime = parseDocument(document, identificationCodeArr[0], machiPath, videoInfoPool);
- } else if ("javdb".equalsIgnoreCase(website) && StringUtils.isNotEmpty(identificationCodeArr[1])) {
- Map<String, String> headerMap = new HashMap<>();
- headerMap.put("referer", identificationCodeArr[1]);
- beforeProxy();
- document = JsoupUtil.requestDocument(identificationCodeArr[1], JsoupUtil.HTTP_GET, proxy2, null, headerMap, null);
- picTime = parseDocument4Javdb(document, identificationCodeArr[0], machiPath, videoInfoPool);
- }
- if (videoInfoPool != null) {
- icodePool.setStatus(2);
- icodePool.setRetryCount(retryCount);
- icodePoolMapper.updateStatus(icodePool);
- videoInfoPoolMapper.insert(videoInfoPool);
- j++;
- }
- log.warn("jsoupIcodePool success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, identificationCodeArr[0]);
- break;
- } catch (Exception e) {
- ++retryCount;
- if (retryCount < 4) {
- log.error("jsoupIcodePool error重试:i={},retryCount={},time={},identificationCode={},javbusUrl={}", i, retryCount, System.currentTimeMillis() - start, identificationCodeArr[0], javbusUrl, e);
- } else if (retryCount == 4) {
- icodePool.setStatus(3);
- icodePool.setRetryCount(retryCount - 1);
- icodePool.setFailureCause(e.getMessage().length() <= 200 ? e.getMessage() : e.getMessage().substring(0, 200));
- icodePoolMapper.updateStatus(icodePool);
- log.error("jsoupIcodePool error:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCodeArr[0], e);
- }
- }
- }
- }
- log.warn("jsoupIcodePool 统计:total={},success={}", icodePoolList.size(), j);
- return "total=".concat(String.valueOf(icodePoolList.size())).concat(",success=").concat(String.valueOf(j));
- }
- private String getUserAgent() {
- Random r = new Random();
- String[] ua = {"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0",
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36 OPR/37.0.2178.32",
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586",
- "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",
- "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
- "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
- "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0)",
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 BIDUBrowser/8.3 Safari/537.36",
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36 Core/1.47.277.400 QQBrowser/9.4.7658.400",
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 UBrowser/5.6.12150.8 Safari/537.36",
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0",
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36 TheWorld 7",
- "Mozilla/5.0 (Windows NT 6.1; W…) Gecko/20100101 Firefox/60.0",
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"};
- int i = r.nextInt(15);
- return ua[i];
- }
- private long parseDocument(Document document, String identificationCode, String machiPath, VideoInfoPool videoInfoPool) throws Exception {
- Elements container = document.select("div.container");
- if (container.size() == 0) {
- throw new Exception("番号无效!");
- }
- // 名称
- String h3 = container.select("h3").first().text().replace("/", "");
- String[] nameArr = h3.split("\\s+");
- if (nameArr.length > 1) {
- videoInfoPool.setName(h3.substring(nameArr[0].length()).trim());
- } else {
- videoInfoPool.setName(nameArr[0]);
- }
- Elements pEles = container.select("div.info > p");
- // 识别码
- Element pEle = pEles.get(0);
- String iCode = pEle.select("span[style]").first().text();
- if (!identificationCode.equalsIgnoreCase(iCode)) {
- throw new Exception("番号与站点不一致");
- }
- videoInfoPool.setIdentificationCode(iCode);
- // 发行日期
- pEle = pEles.get(1);
- String issueDate = pEle.text().split(":")[1].replace("\"", "").trim();
- videoInfoPool.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- // 长度
- pEle = pEles.get(2);
- String length = pEle.text().split(":")[1].replace("\"", "").trim();
- videoInfoPool.setLength(length);
- // 导演
- Elements directorEles = container.select("div.info").select("p:contains(導演)");
- if (directorEles.size() > 0) {
- pEle = directorEles.first().select("a[href]").first();
- videoInfoPool.setDirector(pEle.text());
- }
- // 制作商
- Elements markerEles = container.select("div.info").select("p:contains(製作商)");
- if (markerEles.size() > 0) {
- pEle = markerEles.first().select("a[href]").first();
- videoInfoPool.setMaker(pEle.text());
- }
- // 发行商
- Elements issuerEles = container.select("div.info").select("p:contains(發行商)");
- if (issuerEles.size() > 0) {
- pEle = issuerEles.first().select("a[href]").first();
- videoInfoPool.setIssuer(pEle.text());
- }
- // 类别
- Elements genresEles = container.select("div.info").select("p:contains(類別)");
- if (genresEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = genresEles.first().nextElementSibling().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text()).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoPool.setGenres(sb.toString());
- }
- // 演员
- Elements castEles = container.select("div.info").select("p.star-show:contains(演員)");
- if (castEles.size() > 0) {
- Elements castElesTemp = container.select("div.info:contains(暫無出演者資訊)");
- if (castElesTemp.size() == 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = castEles.first().nextElementSibling().nextElementSibling().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text()).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoPool.setCast(sb.toString());
- }
- }
- // 图片URL
- String href = container.select("a.bigImage").first().attr("abs:href");
- long start = System.currentTimeMillis();
- Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- String fileName = issueDate.concat(" ").concat(h3).replace("?", "?");
- byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
- if (imgUrlBytes.length > 251) {
- byte[] imgUrlDestBytes = new byte[251];
- System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
- fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
- }
- fileName = fileName.concat(".jpg");
- String machiImgUrl = "码池/".concat(fileName);
- saveFile(response.bodyStream(), machiPath.concat(machiImgUrl));
- long end = System.currentTimeMillis();
- videoInfoPool.setImgUrl(machiImgUrl);
- videoInfoPool.setCreateTime(LocalDateTime.now());
- videoInfoPool.setType(1);
- return end - start;
- }
- private long parseDocument4Javdb(Document javdbCodeDocument, String identificationCode, String machiPath, VideoInfoPool videoInfoPool) throws Exception {
- Elements container = javdbCodeDocument.select("section.section > div.container");
- if (container.size() == 0) {
- throw new BusinessException(30000, "番号无效!");
- }
- Elements videoDetail = container.select("div.video-detail");
- // 名称
- videoInfoPool.setName(videoDetail.select("h2.title").select("strong.current-title").text().trim());
- Elements moviePanelInfos = videoDetail.select("nav.movie-panel-info");
- Element pEle = moviePanelInfos.get(0);
- // 识别码
- String iCode = pEle.select("div:contains(番號)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
- if (!identificationCode.equalsIgnoreCase(iCode)) {
- throw new Exception("番号与站点不一致");
- }
- videoInfoPool.setIdentificationCode(iCode);
- // 发行日期
- String issueDate = pEle.select("div:contains(日期)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
- videoInfoPool.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- // 长度
- String length = pEle.select("div:contains(時長)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
- videoInfoPool.setLength(length);
- // 导演
- Elements directorEles = pEle.select("div:contains(導演)").select("span.value");
- if (directorEles.size() > 0) {
- videoInfoPool.setDirector(directorEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
- }
- // 制作商
- Elements markerEles = pEle.select("div:contains(片商)").select("span.value");
- if (markerEles.size() > 0) {
- videoInfoPool.setMaker(markerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
- }
- // 发行商
- Elements issuerEles = pEle.select("div:contains(發行)").select("span.value");
- if (issuerEles.size() > 0) {
- videoInfoPool.setIssuer(issuerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
- }
- // 类别
- Elements genresEles = pEle.select("div:contains(類別)").select("span.value");
- if (genresEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = genresEles.first().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoPool.setGenres(sb.toString());
- }
- // 演员
- Elements castEles = pEle.select("div:contains(演員)").select("span.value");
- if (castEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = castEles.first().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoPool.setCast(sb.toString());
- }
- // 图片URL
- String href = videoDetail.select("div.column-video-cover").select("a > img").first().attr("src");
- long start = System.currentTimeMillis();
- Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- String fileName = issueDate.concat(" ").concat(videoInfoPool.getIdentificationCode()).concat(" ").concat(StringUtils.escapeJavParam(videoInfoPool.getName()));
- byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
- if (imgUrlBytes.length > 251) {
- byte[] imgUrlDestBytes = new byte[251];
- System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
- fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
- }
- fileName = fileName.concat(".jpg");
- String machiImgUrl = "码池/".concat(fileName);
- saveFile(response.bodyStream(), machiPath.concat(machiImgUrl));
- long end = System.currentTimeMillis();
- videoInfoPool.setImgUrl(machiImgUrl);
- videoInfoPool.setCreateTime(LocalDateTime.now());
- videoInfoPool.setType(1);
- return end - start;
- }
- private void parseDocument4Uncensored(Document document, String identificationCode, String machiPath, VideoInfoUncensored videoInfoUncensored) throws Exception {
- Elements container = document.select("div.container");
- if (container.size() == 0) {
- throw new Exception("番号无效!");
- }
- Elements pEles = container.select("div.info > p");
- // 识别码
- Element pEle = pEles.get(0);
- String iCode = pEle.select("span[style]").first().text();
- if (!identificationCode.equalsIgnoreCase(iCode)) {
- throw new Exception("番号与站点不一致");
- }
- // 长度
- pEle = pEles.get(2);
- String length = pEle.text().split(":")[1].replace("\"", "").trim();
- videoInfoUncensored.setLength(length);
- // 导演
- Elements directorEles = container.select("div.info").select("p:contains(導演)");
- if (directorEles.size() > 0) {
- pEle = directorEles.first().select("a[href]").first();
- videoInfoUncensored.setDirector(pEle.text());
- }
- // 制作商
- Elements markerEles = container.select("div.info").select("p:contains(製作商)");
- if (markerEles.size() > 0) {
- pEle = markerEles.first().select("a[href]").first();
- videoInfoUncensored.setMaker(pEle.text());
- }
- // 发行商
- Elements issuerEles = container.select("div.info").select("p:contains(發行商)");
- if (issuerEles.size() > 0) {
- pEle = issuerEles.first().select("a[href]").first();
- videoInfoUncensored.setIssuer(pEle.text());
- }
- // 类别
- Elements genresEles = container.select("div.info").select("p:contains(類別)");
- if (genresEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = genresEles.first().nextElementSibling().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text()).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoUncensored.setGenres(sb.toString());
- }
- // 演员
- Elements castEles = container.select("div.info").select("p.star-show:contains(演員)");
- if (castEles.size() > 0) {
- Elements castElesTemp = container.select("div.info:contains(暫無出演者資訊)");
- if (castElesTemp.size() == 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = castEles.first().nextElementSibling().nextElementSibling().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text()).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoUncensored.setCast(sb.toString());
- }
- }
- }
- private String parseDocument4QiBing(Document document, String identificationCode, String qibingPath, VideoInfo videoInfo) throws Exception {
- Elements container = document.select("div.container");
- if (container.size() == 0) {
- throw new Exception("番号无效!");
- }
- // 名称
- String h3 = container.select("h3").first().text();
- String[] nameArr = h3.split("\\s+");
- if (nameArr.length > 1) {
- videoInfo.setName(h3.substring(nameArr[0].length()).trim());
- } else {
- videoInfo.setName(nameArr[0]);
- }
- Elements pEles = container.select("div.info > p");
- // 识别码
- Element pEle = pEles.get(0);
- String iCode = pEle.select("span[style]").first().text();
- if (!identificationCode.equalsIgnoreCase(iCode)) {
- throw new Exception("番号与站点不一致");
- }
- // 发行日期
- pEle = pEles.get(1);
- String issueDate = pEle.text().split(":")[1].replace("\"", "").trim();
- videoInfo.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- // 长度
- pEle = pEles.get(2);
- String length = pEle.text().split(":")[1].replace("\"", "").trim();
- videoInfo.setLength(length);
- // 导演
- Elements directorEles = container.select("div.info").select("p:contains(導演)");
- if (directorEles.size() > 0) {
- pEle = directorEles.first().select("a[href]").first();
- videoInfo.setDirector(pEle.text());
- }
- // 制作商
- Elements markerEles = container.select("div.info").select("p:contains(製作商)");
- if (markerEles.size() > 0) {
- pEle = markerEles.first().select("a[href]").first();
- videoInfo.setMaker(pEle.text());
- }
- // 发行商
- Elements issuerEles = container.select("div.info").select("p:contains(發行商)");
- if (issuerEles.size() > 0) {
- pEle = issuerEles.first().select("a[href]").first();
- videoInfo.setIssuer(pEle.text());
- }
- // 类别
- Elements genresEles = container.select("div.info").select("p:contains(類別)");
- if (genresEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = genresEles.first().nextElementSibling().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text()).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfo.setGenres(sb.toString());
- }
- // 演员
- Elements castEles = container.select("div.info").select("p.star-show:contains(演員)");
- if (castEles.size() > 0) {
- Elements castElesTemp = container.select("div.info:contains(暫無出演者資訊)");
- if (castElesTemp.size() == 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = castEles.first().nextElementSibling().nextElementSibling().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text()).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfo.setCast(sb.toString());
- }
- }
- // 图片 骑兵
- String qibings = "骑兵/".concat(iCode);
- StringBuffer picTime = new StringBuffer("{cover:");
- // 图片URL bigImage
- String qibingCover = qibings.concat("/cover/");
- String fileName = issueDate.concat(" ").concat(h3).replace("?", "?");
- byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
- if (imgUrlBytes.length > 251) {
- byte[] imgUrlDestBytes = new byte[251];
- System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
- fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
- }
- fileName = fileName.concat(".jpg");
- if (!new File(qibingPath.concat(qibingCover), fileName).exists()) {
- String href = container.select("a.bigImage").first().attr("abs:href");
- long start = System.currentTimeMillis();
- Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- saveFile2(response.bodyStream(), qibingPath.concat(qibingCover), fileName);
- picTime.append(System.currentTimeMillis() - start).append(",");
- }
- videoInfo.setImgUrl(qibingCover.concat(fileName));
- // 图片URL img_gf
- String qibingImgGF = qibings.concat("/img_gf/");
- File qibingImgGFFile = new File(qibingPath.concat(qibingImgGF));
- if (!qibingImgGFFile.exists() || qibingImgGFFile.listFiles().length == 0) {
- Elements sampleBoxEles = container.select("div#sample-waterfall").select("a");
- long start2 = System.currentTimeMillis();
- if (sampleBoxEles.size() > 0) {
- Connection.Response responseImg;
- for (Element sampleBoxEle : sampleBoxEles) {
- String sampleBoxHref = sampleBoxEle.attr("href");
- if (!sampleBoxHref.contains("http")) {
- sampleBoxHref = sampleBoxEle.attr("abs:href");
- }
- try {
- responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- } catch (HttpStatusException e) {
- sampleBoxHref = sampleBoxEle.select("img").attr("src");
- if (!sampleBoxHref.contains("http")) {
- sampleBoxHref = sampleBoxEle.select("img").attr("abs:src");
- }
- responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- }
- String sampleBoxFileName = sampleBoxHref.substring(sampleBoxHref.lastIndexOf("/") + 1);
- saveFile2(responseImg.bodyStream(), qibingPath.concat(qibingImgGF), sampleBoxFileName);
- }
- } else {
- log.error("jsoupVideoInfo img_gf null,identificationCode={}", identificationCode);
- }
- picTime.append("img_gf:").append(System.currentTimeMillis() - start2).append("}");
- }
- return picTime.toString();
- }
- private String parseDocument4QiBing4Javdb(Document javdbCodeDocument, String identificationCode, String qibingPath, VideoInfo videoInfo) throws Exception {
- Elements container = javdbCodeDocument.select("section.section > div.container");
- if (container.size() == 0) {
- throw new BusinessException(30000, "番号无效!");
- }
- Elements videoDetail = container.select("div.video-detail");
- // 名称
- videoInfo.setName(videoDetail.select("h2.title").select("strong.current-title").text().trim());
- Elements originTitle = videoDetail.select("h2.title").select("span.origin-title");
- if (originTitle.size() > 0) {
- videoInfo.setName(originTitle.text().trim());
- }
- Elements moviePanelInfos = videoDetail.select("nav.movie-panel-info");
- Element pEle = moviePanelInfos.get(0);
- // 识别码
- String iCode = pEle.select("div:contains(番號)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
- if (!identificationCode.equalsIgnoreCase(iCode)) {
- throw new Exception("番号与站点不一致");
- }
- // 发行日期
- String issueDate = pEle.select("div:contains(日期)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
- videoInfo.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- // 长度
- String length = pEle.select("div:contains(時長)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
- videoInfo.setLength(length);
- // 导演
- Elements directorEles = pEle.select("div:contains(導演)").select("span.value");
- if (directorEles.size() > 0) {
- videoInfo.setDirector(directorEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
- }
- // 制作商
- Elements markerEles = pEle.select("div:contains(片商)").select("span.value");
- if (markerEles.size() > 0) {
- videoInfo.setMaker(markerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
- }
- // 发行商
- Elements issuerEles = pEle.select("div:contains(發行)").select("span.value");
- if (issuerEles.size() > 0) {
- videoInfo.setIssuer(issuerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
- }
- // 类别
- Elements genresEles = pEle.select("div:contains(類別)").select("span.value");
- if (genresEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = genresEles.first().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfo.setGenres(sb.toString());
- }
- // 演员
- Elements castEles = pEle.select("div:contains(演員)").select("span.value");
- if (castEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = castEles.first().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfo.setCast(sb.toString());
- }
- // 图片 骑兵
- String qibings = "骑兵/".concat(iCode);
- StringBuffer picTime = new StringBuffer("{cover:");
- // 图片URL bigImage
- String qibingCover = qibings.concat("/cover/");
- String fileName = issueDate.concat(" ").concat(videoInfo.getIdentificationCode()).concat(" ").concat(videoInfo.getName()).replace("?", "?");
- byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
- if (imgUrlBytes.length > 251) {
- byte[] imgUrlDestBytes = new byte[251];
- System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
- fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
- }
- fileName = fileName.concat(".jpg");
- if (!new File(qibingPath.concat(qibingCover), fileName).exists()) {
- Elements videoMetaPanel = videoDetail.select("div.column-video-cover");
- String href = videoMetaPanel.select("a > img").first().attr("src");
- long start = System.currentTimeMillis();
- Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- saveFile2(response.bodyStream(), qibingPath.concat(qibingCover), fileName);
- picTime.append(System.currentTimeMillis() - start).append(",");
- }
- videoInfo.setImgUrl(qibingCover.concat(fileName));
- // 图片URL img_gf
- String qibingImgGF = qibings.concat("/img_gf/");
- File qibingImgGFFile = new File(qibingPath.concat(qibingImgGF));
- if (!qibingImgGFFile.exists() || qibingImgGFFile.listFiles().length == 0) {
- Elements sampleBoxEles = videoDetail.select("div.preview-images").select("a.tile-item");
- long start2 = System.currentTimeMillis();
- if (sampleBoxEles.size() > 0) {
- Connection.Response responseImg;
- for (Element sampleBoxEle : sampleBoxEles) {
- String sampleBoxHref = sampleBoxEle.attr("href");
- if (!sampleBoxHref.contains("http")) {
- sampleBoxHref = sampleBoxEle.attr("abs:href");
- }
- try {
- responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- } catch (HttpStatusException e) {
- sampleBoxHref = sampleBoxEle.select("img").attr("src");
- if (!sampleBoxHref.contains("http")) {
- sampleBoxHref = sampleBoxEle.select("img").attr("abs:src");
- }
- responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- }
- String sampleBoxFileName = sampleBoxHref.substring(sampleBoxHref.lastIndexOf("/") + 1);
- saveFile2(responseImg.bodyStream(), qibingPath.concat(qibingImgGF), sampleBoxFileName);
- }
- } else {
- log.error("jsoupVideoInfo img_gf null,identificationCode={}", identificationCode);
- }
- picTime.append("img_gf:").append(System.currentTimeMillis() - start2).append("}");
- }
- return picTime.toString();
- }
- /**
- * 保存文件到本地2
- *
- * @param bufferedInputStream
- * @param savePathPrex
- * @param fileName
- */
- private void saveFile2(BufferedInputStream bufferedInputStream, String savePathPrex, String fileName) throws IOException {
- File savePathPrexFile = new File(savePathPrex);
- // 判断目录是否存在,如果不存在则新建
- if (!savePathPrexFile.exists()) {
- boolean result = savePathPrexFile.mkdirs();
- if (!result) {
- throw new IOException("创建目录失败!");
- }
- }
- //一次最多读取1k
- byte[] buffer = new byte[1024];
- //实际读取的长度
- int readLenghth;
- //创建的一个写出的缓冲流
- BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savePathPrexFile, fileName)));
- //文件逐步写入本地
- while ((readLenghth = bufferedInputStream.read(buffer, 0, 1024)) != -1) {//先读出来,保存在buffer数组中
- bufferedOutputStream.write(buffer, 0, readLenghth);//再从buffer中取出来保存到本地
- }
- //关闭缓冲流
- bufferedOutputStream.close();
- bufferedInputStream.close();
- }
- /**
- * 保存文件到本地
- *
- * @param bufferedInputStream
- * @param savePath
- */
- private void saveFile(BufferedInputStream bufferedInputStream, String savePath) throws IOException {
- //一次最多读取1k
- byte[] buffer = new byte[1024];
- //实际读取的长度
- int readLenghth;
- //创建的一个写出的缓冲流
- BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savePath)));
- //文件逐步写入本地
- while ((readLenghth = bufferedInputStream.read(buffer, 0, 1024)) != -1) {//先读出来,保存在buffer数组中
- bufferedOutputStream.write(buffer, 0, readLenghth);//再从buffer中取出来保存到本地
- }
- //关闭缓冲流
- bufferedOutputStream.close();
- bufferedInputStream.close();
- }
- // 递归获取某目录下的所有子目录以及子文件
- private void getAllFilePaths(String filePath, JavAllInfo javAllInfo, List<String> allIcode) {
- File[] files = new File(filePath).listFiles();
- if (files == null) {
- return;
- }
- int type = 0;
- if (filePath.contains("骑兵")) {
- type = 1;
- } else if (filePath.contains("步兵")) {
- type = 2;
- }
- Set<String> sameNameSet = new HashSet<>();
- for (File file : files) {
- if (file.isDirectory()) {
- // 文件夹
- getAllFilePaths(file.getAbsolutePath(), javAllInfo, allIcode);
- } else {
- String fileName = file.getName();
- String fileSuffix = fileName.substring(fileName.lastIndexOf(".") + 1);
- if (!ignoreFileTypeSuffix.contains(fileSuffix)) {
- String parentName = file.getParentFile().getName();
- // 识别码
- String name = fileName.substring(10, fileName.lastIndexOf(".")).trim();
- String[] nameArr = name.split("\\s+");
- try {
- boolean isMain = false;
- if (!fileName.endsWith(".lnk")) {
- if (allIcode.contains(nameArr[0]) || sameNameSet.contains(nameArr[0])) {
- continue;
- }
- isMain = true;
- // 获取正片信息
- VideoInfo videoInfo = new VideoInfo();
- // 发行日期
- //String issueDate = fileName.substring(0, 10);
- //videoInfo.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- // 识别码
- videoInfo.setIdentificationCode(nameArr[0]);
- // 名称
- //if (nameArr.length > 1) {
- // videoInfo.setName(name.substring(nameArr[0].length()).trim());
- //} else {
- // videoInfo.setName(nameArr[0]);
- //}
- // 类型
- videoInfo.setType(type);
- // 图片URL
- //videoInfo.setImgUrl(parentName.concat("/").concat(fileName));
- // 视频URL
- videoInfo.setVideoUrl(parentName.concat("/").concat(fileName));
- // 创建时间 TODO
- // 修改时间
- videoInfo.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
- // 主体是谁
- videoInfo.setMainWho(parentName);
- javAllInfo.getVideoInfoList().add(videoInfo);
- sameNameSet.add(nameArr[0]);
- }
- if (parentName.contains("类别")) {
- // 获取类别
- String videoGenres = parentName.replace("(类别)", "");
- javAllInfo.getVideoGenresSet().add(videoGenres);
- VideoInfoGenres videoInfoGenres = new VideoInfoGenres();
- videoInfoGenres.setIdentificationCode(nameArr[0]);
- videoInfoGenres.setName(videoGenres);
- videoInfoGenres.setType(isMain ? 1 : 2);
- javAllInfo.getVideoInfoGenresSet().add(videoInfoGenres);
- } else if (parentName.contains("优)")) {
- // 获取演员
- String videoCast = "";
- if (parentName.contains("(男")) {
- videoCast = parentName.replace("(男优)", "");
- javAllInfo.getVideoCastMap().put(videoCast, "1");
- } else if (parentName.contains("(女")) {
- videoCast = parentName.replace("(女优)", "");
- javAllInfo.getVideoCastMap().put(videoCast, "2");
- }
- VideoInfoCast videoInfoCast = new VideoInfoCast();
- videoInfoCast.setIdentificationCode(nameArr[0]);
- videoInfoCast.setName(videoCast);
- videoInfoCast.setType(isMain ? 1 : 2);
- javAllInfo.getVideoInfoCastSet().add(videoInfoCast);
- }
- } catch (Exception e) {
- System.err.println("error:" + file.getAbsolutePath());
- System.err.println("error reason:" + e.getMessage());
- }
- } else {
- System.out.println("other type file:" + file.getAbsolutePath());
- }
- }
- }
- }
- private void getAllFilePaths4Uncensored(String filePath, JavAllInfo4Uncensored javAllInfo4Uncensored) {
- File[] files = new File(filePath).listFiles();
- if (files == null) {
- return;
- }
- for (File file : files) {
- if (file.isDirectory()) {
- // 文件夹
- getAllFilePaths4Uncensored(file.getAbsolutePath(), javAllInfo4Uncensored);
- } else {
- String fileName = file.getName();
- if (fileName.endsWith(".jpg")) {
- String parentName = file.getParentFile().getName();
- // 识别码
- String name = fileName.substring(10).replace(".jpg", "").trim();
- String[] nameArr = name.split("\\s+");
- try {
- // 获取正片信息
- VideoInfoUncensored videoInfoUncensored = new VideoInfoUncensored();
- // 发行日期
- String issueDate = fileName.substring(0, 10);
- videoInfoUncensored.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- videoInfoUncensored.setIdentificationCode(nameArr[0]);
- // 名称
- if (nameArr.length > 1) {
- videoInfoUncensored.setName(name.substring(nameArr[0].length()).trim());
- } else {
- videoInfoUncensored.setName(nameArr[0]);
- }
- // 类型
- videoInfoUncensored.setStatus(1);
- // 图片URL
- videoInfoUncensored.setImgUrl(parentName.concat("/").concat(fileName));
- // 创建时间 TODO
- // 修改时间
- videoInfoUncensored.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
- // 主体是谁
- videoInfoUncensored.setMainWho(parentName);
- javAllInfo4Uncensored.getVideoInfoUncensoredList().add(videoInfoUncensored);
- System.out.println("success:" + file.getAbsolutePath());
- } catch (Exception e) {
- System.err.println("error:" + file.getAbsolutePath());
- System.err.println("error reason:" + e.getMessage());
- }
- } else if (!fileName.endsWith(".jpg") && !fileName.endsWith(".srt")) {
- String[] nameArr = fileName.substring(0, fileName.lastIndexOf(".")).split("\\s+");
- String parentName = file.getParentFile().getName();
- javAllInfo4Uncensored.getVideoUrlMap().put(nameArr[1], parentName.concat("/").concat(fileName));
- }
- }
- }
- }
- private void getAllFilePaths4Infantry(String filePath, JavAllInfo4Infantry javAllInfo4Infantry, String infantryType) {
- File[] files = new File(filePath).listFiles();
- if (files == null) {
- return;
- }
- for (File file : files) {
- if (file.isDirectory()) {
- // 文件夹
- getAllFilePaths4Infantry(file.getAbsolutePath(), javAllInfo4Infantry, infantryType);
- } else {
- String fileName = file.getName();
- if (fileName.endsWith(".jpg")) {
- String parentName = file.getParentFile().getName();
- // 识别码
- String name = fileName.substring(10).replace(".jpg", "").trim();
- String[] nameArr = name.split("\\s+");
- try {
- // 获取正片信息
- VideoInfoInfantry videoInfoInfantry = new VideoInfoInfantry();
- // 发行日期
- String issueDate = fileName.substring(0, 10);
- videoInfoInfantry.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- videoInfoInfantry.setIdentificationCode(nameArr[0]);
- // 名称
- if (nameArr.length > 1) {
- videoInfoInfantry.setName(name.substring(nameArr[0].length()).trim());
- } else {
- videoInfoInfantry.setName(nameArr[0]);
- }
- // 状态
- videoInfoInfantry.setStatus(1);
- // 类型
- videoInfoInfantry.setType(infantryType);
- // 图片URL
- videoInfoInfantry.setImgUrl(parentName.concat("/").concat(fileName));
- // 创建时间 TODO
- // 修改时间
- videoInfoInfantry.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
- // 主体是谁
- videoInfoInfantry.setMainWho(parentName);
- javAllInfo4Infantry.getVideoInfoInfantryList().add(videoInfoInfantry);
- System.out.println("success:" + file.getAbsolutePath());
- } catch (Exception e) {
- System.err.println("error:" + file.getAbsolutePath());
- System.err.println("error reason:" + e.getMessage());
- }
- } else if (!fileName.endsWith(".jpg") && !fileName.endsWith(".srt") && !fileName.endsWith(".txt")) {
- String[] nameArr = fileName.substring(0, fileName.lastIndexOf(".")).split("\\s+");
- String parentName = file.getParentFile().getName();
- javAllInfo4Infantry.getVideoUrlMap().put(nameArr[1], parentName.concat("/").concat(fileName));
- }
- }
- }
- }
- // 保存所有文件
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- public void saveInfo(JavAllInfo javAllInfo, Integer isDel) {
- // 保存分类
- Set<String> videoGenresSet = javAllInfo.getVideoGenresSet();
- //List<VideoGenres> videoGenresList = new ArrayList<>();
- for (String s : videoGenresSet) {
- VideoGenres videoGenres = new VideoGenres();
- videoGenres.setName(s);
- videoGenresMapper.insertOrUpdate(videoGenres);
- System.out.println(videoGenres);
- //videoGenresList.add(videoGenres);
- }
- //Map<String, VideoGenres> stringVideoGenresMap = videoGenresList.stream().collect(Collectors.toMap(VideoGenres::getName, Function.identity(), (k1, k2) -> k2));
- // 保存演员
- Map<String, String> videoCastMap = javAllInfo.getVideoCastMap();
- //List<VideoCast> videoCastList = new ArrayList<>();
- for (Map.Entry<String, String> entry : videoCastMap.entrySet()) {
- VideoCast videoCast = new VideoCast();
- videoCast.setName(entry.getKey());
- videoCast.setType(Integer.parseInt(entry.getValue()));
- videoCastMapper.insertOrUpdate(videoCast);
- System.out.println(videoCast);
- //videoCastList.add(videoCast);
- }
- // Map<String, VideoCast> stringVideoCastMap = videoCastList.stream().collect(Collectors.toMap(VideoCast::getName, Function.identity(), (k1, k2) -> k2));
- // 保存影片信息
- List<VideoInfo> videoInfoList = javAllInfo.getVideoInfoList();
- //Map<String, String> videoUrlMap = javAllInfo.getVideoUrlMap();
- //videoInfoList.parallelStream().forEach(e -> {
- // e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
- //});
- //for (VideoInfo videoInfo : videoInfoList) {
- // try {
- // videoInfoMapper.insert(videoInfo);
- // System.out.println("success:" + videoInfo);
- // } catch (Exception e) {
- // e.printStackTrace();
- // System.out.println("error:" + videoInfo);
- // }
- //}
- int videoInfoCount = videoInfoMapper.insertList(videoInfoList);
- System.out.println("videoInfoCount:" + videoInfoCount);
- // 保存影片类别关联信息
- Set<VideoInfoGenres> videoInfoGenresSet = javAllInfo.getVideoInfoGenresSet();
- videoInfoGenresMapper.insertOrUpdate(videoInfoGenresSet);
- // 保存影片类别关联信息
- Set<VideoInfoCast> videoInfoCastSet = javAllInfo.getVideoInfoCastSet();
- videoInfoCastMapper.insertOrUpdate(videoInfoCastSet);
- }
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- public void saveInfo4Uncensored(JavAllInfo4Uncensored javAllInfo4Uncensored, Integer isDel) {
- // 删除所有
- if (isDel == 1) {
- videoInfoUncensoredMapper.deleteAll();
- }
- List<String> allIcode = videoInfoUncensoredMapper.findAllIcode();
- // 保存影片信息
- List<VideoInfoUncensored> videoInfoUncensoredList = javAllInfo4Uncensored.getVideoInfoUncensoredList();
- int videoInfoUncensoredListBefore = videoInfoUncensoredList.size();
- Map<String, String> videoUrlMap = javAllInfo4Uncensored.getVideoUrlMap();
- Iterator<VideoInfoUncensored> iterator = videoInfoUncensoredList.iterator();
- while (iterator.hasNext()) {
- if (allIcode.contains(iterator.next().getIdentificationCode())) {
- iterator.remove();
- }
- }
- videoInfoUncensoredList.parallelStream().forEach(e -> {
- e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
- });
- System.out.println("videoInfoUncensoredListBefore:" + videoInfoUncensoredListBefore + ",videoInfoUncensoredListAfter:" + videoInfoUncensoredList.size());
- int videoInfoCount = 0;
- if (videoInfoUncensoredList.size() > 0) {
- videoInfoCount = videoInfoUncensoredMapper.insertList(videoInfoUncensoredList);
- }
- System.out.println("videoInfoCount:" + videoInfoCount);
- }
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- public void saveInfo4Infantry(JavAllInfo4Infantry javAllInfo4Infantry, Integer isDel, String infantryType) {
- // 删除所有
- if (isDel == 1) {
- videoInfoInfantryMapper.deleteAll();
- }
- List<String> allIcode = videoInfoInfantryMapper.findAllIcode(infantryType);
- // 保存影片信息
- List<VideoInfoInfantry> videoInfoInfantryList = javAllInfo4Infantry.getVideoInfoInfantryList();
- int videoInfoInfantryListBefore = videoInfoInfantryList.size();
- Map<String, String> videoUrlMap = javAllInfo4Infantry.getVideoUrlMap();
- Iterator<VideoInfoInfantry> iterator = videoInfoInfantryList.iterator();
- while (iterator.hasNext()) {
- if (allIcode.contains(iterator.next().getIdentificationCode())) {
- iterator.remove();
- }
- }
- videoInfoInfantryList.parallelStream().forEach(e -> {
- e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
- });
- System.out.println("videoInfoInfantryListBefore:" + videoInfoInfantryListBefore + ",videoInfoInfantryListAfter:" + videoInfoInfantryList.size());
- int videoInfoCount = 0;
- if (videoInfoInfantryList.size() > 0) {
- videoInfoCount = videoInfoInfantryMapper.insertList(videoInfoInfantryList);
- }
- System.out.println("videoInfoCount:" + videoInfoCount);
- }
- private List<String> readFromIcodeStream(InputStream inputStream) {
- List<String> list = new ArrayList<>();
- BufferedReader br = null;
- try {
- br = new BufferedReader(new InputStreamReader(inputStream));
- String line;
- while ((line = br.readLine()) != null) {
- if (StringUtils.isNotEmpty(line)) {
- list.add(line.trim().toUpperCase());
- }
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (br != null) {
- try {
- br.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return list.stream().distinct().collect(Collectors.toList());
- }
- }
|