|
@@ -1,5 +1,6 @@
|
|
|
package cn.com.ctop.kuaishou.modules.app.service.impl;
|
|
|
|
|
|
+import cn.com.ctop.common.module.utils.Check;
|
|
|
import cn.com.ctop.crawler.modules.account.entity.KuaishouAdAccount;
|
|
|
import cn.com.ctop.crawler.modules.account.entity.KuaishouAppAccount;
|
|
|
import cn.com.ctop.crawler.modules.account.entity.KuaishouIosAccount;
|
|
@@ -40,48 +41,50 @@ public class KuaishouAppServiceImpl implements IKuaishouAppService {
|
|
|
|
|
|
@Override
|
|
|
public void adFetch(KuaishouAppAccount kuaishouAppAccount, Integer page) {
|
|
|
- String videoFeeds = kuaishouCrawlerService.getVideoFeeds(kuaishouAppAccount,page);
|
|
|
+ String videoFeeds = kuaishouCrawlerService.getVideoFeeds(kuaishouAppAccount, page);
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
try {
|
|
|
- AppResult appResult = mapper.readValue(videoFeeds,new TypeReference<AppResult>(){});
|
|
|
- if(appResult != null){
|
|
|
- for(AppFeeds appFeeds : appResult.getFeeds()){
|
|
|
- AppAd ad = appFeeds.getAd();
|
|
|
-
|
|
|
- if(ad != null){
|
|
|
- if (ad.getAdCover() == null ){
|
|
|
- continue;
|
|
|
- }
|
|
|
- ad.setTime(appFeeds.getTime());
|
|
|
- ad.setCoverUrl(ad.getAdCover().getCoverUrls().get(0).getUrl().replace(".kpg",".jpg"));
|
|
|
- ad.setMvUrl(appFeeds.getMainMvUrls().get(0).getUrl());
|
|
|
- ad.setRecoReason(appFeeds.getRecoReason());
|
|
|
- ad.setUserId(appFeeds.getUserId());
|
|
|
- ad.setPageId(appFeeds.getPhotoId());
|
|
|
- ad.setPhotoId(appFeeds.getPhotoId());
|
|
|
- ad.setUserName(appFeeds.getUserName());
|
|
|
- ad.setPhotoStatus(appFeeds.getPhotoStatus());
|
|
|
- ad.setShareInfo(appFeeds.getShareInfo());
|
|
|
- ad.setViewCount(appFeeds.getViewCount());
|
|
|
- ad.setLikeCount(appFeeds.getLikeCount());
|
|
|
- ad.setCommentCount(appFeeds.getCommentCount());
|
|
|
- ad.setForwardCount(appFeeds.getForwardCount());
|
|
|
- ad.setUnlikeCount(appFeeds.getUnlikeCount());
|
|
|
- ad.setCaption(appFeeds.getCaption());
|
|
|
- ad.setWidth(ad.getAdCover().getWidth());
|
|
|
- ad.setHeight(ad.getAdCover().getHeight());
|
|
|
- ad.setType(appFeeds.getType());
|
|
|
- appAdService.saveOrUpdate(ad);
|
|
|
- try {
|
|
|
- KuaishouAdAccount kuaishouAdAccount = kuaishouAdAccountService.getById(ad.getUserId());
|
|
|
- if (kuaishouAdAccount == null){
|
|
|
- kuaishouAdAccount = new KuaishouAdAccount();
|
|
|
- kuaishouAdAccount.setKsid(ad.getUserId());
|
|
|
- kuaishouAdAccount.setName(ad.getUserName());
|
|
|
- kuaishouAdAccountService.save(kuaishouAdAccount);
|
|
|
- this.adAccountFetch(kuaishouAdAccount, "");
|
|
|
+ AppResult appResult = mapper.readValue(videoFeeds, new TypeReference<AppResult>() {
|
|
|
+ });
|
|
|
+ if (appResult != null) {
|
|
|
+ List<AppFeeds> feeds = appResult.getFeeds();
|
|
|
+ if (!Check.isNull(feeds)) {
|
|
|
+ for (AppFeeds appFeeds : feeds) {
|
|
|
+ AppAd ad = appFeeds.getAd();
|
|
|
+ if (ad != null) {
|
|
|
+ if (ad.getAdCover() == null) {
|
|
|
+ continue;
|
|
|
}
|
|
|
+ ad.setTime(appFeeds.getTime());
|
|
|
+ ad.setCoverUrl(ad.getAdCover().getCoverUrls().get(0).getUrl().replace(".kpg", ".jpg"));
|
|
|
+ ad.setMvUrl(appFeeds.getMainMvUrls().get(0).getUrl());
|
|
|
+ ad.setRecoReason(appFeeds.getRecoReason());
|
|
|
+ ad.setUserId(appFeeds.getUserId());
|
|
|
+ ad.setPageId(appFeeds.getPhotoId());
|
|
|
+ ad.setPhotoId(appFeeds.getPhotoId());
|
|
|
+ ad.setUserName(appFeeds.getUserName());
|
|
|
+ ad.setPhotoStatus(appFeeds.getPhotoStatus());
|
|
|
+ ad.setShareInfo(appFeeds.getShareInfo());
|
|
|
+ ad.setViewCount(appFeeds.getViewCount());
|
|
|
+ ad.setLikeCount(appFeeds.getLikeCount());
|
|
|
+ ad.setCommentCount(appFeeds.getCommentCount());
|
|
|
+ ad.setForwardCount(appFeeds.getForwardCount());
|
|
|
+ ad.setUnlikeCount(appFeeds.getUnlikeCount());
|
|
|
+ ad.setCaption(appFeeds.getCaption());
|
|
|
+ ad.setWidth(ad.getAdCover().getWidth());
|
|
|
+ ad.setHeight(ad.getAdCover().getHeight());
|
|
|
+ ad.setType(appFeeds.getType());
|
|
|
+ appAdService.saveOrUpdate(ad);
|
|
|
+ try {
|
|
|
+ KuaishouAdAccount kuaishouAdAccount = kuaishouAdAccountService.getById(ad.getUserId());
|
|
|
+ if (kuaishouAdAccount == null) {
|
|
|
+ kuaishouAdAccount = new KuaishouAdAccount();
|
|
|
+ kuaishouAdAccount.setKsid(ad.getUserId());
|
|
|
+ kuaishouAdAccount.setName(ad.getUserName());
|
|
|
+ kuaishouAdAccountService.save(kuaishouAdAccount);
|
|
|
+ this.adAccountFetch(kuaishouAdAccount, "");
|
|
|
+ }
|
|
|
// AppVideo video = appVideoService.getById(ad.getPhotoId());
|
|
|
|
|
|
// AppVideo video = new AppVideo();
|
|
@@ -89,8 +92,9 @@ public class KuaishouAppServiceImpl implements IKuaishouAppService {
|
|
|
// video.setPhotoId();
|
|
|
// video.setMvUrl();
|
|
|
// video.setCoverUrl();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -117,14 +121,15 @@ public class KuaishouAppServiceImpl implements IKuaishouAppService {
|
|
|
}
|
|
|
String adAccountVideoFeeds = kuaishouCrawlerService.getAdAccountVideoFeeds(kuaishouAdAccount, pcursor);
|
|
|
JsonNode node = mapper.readTree(adAccountVideoFeeds);
|
|
|
- List<AppVideo> list = mapper.readValue(node.get("feeds").toString(),new TypeReference<List<AppVideo>>(){});
|
|
|
+ List<AppVideo> list = mapper.readValue(node.get("feeds").toString(), new TypeReference<List<AppVideo>>() {
|
|
|
+ });
|
|
|
pcursor = node.get("pcursor").asText();
|
|
|
- if(list != null){
|
|
|
- for(AppVideo appVideo : list){
|
|
|
- if(appVideo.getCoverThumbnailUrls() != null){
|
|
|
+ if (list != null) {
|
|
|
+ for (AppVideo appVideo : list) {
|
|
|
+ if (appVideo.getCoverThumbnailUrls() != null) {
|
|
|
appVideo.setCoverUrl(appVideo.getCoverThumbnailUrls().get(0).getUrl());
|
|
|
}
|
|
|
- if(appVideo.getMainMvUrls() != null){
|
|
|
+ if (appVideo.getMainMvUrls() != null) {
|
|
|
appVideo.setMvUrl(appVideo.getMainMvUrls().get(0).getUrl());
|
|
|
}
|
|
|
|
|
@@ -133,7 +138,7 @@ public class KuaishouAppServiceImpl implements IKuaishouAppService {
|
|
|
}
|
|
|
Thread.sleep(10000);
|
|
|
if (pcursor != null && !"no_more".equals(pcursor)) {
|
|
|
- adAccountFetch(kuaishouAdAccount,pcursor);
|
|
|
+ adAccountFetch(kuaishouAdAccount, pcursor);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -141,21 +146,22 @@ public class KuaishouAppServiceImpl implements IKuaishouAppService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void adFetch(KuaishouIosAccount kuaishouIosAccount){
|
|
|
+ public void adFetch(KuaishouIosAccount kuaishouIosAccount) {
|
|
|
String videoFeeds = kuaishouCrawlerService.getVideoFeeds(kuaishouIosAccount);
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
try {
|
|
|
- AppResult appResult = mapper.readValue(videoFeeds,new TypeReference<AppResult>(){});
|
|
|
- if(appResult != null && appResult.getFeeds() != null){
|
|
|
- for(AppFeeds appFeeds : appResult.getFeeds()){
|
|
|
+ AppResult appResult = mapper.readValue(videoFeeds, new TypeReference<AppResult>() {
|
|
|
+ });
|
|
|
+ if (appResult != null && appResult.getFeeds() != null) {
|
|
|
+ for (AppFeeds appFeeds : appResult.getFeeds()) {
|
|
|
AppAd ad = appFeeds.getAd();
|
|
|
- if(ad != null){
|
|
|
- if (ad.getAdCover() == null ){
|
|
|
+ if (ad != null) {
|
|
|
+ if (ad.getAdCover() == null) {
|
|
|
continue;
|
|
|
}
|
|
|
ad.setTime(appFeeds.getTime());
|
|
|
- ad.setCoverUrl(ad.getAdCover().getCoverUrls().get(0).getUrl().replace(".kpg",".jpg"));
|
|
|
+ ad.setCoverUrl(ad.getAdCover().getCoverUrls().get(0).getUrl().replace(".kpg", ".jpg"));
|
|
|
ad.setMvUrl(appFeeds.getMainMvUrls().get(0).getUrl());
|
|
|
ad.setRecoReason(appFeeds.getRecoReason());
|
|
|
ad.setUserId(appFeeds.getUserId());
|
|
@@ -176,7 +182,7 @@ public class KuaishouAppServiceImpl implements IKuaishouAppService {
|
|
|
appAdService.saveOrUpdate(ad);
|
|
|
try {
|
|
|
KuaishouAdAccount kuaishouAdAccount = kuaishouAdAccountService.getById(ad.getUserId());
|
|
|
- if (kuaishouAdAccount == null){
|
|
|
+ if (kuaishouAdAccount == null) {
|
|
|
kuaishouAdAccount = new KuaishouAdAccount();
|
|
|
kuaishouAdAccount.setKsid(ad.getUserId());
|
|
|
kuaishouAdAccount.setName(ad.getUserName());
|