mirror of
https://github.com/Geniusay/ChopperBot.git
synced 2026-08-31 01:00:49 +08:00
标题生成插件
描述生成插件
This commit is contained in:
@@ -10,6 +10,7 @@ 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;
|
||||
@@ -68,10 +69,13 @@ 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;
|
||||
}
|
||||
@@ -107,6 +111,7 @@ public class OpenAPIPlugin extends SpringBootPlugin {
|
||||
private Headers buildHeader(String key){
|
||||
return new Headers.Builder()
|
||||
.add("content-type", "application/json")
|
||||
.add("scheme","https")
|
||||
.add("Authorization", "Bearer " + key)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -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<String> labels;
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class VideoSection {
|
||||
|
||||
private String barrageFile;
|
||||
@TableField(exist = false)
|
||||
private List<Barrage> barrages;
|
||||
private List<String> barrages;
|
||||
private String platform;
|
||||
|
||||
public VideoSection(String videoPath, String tag, String liver, String platform) {
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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<String, Object> toMap(Object obj) throws IllegalAccessException {
|
||||
Map<String, Object> 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<String, Object> toDeepMap(Object obj) throws IllegalAccessException {
|
||||
Map<String, Object> 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) {
|
||||
// 忽略字段不存在的异常
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String,Object> map, String key){
|
||||
return Optional.ofNullable(map.get(key)).orElse("").toString();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -12,7 +12,7 @@ import org.springframework.stereotype.Component;
|
||||
* @author Genius
|
||||
* @date 2023/10/16 23:06
|
||||
**/
|
||||
@Component
|
||||
@Component
|
||||
public class HuyaLiverCheckerBuilder extends CommonLoadConfigBuilder<HuyaLiverCheckerConfig> {
|
||||
@Override
|
||||
public HuyaLiverCheckerConfig build(Object obj) {
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package org.example.core.auto;
|
||||
|
||||
import org.example.bean.section.VideoSection;
|
||||
import org.example.plugin.SpringBootPlugin;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Genius
|
||||
* @date 2023/10/25 20:41
|
||||
**/
|
||||
public abstract class AbstractGeneratePlugin<G extends SectionGenerator<?>> extends SpringBootPlugin implements SectionPipeline{
|
||||
@Resource
|
||||
protected Map<String, G> 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 extends VideoSection, V extends VideoSection> T process(V section) {
|
||||
generator.preGenerate();
|
||||
return generator.generator(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<String> types(){
|
||||
return new ArrayList<>(generatorMap.keySet());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package org.example.core.auto;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface AutoGenerator <T>{
|
||||
T generate(Object data);
|
||||
|
||||
void preGenerate();
|
||||
T generate(Map<String,Object> data);
|
||||
}
|
||||
|
||||
@@ -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<R> implements AutoGenerator<R>,SQLInitMachine {
|
||||
public abstract <T extends VideoSection,V extends VideoSection> V generator(T section);
|
||||
}
|
||||
@@ -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 extends VideoSection,I extends VideoSection> O process(I section);
|
||||
}
|
||||
+29
@@ -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<String> {
|
||||
@Override
|
||||
public <T extends VideoSection, V extends VideoSection> V generator(T section) {
|
||||
PackageSection packageSection = new PackageSection();
|
||||
BeanUtils.copyProperties(section,packageSection);
|
||||
try {
|
||||
Map<String, Object> map = ClassUtil.toDeepMap(packageSection);
|
||||
String desc = this.generate(map);
|
||||
packageSection.setDescription(desc);
|
||||
}catch (Exception e){
|
||||
return (V) section;
|
||||
}
|
||||
return (V) packageSection;
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Genius
|
||||
* @date 2023/10/25 21:16
|
||||
**/
|
||||
@Component
|
||||
public class DescGeneratorPlugin extends AbstractGeneratePlugin<DescGenerator> {
|
||||
|
||||
@Override
|
||||
public boolean init() {
|
||||
this.type = StringUtil.lowerCaseFirstLetter(GptDescGenerator.class.getName());
|
||||
return super.init();
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
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.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<DescScheme> 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 = TitleSchemeMapper.class)
|
||||
public List<?> sqlInit() {
|
||||
return List.of(new TitleScheme(null,"作为一个资深的直播运营人员,请你根据我提供给你的直播弹幕内容,标签和主播来叙述一下该段直播发生了什么事情,叙述过程要有趣符合当前短视频快节奏和吸引眼球的风格,生成一个即可,不需要任何标识和说明"
|
||||
,"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<String, Object> data) {
|
||||
if (schemeList.isEmpty())return "";
|
||||
try {
|
||||
return PluginCheckAndDo.CheckAndGet((plugin)->{
|
||||
String liver = MapUtil.getString(data,"liver");
|
||||
String barrages = MapUtil.getString(data,"barrages");
|
||||
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,barrages))
|
||||
.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){
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
@@ -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<String, Object> data) {
|
||||
try {
|
||||
String liver = MapUtil.getString(data,"liver");
|
||||
return String.format("%s直播精彩集锦",liver);
|
||||
} catch (Exception e){
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
+53
-13
@@ -1,25 +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.bean.Barrage;
|
||||
import org.example.bean.section.PackageSection;
|
||||
import org.example.bean.section.VideoSection;
|
||||
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 mapper;
|
||||
@@ -30,8 +47,39 @@ public class GptTitleGenerator implements TitleGenerator{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generate(Object data) {
|
||||
return null;
|
||||
public String generate(Map<String,Object> data) {
|
||||
if (schemeList.isEmpty())return "";
|
||||
try {
|
||||
return PluginCheckAndDo.CheckAndGet((plugin)->{
|
||||
String barrages = MapUtil.getString(data,"barrages");
|
||||
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,barrages))
|
||||
.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,15 +89,7 @@ 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 = mapper.selectList(new QueryWrapper<>());
|
||||
}catch (Exception e){
|
||||
throw new RuntimeException("读取title_scheme表失败");
|
||||
}
|
||||
public List<?> sqlInit() {
|
||||
return List.of(new TitleScheme(null,"请你学习以下标题风格,并对这种风格做出总结。命名为风格A\n" +
|
||||
"标题一:姿态被搞到破防崩溃,上演大型红温现场,这次生气不像演的感觉要掉小珍珠了!\n" +
|
||||
"标题二:PDD节食减肥高光时刻回顾,饭后猛炫6只去皮鸡腿! \n" +
|
||||
|
||||
+57
@@ -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<String, Object> 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 "";
|
||||
}
|
||||
}
|
||||
+13
-9
@@ -1,28 +1,32 @@
|
||||
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.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<TitleGenerator> {
|
||||
@Override
|
||||
public boolean init() {
|
||||
this.type = StringUtil.lowerCaseFirstLetter(GptTitleGenerator.class.getSimpleName());
|
||||
return super.init();
|
||||
}
|
||||
|
||||
public String generate(Object data) {
|
||||
autoGenerator.preGenerate();
|
||||
return autoGenerator.generate(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+23
-2
@@ -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<String> {
|
||||
import java.util.Map;
|
||||
|
||||
Object preGenerate();
|
||||
public abstract class TitleGenerator extends SectionGenerator<String> {
|
||||
@Override
|
||||
public <T extends VideoSection, V extends VideoSection> V generator(T section) {
|
||||
PackageSection packageSection = new PackageSection();
|
||||
BeanUtils.copyProperties(section,packageSection);
|
||||
try {
|
||||
Map<String, Object> map = ClassUtil.toDeepMap(packageSection);
|
||||
String title = this.generate(map);
|
||||
packageSection.setTitle(title);
|
||||
}catch (Exception e){
|
||||
return (V) section;
|
||||
}
|
||||
return (V) packageSection;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+25
@@ -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{
|
||||
}
|
||||
+24
@@ -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{
|
||||
}
|
||||
@@ -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<DescScheme> {
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -74,7 +74,9 @@ 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);
|
||||
return 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 (Exception e){
|
||||
|
||||
@@ -3,12 +3,15 @@ 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.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 +24,8 @@ import java.util.stream.Collectors;
|
||||
@SpringBootTest(classes = ConsoleApplication.class,webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
public class TitleGenerateTest {
|
||||
|
||||
@Resource
|
||||
TitleGeneratePlugin plugin;
|
||||
@Test
|
||||
public void test(){
|
||||
Map<String, Object> map = JsonFileUtil.readJsonFile("E:\\Project\\ChopperBot\\config\\Barrage\\online\\huya\\Uzi_2023-10-18 21_22_57.json");
|
||||
@@ -32,7 +37,11 @@ public class TitleGenerateTest {
|
||||
}
|
||||
return "";
|
||||
}).collect(Collectors.toList());
|
||||
System.out.println(content);
|
||||
VideoSection videoSection = new VideoSection();
|
||||
videoSection.setBarrages(content);
|
||||
videoSection.setTag("英雄联盟");
|
||||
videoSection.setLiver("大司马");
|
||||
System.out.println(plugin.process(videoSection));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user