From 791b164a270902faa11581029714664ade8ca08f Mon Sep 17 00:00:00 2001 From: welsir <1824379011@qq.com> Date: Sat, 1 Jun 2024 17:21:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E6=A8=A1=E5=9D=97=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E8=B4=A6=E5=8F=B7=E9=80=9A=E9=81=93=E6=90=AD=E5=BB=BA?= =?UTF-8?q?=EF=BC=8C=E7=BC=BA=E5=B0=91=E8=87=AA=E5=8A=A8=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/example/api/AccountApi.java | 7 ++++- .../core/account/Impl/AccountOperator.java | 4 +-- .../core/channel/AccountBindChannel.java | 3 --- .../org/example/core/exchange/Exchange.java | 4 +-- .../core/exchange/PostWorkerManager.java | 7 +++-- .../core/guard/VideoPushChannelGuard.java | 6 +++-- .../init/PostWorkerPluginInitMachine.java | 25 ++++++++++++++++++ .../main/java/org/example/pojo/Account.java | 4 +-- .../org/example/constpool/PluginName.java | 2 ++ .../java/org/example/api/VideoPublishApi.java | 3 +++ .../factory/platformSelectionFactory.java | 9 ++++--- .../impl/BilibiliVideoPublisher.java | 2 ++ .../publisher/impl/DouyinVideoPublisher.java | 8 +++--- chopperbot-section/pom.xml | 4 +++ .../core/section/VideoSectionWorkShop.java | 4 +++ database.db | Bin 135168 -> 143360 bytes 16 files changed, 69 insertions(+), 23 deletions(-) create mode 100644 chopperbot-account/src/main/java/org/example/init/PostWorkerPluginInitMachine.java 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 e09c4345191906daf7240414ed3d0ee613c1b065..5f9ea94ea88430262eb297e4154642f3a741d464 100644 GIT binary patch delta 2943 zcmbVOdu&@*8TWCM*m2^x*^tt%QhS%QVx8)6pZ2|21{^<sKV^h5m!YL>GD5{i71Junq~tm=?MY(1g&0CQX3gk7>LF1+8lb601c27))p!C+kSc zqz10ex%ZxPzQ^zTzH`3sJaNhX#C7{qCnle@SS&NByHK~HKDm94dhl7xZ050HGy<;o z(c3cZdVgo~=#wt%N#~14pZOF>?3kZbFO3hD&;wAPLF@0jwv)q8gQ1z8+&JB#`y=w_r|_&zwPKa0uF~A0E?|Y z60!MgL&Iw$Q$s%)nmW?3z7FnKFIwK)zFZu&4^(b#OxU(BOW;m_^62d$>+6zoUhc_2G-oul(!gSD*RY%h!R;GIO=(0tAJ7S)9Q+ zlBx3AntA{sEJs_xZ}538sx$Tu61Z?z=<8In|lN&}*=4>OFmD*K5u-XOu}n5Mho zt`qsyjn-0#WSY1ZO)kvwwPr97WedC(%oPZ{o0bODUYw;o3`^l>dT0b?mJ67LV<%K?omXB@zOFBy)@;)JtDzK6e%)jsa$YQq?S zt^0%PZMs6^A+3-o>5JM%x0MekrHy>ODzIXZ=)_i7IbQCyDSFeL*`SGFYctu^;%yS= z!<+JEb1jlB&8LkeqO(v98zr4&MOw(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