diff --git a/CHANGELOG.md b/CHANGELOG.md index 00134f7..8b2a018 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,7 +64,7 @@ ------ ## [V 1.0.10] - 2023.7.31 - 🐞Bug:**#00005** 删除config文件无法修复 -- ⛏修复:**#00005** 将ModuleSrcConfigInitMachine移除插件范围,不作为File模块的插件启动,将ModuleSrcConfigInitMachine提前到WorldInit前启动。详情请看 https://github.com/969025903/ChopperBot/issues/5 +- ⛏修复:**#00005** 将ModuleSrcConfigInitMachine移除插件范围,不作为File模块的插件启动,将ModuleSrcConfigInitMachine提前到WorldInit前启动。详情请看 https://github.com/Geniusay/ChopperBot/issues/5 ------ ## [V 1.0.9] - 2023.7.30 **💥GREAT CHANGE:** diff --git a/README.md b/README.md index 2bdee7e..189f3c1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

- + ChopperBot

@@ -13,19 +13,19 @@

- + 简体中文文档 - + Update Log - - github stars + + github stars @@ -34,7 +34,7 @@

- English | 简体中文 + English | 简体中文

@@ -56,22 +56,22 @@ - **Visualization**: Provide a visual management interface to make your user experience more convenient。 # ⚙ Architecture -![image](https://github.com/969025903/ChopperBot/assets/77137063/eeca58de-611b-41ee-973f-cd375f98e569) +![image](https://github.com/Geniusay/ChopperBot/assets/77137063/eeca58de-611b-41ee-973f-cd375f98e569) # 🎥 Preview ## Plugin Center -![e6cb59bdbc2db690610d7dec956aed4](https://github.com/969025903/ChopperBot/assets/77137063/ac83fbae-d720-4b98-8701-687436605e97) +![e6cb59bdbc2db690610d7dec956aed4](https://github.com/Geniusay/ChopperBot/assets/77137063/ac83fbae-d720-4b98-8701-687436605e97) ## Task Center -![Task Center](https://github.com/969025903/ChopperBot/assets/77137063/62ab3560-c5c2-4808-be84-a765349e4c39) -![Task Monitor](https://github.com/969025903/ChopperBot/assets/77137063/95843e98-fdc3-4ff4-805a-4a0dd8ef28be) +![Task Center](https://github.com/Geniusay/ChopperBot/assets/77137063/62ab3560-c5c2-4808-be84-a765349e4c39) +![Task Monitor](https://github.com/Geniusay/ChopperBot/assets/77137063/95843e98-fdc3-4ff4-805a-4a0dd8ef28be) ## Creeper Library -![02754f052b22234db1081dec379e8fa](https://github.com/969025903/ChopperBot/assets/77137063/5e12b279-ff34-450f-a408-c4b1f2d797d9) +![02754f052b22234db1081dec379e8fa](https://github.com/Geniusay/ChopperBot/assets/77137063/5e12b279-ff34-450f-a408-c4b1f2d797d9) ## Hot Guard -![9f9a0e3127245ae70e5375c1bf90509](https://github.com/969025903/ChopperBot/assets/77137063/6d8c0f1e-a02f-4d04-a047-f03888358790) +![9f9a0e3127245ae70e5375c1bf90509](https://github.com/Geniusay/ChopperBot/assets/77137063/6d8c0f1e-a02f-4d04-a047-f03888358790) ## Heat Recommend -![431e8b1880825e528b07f9c11360577](https://github.com/969025903/ChopperBot/assets/77137063/adeab4ae-25fe-4752-a6ce-2a79a6f5703e) +![431e8b1880825e528b07f9c11360577](https://github.com/Geniusay/ChopperBot/assets/77137063/adeab4ae-25fe-4752-a6ce-2a79a6f5703e) ## Hot Live -![T4)XK652SFQ1FH7BF53~1 J](https://github.com/969025903/ChopperBot/assets/77137063/6fe79608-6724-4768-8b39-3f4b9b2483c2) +![T4)XK652SFQ1FH7BF53~1 J](https://github.com/Geniusay/ChopperBot/assets/77137063/6fe79608-6724-4768-8b39-3f4b9b2483c2) **More pages in development....** # 🕹 ChopperBot Module @@ -92,18 +92,18 @@ ![Alt](https://repobeats.axiom.co/api/embed/0ae23655bb105addf8d90a999df36f690d615af7.svg "Repobeats analytics image") # 🔗 Links -👉 [Document](https://969025903.github.io/ChopperBot-Doc/) +👉 [Document](https://Geniusay.github.io/ChopperBot-Doc/) -👉 [Developer's Guide](https://969025903.github.io/ChopperBot-Doc/pages/779a67/#chopperbot%E7%B3%BB%E7%BB%9F%E6%9E%B6%E6%9E%84) +👉 [Developer's Guide](https://Geniusay.github.io/ChopperBot-Doc/pages/779a67/#chopperbot%E7%B3%BB%E7%BB%9F%E6%9E%B6%E6%9E%84) -👉 [CHANGE LOG](https://github.com/969025903/ChopperBot/blob/master/CHANGELOG.md) +👉 [CHANGE LOG](https://github.com/Geniusay/ChopperBot/blob/master/CHANGELOG.md) # 💬Contact Us -- Email: 969025903@qq.com | geniusssbg@gmail.com +- Email: Geniusay@qq.com | geniusssbg@gmail.com - QQ - + - Wechat - + diff --git a/README.zh-CN.md b/README.zh-CN.md index b974cf4..075808e 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,6 +1,6 @@

- + ChopperBot

@@ -10,19 +10,19 @@

- + 简体中文文档 - + Update Log - - github stars + + github stars @@ -31,7 +31,7 @@

- 简体中文 | English + 简体中文 | English

