diff --git a/chopperbot-account/src/main/java/org/example/api/AccountApi.java b/chopperbot-account/src/main/java/org/example/api/AccountApi.java index e22aebf..c22e57a 100644 --- a/chopperbot-account/src/main/java/org/example/api/AccountApi.java +++ b/chopperbot-account/src/main/java/org/example/api/AccountApi.java @@ -6,6 +6,9 @@ import org.example.pojo.Channel; import org.example.pojo.vo.AccountVO; import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.List; @@ -15,7 +18,8 @@ * @Author welsir * @Date 2023/9/22 14:11 */ -@Component +@RestController +@RequestMapping("/account") public class AccountApi { @Resource @@ -30,6 +34,7 @@ public class AccountApi { * 抖音登录默认为验证码登录 * b站登录默认为账号密码登录 */ + @PostMapping("/login") public void addAccountSaveCookie(int platformId, String username){ accountOperator.insertAccount(platformId,username); } diff --git a/chopperbot-account/src/main/java/org/example/core/account/Impl/AccountOperator.java b/chopperbot-account/src/main/java/org/example/core/account/Impl/AccountOperator.java index 5401007..dd18dd4 100644 --- a/chopperbot-account/src/main/java/org/example/core/account/Impl/AccountOperator.java +++ b/chopperbot-account/src/main/java/org/example/core/account/Impl/AccountOperator.java @@ -53,7 +53,7 @@ public void insertAccount(int platformId,String username) { } String realCookies = list.toString(); Account account = new Account(); - account.setPlatform_id(platformId); + account.setPlatformId(platformId); account.setCookies(realCookies); account.setUsername(username); System.out.println(account); @@ -91,7 +91,7 @@ public List addTypeToAccount(List accountTypes,List> channelAccount = channel.getChannelAccount(); channels.forEach((k,v)->{ if(channels.get(k)==null||channelAccount.get(k)==null){ @@ -64,7 +63,7 @@ public void work(){ video.setCoverPath(packageSection.getCoverPath()); video.setDescription(packageSection.getDescription()); video.setLabels(packageSection.getLabels()); - video.setPlatform(packageSection.getPlatform()); + video.setPlatform(String.valueOf(account.getPlatformId())); pushVideo.publishVideo(video); } } @@ -92,5 +91,4 @@ private String getDevicePath(String filePath){ String directory = (directoryPath != null) ? directoryPath.toString() : "No Directory"; return directory+"\\"+fileName+"\\"; } - } diff --git a/chopperbot-account/src/main/java/org/example/core/exchange/PostWorkerManager.java b/chopperbot-account/src/main/java/org/example/core/exchange/PostWorkerManager.java index 994c2cd..bb46b8e 100644 --- a/chopperbot-account/src/main/java/org/example/core/exchange/PostWorkerManager.java +++ b/chopperbot-account/src/main/java/org/example/core/exchange/PostWorkerManager.java @@ -63,11 +63,10 @@ public void run() { video.setFinish(true); videoStorehouse.decrementCount(); } + //如何保证数据一定会被消费且不会重复消费 + exchange.work(); + saveToLocal(); } - //如何保证数据一定会被消费且不会重复消费 - - exchange.work(); - saveToLocal(); } }; timer.scheduleAtFixedRate(task,0,2000); diff --git a/chopperbot-account/src/main/java/org/example/core/guard/VideoPushChannelGuard.java b/chopperbot-account/src/main/java/org/example/core/guard/VideoPushChannelGuard.java index 91c63be..23770ab 100644 --- a/chopperbot-account/src/main/java/org/example/core/guard/VideoPushChannelGuard.java +++ b/chopperbot-account/src/main/java/org/example/core/guard/VideoPushChannelGuard.java @@ -2,6 +2,7 @@ import lombok.extern.slf4j.Slf4j; import org.example.bean.section.PackageSection; +import org.example.bean.section.VideoSection; import org.example.core.factory.videoPushFactory.StrategyFactory; import org.example.plugin.SpringGuardPlugin; import org.example.pojo.PacketSectionVideo; @@ -46,14 +47,15 @@ public void start() { if(p==null){ return; } + System.out.println(p); //数据库持久化保存 PacketSectionVideo packedVideo = factory.wrapperSectionVideo(p); videosCollection.put(packedVideo.getId(),packedVideo); count.incrementAndGet(); } - public void sendVideo(PackageSection p) { - queue.add(p); + public void sendVideo(VideoSection p) { + queue.add((PackageSection) p); } public boolean pushNotify(){ diff --git a/chopperbot-account/src/main/java/org/example/init/PostWorkerPluginInitMachine.java b/chopperbot-account/src/main/java/org/example/init/PostWorkerPluginInitMachine.java new file mode 100644 index 0000000..226857d --- /dev/null +++ b/chopperbot-account/src/main/java/org/example/init/PostWorkerPluginInitMachine.java @@ -0,0 +1,25 @@ +package org.example.init; + +import org.example.constpool.ModuleName; +import org.example.constpool.PluginName; +import org.example.core.exchange.PostWorkerManager; +import org.example.core.guard.VideoPushChannelGuard; +import org.example.plugin.annotation.Plugin; +import org.springframework.stereotype.Component; + +/** + * @Description + * @Author welsir + * @Date 2024/5/31 17:15 + */ +@Plugin(moduleName = ModuleName.ACCOUNT, + pluginName = PluginName.POST_WORKER, + pluginName_CN = "快递员插件", + pluginDescription = "用于将切片仓库中包装好的切片推送至用户管道", + pluginClass= PostWorkerManager.class, + springBootPlugin = true, + ignore = true +) +@Component +public class PostWorkerPluginInitMachine extends SpringPlugInitMachine{ +} diff --git a/chopperbot-account/src/main/java/org/example/pojo/Account.java b/chopperbot-account/src/main/java/org/example/pojo/Account.java index 145484d..b0f1bba 100644 --- a/chopperbot-account/src/main/java/org/example/pojo/Account.java +++ b/chopperbot-account/src/main/java/org/example/pojo/Account.java @@ -26,7 +26,7 @@ public class Account implements Serializable { private Long id; private String username; private String cookies; - private boolean is_complete_match; - private int platform_id; + private Boolean isCompleteMatch; + private Integer platformId; } diff --git a/chopperbot-common/src/main/java/org/example/constpool/PluginName.java b/chopperbot-common/src/main/java/org/example/constpool/PluginName.java index 3fa23ac..73f55e8 100644 --- a/chopperbot-common/src/main/java/org/example/constpool/PluginName.java +++ b/chopperbot-common/src/main/java/org/example/constpool/PluginName.java @@ -51,6 +51,8 @@ public class PluginName { public static final String CHANNEL = "channel"; + public static final String POST_WORKER = "postWorker"; + public static final String LIVE_CONFIG_PLUGIN= "LiveConfig"; public static final String LIVE_MANAGER_PLUGIN= "LiveDownLoadManager"; diff --git a/chopperbot-publish/src/main/java/org/example/api/VideoPublishApi.java b/chopperbot-publish/src/main/java/org/example/api/VideoPublishApi.java index 9bc8ead..d0a5a89 100644 --- a/chopperbot-publish/src/main/java/org/example/api/VideoPublishApi.java +++ b/chopperbot-publish/src/main/java/org/example/api/VideoPublishApi.java @@ -6,6 +6,7 @@ import org.springframework.stereotype.Component; import org.springframework.util.Assert; +import javax.annotation.Resource; import java.util.Map; /** @@ -16,6 +17,8 @@ @Component public class VideoPublishApi { + @Resource + platformSelectionFactory platformSelectionFactory; public void publishVideo(VideoToPublish video){ PlatformVideoPublisher publisher = platformSelectionFactory.creatPlatformPublisher(video.getPlatform()); publisher.publishVideo(video); diff --git a/chopperbot-publish/src/main/java/org/example/core/factory/platformSelectionFactory.java b/chopperbot-publish/src/main/java/org/example/core/factory/platformSelectionFactory.java index 2d74822..e2842b9 100644 --- a/chopperbot-publish/src/main/java/org/example/core/factory/platformSelectionFactory.java +++ b/chopperbot-publish/src/main/java/org/example/core/factory/platformSelectionFactory.java @@ -3,17 +3,20 @@ import org.example.core.publisher.PlatformVideoPublisher; import org.example.core.publisher.impl.BilibiliVideoPublisher; import org.example.core.publisher.impl.DouyinVideoPublisher; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Component; /** * @Description * @Author welsir * @Date 2023/10/13 21:09 */ +@Component public class platformSelectionFactory { - public static PlatformVideoPublisher creatPlatformPublisher(String platform) { - if("BILIBILI".equals(platform)){ + public PlatformVideoPublisher creatPlatformPublisher(String platform) { + if("1".equals(platform)){ return new BilibiliVideoPublisher(); - }else if(platform.equals("DOUYIN")){ + }else if(("2").equals(platform)){ return new DouyinVideoPublisher(); } return null; diff --git a/chopperbot-publish/src/main/java/org/example/core/publisher/impl/BilibiliVideoPublisher.java b/chopperbot-publish/src/main/java/org/example/core/publisher/impl/BilibiliVideoPublisher.java index 788ba2e..14f44a9 100644 --- a/chopperbot-publish/src/main/java/org/example/core/publisher/impl/BilibiliVideoPublisher.java +++ b/chopperbot-publish/src/main/java/org/example/core/publisher/impl/BilibiliVideoPublisher.java @@ -20,6 +20,7 @@ import org.example.utils.HttpClientUtil; import org.example.utils.VideoDeviceUtil; import org.openqa.selenium.Cookie; +import org.springframework.stereotype.Component; import java.io.File; import java.io.FileInputStream; @@ -35,6 +36,7 @@ * @author dhx * @date 2023/9/18 20:49 */ +@Component public class BilibiliVideoPublisher implements PlatformVideoPublisher { @Override diff --git a/chopperbot-publish/src/main/java/org/example/core/publisher/impl/DouyinVideoPublisher.java b/chopperbot-publish/src/main/java/org/example/core/publisher/impl/DouyinVideoPublisher.java index 1308f4e..0f097a7 100644 --- a/chopperbot-publish/src/main/java/org/example/core/publisher/impl/DouyinVideoPublisher.java +++ b/chopperbot-publish/src/main/java/org/example/core/publisher/impl/DouyinVideoPublisher.java @@ -10,8 +10,10 @@ import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; +import org.springframework.stereotype.Component; import java.io.IOException; +import java.sql.Time; import java.util.*; import java.util.concurrent.TimeUnit; @@ -21,6 +23,7 @@ * @Author welsir * @Date 2023/10/13 20:11 */ +@Component public class DouyinVideoPublisher implements PlatformVideoPublisher { final String DOUYIN_PUBLISH_VIDEO = "org/example/core/script/douyin/DouyinVideoPublish.py"; @@ -34,8 +37,6 @@ public void publishVideo(VideoToPublish video) { ChromeDriver webDriver = new ChromeDriver(options); String url = "https://www.douyin.com/"; webDriver.get(url); - webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); - webDriver.manage().deleteAllCookies(); String cookies = video.getCookies().substring(1, video.getCookies().length() - 1); String[] split = cookies.split(", "); Set cookies1 = new HashSet<>(); @@ -49,8 +50,9 @@ public void publishVideo(VideoToPublish video) { Cookie cookie = new Cookie(map.get("name"), map.get("value"), map.get("path"), null); cookies1.add(cookie); } - webDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS); + webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); webDriver.manage().deleteAllCookies(); + Thread.sleep(5000L); for (Cookie cookie : cookies1) { webDriver.manage().addCookie(cookie); } diff --git a/chopperbot-section/pom.xml b/chopperbot-section/pom.xml index 95cd5e5..936d03f 100644 --- a/chopperbot-section/pom.xml +++ b/chopperbot-section/pom.xml @@ -112,6 +112,10 @@ spring-boot-starter-test test + + org.example + chopperbot-account + diff --git a/chopperbot-section/src/main/java/org/example/core/section/VideoSectionWorkShop.java b/chopperbot-section/src/main/java/org/example/core/section/VideoSectionWorkShop.java index 946f0dc..d633444 100644 --- a/chopperbot-section/src/main/java/org/example/core/section/VideoSectionWorkShop.java +++ b/chopperbot-section/src/main/java/org/example/core/section/VideoSectionWorkShop.java @@ -5,6 +5,7 @@ import org.example.constpool.ConstPool; import org.example.constpool.FileNameBuilder; import org.example.constpool.GlobalFileCache; +import org.example.core.guard.VideoPushChannelGuard; import org.example.plugin.SpringGuardPlugin; import org.example.sql.annotation.SQLInit; import org.example.util.ExceptionUtil; @@ -34,6 +35,8 @@ public class VideoSectionWorkShop extends SpringGuardPlugin { @Resource SectionParking sectionParking; + @Resource + VideoPushChannelGuard videoGuard; @Override public boolean init() { @@ -50,6 +53,7 @@ public void start() { return; VideoSection videoSection = generateSection(request); sectionParking.parking(videoSection); + videoGuard.sendVideo(videoSection); }catch (InterruptedException e){ return; }catch (Exception e){ diff --git a/database.db b/database.db index e09c434..5f9ea94 100644 Binary files a/database.db and b/database.db differ