@@ -53,22 +53,22 @@ - **可视化管理**: 提供可视化管理界面,让您的使用体验更方便。 # ⚙ 系统架构 -![image](https://github.com/969025903/ChopperBot/assets/77137063/eeca58de-611b-41ee-973f-cd375f98e569) +![image](https://github.com/Geniusay/ChopperBot/assets/77137063/eeca58de-611b-41ee-973f-cd375f98e569) # 🎥 项目预览 ## 插件中心 -![e6cb59bdbc2db690610d7dec956aed4](https://github.com/969025903/ChopperBot/assets/77137063/ac83fbae-d720-4b98-8701-687436605e97) +![e6cb59bdbc2db690610d7dec956aed4](https://github.com/Geniusay/ChopperBot/assets/77137063/ac83fbae-d720-4b98-8701-687436605e97) ## 爬虫任务中心 -![Task Center](https://github.com/969025903/ChopperBot/assets/77137063/62ab3560-c5c2-4808-be84-a765349e4c39) -![Task Monitor](https://github.com/969025903/ChopperBot/assets/77137063/95843e98-fdc3-4ff4-805a-4a0dd8ef28be) +![Task Center](https://github.com/Geniusay/ChopperBot/assets/77137063/62ab3560-c5c2-4808-be84-a765349e4c39) +![Task Monitor](https://github.com/Geniusay/ChopperBot/assets/77137063/95843e98-fdc3-4ff4-805a-4a0dd8ef28be) ## 爬虫仓库 -![02754f052b22234db1081dec379e8fa](https://github.com/969025903/ChopperBot/assets/77137063/5e12b279-ff34-450f-a408-c4b1f2d797d9) +![02754f052b22234db1081dec379e8fa](https://github.com/Geniusay/ChopperBot/assets/77137063/5e12b279-ff34-450f-a408-c4b1f2d797d9) ## 平台热门监控 -![9f9a0e3127245ae70e5375c1bf90509](https://github.com/969025903/ChopperBot/assets/77137063/6d8c0f1e-a02f-4d04-a047-f03888358790) +![9f9a0e3127245ae70e5375c1bf90509](https://github.com/Geniusay/ChopperBot/assets/77137063/6d8c0f1e-a02f-4d04-a047-f03888358790) ## 热门直播推荐 -![431e8b1880825e528b07f9c11360577](https://github.com/969025903/ChopperBot/assets/77137063/adeab4ae-25fe-4752-a6ce-2a79a6f5703e) +![431e8b1880825e528b07f9c11360577](https://github.com/Geniusay/ChopperBot/assets/77137063/adeab4ae-25fe-4752-a6ce-2a79a6f5703e) ## 多平台热门直播 -![T4)XK652SFQ1FH7BF53~1 J](https://github.com/969025903/ChopperBot/assets/77137063/6fe79608-6724-4768-8b39-3f4b9b2483c2) +![T4)XK652SFQ1FH7BF53~1 J](https://github.com/Geniusay/ChopperBot/assets/77137063/6fe79608-6724-4768-8b39-3f4b9b2483c2) **更多页面正在开发中....** # 🕹 ChopperBot模块介绍 @@ -88,18 +88,18 @@ # 📈 项目动态 ![Alt](https://repobeats.axiom.co/api/embed/0ae23655bb105addf8d90a999df36f690d615af7.svg "Repobeats analytics image") # 🔗 相关链接 -👉 [项目文档](https://969025903.github.io/ChopperBot-Doc/) +👉 [项目文档](https://Geniusay.github.io/ChopperBot-Doc/) -👉 [项目开发指南](https://969025903.github.io/ChopperBot-Doc/pages/779a67/#chopperbot%E7%B3%BB%E7%BB%9F%E6%9E%B6%E6%9E%84) +👉 [项目开发指南](https://Geniusay.github.io/ChopperBot-Doc/pages/779a67/#chopperbot%E7%B3%BB%E7%BB%9F%E6%9E%B6%E6%9E%84) -👉 [更新日志](https://github.com/969025903/ChopperBot/blob/master/CHANGELOG.md) +👉 [更新日志](https://github.com/Geniusay/ChopperBot/blob/master/CHANGELOG.md) # 💬联系我们 -- Email: 969025903@qq.com | geniusssbg@gmail.com +- Email: Geniusay@qq.com | geniusssbg@gmail.com - QQ - + - Wechat - + diff --git a/chopperbot-account/src/main/java/org/example/api/LabelManagerPluginApi.java b/chopperbot-account/src/main/java/org/example/api/LabelManagerPluginApi.java new file mode 100644 index 0000000..0b5484b --- /dev/null +++ b/chopperbot-account/src/main/java/org/example/api/LabelManagerPluginApi.java @@ -0,0 +1,44 @@ +package org.example.api; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.example.core.label.LabelManagerPlugin; +import org.example.pojo.VideoLabel; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +/** + * @author Genius + * @date 2023/10/23 17:22 + **/ +@Component +public class LabelManagerPluginApi { + @Resource + LabelManagerPlugin plugin; + + public List labelList(){ + return plugin.getMapper().selectList(new QueryWrapper<>()); + } + + public VideoLabel addLabel(VideoLabel label){ + try { + label.setLabelId(UUID.randomUUID().toString()); + if (plugin.getMapper().insert(label)>0) { + return label; + } + }catch (Exception e){ + } + return null; + } + + public boolean deleteLabel(String label){ + return plugin.getMapper().deleteByMap(Map.of("label",label))>0; + } + + public boolean updateLabel(VideoLabel label){ + return plugin.getMapper().update(label,new QueryWrapper().eq("label_id",label.getLabelId()))>0; + } +} diff --git a/chopperbot-account/src/main/java/org/example/api/OpenAPIPluginApi.java b/chopperbot-account/src/main/java/org/example/api/OpenAPIPluginApi.java index 9136e15..b1175dd 100644 --- a/chopperbot-account/src/main/java/org/example/api/OpenAPIPluginApi.java +++ b/chopperbot-account/src/main/java/org/example/api/OpenAPIPluginApi.java @@ -8,6 +8,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.List; +import java.util.Map; /** * @Date 2023/10/12 @@ -22,6 +23,9 @@ public class OpenAPIPluginApi { return plugin.getMapper().update(newKey, new QueryWrapper().eq("function", newKey.getFunction())) == 1; } + public boolean deleteKey(String function){ + return plugin.getMapper().deleteByMap(Map.of("function",function))==1; + } public boolean addKey(GPTKey key){ return plugin.getMapper().insert(key)==1; } diff --git a/chopperbot-account/src/main/java/org/example/core/gpt/ChatGPTMsgBuilder.java b/chopperbot-account/src/main/java/org/example/core/gpt/ChatGPTMsgBuilder.java index 85cbe77..d455c19 100644 --- a/chopperbot-account/src/main/java/org/example/core/gpt/ChatGPTMsgBuilder.java +++ b/chopperbot-account/src/main/java/org/example/core/gpt/ChatGPTMsgBuilder.java @@ -35,6 +35,7 @@ public class ChatGPTMsgBuilder extends AbstractMsgBuilder { @Override public String done() { + build("temperature",1); this.map.put("messages", List.of(system,user)); return super.done(); } diff --git a/chopperbot-account/src/main/java/org/example/core/gpt/OpenAPIPlugin.java b/chopperbot-account/src/main/java/org/example/core/gpt/OpenAPIPlugin.java index 2659840..1ebb42d 100644 --- a/chopperbot-account/src/main/java/org/example/core/gpt/OpenAPIPlugin.java +++ b/chopperbot-account/src/main/java/org/example/core/gpt/OpenAPIPlugin.java @@ -10,12 +10,12 @@ import org.example.mapper.GPTKeyMapper; import org.example.plugin.SpringBootPlugin; import org.example.pojo.GPTKey; import org.example.sql.annotation.SQLInit; +import org.example.util.ExceptionUtil; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.io.IOException; -import java.util.Arrays; -import java.util.List; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -68,22 +68,20 @@ public class OpenAPIPlugin extends SpringBootPlugin { try (Response response = client.newCall(request).execute()){ if (response.body() != null) { String content = response.body().string(); + if(content.contains("error")){ + this.error("OpenAI API 调用错误!",String.format("OpenAI API 调用错误,原因:%s", content),true); + } return JSONObject.parseObject(content); } } catch (IOException e) { - this.error(String.format("Error: api request fail,Cause:%s", e.getCause())); + this.error(String.format("Error: api request fail,Cause:%s", ExceptionUtil.getCause(e))); } return null; } public String getCommonRes(JSONObject resp){ - Pattern pattern = Pattern.compile("\\[(.*?)]"); - - Matcher matcher = pattern.matcher(resp.getJSONArray("choices").getJSONObject(0).getJSONObject("message").getString("content")); - - if (matcher.find()) return matcher.group(1); - return ""; + return resp.getJSONArray("choices").getJSONObject(0).getJSONObject("message").getString("content"); } private RequestBody buildBody(String msg){ @@ -115,6 +113,17 @@ public class OpenAPIPlugin extends SpringBootPlugin { return Arrays.stream(APIFunc.values()).map(APIFunc::funcName).collect(Collectors.toList()); } + public static List zipContent(List contents){ + Set zipContent = new TreeSet<>(contents); + return new ArrayList<>(zipContent); + } + + public static String zipContent(String contents){ + if(contents.length()>3000){ + return contents.substring(0,3000); + } + return contents; + } @Override @SQLInit(table = "gpt_key",tableSQL = "CREATE TABLE \"gpt_key\" (\n" + "\t\"key\"\tTEXT NOT NULL,\n" + @@ -123,6 +132,6 @@ public class OpenAPIPlugin extends SpringBootPlugin { "\t\"function\"\tTEXT NOT NULL DEFAULT 'chatgpt' UNIQUE\n" + ")",mapper = GPTKeyMapper.class) public List sqlInit() { - return List.of(new GPTKey("sk-xgUDtOdRgQLigz2D0e4cA665441e4287AfCf8458B1C21b0f","https://oneapi.a9.gay/v1/chat/completions","gpt-3.5-turbo",APIFunc.CHAT_GPT.funcName())); + return List.of(new GPTKey("sk-xgUDtOdRgQLigz2D0e4cA665441e4287AfCf8458B1C21b0f","https://oneapi.a9.gay/v1/chat/completions","gpt-4",APIFunc.CHAT_GPT.funcName())); } } diff --git a/chopperbot-account/src/main/java/org/example/core/label/LabelManagerPlugin.java b/chopperbot-account/src/main/java/org/example/core/label/LabelManagerPlugin.java index 6ccdd6e..80088ce 100644 --- a/chopperbot-account/src/main/java/org/example/core/label/LabelManagerPlugin.java +++ b/chopperbot-account/src/main/java/org/example/core/label/LabelManagerPlugin.java @@ -1,6 +1,7 @@ package org.example.core.label; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import lombok.Data; import org.example.mapper.LabelMapper; import org.example.plugin.SpringBootPlugin; import org.example.pojo.VideoLabel; @@ -11,6 +12,7 @@ import javax.annotation.Resource; import java.awt.*; import java.util.List; import java.util.Map; +import java.util.UUID; import java.util.stream.Collectors; /** @@ -18,6 +20,7 @@ import java.util.stream.Collectors; * @date 2023/10/23 00:10 **/ @Component +@Data public class LabelManagerPlugin extends SpringBootPlugin { @Resource @@ -31,32 +34,19 @@ public class LabelManagerPlugin extends SpringBootPlugin { @Override @SQLInit(table = "video_label",tableSQL = "CREATE TABLE \"video_label\" (\n" + "\t\"id\"\tINTEGER NOT NULL,\n" + + "\t\"label_id\"\tTEXT NOT NULL UNIQUE,\n" + "\t\"label\"\tTEXT NOT NULL UNIQUE,\n" + "\tPRIMARY KEY(\"id\" AUTOINCREMENT)\n" + ")",mapper = LabelMapper.class) public List sqlInit() { - return List.of(new VideoLabel(null,"搞笑"), - new VideoLabel(null,"破防"),new VideoLabel(null,"泪目"), - new VideoLabel(null,"精彩操作")); + return List.of(new VideoLabel(null, UUID.randomUUID().toString(),"搞笑"), + new VideoLabel(null, UUID.randomUUID().toString(),"破防"), + new VideoLabel(null, UUID.randomUUID().toString(),"泪目"), + new VideoLabel(null, UUID.randomUUID().toString(),"精彩操作")); } public List labelStrList(){ return mapper.selectList(new QueryWrapper<>()).stream().map(VideoLabel::getLabel).collect(Collectors.toList()); } - public List labelList(){ - return mapper.selectList(new QueryWrapper<>()); - } - - public boolean addLabel(VideoLabel label){ - return mapper.insert(label)>0; - } - - public boolean deleteLabel(String label){ - return mapper.deleteByMap(Map.of("label",label))>0; - } - - public boolean updateLabel(VideoLabel label){ - return mapper.update(label,new QueryWrapper().eq("id",label.getId()))>0; - } } diff --git a/chopperbot-account/src/main/java/org/example/pojo/VideoLabel.java b/chopperbot-account/src/main/java/org/example/pojo/VideoLabel.java index 9142e96..fca4f6e 100644 --- a/chopperbot-account/src/main/java/org/example/pojo/VideoLabel.java +++ b/chopperbot-account/src/main/java/org/example/pojo/VideoLabel.java @@ -15,5 +15,6 @@ import lombok.NoArgsConstructor; @NoArgsConstructor public class VideoLabel { private Integer id; + private String labelId; private String label; } diff --git a/chopperbot-barrage/src/main/java/org/example/core/LiveAndBarrageHandlerObserver.java b/chopperbot-barrage/src/main/java/org/example/core/LiveAndBarrageHandlerObserver.java index 1d76dd1..650ed1b 100644 --- a/chopperbot-barrage/src/main/java/org/example/core/LiveAndBarrageHandlerObserver.java +++ b/chopperbot-barrage/src/main/java/org/example/core/LiveAndBarrageHandlerObserver.java @@ -52,20 +52,6 @@ public class LiveAndBarrageHandlerObserver extends AbstractTaskCenterObserver { ((BarrageEventCenter)plugin).event(event); } },PluginName.BARRAGE_EVENT_PLUGIN); - } else{ - PluginCheckAndDo.CheckAndDo(plugin -> { - Object param = task.getRequest().getParam(); - - if(param instanceof Live){ - SectionRequest request = ((VideoSectionWorkShop)plugin).wrapperReq((Live)param,task.getLoadConfig().getSuffix() - ,"online", - task.getLoadConfig().getStartTime(), - 0,TimeUtil.getTimeNaos(task.getEndTime()) - ); - ((VideoSectionWorkShop)plugin).request(request); - } - - },PluginName.VIDEO_SECTION_WORK_SHOP); } } diff --git a/chopperbot-barrage/src/main/java/org/example/core/bgevnet/BarrageEventCenter.java b/chopperbot-barrage/src/main/java/org/example/core/bgevnet/BarrageEventCenter.java index 6643d3f..aac6707 100644 --- a/chopperbot-barrage/src/main/java/org/example/core/bgevnet/BarrageEventCenter.java +++ b/chopperbot-barrage/src/main/java/org/example/core/bgevnet/BarrageEventCenter.java @@ -93,11 +93,14 @@ public class BarrageEventCenter extends SpringBootPlugin { String fileName = event.getFileName().split("\\.")[0]+suffix; String date = event.getDate(); SectionRequest request = new SectionRequest(fileName, action, popularRange.getStartTime(), popularRange.getEndTime(), liver, platform,date); + for (BarragePoint point : popularRange.getList()) { + List barrages = point.getBarrages(); + request.getBarrages().addAll(barrages); + } ((VideoSectionWorkShop)plugin).request(request); } },PluginName.VIDEO_SECTION_WORK_SHOP); } - //TODO 弹幕标签插件 } } diff --git a/chopperbot-common/src/main/java/org/example/aop/PluginAspect.java b/chopperbot-common/src/main/java/org/example/aop/PluginAspect.java index af57ea4..77e789d 100644 --- a/chopperbot-common/src/main/java/org/example/aop/PluginAspect.java +++ b/chopperbot-common/src/main/java/org/example/aop/PluginAspect.java @@ -35,7 +35,7 @@ public class PluginAspect { for (String plugin : annotation.needPlugin()) { if(!InitPluginRegister.isRegister(plugin)){ - throw new PluginNotRegisterException(); + throw new PluginNotRegisterException(annotation.needPlugin()); } } } diff --git a/chopperbot-common/src/main/java/org/example/bean/section/PackageSection.java b/chopperbot-common/src/main/java/org/example/bean/section/PackageSection.java new file mode 100644 index 0000000..6fada73 --- /dev/null +++ b/chopperbot-common/src/main/java/org/example/bean/section/PackageSection.java @@ -0,0 +1,22 @@ +package org.example.bean.section; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author Genius + * @date 2023/10/25 17:59 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class PackageSection extends VideoSection{ + private String title; + private String description; + private String coverPath; + private String content; + private List labels; +} diff --git a/chopperbot-section/src/main/java/org/example/core/section/VideoSection.java b/chopperbot-common/src/main/java/org/example/bean/section/VideoSection.java similarity index 60% rename from chopperbot-section/src/main/java/org/example/core/section/VideoSection.java rename to chopperbot-common/src/main/java/org/example/bean/section/VideoSection.java index d112e83..3410e8f 100644 --- a/chopperbot-section/src/main/java/org/example/core/section/VideoSection.java +++ b/chopperbot-common/src/main/java/org/example/bean/section/VideoSection.java @@ -1,9 +1,16 @@ -package org.example.core.section; +package org.example.bean.section; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import org.example.bean.Barrage; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -13,12 +20,16 @@ import java.util.List; **/ @Data @TableName("section_parking") +@NoArgsConstructor +@AllArgsConstructor public class VideoSection { private String videoPath; private String tag; private String liver; - private List barrages; + private String barrageFile; + @TableField(exist = false) + private List barrages; private String platform; public VideoSection(String videoPath, String tag, String liver, String platform) { 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 19031c9..025b7e7 100644 --- a/chopperbot-common/src/main/java/org/example/constpool/PluginName.java +++ b/chopperbot-common/src/main/java/org/example/constpool/PluginName.java @@ -45,8 +45,6 @@ public class PluginName { public static final String CHAT_GPT = "OpenAPI"; - public static final String EMOTION_ANALYSIS = "EmotionAnalysis"; - public static final String ACCOUNT_MANAGER = "AccountManager"; public static final String LABEL_MANAGER = "LabelManager"; @@ -56,4 +54,9 @@ public class PluginName { public static final String LIVE_MANAGER_PLUGIN= "LiveDownLoadManager"; public static final String VIDEO_SECTION_WORK_SHOP = "SectionWorkShop"; + + public static final String EMOTION_ANALYSIS = "EmotionAnalysis"; + + public static final String TITLE_GENERATE = "TitleGenerate"; + public static final String DESC_GENERATE = "DescriptionGenerate"; } diff --git a/chopperbot-common/src/main/java/org/example/exception/plugin/PluginNotRegisterException.java b/chopperbot-common/src/main/java/org/example/exception/plugin/PluginNotRegisterException.java index f36f9d9..5e80fa2 100644 --- a/chopperbot-common/src/main/java/org/example/exception/plugin/PluginNotRegisterException.java +++ b/chopperbot-common/src/main/java/org/example/exception/plugin/PluginNotRegisterException.java @@ -2,14 +2,24 @@ package org.example.exception.plugin; import org.example.exception.Impl.ResultCode; +import java.util.Arrays; +import java.util.stream.Collectors; + /** * @author Genius * @date 2023/08/02 16:59 **/ public class PluginNotRegisterException extends PluginException{ + private String pluginName[]; public PluginNotRegisterException() { super("Error! Plugin Not Register!"); resultCode = ResultCode.PLUGIN_NOT_REGISTER; } + + public PluginNotRegisterException(String...pluginName) { + super(String.format("Error! %s Plugin Not Register!",Arrays.stream(pluginName).collect(Collectors.toList()).toString())); + resultCode = ResultCode.PLUGIN_NOT_REGISTER; + this.pluginName = pluginName; + } } diff --git a/chopperbot-common/src/main/java/org/example/http/OkHttpAgent.java b/chopperbot-common/src/main/java/org/example/http/OkHttpAgent.java index 42569eb..f8f1a6d 100644 --- a/chopperbot-common/src/main/java/org/example/http/OkHttpAgent.java +++ b/chopperbot-common/src/main/java/org/example/http/OkHttpAgent.java @@ -19,11 +19,16 @@ public class OkHttpAgent implements ProxyAgent{ @Override public OkHttpClient agentClient() { + OkHttpClient.Builder builder; if(httpProxy.isEnable()){ Proxy proxy = httpProxy.httpProxy(); - return new OkHttpClient.Builder().proxy(proxy).connectTimeout(60, TimeUnit.SECONDS).build(); + builder = new OkHttpClient.Builder().proxy(proxy); }else{ - return new OkHttpClient.Builder().build(); + builder = new OkHttpClient.Builder(); } + return builder.connectTimeout(120,TimeUnit.SECONDS) + .readTimeout(60,TimeUnit.SECONDS) + .writeTimeout(60,TimeUnit.SECONDS) + .build(); } } diff --git a/chopperbot-common/src/main/java/org/example/util/ClassUtil.java b/chopperbot-common/src/main/java/org/example/util/ClassUtil.java index d328de7..008a7a0 100644 --- a/chopperbot-common/src/main/java/org/example/util/ClassUtil.java +++ b/chopperbot-common/src/main/java/org/example/util/ClassUtil.java @@ -1,12 +1,12 @@ package org.example.util; +import org.example.bean.section.VideoSection; import org.reflections.Reflections; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; +import java.lang.reflect.Field; +import java.util.*; /** * @author Genius @@ -71,4 +71,55 @@ public class ClassUtil { // return List.of(objects); return set; } + + public static Map toMap(Object obj) throws IllegalAccessException { + Map map = new HashMap<>(); + Class clazz = obj.getClass(); + + for (Field field : clazz.getDeclaredFields()) { + field.setAccessible(true); + map.put(field.getName(), field.get(obj)); + } + + return map; + } + + public static Map toDeepMap(Object obj) throws IllegalAccessException { + Map map = new HashMap<>(); + Class clazz = obj.getClass(); + + // 获取当前类的字段 + for (Field field : clazz.getDeclaredFields()) { + field.setAccessible(true); + map.put(field.getName(), field.get(obj)); + } + + // 如果有父类且不是 Object 类,递归调用获取父类的字段 + Class superClass = clazz.getSuperclass(); + if (superClass != null && !superClass.equals(Object.class)) { + try { + Object superObj = superClass.getDeclaredConstructor().newInstance(); + copyFields(superObj, obj, superClass); + map.putAll(toDeepMap(superObj)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + return map; + } + + private static void copyFields(Object dest, Object source, Class clazz) throws IllegalAccessException { + for (Field field : clazz.getDeclaredFields()) { + field.setAccessible(true); + Field destField; + try { + destField = dest.getClass().getDeclaredField(field.getName()); + destField.setAccessible(true); + destField.set(dest, field.get(source)); + } catch (NoSuchFieldException e) { + // 忽略字段不存在的异常 + } + } + } } diff --git a/chopperbot-common/src/main/java/org/example/util/MapUtil.java b/chopperbot-common/src/main/java/org/example/util/MapUtil.java new file mode 100644 index 0000000..2a650e9 --- /dev/null +++ b/chopperbot-common/src/main/java/org/example/util/MapUtil.java @@ -0,0 +1,14 @@ +package org.example.util; + +import java.util.Map; +import java.util.Optional; + +/** + * @author Genius + * @date 2023/10/25 18:44 + **/ +public class MapUtil { + public static String getString(Map map, String key){ + return Optional.ofNullable(map.get(key)).orElse("").toString(); + } +} diff --git a/chopperbot-common/src/main/java/org/example/util/StringUtil.java b/chopperbot-common/src/main/java/org/example/util/StringUtil.java new file mode 100644 index 0000000..f2222c6 --- /dev/null +++ b/chopperbot-common/src/main/java/org/example/util/StringUtil.java @@ -0,0 +1,14 @@ +package org.example.util; + +/** + * @author Genius + * @date 2023/10/25 21:31 + **/ +public class StringUtil { + public static String lowerCaseFirstLetter(String input){ + if (input == null || input.isEmpty()) { + return input; + } + return Character.toLowerCase(input.charAt(0)) + input.substring(1); + } +} diff --git a/chopperbot-console/src/main/java/org/example/controller/AccountController.java b/chopperbot-console/src/main/java/org/example/controller/AccountController.java index e214af1..6238ddd 100644 --- a/chopperbot-console/src/main/java/org/example/controller/AccountController.java +++ b/chopperbot-console/src/main/java/org/example/controller/AccountController.java @@ -1,9 +1,11 @@ package org.example.controller; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.example.pojo.Account; import org.example.pojo.AccountVO; import org.example.pojo.GPTKey; +import org.example.pojo.VideoLabel; import org.example.service.AccountService; import org.example.util.Result; import org.springframework.web.bind.annotation.*; @@ -47,11 +49,16 @@ public class AccountController { return Result.success(); } - @GetMapping(value = "/gpt/key") + @GetMapping(value = "/gpt/keys") public Result getGPT(){ return Result.success(Map.of("list",accountService.chatGptPlugin().getKeys())); } + @GetMapping(value = "/gpt/delete") + public Result deleteGPT(@RequestParam String function){ + return Result.success(Map.of("success",accountService.chatGptPlugin().deleteKey(function))); + } + @PostMapping(value = "/gpt/add") public Result addGPT(@RequestBody GPTKey key){ boolean b = accountService.chatGptPlugin().addKey(key); @@ -63,4 +70,32 @@ public class AccountController { boolean b = accountService.chatGptPlugin().changeKey(key); return Result.success(Map.of("success",b)); } + + @GetMapping(value = "/gpt/functions") + public Result getFunctions(){ + return Result.success(Map.of("list",accountService.chatGptPlugin().functions())); + } + + @GetMapping(value = "/label/list") + public Result labelList(){ + return Result.success(Map.of("list",accountService.labelManagerPlugin().labelList())); + } + + @PostMapping(value = "/label/add") + public Result addLabel(@RequestBody VideoLabel label){ + if (accountService.labelManagerPlugin().addLabel(label)==null) { + return Result.error("添加失败"); + } + return Result.success(Map.of("data",label)); + } + + @GetMapping(value = "/label/delete") + public Result deleteLabel(@RequestParam String label){ + return Result.success(Map.of("success",accountService.labelManagerPlugin().deleteLabel(label))); + } + + @PostMapping(value = "/label/update") + public Result updateLabel(@RequestBody VideoLabel label){ + return Result.success(Map.of("success",accountService.labelManagerPlugin().updateLabel(label))); + } } diff --git a/chopperbot-console/src/main/java/org/example/exception/GlobalExceptionHandler.java b/chopperbot-console/src/main/java/org/example/exception/GlobalExceptionHandler.java index 7dd8870..00e466a 100644 --- a/chopperbot-console/src/main/java/org/example/exception/GlobalExceptionHandler.java +++ b/chopperbot-console/src/main/java/org/example/exception/GlobalExceptionHandler.java @@ -7,6 +7,7 @@ import org.example.exception.plugin.PluginException; import org.example.exception.plugin.PluginNotRegisterException; import org.example.log.ChopperLogFactory; import org.example.log.LoggerType; +import org.example.util.ExceptionUtil; import org.example.util.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,10 +33,10 @@ public class GlobalExceptionHandler { @ExceptionHandler(PluginException.class) public Result handlerPluginException(HttpServletRequest request,PluginException ex){ - logger.error("Handle Exception Request Url:{},Exception:{}", request.getRequestURL(), ex); + logger.error("Handle Exception Request Url:{},Exception:{}", request.getRequestURL(), ExceptionUtil.getCause(ex)); if(ex instanceof PluginNotRegisterException){ PluginNotRegisterException exception = (PluginNotRegisterException) ex; - return Result.error(exception.getResultCode()); + return Result.error(exception.getResultCode(),ExceptionUtil.getCause(ex)); }else if(ex instanceof PluginDependOnException){ PluginDependOnException exception = (PluginDependOnException) ex; String msg = "[%s] plugin depend on [%s]!"; diff --git a/chopperbot-console/src/main/java/org/example/init/WorldInitMachine.java b/chopperbot-console/src/main/java/org/example/init/WorldInitMachine.java index 66229d0..9e563ce 100644 --- a/chopperbot-console/src/main/java/org/example/init/WorldInitMachine.java +++ b/chopperbot-console/src/main/java/org/example/init/WorldInitMachine.java @@ -20,7 +20,7 @@ import java.util.function.Supplier; @Component public class WorldInitMachine extends ModuleInitMachine{ - private static final String githubUrl = "https://github.com/969025903/ChopperBot"; + private static final String githubUrl = "https://github.com/Geniusay/ChopperBot"; public WorldInitMachine() throws Exception { super("ChopperBot",ChopperLogFactory.getLogger(LoggerType.System)); diff --git a/chopperbot-console/src/main/java/org/example/service/AccountService.java b/chopperbot-console/src/main/java/org/example/service/AccountService.java index 4ea0e82..14487ed 100644 --- a/chopperbot-console/src/main/java/org/example/service/AccountService.java +++ b/chopperbot-console/src/main/java/org/example/service/AccountService.java @@ -3,6 +3,7 @@ package org.example.service; import org.example.api.AccountApi; +import org.example.api.LabelManagerPluginApi; import org.example.api.OpenAPIPluginApi; /** @@ -15,4 +16,6 @@ public interface AccountService { AccountApi accountPlugin(); OpenAPIPluginApi chatGptPlugin(); + + LabelManagerPluginApi labelManagerPlugin(); } diff --git a/chopperbot-console/src/main/java/org/example/service/impl/AccountServiceImpl.java b/chopperbot-console/src/main/java/org/example/service/impl/AccountServiceImpl.java index b9ce879..0056fac 100644 --- a/chopperbot-console/src/main/java/org/example/service/impl/AccountServiceImpl.java +++ b/chopperbot-console/src/main/java/org/example/service/impl/AccountServiceImpl.java @@ -2,6 +2,7 @@ package org.example.service.impl; import org.example.api.AccountApi; +import org.example.api.LabelManagerPluginApi; import org.example.api.OpenAPIPluginApi; import org.example.service.AccountService; @@ -22,6 +23,9 @@ public class AccountServiceImpl implements AccountService { @Resource OpenAPIPluginApi openAPIPluginApi; + @Resource + LabelManagerPluginApi labelManagerPluginApi; + @Override public AccountApi accountPlugin() { return accountApi; @@ -31,4 +35,9 @@ public class AccountServiceImpl implements AccountService { public OpenAPIPluginApi chatGptPlugin() { return openAPIPluginApi; } + + @Override + public LabelManagerPluginApi labelManagerPlugin() { + return labelManagerPluginApi; + } } diff --git a/chopperbot-hot/src/main/java/org/example/core/creeper/builder/HuyaLiverCheckerBuilder.java b/chopperbot-hot/src/main/java/org/example/core/creeper/builder/HuyaLiverCheckerBuilder.java index 04f0916..9277861 100644 --- a/chopperbot-hot/src/main/java/org/example/core/creeper/builder/HuyaLiverCheckerBuilder.java +++ b/chopperbot-hot/src/main/java/org/example/core/creeper/builder/HuyaLiverCheckerBuilder.java @@ -12,12 +12,12 @@ import org.springframework.stereotype.Component; * @author Genius * @date 2023/10/16 23:06 **/ -@Component +@Component public class HuyaLiverCheckerBuilder extends CommonLoadConfigBuilder { @Override public HuyaLiverCheckerConfig build(Object obj) { if(obj instanceof FocusLiver){ - return new HuyaLiverCheckerConfig(((HuyaLive) obj).getLiveId()); + return new HuyaLiverCheckerConfig(((FocusLiver) obj).getRoomId()); }else if(obj instanceof HuyaLive){ return new HuyaLiverCheckerConfig(((HuyaLive) obj).getLiveId()); } diff --git a/chopperbot-hot/src/main/java/org/example/service/impl/FocusLiverServiceImpl.java b/chopperbot-hot/src/main/java/org/example/service/impl/FocusLiverServiceImpl.java index a9f6be5..1a203d4 100644 --- a/chopperbot-hot/src/main/java/org/example/service/impl/FocusLiverServiceImpl.java +++ b/chopperbot-hot/src/main/java/org/example/service/impl/FocusLiverServiceImpl.java @@ -37,6 +37,7 @@ public class FocusLiverServiceImpl extends ServiceImpl> extends SpringBootPlugin implements SectionPipeline{ + @Resource + protected Map generatorMap; + + private G generator; + + protected String type; + + @Override + public boolean init() { + if(!StringUtils.hasText(type)){ + generatorMap.forEach((k,v)->{ + this.type = k; + this.generator = v; + }); + }else{ + this.generator = generatorMap.get(type); + } + if(generator==null){ + throw new RuntimeException("Invalid generator type"); + } + generator.sqlInit(); + return super.init(); + } + + @Override + public T process(V section) { + generator.preGenerate(); + try { + return generator.generator(section); + }catch (Exception e){ + this.info("生成失败", String.format("生成失败,原因:%s", ExceptionUtil.getCause(e)),true); + return (T) section; + } + + } + + public boolean changeType(String type){ + if(generatorMap.containsKey(this.type)){ + this.generator = generatorMap.get(this.type); + generator.sqlInit(); + this.type = type; + return true; + } + return false; + } + + public List types(){ + return new ArrayList<>(generatorMap.keySet()); + } +} diff --git a/chopperbot-section-work/src/main/java/org/example/core/auto/AutoGenerator.java b/chopperbot-section-work/src/main/java/org/example/core/auto/AutoGenerator.java index 237f119..175c34c 100644 --- a/chopperbot-section-work/src/main/java/org/example/core/auto/AutoGenerator.java +++ b/chopperbot-section-work/src/main/java/org/example/core/auto/AutoGenerator.java @@ -1,5 +1,9 @@ package org.example.core.auto; +import java.util.Map; + public interface AutoGenerator { - T generate(Object data); + + void preGenerate(); + T generate(Map data); } diff --git a/chopperbot-section-work/src/main/java/org/example/core/auto/SectionGenerator.java b/chopperbot-section-work/src/main/java/org/example/core/auto/SectionGenerator.java new file mode 100644 index 0000000..4d9c22b --- /dev/null +++ b/chopperbot-section-work/src/main/java/org/example/core/auto/SectionGenerator.java @@ -0,0 +1,17 @@ +package org.example.core.auto; + +import org.example.bean.section.PackageSection; +import org.example.bean.section.VideoSection; +import org.example.sql.SQLInitMachine; +import org.example.util.ClassUtil; +import org.springframework.beans.BeanUtils; + +import java.util.Map; + +/** + * @author Genius + * @date 2023/10/25 20:42 + **/ +public abstract class SectionGenerator implements AutoGenerator,SQLInitMachine { + public abstract V generator(T section); +} diff --git a/chopperbot-section-work/src/main/java/org/example/core/auto/SectionPipeline.java b/chopperbot-section-work/src/main/java/org/example/core/auto/SectionPipeline.java new file mode 100644 index 0000000..d6a0118 --- /dev/null +++ b/chopperbot-section-work/src/main/java/org/example/core/auto/SectionPipeline.java @@ -0,0 +1,8 @@ +package org.example.core.auto; + +import org.example.bean.section.PackageSection; +import org.example.bean.section.VideoSection; + +public interface SectionPipeline { + O process(I section); +} diff --git a/chopperbot-section-work/src/main/java/org/example/core/auto/video/description/DescGenerator.java b/chopperbot-section-work/src/main/java/org/example/core/auto/video/description/DescGenerator.java new file mode 100644 index 0000000..3da89c6 --- /dev/null +++ b/chopperbot-section-work/src/main/java/org/example/core/auto/video/description/DescGenerator.java @@ -0,0 +1,29 @@ +package org.example.core.auto.video.description; + +import org.example.bean.section.PackageSection; +import org.example.bean.section.VideoSection; +import org.example.core.auto.SectionGenerator; +import org.example.util.ClassUtil; +import org.springframework.beans.BeanUtils; + +import java.util.Map; + +/** + * @author Genius + * @date 2023/10/25 20:38 + **/ +public abstract class DescGenerator extends SectionGenerator { + @Override + public V generator(T section) { + PackageSection packageSection = new PackageSection(); + BeanUtils.copyProperties(section,packageSection); + try { + Map map = ClassUtil.toDeepMap(packageSection); + String desc = this.generate(map); + packageSection.setDescription(desc); + }catch (Exception e){ + return (V) section; + } + return (V) packageSection; + } +} diff --git a/chopperbot-section-work/src/main/java/org/example/core/auto/video/description/DescGeneratorPlugin.java b/chopperbot-section-work/src/main/java/org/example/core/auto/video/description/DescGeneratorPlugin.java new file mode 100644 index 0000000..c4afd9c --- /dev/null +++ b/chopperbot-section-work/src/main/java/org/example/core/auto/video/description/DescGeneratorPlugin.java @@ -0,0 +1,26 @@ +package org.example.core.auto.video.description; + +import org.example.core.auto.AbstractGeneratePlugin; +import org.example.core.auto.video.title.GptTitleGenerator; +import org.example.util.StringUtil; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.Map; + +/** + * @author Genius + * @date 2023/10/25 21:16 + **/ +@Component +public class DescGeneratorPlugin extends AbstractGeneratePlugin { + + @Resource + Map descGeneratorMap; + @Override + public boolean init() { + this.generatorMap = descGeneratorMap; + this.type = StringUtil.lowerCaseFirstLetter(GptDescGenerator.class.getSimpleName()); + return super.init(); + } +} diff --git a/chopperbot-section-work/src/main/java/org/example/core/auto/video/description/GptDescGenerator.java b/chopperbot-section-work/src/main/java/org/example/core/auto/video/description/GptDescGenerator.java new file mode 100644 index 0000000..54d22b9 --- /dev/null +++ b/chopperbot-section-work/src/main/java/org/example/core/auto/video/description/GptDescGenerator.java @@ -0,0 +1,91 @@ +package org.example.core.auto.video.description; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.example.constpool.PluginName; +import org.example.core.gpt.ChatGPTMsgBuilder; +import org.example.core.gpt.OpenAPIPlugin; +import org.example.exception.plugin.PluginDependOnException; +import org.example.init.InitPluginRegister; +import org.example.mapper.DescSchemeMapper; +import org.example.mapper.TitleSchemeMapper; +import org.example.plugin.PluginCheckAndDo; +import org.example.pojo.DescScheme; +import org.example.pojo.GPTKey; +import org.example.pojo.TitleScheme; +import org.example.sql.annotation.SQLInit; +import org.example.util.ExceptionUtil; +import org.example.util.MapUtil; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author Genius + * @date 2023/10/25 20:55 + **/ +@Component +public class GptDescGenerator extends DescGenerator { + + @Resource + DescSchemeMapper mapper; + private List schemeList; + + public GptDescGenerator() { + this.schemeList = new ArrayList<>(); + } + + @Override + @SQLInit(table = "desc_scheme",tableSQL = "CREATE TABLE \"desc_scheme\" (\n" + + "\t\"id\"\tINTEGER NOT NULL,\n" + + "\t\"system\"\tTEXT NOT NULL,\n" + + "\t\"type\"\tTEXT,\n" + + "\tPRIMARY KEY(\"id\" AUTOINCREMENT)\n" + + ")",mapper = DescSchemeMapper.class) + public List sqlInit() { + return List.of(new DescScheme(null,"作为一个资深的直播运营人员,请你根据我提供给你的直播弹幕内容,标签和主播来叙述一下该段直播发生了什么事情,叙述过程要有趣符合当前短视频快节奏和吸引眼球的风格,生成一个即可,不需要任何标识和说明,字数不超过100字" + ,"global")); + } + + @Override + public void preGenerate() { + if (!InitPluginRegister.isRegister(PluginName.CHAT_GPT)) { + throw PluginDependOnException.MissingFatherPlugin(PluginName.CHAT_GPT,""); + } + try { + schemeList = mapper.selectList(new QueryWrapper<>()); + }catch (Exception e){ + throw new RuntimeException("读取desc_scheme表失败"); + } + } + + @Override + public String generate(Map data) { + if (schemeList.isEmpty())return ""; + try { + return PluginCheckAndDo.CheckAndGet((plugin)->{ + String liver = MapUtil.getString(data,"liver"); + Object barrages = data.get("barrages"); + String barrageStr = ""; + if(barrages instanceof List){ + barrageStr = OpenAPIPlugin.zipContent(OpenAPIPlugin.zipContent((List) barrages).toString()); + } + String content = MapUtil.getString(data,"content"); + GPTKey gptKey = ((OpenAPIPlugin) plugin).choseKey(OpenAPIPlugin.APIFunc.CHAT_GPT); + DescScheme scheme = schemeList.get(0); + if(gptKey==null)return ""; + ChatGPTMsgBuilder builder = new ChatGPTMsgBuilder().model(gptKey.getModel()) + .system(scheme.getSystem()) + .user(String.format("主播:%s\n内容:%s\n直播弹幕:%s", liver,content,barrageStr)) + .stream(false); + JSONObject object = ((OpenAPIPlugin) plugin).reqGPT(builder, OpenAPIPlugin.APIFunc.CHAT_GPT); + return ((OpenAPIPlugin) plugin).getCommonRes(object); + },PluginName.CHAT_GPT,String.class); + } catch (Exception e){ + throw new RuntimeException(ExceptionUtil.getCause(e)); + } + } +} diff --git a/chopperbot-section-work/src/main/java/org/example/core/auto/video/description/RandomDescGenerator.java b/chopperbot-section-work/src/main/java/org/example/core/auto/video/description/RandomDescGenerator.java new file mode 100644 index 0000000..ad3e949 --- /dev/null +++ b/chopperbot-section-work/src/main/java/org/example/core/auto/video/description/RandomDescGenerator.java @@ -0,0 +1,36 @@ +package org.example.core.auto.video.description; + +import org.example.util.MapUtil; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; +import java.util.Random; + +/** + * @author Genius + * @date 2023/10/25 21:17 + **/ +@Component +public class RandomDescGenerator extends DescGenerator{ + + @Override + public List sqlInit() { + return null; + } + + @Override + public void preGenerate() { + + } + + @Override + public String generate(Map data) { + try { + String liver = MapUtil.getString(data,"liver"); + return String.format("%s直播精彩集锦",liver); + } catch (Exception e){ + return ""; + } + } +} diff --git a/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/GptTitleGenerator.java b/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/GptTitleGenerator.java index e60f886..9793c8e 100644 --- a/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/GptTitleGenerator.java +++ b/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/GptTitleGenerator.java @@ -1,28 +1,42 @@ package org.example.core.auto.video.title; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.example.constpool.PluginName; +import org.example.core.auto.SectionPipeline; +import org.example.core.gpt.ChatGPTMsgBuilder; +import org.example.core.gpt.OpenAPIPlugin; +import org.example.core.label.LabelManagerPlugin; import org.example.exception.plugin.PluginDependOnException; -import org.example.exception.plugin.PluginNotRegisterException; import org.example.init.InitPluginRegister; import org.example.mapper.TitleSchemeMapper; +import org.example.plugin.PluginCheckAndDo; +import org.example.pojo.GPTKey; import org.example.pojo.TitleScheme; +import org.example.sql.SQLInitMachine; import org.example.sql.annotation.SQLInit; +import org.example.util.ClassUtil; +import org.example.util.ExceptionUtil; +import org.example.util.MapUtil; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; /** * @author Genius * @date 2023/10/22 18:03 **/ @Component -public class GptTitleGenerator implements TitleGenerator{ +public class GptTitleGenerator extends TitleGenerator{ @Resource - TitleSchemeMapper titleSchemeMapper; + TitleSchemeMapper mapper; private List schemeList; public GptTitleGenerator() { @@ -30,8 +44,43 @@ public class GptTitleGenerator implements TitleGenerator{ } @Override - public String generate(Object data) { - return null; + public String generate(Map data) { + if (schemeList.isEmpty())return ""; + try { + return PluginCheckAndDo.CheckAndGet((plugin)->{ + Object barrages = data.get("barrages"); + String barrageStr = ""; + if(barrages instanceof List){ + barrageStr = OpenAPIPlugin.zipContent(OpenAPIPlugin.zipContent((List) barrages).toString()); + } + String content = MapUtil.getString(data,"content"); + String liver = MapUtil.getString(data,"liver"); + String labels = MapUtil.getString(data,"labels"); + GPTKey gptKey = ((OpenAPIPlugin) plugin).choseKey(OpenAPIPlugin.APIFunc.CHAT_GPT); + TitleScheme scheme = schemeList.get(0); + if(gptKey==null)return ""; + ChatGPTMsgBuilder builder = new ChatGPTMsgBuilder().model(gptKey.getModel()) + .system(scheme.getSystem()) + .user(String.format("主播:%s\n内容:%s\n类型:%s\n弹幕:%s\n", liver,content,labels,barrageStr)) + .stream(false); + JSONObject object = ((OpenAPIPlugin) plugin).reqGPT(builder, OpenAPIPlugin.APIFunc.CHAT_GPT); + return ((OpenAPIPlugin) plugin).getCommonRes(object); + },PluginName.CHAT_GPT,String.class); + } catch (Exception e){ + throw new RuntimeException(ExceptionUtil.getCause(e)); + } + } + + @Override + public void preGenerate() { + if (!InitPluginRegister.isRegister(PluginName.CHAT_GPT)) { + throw PluginDependOnException.MissingFatherPlugin(PluginName.CHAT_GPT,""); + } + try { + schemeList = mapper.selectList(new QueryWrapper<>()); + }catch (Exception e){ + throw new RuntimeException("读取title_scheme表失败"); + } } @Override @@ -41,21 +90,8 @@ public class GptTitleGenerator implements TitleGenerator{ "\t\"type\"\tTEXT,\n" + "\tPRIMARY KEY(\"id\" AUTOINCREMENT)\n" + ")",mapper = TitleSchemeMapper.class) - public Object preGenerate() { - if (!InitPluginRegister.isRegister(PluginName.CHAT_GPT)) { - throw PluginDependOnException.MissingFatherPlugin(PluginName.CHAT_GPT,""); - } - try { - schemeList = titleSchemeMapper.selectList(new QueryWrapper<>()); - }catch (Exception e){ - throw new RuntimeException("读取title_scheme表失败"); - } - return List.of(new TitleScheme(null,"请你学习以下标题风格,并对这种风格做出总结。命名为风格A\n" + - "标题一:姿态被搞到破防崩溃,上演大型红温现场,这次生气不像演的感觉要掉小珍珠了!\n" + - "标题二:PDD节食减肥高光时刻回顾,饭后猛炫6只去皮鸡腿! \n" + - "标题三:BLG击败FNC!外战一把不输!外战幻神BLG!武器神Bin天降晕四个斩获三杀! \n" + - "标题四:前有TheShy天神下凡一锤四,今有刚神下凡一斩四,海龟剑姬jjking荣归故里吊打小代!\n" + - "标题五:属于男生的综艺来了!姿态最新惩罚局,一手辅助维克托上演“超鬼”" + public List sqlInit() { + return List.of(new TitleScheme(null,"标题一:主播被搞到破防崩溃,上演大型红温现场,这次生气不像演的感觉要掉小珍珠了!\\n标题二:主播节食减肥高光时刻回顾,饭后猛炫6只去皮鸡腿! \\n标题三:BLG击败FNC!外战一把不输!外战幻神BLG!武器神Bin天降晕四个斩获三杀! \\n标题四:前有TheShy天神下凡一锤四,今有刚神下凡一斩四,海龟剑姬jjking荣归故里吊打小代!\\n标题五:属于男生的综艺来了!姿态最新惩罚局,一手辅助维克托上演“超鬼”。请你学习以上标题样例总结出一种风格,我接下来为您提供的主播名称,弹幕内容,直播内容,标签等信息,请你作为一个热门短视频博主,根据你总结的风格和我提供的信息来生成一个吸引眼球,爆火,符合当今流行梗的短视频标题。注意:只需要给我标题,不需要“标题:”等任何前缀词语。你的所有数据信息应该从我为你提供的信息中获取,不要从标题样例中获取任何数据信息。" ,"global")); } } diff --git a/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/RandomTitleGenerator.java b/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/RandomTitleGenerator.java new file mode 100644 index 0000000..f488d21 --- /dev/null +++ b/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/RandomTitleGenerator.java @@ -0,0 +1,57 @@ +package org.example.core.auto.video.title; + +import com.alibaba.fastjson.JSONObject; +import org.example.bean.section.PackageSection; +import org.example.bean.section.VideoSection; +import org.example.constpool.PluginName; +import org.example.core.gpt.ChatGPTMsgBuilder; +import org.example.core.gpt.OpenAPIPlugin; +import org.example.plugin.PluginCheckAndDo; +import org.example.pojo.GPTKey; +import org.example.pojo.TitleScheme; +import org.example.util.ClassUtil; +import org.example.util.MapUtil; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; + +/** + * @author Genius + * @date 2023/10/25 20:17 + **/ +@Component +public class RandomTitleGenerator extends TitleGenerator{ + + @Override + public List sqlInit() { + return null; + } + + @Override + public void preGenerate() { + + } + + @Override + public String generate(Map data) { + try { + Object barrages = data.get("barrages"); + Object labels = data.get("labels"); + if(barrages instanceof List){ + String barrage = ((List) barrages).get((int) (Math.random() * ((List) barrages).size())).toString(); + String liver = MapUtil.getString(data,"liver"); + String tag = MapUtil.getString(data,"tag"); + String label = ""; + if(labels instanceof List){ + label = ((List) labels).get((int) (Math.random() * ((List) labels).size())).toString(); + } + return String.format("【%s】%s%s直播,弹幕直呼:%s!!",tag,liver,label,barrage); + } + } catch (Exception e){ + return ""; + } + return ""; + } +} diff --git a/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/TitleGeneratePlugin.java b/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/TitleGeneratePlugin.java index de21299..64fb545 100644 --- a/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/TitleGeneratePlugin.java +++ b/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/TitleGeneratePlugin.java @@ -1,28 +1,37 @@ package org.example.core.auto.video.title; -import org.example.core.auto.AutoGenerator; +import org.example.bean.section.PackageSection; +import org.example.bean.section.VideoSection; +import org.example.core.auto.AbstractGeneratePlugin; +import org.example.core.auto.SectionPipeline; +import org.example.core.auto.video.description.DescGenerator; import org.example.plugin.SpringBootPlugin; +import org.example.util.StringUtil; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * @author Genius * @date 2023/10/22 17:53 **/ @Component -public class TitleGeneratePlugin extends SpringBootPlugin { - - private TitleGenerator autoGenerator; +public class TitleGeneratePlugin extends AbstractGeneratePlugin { + @Resource + Map titleGeneratorMap; @Override public boolean init() { + this.generatorMap = titleGeneratorMap; + this.type = StringUtil.lowerCaseFirstLetter(GptTitleGenerator.class.getSimpleName()); return super.init(); } - public String generate(Object data) { - autoGenerator.preGenerate(); - return autoGenerator.generate(data); - } } diff --git a/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/TitleGenerator.java b/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/TitleGenerator.java index c22efe7..9f555d8 100644 --- a/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/TitleGenerator.java +++ b/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/TitleGenerator.java @@ -1,8 +1,29 @@ package org.example.core.auto.video.title; +import org.example.bean.section.PackageSection; +import org.example.bean.section.VideoSection; import org.example.core.auto.AutoGenerator; +import org.example.core.auto.SectionGenerator; +import org.example.sql.SQLInitMachine; +import org.example.sql.annotation.SQLInit; +import org.example.util.ClassUtil; +import org.springframework.beans.BeanUtils; -public interface TitleGenerator extends AutoGenerator { +import java.util.Map; - Object preGenerate(); +public abstract class TitleGenerator extends SectionGenerator { + @Override + public V generator(T section) { + PackageSection packageSection = new PackageSection(); + BeanUtils.copyProperties(section,packageSection); + try { + Map map = ClassUtil.toDeepMap(packageSection); + String title = this.generate(map); + packageSection.setTitle(title); + }catch (Exception e){ + return (V) section; + } + return (V) packageSection; + } } + diff --git a/chopperbot-section-work/src/main/java/org/example/init/DescGeneratorPluginInitMachine.java b/chopperbot-section-work/src/main/java/org/example/init/DescGeneratorPluginInitMachine.java new file mode 100644 index 0000000..4d1173b --- /dev/null +++ b/chopperbot-section-work/src/main/java/org/example/init/DescGeneratorPluginInitMachine.java @@ -0,0 +1,25 @@ +package org.example.init; + +import org.example.constpool.ModuleName; +import org.example.constpool.PluginName; +import org.example.core.auto.video.description.DescGeneratorPlugin; +import org.example.core.auto.video.title.TitleGeneratePlugin; +import org.example.plugin.annotation.Plugin; +import org.springframework.stereotype.Component; + +/** + * @author Genius + * @date 2023/10/25 21:26 + **/ + +@Plugin(moduleName = ModuleName.SECTION_WORK, + pluginName = PluginName.DESC_GENERATE, + pluginName_CN = "标题生成插件", + pluginDescription = "根据切片内容自动生成切片标题", + pluginClass= DescGeneratorPlugin.class, + springBootPlugin = true, + ignore=true +) +@Component +public class DescGeneratorPluginInitMachine extends SpringPlugInitMachine{ +} diff --git a/chopperbot-section-work/src/main/java/org/example/init/TitleGeneratePluginInitMachine.java b/chopperbot-section-work/src/main/java/org/example/init/TitleGeneratePluginInitMachine.java new file mode 100644 index 0000000..d1d3893 --- /dev/null +++ b/chopperbot-section-work/src/main/java/org/example/init/TitleGeneratePluginInitMachine.java @@ -0,0 +1,24 @@ +package org.example.init; + +import org.example.constpool.ModuleName; +import org.example.constpool.PluginName; +import org.example.core.analysis.EmotionAnalysisPlugin; +import org.example.core.auto.video.title.TitleGeneratePlugin; +import org.example.plugin.annotation.Plugin; +import org.springframework.stereotype.Component; + +/** + * @author Genius + * @date 2023/10/25 19:28 + **/ +@Plugin(moduleName = ModuleName.SECTION_WORK, + pluginName = PluginName.TITLE_GENERATE, + pluginName_CN = "标题生成插件", + pluginDescription = "根据切片内容自动生成切片标题", + pluginClass= TitleGeneratePlugin.class, + springBootPlugin = true, + ignore=true +) +@Component +public class TitleGeneratePluginInitMachine extends SpringPlugInitMachine{ +} diff --git a/chopperbot-section-work/src/main/java/org/example/mapper/DescSchemeMapper.java b/chopperbot-section-work/src/main/java/org/example/mapper/DescSchemeMapper.java new file mode 100644 index 0000000..b80e9a4 --- /dev/null +++ b/chopperbot-section-work/src/main/java/org/example/mapper/DescSchemeMapper.java @@ -0,0 +1,7 @@ +package org.example.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.example.pojo.DescScheme; + +public interface DescSchemeMapper extends BaseMapper { +} diff --git a/chopperbot-section-work/src/main/java/org/example/pojo/DescScheme.java b/chopperbot-section-work/src/main/java/org/example/pojo/DescScheme.java new file mode 100644 index 0000000..0b6eb6f --- /dev/null +++ b/chopperbot-section-work/src/main/java/org/example/pojo/DescScheme.java @@ -0,0 +1,23 @@ +package org.example.pojo; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author Genius + * @date 2023/10/25 21:07 + **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("desc_scheme") +public class DescScheme { + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + private String system; + private String type; +} diff --git a/chopperbot-section/src/main/java/org/example/core/section/SectionParking.java b/chopperbot-section/src/main/java/org/example/core/section/SectionParking.java index b728b9c..fd09e95 100644 --- a/chopperbot-section/src/main/java/org/example/core/section/SectionParking.java +++ b/chopperbot-section/src/main/java/org/example/core/section/SectionParking.java @@ -1,11 +1,40 @@ package org.example.core.section; +import org.example.bean.Barrage; +import org.example.bean.section.VideoSection; +import org.example.constpool.ConstPool; +import org.example.constpool.GlobalFileCache; +import org.example.mapper.VideoSectionMapper; +import org.example.util.JsonFileUtil; import org.springframework.stereotype.Component; +import javax.annotation.Resource; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.Map; +import java.util.UUID; + /** * @author Genius * @date 2023/10/22 20:56 **/ @Component public class SectionParking { + + @Resource + VideoSectionMapper mapper; + + private void saveData(VideoSection section){ + String root = (String) GlobalFileCache.ModuleSrcConfigFile.get("src", ConstPool.BARRAGE); + String liveRoot = (String)GlobalFileCache.ModuleSrcConfigFile.get("src", ConstPool.LIVE_RECORD); + String path = section.getVideoPath().replace(liveRoot,root); + if (JsonFileUtil.writeJsonFile(path, Map.of("data",section.getBarrages())).isFile()) { + section.setBarrageFile(path); + } + } + public void parking(VideoSection section){ + saveData(section); + mapper.insert(section); + } } 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 bb73e40..6ea408b 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 @@ -1,18 +1,19 @@ package org.example.core.section; -import org.apache.coyote.Request; import org.example.bean.Live; -import org.example.cache.FileCache; +import org.example.bean.section.VideoSection; import org.example.constpool.ConstPool; import org.example.constpool.FileNameBuilder; import org.example.constpool.GlobalFileCache; import org.example.plugin.SpringGuardPlugin; import org.example.sql.annotation.SQLInit; +import org.example.util.ExceptionUtil; import org.example.util.FileUtil; import org.example.util.TimeUtil; import org.example.util.VideoUtil; import org.springframework.stereotype.Component; +import javax.annotation.Resource; import java.nio.file.Paths; import java.util.List; import java.util.concurrent.BlockingQueue; @@ -30,6 +31,9 @@ public class VideoSectionWorkShop extends SpringGuardPlugin { private String liveRoot; + @Resource + SectionParking sectionParking; + @Override public boolean init() { requests = new LinkedBlockingQueue<>(1000); @@ -41,12 +45,23 @@ public class VideoSectionWorkShop extends SpringGuardPlugin { public void start() { try { SectionRequest request = requests.poll(1000, TimeUnit.SECONDS); + VideoSection videoSection = generateSection(request); + sectionParking.parking(videoSection); + }catch (InterruptedException e){ + return; + }catch (Exception e){ + e.printStackTrace(); + } + } + + private VideoSection generateSection(SectionRequest request){ + try { if(request!=null){ long videoStartTime = TimeUtil.getTimeNaos(request.getDate()); long start = (timeBias(request.getStartTime())-videoStartTime)/1000; start = start<0?0:start; long end = (timeBias(request.getEndTime())-videoStartTime)/1000; - + List barrages = request.getBarrages(); String root = Paths.get(liveRoot,request.getAction(),request.getPlatform()).toString(); String startTime = VideoUtil.formatTimeToFFMpeg(start); String endTime = VideoUtil.formatTimeToFFMpeg(end); @@ -59,14 +74,15 @@ public class VideoSectionWorkShop extends SpringGuardPlugin { String newPath = Paths.get(root,newVideoName).toString(); if (VideoUtil.cutVideoByFFMpeg(oldPath,newPath,startTime,endTime)) { this.info("切片生成", String.format("产生切片文件%s 主播:%s", newVideoName,liver),true); - VideoSection videoSection = new VideoSection(newVideoName,request.getTag(),request.getLiver(),request.getPlatform()); + VideoSection videoSection = new VideoSection(newVideoName, request.getTag(), request.getLiver(), request.getPlatform()); + videoSection.setBarrages(barrages); + return videoSection; } } - }catch (InterruptedException e){ - return; }catch (Exception e){ - e.printStackTrace(); + this.error("切片生成失败", String.format("切片生成失败,原因:%s", ExceptionUtil.getCause(e)),true); } + return null; } public long timeBias(long time){ return time+8*1000; @@ -89,12 +105,12 @@ public class VideoSectionWorkShop extends SpringGuardPlugin { "\t\"id\"\tINTEGER NOT NULL,\n" + "\t\"video_name\"\tTEXT NOT NULL,\n" + "\t\"liver\"\tTEXT NOT NULL,\n" + - "\t\"barrages\"\tTEXT NOT NULL,\n" + + "\t\"barrage_file\"\tTEXT NOT NULL,\n" + "\t\"tag\"\tTEXT NOT NULL,\n" + "\t\"date\"\tTEXT NOT NULL,\n" + "\t\"platform\"\tTEXT,\n" + "\tPRIMARY KEY(\"id\" AUTOINCREMENT)\n" + - ")") + ");") public List sqlInit() { return null; } diff --git a/chopperbot-section/src/main/java/org/example/mapper/VideoSectionMapper.java b/chopperbot-section/src/main/java/org/example/mapper/VideoSectionMapper.java new file mode 100644 index 0000000..d1d2669 --- /dev/null +++ b/chopperbot-section/src/main/java/org/example/mapper/VideoSectionMapper.java @@ -0,0 +1,7 @@ +package org.example.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.example.bean.section.VideoSection; + +public interface VideoSectionMapper extends BaseMapper { +} diff --git a/chopperbot-test/src/test/java/org/example/sectionwork/TitleGenerateTest.java b/chopperbot-test/src/test/java/org/example/sectionwork/TitleGenerateTest.java index 51dadb0..6750475 100644 --- a/chopperbot-test/src/test/java/org/example/sectionwork/TitleGenerateTest.java +++ b/chopperbot-test/src/test/java/org/example/sectionwork/TitleGenerateTest.java @@ -3,12 +3,16 @@ package org.example.sectionwork; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.example.ConsoleApplication; +import org.example.bean.section.VideoSection; +import org.example.core.auto.video.description.DescGeneratorPlugin; +import org.example.core.auto.video.title.TitleGeneratePlugin; import org.example.util.JsonFileUtil; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import javax.annotation.Resource; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -21,6 +25,11 @@ import java.util.stream.Collectors; @SpringBootTest(classes = ConsoleApplication.class,webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) public class TitleGenerateTest { + @Resource + TitleGeneratePlugin plugin; + + @Resource + DescGeneratorPlugin descGeneratorPlugin; @Test public void test(){ Map map = JsonFileUtil.readJsonFile("E:\\Project\\ChopperBot\\config\\Barrage\\online\\huya\\Uzi_2023-10-18 21_22_57.json"); @@ -32,7 +41,14 @@ public class TitleGenerateTest { } return ""; }).collect(Collectors.toList()); - System.out.println(content); + VideoSection videoSection = new VideoSection(); + videoSection.setBarrages(content.subList(0,100)); + videoSection.setTag("英雄联盟"); + videoSection.setLiver("UZI"); + VideoSection process = plugin.process(videoSection); + System.out.println(process); + VideoSection process1 = descGeneratorPlugin.process(process); + System.out.println(process1); } } } diff --git a/chopperbot-test/src/test/java/org/example/sectionwork/VoiceToTextTest.java b/chopperbot-test/src/test/java/org/example/sectionwork/VoiceToTextTest.java index 831c122..b61961a 100644 --- a/chopperbot-test/src/test/java/org/example/sectionwork/VoiceToTextTest.java +++ b/chopperbot-test/src/test/java/org/example/sectionwork/VoiceToTextTest.java @@ -22,9 +22,10 @@ public class VoiceToTextTest { public static final MediaType MEDIA_TYPE_WAV = MediaType.parse("audio/wav"); public static void main(String... args) throws IOException { - Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890)); - OkHttpClient client = new OkHttpClient.Builder().proxy(proxy).connectTimeout(60, TimeUnit.SECONDS).build(); +// Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890)); + OkHttpClient client = new OkHttpClient.Builder().connectTimeout(120, TimeUnit.SECONDS).readTimeout(120,TimeUnit.SECONDS).writeTimeout(60,TimeUnit.SECONDS).build(); + long l = System.currentTimeMillis(); // 音频文件 File audioFile = new File("E:\\Project\\chopperbot-1.0\\audioTest.mp3"); @@ -39,8 +40,10 @@ public class VoiceToTextTest { // 请求 Request request = new Request.Builder() - .addHeader("Authorization", "Bearer " + "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") - .url("https://api.openai.com/v1/audio/transcriptions") + .addHeader("Authorization", "Bearer " + "sk-xgUDtOdRgQLigz2D0e4cA665441e4287AfCf8458B1C21b0f") +// .url("https://api.openai.com/v1/audio/transcriptions") + //.url("https://oneapi.a9.gay/v1/audio/transcriptions") + .url(" https://oneapi.a9.gay/openai/deployments/whisper-1/audio/transcriptions?api-version=2023-09-01-preview") .post(requestBody) .build(); @@ -49,6 +52,7 @@ public class VoiceToTextTest { if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); System.out.println(response.body().string()); + System.out.println((System.currentTimeMillis() - l)/1000); } } diff --git a/config/chopperBotConfig.json b/config/chopperBotConfig.json index 56d3827..3c35fff 100644 --- a/config/chopperBotConfig.json +++ b/config/chopperBotConfig.json @@ -38,5 +38,5 @@ "OpenAPI":true } }, - "updateTime":"2023-10-23 15:10:01" + "updateTime":"2023-10-25 15:01:54" } \ No newline at end of file diff --git a/console-ui/src/api/account/labelApi.ts b/console-ui/src/api/account/labelApi.ts new file mode 100644 index 0000000..50d6007 --- /dev/null +++ b/console-ui/src/api/account/labelApi.ts @@ -0,0 +1,26 @@ +import request from "@/utils/request"; +import { Label } from "@/views/app/label/LabelTypes"; +export function list() { + return request({ + url: "/account/label/list/", + method: "get", + }); +} + +export function add(label: string) { + return request.post("/account/label/add/", { label: label }); +} + +export function remove(label: string) { + return request({ + url: "/account/label/delete/", + method: "get", + params: { + label: label, + }, + }); +} + +export function update(Label: Label) { + return request.post("/account/label/update/", Label); +} diff --git a/console-ui/src/components/navigation/MainMenu.vue b/console-ui/src/components/navigation/MainMenu.vue index 74634ed..caa6db6 100644 --- a/console-ui/src/components/navigation/MainMenu.vue +++ b/console-ui/src/components/navigation/MainMenu.vue @@ -1,7 +1,8 @@