Commit b5d5f243 by liyaoting

first

0 parents
Showing 28 changed files with 2579 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>cn.bxe</groupId>
<artifactId>update-video</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>update-video</name>
<description>update-video</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.31</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cn.zhxu</groupId>
<artifactId>okhttps</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>cn.zhxu</groupId>
<artifactId>okhttps-fastjson</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>cn.zhxu</groupId>
<artifactId>okhttps-gson</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.22</version>
</dependency>
<!-- mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-core</artifactId>
<version>2.4.6</version>
</dependency>
<!-- window64位 ffmpeg -->
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-native-win64</artifactId>
<version>2.4.6</version>
</dependency>
<!-- linux64位 ffmpeg -->
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-native-linux64</artifactId>
<version>2.4.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package cn.bxe.updatevideo;
import cn.bxe.updatevideo.model.TbxXrBook;
import cn.bxe.updatevideo.model.TbxXrChapter;
import cn.bxe.updatevideo.model.TbxXrModule;
import cn.bxe.updatevideo.model.TbxXrVideo;
import cn.bxe.updatevideo.model.original.Chapter;
import cn.bxe.updatevideo.model.original.Module;
import cn.bxe.updatevideo.model.original.Textbook;
import cn.bxe.updatevideo.model.original.Video;
import cn.bxe.updatevideo.service.impl.TbxXrBookServiceImpl;
import cn.bxe.updatevideo.service.impl.TbxXrChapterServiceImpl;
import cn.bxe.updatevideo.service.impl.TbxXrModuleServiceImpl;
import cn.bxe.updatevideo.service.impl.TbxXrVideoServiceImpl;
import cn.bxe.updatevideo.util.JsonUtil;
import cn.zhxu.okhttps.Download;
import cn.zhxu.okhttps.HTTP;
import cn.zhxu.okhttps.HttpResult;
import cn.zhxu.okhttps.gson.GsonMsgConvertor;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.CollectionUtils;
import ws.schild.jave.FfmpegFileInfo;
import ws.schild.jave.MultimediaInfo;
import java.io.File;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import static cn.bxe.updatevideo.util.VersionUtil.*;
@SpringBootApplication
@MapperScan("cn.bxe.updatevideo.mapper")
public class UpdateVideoApplication {
private static TbxXrBookServiceImpl bookService;
private static TbxXrChapterServiceImpl chapterService;
private static TbxXrModuleServiceImpl moduleService;
private static TbxXrVideoServiceImpl videoService;
static Logger logger = LoggerFactory.getLogger(UpdateVideoApplication.class);
private static final HTTP http = HTTP
.builder()
.bodyType("json")
.addMsgConvertor(new GsonMsgConvertor())
.build();
private static ThreadPoolExecutor pool = new ThreadPoolExecutor(20, 20,
0, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(30),
new ThreadPoolExecutor.DiscardPolicy());
public static void main(String[] args) throws InterruptedException {
ConfigurableApplicationContext ctx = SpringApplication.run(UpdateVideoApplication.class, args);
bookService = ctx.getBean(TbxXrBookServiceImpl.class);
chapterService = ctx.getBean(TbxXrChapterServiceImpl.class);
moduleService = ctx.getBean(TbxXrModuleServiceImpl.class);
videoService = ctx.getBean(TbxXrVideoServiceImpl.class);
menu();
Thread.currentThread().join();
}
private static void menu() throws InterruptedException {
System.out.println("=========菜单=========");
System.out.println("1: 更新书籍");
System.out.println("2: 更新章节");
System.out.println("3: 更新模块");
System.out.println("4: 更新视频");
System.out.println("5: 下载封面");
System.out.println("6: 更新数据库视频封面链接");
System.out.println("7: 补充视频时长");
System.out.println("0: 退出");
Scanner scanner = new Scanner(System.in);
System.out.print("请输入功能代码: ");
String input = scanner.nextLine().trim();
switch (input) {
case "1":
System.out.println("更新书籍咯");
updateTextbook();
break;
case "2":
System.out.println("更新章节咯");
updateChapter();
break;
case "3":
System.out.println("更新模块咯");
updateModule();
break;
case "4":
System.out.println("更新视频咯");
updateVideo();
break;
case "5":
System.out.println("下载封面咯");
downloadCoverPic();
break;
case "6":
System.out.println("更新数据库视频封面链接咯");
updateDbVideoCoverUrl();
break;
case "7":
System.out.println("补充视频时长咯");
updateVideoDuration();
break;
case "0":
System.out.println("退出咯");
System.exit(0);
break;
default:
System.out.println("你想做咩啊?");
TimeUnit.SECONDS.sleep(2);
break;
}
menu();
}
private static void updateTextbook() throws InterruptedException {
String url = "https://api.bendiclass.com/external/api/textbook/v1/getTextbookListByLabel";
HttpResult.Body body = http
.sync(url)
.addHeader("authorize", "banxiaoer")
.setBodyPara(new Object())
.post()
.getBody();
JSONObject jsonObject = JSONObject.parseObject(body.toString());
boolean hasData = jsonObject.containsKey("data");
if (hasData) {
String data = jsonObject.getObject("data", String.class);
List<Textbook> textbooks = JsonUtil.tranJsonStrToArray(data, Textbook.class);
List<TbxXrBook> tbxXrBookList = new ArrayList<>();
for (Textbook original : textbooks) {
if (original.getGradeName().contains("修")) {
//过滤掉选修啥的 目前大概不需要
continue;
}
TbxXrBook pojo = new TbxXrBook();
pojo.setBookName(original.getSubjectName() + original.getTextbookVersionName() + original.getGradeName() + original.getSchoolYearName());
pojo.setTextbookId((int) original.getId());
pojo.setSubject(SUBJECT_MAP.get(original.getSubject()));
pojo.setGradeCode(GRADE_MAP.get(original.getGrade()));
pojo.setTerm(SCHOOL_YEAR_MAP.get(original.getSchoolYear()));
pojo.setStatus(10);
pojo.setTextbookVersion(VERSION_MAP.get(original.getTextbookVersion()));
pojo.setCreateTime(System.currentTimeMillis());
tbxXrBookList.add(pojo);
}
if (tbxXrBookList.size() > 0) {
//查询已存在的book
LambdaQueryWrapper<TbxXrBook> qw = new LambdaQueryWrapper<>();
qw.select(TbxXrBook::getTextbookId);
List<TbxXrBook> list = bookService.list(qw);
//根据textbookId过滤已存在的
Set<Integer> textBookSet = list.stream().map(TbxXrBook::getTextbookId).collect(Collectors.toSet());
tbxXrBookList = tbxXrBookList.stream().filter(o -> !textBookSet.contains(o.getTextbookId())).collect(Collectors.toList());
//保存新增的
bookService.saveBatch(tbxXrBookList);
}
}
}
private static void updateChapter() throws InterruptedException {
LambdaQueryWrapper<TbxXrBook> qw = new LambdaQueryWrapper<>();
Scanner scanner = new Scanner(System.in);
System.out.print("请输入你想更新的Textbook Id,直接回车为全部: ");
String textbookId = scanner.nextLine().trim();
if (StringUtils.isNotBlank(textbookId)) {
qw.eq(TbxXrBook::getTextbookId, textbookId);
} else {
System.out.print("请输入你想更新的版本,直接回车为全部: ");
String version = scanner.nextLine().trim();
if (StringUtils.isNotBlank(version)) {
System.out.println(version);
qw.eq(TbxXrBook::getTextbookVersion, version);
}
System.out.print("请输入你想更新的年级,直接回车为全部: ");
String grade = scanner.nextLine().trim();
if (StringUtils.isNotBlank(grade)) {
qw.eq(TbxXrBook::getGradeCode, grade);
}
}
qw.select(TbxXrBook::getTextbookId, TbxXrBook::getBookName);
List<TbxXrBook> list = bookService.list(qw);
int bookNum = list.size();
AtomicInteger count = new AtomicInteger();
CountDownLatch cdl = new CountDownLatch(bookNum);
for (TbxXrBook book : list) {
pool.submit(() -> {
try {
int currentNum = count.addAndGet(1);
String url = "https://api.bendiclass.com/external/textbookChapter/v1/queryTextbookChapter";
HttpResult.Body body = http
.sync(url)
.addHeader("authorize", "banxiaoer")
.addUrlPara("textbookId", book.getTextbookId())
.get()
.getBody();
TimeUnit.MILLISECONDS.sleep(200);
JSONObject jsonObject = JSONObject.parseObject(body.toString());
boolean hasData = jsonObject.containsKey("data");
if (hasData) {
String data = jsonObject.getObject("data", String.class);
List<Chapter> originalChaperList = JsonUtil.tranJsonStrToArray(data, Chapter.class);
List<TbxXrChapter> tbxXrChapterList = new ArrayList<>();
for (Chapter original : originalChaperList) {
TbxXrChapter chapter = new TbxXrChapter();
chapter.setLevel(original.getLevel());
chapter.setChapterId(original.getId());
chapter.setChapterName(original.getChapterName());
chapter.setTextbookId(original.getTextbookID());
chapter.setParentId(original.getParentID());
chapter.setSortIndex(original.getSortIndex());
chapter.setChildrenJson(original.getChildren());
chapter.setStatus(10);
chapter.setCreateTime(System.currentTimeMillis());
tbxXrChapterList.add(chapter);
}
if (tbxXrChapterList.size() > 0) {
List<Integer> chapterIdList = tbxXrChapterList.stream().map(TbxXrChapter::getChapterId).collect(Collectors.toList());
LambdaQueryWrapper<TbxXrChapter> chapterQW = new LambdaQueryWrapper<>();
chapterQW.eq(TbxXrChapter::getTextbookId, book.getTextbookId());
chapterQW.in(TbxXrChapter::getChapterId, chapterIdList);
chapterQW.select(TbxXrChapter::getChapterId);
List<TbxXrChapter> dbList = chapterService.list(chapterQW);
Set<Integer> dbChapterIdSet = dbList.stream().map(TbxXrChapter::getChapterId).collect(Collectors.toSet());
tbxXrChapterList = tbxXrChapterList.stream().filter(o -> !dbChapterIdSet.contains(o.getChapterId())).collect(Collectors.toList());
if (tbxXrChapterList.size() > 0) {
logger.info("{}/{},{},新增{}条数据", currentNum, bookNum, book.getBookName(), tbxXrChapterList.size());
chapterService.saveBatch(tbxXrChapterList);
} else {
logger.info("{}/{},{}无新内容", currentNum, bookNum, book.getBookName());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
cdl.countDown();
});
TimeUnit.MILLISECONDS.sleep(100);
}
cdl.await();
}
private static void updateModule() throws InterruptedException {
LambdaQueryWrapper<TbxXrBook> qw = new LambdaQueryWrapper<>();
Scanner scanner = new Scanner(System.in);
System.out.print("也许你想按textbookId更新?,直接回车为全部: ");
String textbookId = scanner.nextLine().trim();
if (StringUtils.isNotBlank(textbookId)) {
qw.eq(TbxXrBook::getTextbookId, textbookId);
} else {
System.out.print("请输入你想更新的版本,直接回车为全部: ");
String version = scanner.nextLine().trim();
if (StringUtils.isNotBlank(version)) {
System.out.println(version);
qw.eq(TbxXrBook::getTextbookVersion, version);
}
System.out.print("请输入你想更新的年级,直接回车为全部: ");
String grade = scanner.nextLine().trim();
if (StringUtils.isNotBlank(grade)) {
qw.eq(TbxXrBook::getGradeCode, grade);
}
}
qw.select(TbxXrBook::getTextbookId, TbxXrBook::getBookName);
List<TbxXrBook> list = bookService.list(qw);
int bookNum = list.size();
AtomicInteger bookCounter = new AtomicInteger();
CountDownLatch bookCDL = new CountDownLatch(bookNum);
for (TbxXrBook tbxXrBook : list) {
int currentBookNum = bookCounter.addAndGet(1);
logger.info("查询书籍{}/{} :: 书名: {}", currentBookNum, bookNum, tbxXrBook.getBookName());
LambdaQueryWrapper<TbxXrChapter> chapterQW = new LambdaQueryWrapper<>();
chapterQW.eq(TbxXrChapter::getTextbookId, tbxXrBook.getTextbookId());
chapterQW.select(TbxXrChapter::getChapterId, TbxXrChapter::getChildrenJson);
List<TbxXrChapter> chapterList = chapterService.list(chapterQW);
List<Integer> chapterIdList = new ArrayList<>();
for (TbxXrChapter chapter : chapterList) {
chapterIdList.add(chapter.getChapterId());
List<Integer> childrenIdList = JsonUtil
.tranJsonStrToArray(chapter.getChildrenJson(), Chapter.class)
.stream()
.map(Chapter::getId)
.collect(Collectors.toList());
chapterIdList.addAll(childrenIdList);
}
int chapterNum = chapterIdList.size();
AtomicInteger chapterCounter = new AtomicInteger();
CountDownLatch chapterCDL = new CountDownLatch(chapterNum);
for (Integer id : chapterIdList) {
pool.execute(() -> {
try {
int currentChapterNum = chapterCounter.addAndGet(1);
String url = "https://api.bendiclass.com/external/textbookCategory/v1/queryValidCategory";
HttpResult.Body body = http
.sync(url)
.addUrlPara("textbookId", tbxXrBook.getTextbookId())
.addUrlPara("chapterId", id)
.get()
.getBody();
TimeUnit.MILLISECONDS.sleep(100);
JSONObject jsonObject = JSONObject.parseObject(body.toString());
String dataList = jsonObject.getObject("data", String.class);
List<Module> modules = JsonUtil.tranJsonStrToArray(dataList, Module.class);
if (modules.size() > 0) {
List<TbxXrModule> tbxXrModuleList = new ArrayList<>();
List<Integer> moduleIdList = new ArrayList<>();
for (Module module : modules) {
TbxXrModule tbxXrModule = moduleConvert(module);
tbxXrModule.setChapterId(id);
tbxXrModuleList.add(tbxXrModule);
moduleIdList.add(tbxXrModule.getModuleId());
List<Module> moduleList = module.getModuleList();
for (Module module1 : moduleList) {
TbxXrModule subTbxXrModule = moduleConvert(module1);
subTbxXrModule.setChapterId(id);
subTbxXrModule.setCategoryName(module.getCategoryName());
subTbxXrModule.setCategoryDesc(module1.getModuleDesc());
moduleIdList.add(subTbxXrModule.getModuleId());
tbxXrModuleList.add(subTbxXrModule);
}
}
LambdaQueryWrapper<TbxXrModule> moduleQW = new LambdaQueryWrapper<>();
moduleQW.in(TbxXrModule::getModuleId, moduleIdList);
moduleQW.eq(TbxXrModule::getChapterId, id);
moduleQW.eq(TbxXrModule::getTextbookId, tbxXrBook.getTextbookId());
moduleQW.select(TbxXrModule::getModuleId, TbxXrModule::getTextbookId, TbxXrModule::getChapterId);
List<TbxXrModule> dbExistModule = moduleService.list(moduleQW);
for (TbxXrModule tbxXrModule : dbExistModule) {
tbxXrModuleList.remove(tbxXrModule);
}
if (tbxXrModuleList.size() > 0) {
moduleService.saveBatch(tbxXrModuleList);
logger.info("书籍{}/{},开始处理章节: {}/{},更新模块数:{}", currentBookNum, bookNum, currentChapterNum, chapterNum, tbxXrModuleList.size());
} else {
logger.info("章节: {}/{},无更新", currentChapterNum, chapterNum);
}
} else {
logger.info("章节: {}/{},无内容~", currentChapterNum, chapterNum);
}
} catch (Exception e) {
e.printStackTrace();
}
chapterCDL.countDown();
});
TimeUnit.MILLISECONDS.sleep(100);
}
chapterCDL.await();
bookCDL.countDown();
}
bookCDL.await();
}
private static void updateVideo() throws InterruptedException {
LambdaQueryWrapper<TbxXrBook> qw = new LambdaQueryWrapper<>();
Scanner scanner = new Scanner(System.in);
System.out.print("也许你想按textbookId更新?,直接回车为全部: ");
String textbookId = scanner.nextLine().trim();
if (StringUtils.isNotBlank(textbookId)) {
qw.eq(TbxXrBook::getTextbookId, textbookId);
} else {
System.out.print("请输入你想更新的版本,直接回车为全部: ");
String version = scanner.nextLine().trim();
if (StringUtils.isNotBlank(version)) {
qw.eq(TbxXrBook::getTextbookVersion, version);
}
System.out.print("请输入你想更新的年级,直接回车为全部: ");
String grade = scanner.nextLine().trim();
if (StringUtils.isNotBlank(grade)) {
qw.eq(TbxXrBook::getGradeCode, grade);
}
}
qw.select(TbxXrBook::getTextbookId, TbxXrBook::getBookName);
List<TbxXrBook> bookList = bookService.list(qw);
AtomicInteger bookCount = new AtomicInteger();
CountDownLatch bookCDL = new CountDownLatch(bookList.size());
for (TbxXrBook book : bookList) {
int currentBookNum = bookCount.addAndGet(1);
LambdaQueryWrapper<TbxXrChapter> chapterQW = new LambdaQueryWrapper<>();
chapterQW.eq(TbxXrChapter::getTextbookId, book.getTextbookId());
chapterQW.select(TbxXrChapter::getChapterId, TbxXrChapter::getChildrenJson, TbxXrChapter::getChapterName);
List<TbxXrChapter> dbChapterList = chapterService.list(chapterQW);
//key: chapterId, value: moduleIdList
Map<Integer, List<Integer>> chapterAndModuleIdMap = new HashMap<>();
//整理章节id
for (TbxXrChapter chapter : dbChapterList) {
chapterAndModuleIdMap.put(chapter.getChapterId(), new ArrayList<>());
List<Chapter> childChapter = JsonUtil.tranJsonStrToArray(chapter.getChildrenJson(), Chapter.class);
chapterAndModuleIdMap.put(chapter.getChapterId(), new ArrayList<>());
for (Chapter chapter1 : childChapter) {
chapterAndModuleIdMap.put(chapter1.getId(), new ArrayList<>());
}
}
List<Integer> emptyModuleIdList = new ArrayList<>();
//整理模块id
chapterAndModuleIdMap.forEach((k, v) -> {
LambdaQueryWrapper<TbxXrModule> moduleQW = new LambdaQueryWrapper<>();
moduleQW.eq(TbxXrModule::getChapterId, k);
moduleQW.select(TbxXrModule::getModuleId);
List<TbxXrModule> dbModuleList = moduleService.list(moduleQW);
if (CollectionUtils.isEmpty(dbModuleList)) {
emptyModuleIdList.add(k);
} else {
for (TbxXrModule module : dbModuleList) {
v.add(module.getModuleId());
}
}
});
emptyModuleIdList.forEach(chapterAndModuleIdMap::remove);
//获取视频 整理需要更新的视频
AtomicInteger chapterCount = new AtomicInteger();
int allModuleNum = chapterAndModuleIdMap.values().stream().mapToInt(List::size).sum();
AtomicInteger moduleCount = new AtomicInteger();
chapterAndModuleIdMap.forEach((chapterId, moduleIdList) -> {
int currentChapterNum = chapterCount.addAndGet(1);
if (moduleIdList.size() > 0) {
CountDownLatch moduleCDL = new CountDownLatch(moduleIdList.size());
CopyOnWriteArrayList<TbxXrVideo> chapterVideoList = new CopyOnWriteArrayList<>();
CopyOnWriteArrayList<Integer> videoIdList = new CopyOnWriteArrayList<>();
for (Integer moduleId : moduleIdList) {
pool.submit(() -> {
try {
int currentModuleNum = moduleCount.addAndGet(1);
List<TbxXrVideo> moduleVideoList = new ArrayList<>();
String baseUrl = "https://api.bendiclass.com/external/textbookVideo/v1/queryTextbookVideo";
HttpResult.Body body = http
.sync(baseUrl)
.addUrlPara("chapterId", chapterId)
.addUrlPara("moduleId", moduleId)
.get()
.getBody();
TimeUnit.MILLISECONDS.sleep(100);
JSONObject jsonObject = JSONObject.parseObject(body.toString());
List<Video> videoDataList = JsonUtil.tranJsonStrToArray(jsonObject.getObject("data", String.class), Video.class);
if (videoDataList.size() > 0) {
for (Video video : videoDataList) {
TbxXrVideo record = new TbxXrVideo();
record.setVideoId(video.getId());
record.setModuleId(moduleId);
record.setChapterId(chapterId);
video.setVideoName(video.getVideoName().trim());
record.setVideoName(video.getVideoName());
if (video.getVideoName().length() > 50) {
System.out.println(video.getVideoName());
record.setVideoName(video.getVideoName().substring(0, 46) + "...");
}
record.setUrl(video.getUrl());
record.setTimeDuration(video.getTimeDuration());
record.setStatus(10);
record.setCreateTime(System.currentTimeMillis());
moduleVideoList.add(record);
}
videoIdList.addAll(moduleVideoList.stream().map(TbxXrVideo::getVideoId).collect(Collectors.toList()));
if (moduleVideoList.size() > 0) {
chapterVideoList.addAll(moduleVideoList);
} else {
logger.info("书籍进度{}/{},章节进度{}/{},无更新视频", currentBookNum, bookList.size(), currentChapterNum, chapterAndModuleIdMap.size());
}
}
} catch (Exception e) {
e.printStackTrace();
}
moduleCDL.countDown();
});
}
try {
moduleCDL.await();
if (videoIdList.size() > 0) {
LambdaQueryWrapper<TbxXrVideo> tbxXrVideoQW = new LambdaQueryWrapper<>();
tbxXrVideoQW.select(TbxXrVideo::getVideoId, TbxXrVideo::getChapterId, TbxXrVideo::getModuleId);
tbxXrVideoQW.eq(TbxXrVideo::getStatus, 10);
tbxXrVideoQW.in(TbxXrVideo::getVideoId, videoIdList);
List<TbxXrVideo> dbVideoList = videoService.list(tbxXrVideoQW);
for (TbxXrVideo tbxXrVideo : dbVideoList) {
chapterVideoList.remove(tbxXrVideo);
}
if (chapterVideoList.size() > 0) {
videoService.saveBatch(chapterVideoList);
logger.info("书籍进度{}/{},章节进度{}/{},新增视频{}条", currentBookNum, bookList.size(), currentChapterNum, chapterAndModuleIdMap.size(), chapterVideoList.size());
} else {
logger.info("书籍进度{}/{},章节进度{}/{},无新视频", currentBookNum, bookList.size(), currentChapterNum, chapterAndModuleIdMap.size());
}
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} else {
logger.info("书籍进度{}/{},章节进度{}/{},无模块", currentBookNum, bookList.size(), currentChapterNum, chapterAndModuleIdMap.size());
}
});
logger.info("书籍进度{}/{},更新完成", currentBookNum, bookList.size());
bookCDL.countDown();
}
bookCDL.await();
}
private static void downloadCoverPic() throws InterruptedException {
LambdaQueryWrapper<TbxXrVideo> qw = new LambdaQueryWrapper<>();
qw.select(TbxXrVideo::getVideoId, TbxXrVideo::getChapterId, TbxXrVideo::getModuleId, TbxXrVideo::getVideoName, TbxXrVideo::getUrl);
qw.eq(TbxXrVideo::getStatus, 10);
qw.notLike(TbxXrVideo::getUrl, "https://oss.5rs.me");
qw.isNull(TbxXrVideo::getCoverUrl);
List<TbxXrVideo> list = videoService.list(qw);
for (int i = 0; i < list.size(); i++) {
//remove exists file in list
TbxXrVideo tbxXrVideo = list.get(i);
String fileName = "xrv_" + tbxXrVideo.getVideoId() + ".jpg";
String filePath = "D:\\video\\" + fileName;
File file = new File(filePath);
if (file.exists()) {
//如果文件小于50kb,可能是下载失败的文件,重新下载
if (file.length() / 1024 < 50) {
boolean delete = file.delete();
System.out.println("删除未成功下载的文件");
} else {
list.remove(i);
i--;
}
}
}
int size = list.size();
AtomicInteger count = new AtomicInteger();
for (TbxXrVideo tbxXrVideo : list) {
pool.submit(() -> {
int currentCount = count.addAndGet(1);
String coverUrl = tbxXrVideo.getUrl() + "?spm=a2c4g.11186623.2.1.yjOb8V&x-oss-process=video/snapshot,t_7000,f_jpg,w_800,h_600,m_fast";
String fileName = "xrv_" + tbxXrVideo.getVideoId() + ".jpg";
String filePath = "D:\\video\\" + fileName;
if (new File(filePath).exists()) {
logger.info("视频封面{}/{},已存在", currentCount, size);
return;
}
//下载封面
try {
Download.Ctrl start = http.sync(coverUrl)
.get()
.getBody()
.toFile(filePath)
.start();
logger.info("{}/{},{},下载封面成功", currentCount, size, tbxXrVideo.getVideoName());
} catch (Exception e) {
e.printStackTrace();
}
});
TimeUnit.MILLISECONDS.sleep(200);
}
}
private static void updateVideoDuration() throws InterruptedException {
LambdaQueryWrapper<TbxXrVideo> qw = new LambdaQueryWrapper<>();
qw.select(TbxXrVideo::getId, TbxXrVideo::getUrl);
qw.eq(TbxXrVideo::getTimeDuration, "");
qw.eq(TbxXrVideo::getStatus, 10);
List<TbxXrVideo> list = videoService.list(qw);
int size = list.size();
AtomicInteger counter = new AtomicInteger();
for (TbxXrVideo tbxXrVideo : list) {
pool.submit(() -> {
int current = counter.addAndGet(1);
try {
String url = tbxXrVideo.getUrl();
FfmpegFileInfo ffmpegFileInfo = new FfmpegFileInfo();
MultimediaInfo info = ffmpegFileInfo.getInfo(url);
long duration = info.getDuration();
long minutes = duration / 1000L / 60L;
long seconds = duration / 1000L % 60L;
String minutesStr = minutes + "";
String secondsStr = seconds + "";
if (minutesStr.length() == 1) {
minutesStr = "0" + minutesStr;
}
if (secondsStr.length() == 1) {
secondsStr = "0" + secondsStr;
}
tbxXrVideo.setTimeDuration(minutesStr + ":" + secondsStr);
LambdaUpdateWrapper<TbxXrVideo> uw = new LambdaUpdateWrapper<>();
uw.eq(TbxXrVideo::getVideoId, tbxXrVideo.getVideoId());
uw.eq(TbxXrVideo::getChapterId, tbxXrVideo.getChapterId());
uw.eq(TbxXrVideo::getModuleId, tbxXrVideo.getModuleId());
tbxXrVideo.updateById();
logger.info("{}/{}更新视频时长成功,时长:{}", current, size, tbxXrVideo.getTimeDuration());
} catch (Exception e) {
e.printStackTrace();
}
});
Thread.sleep(500);
}
logger.info("更新视频时长完成");
}
private static void updateDbVideoCoverUrl() throws InterruptedException {
LambdaQueryWrapper<TbxXrVideo> qw = new LambdaQueryWrapper<>();
qw.select(TbxXrVideo::getVideoId,TbxXrVideo::getId);
qw.eq(TbxXrVideo::getStatus, 10);
qw.notLike(TbxXrVideo::getUrl, "https://oss.5rs.me");
qw.isNull(TbxXrVideo::getCoverUrl);
List<TbxXrVideo> list = videoService.list(qw);
int size = list.size();
AtomicInteger counter = new AtomicInteger();
for (TbxXrVideo video : list) {
pool.execute(()->{
video.setCoverUrl("https://pics-cos.banxiaoer.net/tbx/xrv/covers_images/xrv_" + video.getVideoId() + ".jpg");
video.updateById();
int count = counter.addAndGet(1);
logger.info("{}/{}更新视频封面成功", count, size);
});
TimeUnit.MILLISECONDS.sleep(100);
}
}
private static TbxXrModule moduleConvert(Module module) {
TbxXrModule tbxXrModule = new TbxXrModule();
tbxXrModule.setModuleId((int) module.getId());
tbxXrModule.setCategoryDesc(module.getCategoryDesc());
tbxXrModule.setCategoryName(module.getCategoryName());
tbxXrModule.setTextbookId((int) module.getTextbookID());
tbxXrModule.setStatus(10);
tbxXrModule.setCreateTime(System.currentTimeMillis());
return tbxXrModule;
}
}
package cn.bxe.updatevideo.mapper;
import cn.bxe.updatevideo.model.TbxXrBook;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 小睿书籍 Mapper 接口
* </p>
*
* @author ting
* @since 2023-01-17
*/
public interface TbxXrBookMapper extends BaseMapper<TbxXrBook> {
}
package cn.bxe.updatevideo.mapper;
import cn.bxe.updatevideo.model.TbxXrChapter;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 小睿书籍内类目章节 Mapper 接口
* </p>
*
* @author ting
* @since 2023-01-17
*/
public interface TbxXrChapterMapper extends BaseMapper<TbxXrChapter> {
}
package cn.bxe.updatevideo.mapper;
import cn.bxe.updatevideo.model.TbxXrModule;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 小睿书籍章节类目可用类目模块 Mapper 接口
* </p>
*
* @author ting
* @since 2023-01-17
*/
public interface TbxXrModuleMapper extends BaseMapper<TbxXrModule> {
}
package cn.bxe.updatevideo.mapper;
import cn.bxe.updatevideo.model.TbxXrVideo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 小睿章节模块视频 Mapper 接口
* </p>
*
* @author ting
* @since 2023-01-17
*/
public interface TbxXrVideoMapper extends BaseMapper<TbxXrVideo> {
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.bxe.updatevideo.mapper.TbxXrBookMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.bxe.updatevideo.mapper.TbxXrChapterMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.bxe.updatevideo.mapper.TbxXrModuleMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.bxe.updatevideo.mapper.TbxXrVideoMapper">
</mapper>
package cn.bxe.updatevideo.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
/**
* <p>
* 小睿书籍
* </p>
*
* @author ting
* @since 2023-01-17
*/
@TableName("tbx_xr_book")
public class TbxXrBook implements Serializable {
@TableId(type = IdType.ASSIGN_ID)
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
private static final long serialVersionUID = 1L;
/**
* 书籍ID
*/
private Integer textbookId;
/**
* 书名
*/
private String bookName;
/**
* 年级
*/
private String gradeCode;
/**
* 科目
*/
private String subject;
/**
* 教材版本
*/
private String textbookVersion;
/**
* 学期
*/
private Integer term;
/**
* 记录状态@10,正常|30,删除状态
*/
private Integer status;
/**
* 创建时间
*/
private Long createTime;
public Integer getTextbookId() {
return textbookId;
}
public void setTextbookId(Integer textbookId) {
this.textbookId = textbookId;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getGradeCode() {
return gradeCode;
}
public void setGradeCode(String gradeCode) {
this.gradeCode = gradeCode;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getTextbookVersion() {
return textbookVersion;
}
public void setTextbookVersion(String textbookVersion) {
this.textbookVersion = textbookVersion;
}
public Integer getTerm() {
return term;
}
public void setTerm(Integer term) {
this.term = term;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
@Override
public String toString() {
return "TbxXrBook{" +
"textbookId=" + textbookId +
", bookName='" + bookName + '\'' +
", gradeCode='" + gradeCode + '\'' +
", subject='" + subject + '\'' +
", textbookVersion='" + textbookVersion + '\'' +
", term=" + term +
", status=" + status +
", createTime=" + createTime +
'}';
}
}
package cn.bxe.updatevideo.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
/**
* <p>
* 小睿书籍内类目章节
* </p>
*
* @author ting
* @since 2023-01-17
*/
public class TbxXrChapter implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.ASSIGN_ID)
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/**
* 等级
*/
private Integer level;
/**
* 类目id
*/
private Integer chapterId;
/**
* 书籍ID
*/
private Integer textbookId;
/**
* 类目章节父ID
*/
private Integer parentId;
/**
* 章节名
*/
private String chapterName;
/**
* 排序
*/
private Integer sortIndex;
/**
* 子章节
*/
private String childrenJson;
/**
* 记录状态@10,正常|30,删除状态
*/
private Integer status;
/**
* 创建时间
*/
private Long createTime;
public Integer getLevel() {
return level;
}
public void setLevel(Integer level) {
this.level = level;
}
public Integer getChapterId() {
return chapterId;
}
public void setChapterId(Integer chapterId) {
this.chapterId = chapterId;
}
public Integer getTextbookId() {
return textbookId;
}
public void setTextbookId(Integer textbookId) {
this.textbookId = textbookId;
}
public Integer getParentId() {
return parentId;
}
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
public String getChapterName() {
return chapterName;
}
public void setChapterName(String chapterName) {
this.chapterName = chapterName;
}
public Integer getSortIndex() {
return sortIndex;
}
public void setSortIndex(Integer sortIndex) {
this.sortIndex = sortIndex;
}
public String getChildrenJson() {
return childrenJson;
}
public void setChildrenJson(String childrenJson) {
this.childrenJson = childrenJson;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
}
package cn.bxe.updatevideo.model;
import java.io.Serializable;
import java.util.Objects;
/**
* <p>
* 小睿书籍章节类目可用类目模块
* </p>
*
* @author ting
* @since 2023-01-17
*/
public class TbxXrModule implements Serializable {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TbxXrModule that = (TbxXrModule) o;
return Objects.equals(chapterId, that.chapterId) && Objects.equals(moduleId, that.moduleId) && Objects.equals(textbookId, that.textbookId);
}
@Override
public int hashCode() {
return Objects.hash(chapterId, moduleId, textbookId);
}
private static final long serialVersionUID = 1L;
/**
* 类目id
*/
private Integer chapterId;
/**
* 模块ID
*/
private Integer moduleId;
/**
* 书籍ID
*/
private Integer textbookId;
/**
* 分类名
*/
private String categoryName;
/**
* 分类详情
*/
private String categoryDesc;
/**
* 模块列表json
*/
private String moduleList;
/**
* 记录状态@10,正常|30,删除状态
*/
private Integer status;
/**
* 创建时间
*/
private Long createTime;
public Integer getChapterId() {
return chapterId;
}
public void setChapterId(Integer chapterId) {
this.chapterId = chapterId;
}
public Integer getModuleId() {
return moduleId;
}
public void setModuleId(Integer moduleId) {
this.moduleId = moduleId;
}
public Integer getTextbookId() {
return textbookId;
}
public void setTextbookId(Integer textbookId) {
this.textbookId = textbookId;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public String getCategoryDesc() {
return categoryDesc;
}
public void setCategoryDesc(String categoryDesc) {
this.categoryDesc = categoryDesc;
}
public String getModuleList() {
return moduleList;
}
public void setModuleList(String moduleList) {
this.moduleList = moduleList;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
@Override
public String toString() {
return "TbxXrModule{" +
"chapterId=" + chapterId +
", moduleId=" + moduleId +
", textbookId=" + textbookId +
", categoryName='" + categoryName + '\'' +
", categoryDesc='" + categoryDesc + '\'' +
", moduleList='" + moduleList + '\'' +
", status=" + status +
", createTime=" + createTime +
'}';
}
}
package cn.bxe.updatevideo.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.Objects;
/**
* <p>
* 小睿章节模块视频
* </p>
*
* @author ting
* @since 2023-01-17
*/
public class TbxXrVideo extends Model<TbxXrVideo> implements Serializable{
private static final long serialVersionUID = 1L;
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 视频id
*/
private Integer videoId;
/**
* 类目id
*/
private Integer chapterId;
/**
* 模块ID
*/
private Integer moduleId;
/**
* 视频名
*/
private String videoName;
/**
* 视频链接
*/
private String url;
/**
* 视频时长
*/
private String timeDuration;
/**
* 记录状态@10,正常|30,删除状态
*/
private Integer status;
/**
* 创建时间
*/
private Long createTime;
/**
* 视频封面链接
*/
private String coverUrl;
public TbxXrVideo() {
}
public Integer getVideoId() {
return videoId;
}
public void setVideoId(Integer videoId) {
this.videoId = videoId;
}
public Integer getChapterId() {
return chapterId;
}
public void setChapterId(Integer chapterId) {
this.chapterId = chapterId;
}
public Integer getModuleId() {
return moduleId;
}
public void setModuleId(Integer moduleId) {
this.moduleId = moduleId;
}
public String getVideoName() {
return videoName;
}
public void setVideoName(String videoName) {
this.videoName = videoName;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTimeDuration() {
return timeDuration;
}
public void setTimeDuration(String timeDuration) {
this.timeDuration = timeDuration;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public String getCoverUrl() {
return coverUrl;
}
public void setCoverUrl(String coverUrl) {
this.coverUrl = coverUrl;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TbxXrVideo that = (TbxXrVideo) o;
return Objects.equals(videoId, that.videoId) && Objects.equals(chapterId, that.chapterId) && Objects.equals(moduleId, that.moduleId);
}
@Override
public int hashCode() {
return Objects.hash(videoId, chapterId, moduleId);
}
@Override
public String toString() {
return "TbxXrVideo{" +
"videoId=" + videoId +
", chapterId=" + chapterId +
", moduleId=" + moduleId +
", videoName='" + videoName + '\'' +
", url='" + url + '\'' +
", timeDuration='" + timeDuration + '\'' +
", status=" + status +
", createTime=" + createTime +
", coverUrl='" + coverUrl + '\'' +
'}';
}
}
package cn.bxe.updatevideo.model.original;
import java.util.List;
public class Chapter {
private Integer id;
private Integer textbookID;
private int parentID;
private Integer level;
private String chapterName;
private int sortIndex;
private Integer freeStatus;
private boolean lastStudyFlag;
private boolean expand;
private boolean vip;
private String children;
@Override
public String toString() {
return "Chapter{" +
"id=" + id +
", textbookID=" + textbookID +
", parentID=" + parentID +
", level=" + level +
", chapterName='" + chapterName + '\'' +
", sortIndex=" + sortIndex +
", freeStatus=" + freeStatus +
", lastStudyFlag=" + lastStudyFlag +
", expand=" + expand +
", vip=" + vip +
", children=" + children +
'}';
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getTextbookID() {
return textbookID;
}
public void setTextbookID(Integer textbookID) {
this.textbookID = textbookID;
}
public int getParentID() {
return parentID;
}
public void setParentID(int parentID) {
this.parentID = parentID;
}
public Integer getLevel() {
return level;
}
public void setLevel(Integer level) {
this.level = level;
}
public String getChapterName() {
return chapterName;
}
public void setChapterName(String chapterName) {
this.chapterName = chapterName;
}
public int getSortIndex() {
return sortIndex;
}
public void setSortIndex(int sortIndex) {
this.sortIndex = sortIndex;
}
public Integer getFreeStatus() {
return freeStatus;
}
public void setFreeStatus(Integer freeStatus) {
this.freeStatus = freeStatus;
}
public boolean isLastStudyFlag() {
return lastStudyFlag;
}
public void setLastStudyFlag(boolean lastStudyFlag) {
this.lastStudyFlag = lastStudyFlag;
}
public boolean isExpand() {
return expand;
}
public void setExpand(boolean expand) {
this.expand = expand;
}
public boolean isVip() {
return vip;
}
public void setVip(boolean vip) {
this.vip = vip;
}
public String getChildren() {
return children;
}
public void setChildren(String children) {
this.children = children;
}
}
// Module.java
package cn.bxe.updatevideo.model.original;
import java.util.List;
public class Module {
private long id;
private long textbookID;
private String categoryName;
private String categoryDesc;
private long categoryID;
private String moduleName;
private long moduleType;
private String moduleURL;
private long count;
private long freeStatus;
private String moduleDesc;
private boolean unlock;
private List<Module> moduleList;
public long getTextbookID() {
return textbookID;
}
public void setTextbookID(long value) {
this.textbookID = value;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String value) {
this.categoryName = value;
}
public String getCategoryDesc() {
return categoryDesc;
}
public void setCategoryDesc(String value) {
this.categoryDesc = value;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getCategoryID() {
return categoryID;
}
public void setCategoryID(long categoryID) {
this.categoryID = categoryID;
}
public String getModuleName() {
return moduleName;
}
public void setModuleName(String moduleName) {
this.moduleName = moduleName;
}
public long getModuleType() {
return moduleType;
}
public void setModuleType(long moduleType) {
this.moduleType = moduleType;
}
public String getModuleURL() {
return moduleURL;
}
public void setModuleURL(String moduleURL) {
this.moduleURL = moduleURL;
}
public long getCount() {
return count;
}
public void setCount(long count) {
this.count = count;
}
public long getFreeStatus() {
return freeStatus;
}
public void setFreeStatus(long freeStatus) {
this.freeStatus = freeStatus;
}
public String getModuleDesc() {
return moduleDesc;
}
public void setModuleDesc(String moduleDesc) {
this.moduleDesc = moduleDesc;
}
public boolean isUnlock() {
return unlock;
}
public void setUnlock(boolean unlock) {
this.unlock = unlock;
}
public List<Module> getModuleList() {
return moduleList;
}
public void setModuleList(List<Module> moduleList) {
this.moduleList = moduleList;
}
@Override
public String toString() {
return "Module{" +
"id=" + id +
", textbookID=" + textbookID +
", categoryName='" + categoryName + '\'' +
", categoryDesc='" + categoryDesc + '\'' +
", moduleList=" + moduleList +
'}';
}
}
\ No newline at end of file \ No newline at end of file
package cn.bxe.updatevideo.model.original;
import java.util.Arrays;
public class Textbook {
private long id;
private String textbookCover;
private String grade;
private String gradeName;
private String subject;
private String subjectName;
private String textbookVersion;
private String textbookVersionName;
private String schoolYear;
private String schoolYearName;
private String volumeType;
private String volumeName;
private long bookID;
private String bookName;
private long status;
private boolean isAnalysis;
private long sectionNum;
private String resourceURL;
private String bookIDS;
private String[] posters;
private String wordsModuleID;
private String resourceName;
private String resourceIdentity;
private long sequence;
private long planStatus;
private String planName;
private String appID;
private String url;
private long lastPageNumber;
private boolean isBuy;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getTextbookCover() {
return textbookCover;
}
public void setTextbookCover(String textbookCover) {
this.textbookCover = textbookCover;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getGradeName() {
return gradeName;
}
public void setGradeName(String gradeName) {
this.gradeName = gradeName;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getSubjectName() {
return subjectName;
}
public void setSubjectName(String subjectName) {
this.subjectName = subjectName;
}
public String getTextbookVersion() {
return textbookVersion;
}
public void setTextbookVersion(String textbookVersion) {
this.textbookVersion = textbookVersion;
}
public String getTextbookVersionName() {
return textbookVersionName;
}
public void setTextbookVersionName(String textbookVersionName) {
this.textbookVersionName = textbookVersionName;
}
public String getSchoolYear() {
return schoolYear;
}
public void setSchoolYear(String schoolYear) {
this.schoolYear = schoolYear;
}
public String getSchoolYearName() {
return schoolYearName;
}
public void setSchoolYearName(String schoolYearName) {
this.schoolYearName = schoolYearName;
}
public String getVolumeType() {
return volumeType;
}
public void setVolumeType(String volumeType) {
this.volumeType = volumeType;
}
public String getVolumeName() {
return volumeName;
}
public void setVolumeName(String volumeName) {
this.volumeName = volumeName;
}
public long getBookID() {
return bookID;
}
public void setBookID(long bookID) {
this.bookID = bookID;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public long getStatus() {
return status;
}
public void setStatus(long status) {
this.status = status;
}
public boolean isAnalysis() {
return isAnalysis;
}
public void setAnalysis(boolean analysis) {
isAnalysis = analysis;
}
public long getSectionNum() {
return sectionNum;
}
public void setSectionNum(long sectionNum) {
this.sectionNum = sectionNum;
}
public String getResourceURL() {
return resourceURL;
}
public void setResourceURL(String resourceURL) {
this.resourceURL = resourceURL;
}
public String getBookIDS() {
return bookIDS;
}
public void setBookIDS(String bookIDS) {
this.bookIDS = bookIDS;
}
public String[] getPosters() {
return posters;
}
public void setPosters(String[] posters) {
this.posters = posters;
}
public String getWordsModuleID() {
return wordsModuleID;
}
public void setWordsModuleID(String wordsModuleID) {
this.wordsModuleID = wordsModuleID;
}
public String getResourceName() {
return resourceName;
}
public void setResourceName(String resourceName) {
this.resourceName = resourceName;
}
public String getResourceIdentity() {
return resourceIdentity;
}
public void setResourceIdentity(String resourceIdentity) {
this.resourceIdentity = resourceIdentity;
}
public long getSequence() {
return sequence;
}
public void setSequence(long sequence) {
this.sequence = sequence;
}
public long getPlanStatus() {
return planStatus;
}
public void setPlanStatus(long planStatus) {
this.planStatus = planStatus;
}
public String getPlanName() {
return planName;
}
public void setPlanName(String planName) {
this.planName = planName;
}
public String getAppID() {
return appID;
}
public void setAppID(String appID) {
this.appID = appID;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public long getLastPageNumber() {
return lastPageNumber;
}
public void setLastPageNumber(long lastPageNumber) {
this.lastPageNumber = lastPageNumber;
}
public boolean isBuy() {
return isBuy;
}
public void setBuy(boolean buy) {
isBuy = buy;
}
@Override
public String toString() {
return "Textbook{" +
"id=" + id +
", textbookCover='" + textbookCover + '\'' +
", grade='" + grade + '\'' +
", gradeName='" + gradeName + '\'' +
", subject='" + subject + '\'' +
", subjectName='" + subjectName + '\'' +
", textbookVersion='" + textbookVersion + '\'' +
", textbookVersionName='" + textbookVersionName + '\'' +
", schoolYear='" + schoolYear + '\'' +
", schoolYearName='" + schoolYearName + '\'' +
", volumeType='" + volumeType + '\'' +
", volumeName='" + volumeName + '\'' +
", bookID=" + bookID +
", bookName='" + bookName + '\'' +
", status=" + status +
", isAnalysis=" + isAnalysis +
", sectionNum=" + sectionNum +
", resourceURL='" + resourceURL + '\'' +
", bookIDS='" + bookIDS + '\'' +
", posters=" + Arrays.toString(posters) +
", wordsModuleID='" + wordsModuleID + '\'' +
", resourceName='" + resourceName + '\'' +
", resourceIdentity='" + resourceIdentity + '\'' +
", sequence=" + sequence +
", planStatus=" + planStatus +
", planName='" + planName + '\'' +
", appID='" + appID + '\'' +
", url='" + url + '\'' +
", lastPageNumber=" + lastPageNumber +
", isBuy=" + isBuy +
'}';
}
}
package cn.bxe.updatevideo.model.original;
public class Video {
private Integer id;
private Integer chapterID;
private Integer moduleID;
private String videoName;
private String url;
private String timeDuration;
private Integer sortIndex;
@Override
public String toString() {
return "Video{" +
"id=" + id +
", chapterID=" + chapterID +
", moduleID=" + moduleID +
", videoName='" + videoName + '\'' +
", url='" + url + '\'' +
", timeDuration='" + timeDuration + '\'' +
", sortIndex=" + sortIndex +
'}';
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getChapterID() {
return chapterID;
}
public void setChapterID(Integer chapterID) {
this.chapterID = chapterID;
}
public Integer getModuleID() {
return moduleID;
}
public void setModuleID(Integer moduleID) {
this.moduleID = moduleID;
}
public String getVideoName() {
return videoName;
}
public void setVideoName(String videoName) {
this.videoName = videoName;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTimeDuration() {
return timeDuration;
}
public void setTimeDuration(String timeDuration) {
this.timeDuration = timeDuration;
}
public Integer getSortIndex() {
return sortIndex;
}
public void setSortIndex(Integer sortIndex) {
this.sortIndex = sortIndex;
}
}
package cn.bxe.updatevideo.service.impl;
import cn.bxe.updatevideo.model.TbxXrBook;
import cn.bxe.updatevideo.mapper.TbxXrBookMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 小睿书籍 服务实现类
* </p>
*
* @author ting
* @since 2023-01-17
*/
@Service
public class TbxXrBookServiceImpl extends ServiceImpl<TbxXrBookMapper, TbxXrBook>{
}
package cn.bxe.updatevideo.service.impl;
import cn.bxe.updatevideo.model.TbxXrChapter;
import cn.bxe.updatevideo.mapper.TbxXrChapterMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 小睿书籍内类目章节 服务实现类
* </p>
*
* @author ting
* @since 2023-01-17
*/
@Service
public class TbxXrChapterServiceImpl extends ServiceImpl<TbxXrChapterMapper, TbxXrChapter> {
}
package cn.bxe.updatevideo.service.impl;
import cn.bxe.updatevideo.model.TbxXrModule;
import cn.bxe.updatevideo.mapper.TbxXrModuleMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 小睿书籍章节类目可用类目模块 服务实现类
* </p>
*
* @author ting
* @since 2023-01-17
*/
@Service
public class TbxXrModuleServiceImpl extends ServiceImpl<TbxXrModuleMapper, TbxXrModule>{
}
package cn.bxe.updatevideo.service.impl;
import cn.bxe.updatevideo.model.TbxXrVideo;
import cn.bxe.updatevideo.mapper.TbxXrVideoMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 小睿章节模块视频 服务实现类
* </p>
*
* @author ting
* @since 2023-01-17
*/
@Service
public class TbxXrVideoServiceImpl extends ServiceImpl<TbxXrVideoMapper, TbxXrVideo> {
}
package cn.bxe.updatevideo.util;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
import java.util.Map;
/**
* json工具类
* @author yonson
*/
public class JsonUtil {
/**
* 对像转化为json字符串
* @param obj
* @return
*/
public static String tranObjectToJsonStr(Object obj){
return JSONObject.toJSONString(obj);
}
/**
* json字符串转化为对像
* @param jsonStr
* @return
* @return
*/
public static <T extends Object> T tranJsonStrToObject(String jsonStr,Class<T> clazz){
return (T)JSONObject.parseObject(jsonStr,clazz);
}
/**
* json字符串转化为列表
* @param jsonStr
* @param clazz
* @return
*/
public static <T extends Object> List<T> tranJsonStrToArray(String jsonStr,Class<T> clazz){
return JSONObject.parseArray(jsonStr, clazz);
}
public static JSONObject tranJsonStrToJSONObject(String jsonStr){
return JSONObject.parseObject(jsonStr);
}
public static Map tranJsonToMap(String jsonStr){
try {
Map mapObj = JSONObject.parseObject(jsonStr, Map.class);
//for (Object map: mapObj.entrySet()){
// System.out.println(((Map.Entry)map).getKey()+" "+((Map.Entry)map).getValue());
//}
return mapObj;
}catch (Exception e){
e.printStackTrace();
}
return null;
}
/**
*
* @param jsonStr
* @param keyField
* @return
*/
public static String tranJsonToMapAndGetKValue(String jsonStr,String keyField){
try {
Map mapObj = tranJsonToMap(jsonStr);
if(mapObj!=null && mapObj.containsKey(keyField)) {
return String.valueOf(mapObj.get(keyField));
}
else
return "";
}catch (Exception e){
e.printStackTrace();
}
return "";
}
}
package cn.bxe.updatevideo.util;
import java.util.HashMap;
public class VersionUtil {
public static HashMap<String,String> SUBJECT_MAP = new HashMap<>();
public static HashMap<String,String> GRADE_MAP = new HashMap<>();
public static HashMap<String,String> VERSION_MAP = new HashMap<>();
public static HashMap<String,Integer> SCHOOL_YEAR_MAP = new HashMap<>();
static{
//科目
SUBJECT_MAP.put("GEOGRAPHY","dili");
SUBJECT_MAP.put("CHEMISTRY","huaxue");
SUBJECT_MAP.put("PHYSICS","wuli");
SUBJECT_MAP.put("BIOLOGY","shengwu");
SUBJECT_MAP.put("HISTORY","lishi");
SUBJECT_MAP.put("MORALITY","daode");
SUBJECT_MAP.put("MATHEMATICS","shuxue");
SUBJECT_MAP.put("CHINESE","yuwen");
SUBJECT_MAP.put("ENGLISH","yingyu");
//年级
GRADE_MAP.put("FIRST_GRADE","1");
GRADE_MAP.put("SECOND_GRADE","2");
GRADE_MAP.put("THIRD_GRADE","3");
GRADE_MAP.put("FOURTH_GRADE","4");
GRADE_MAP.put("FIFTH_GRADE","5");
GRADE_MAP.put("SIXTH_GRADE","6");
GRADE_MAP.put("GRADE_ONE","7");
GRADE_MAP.put("GRADE_TWO","8");
GRADE_MAP.put("GRADE_THREE","9");
GRADE_MAP.put("SENIOR_ONE","10");
//书籍版本
VERSION_MAP.put("CHINA","zhongtu");
VERSION_MAP.put("LUKE","luke");
VERSION_MAP.put("BEISHIDA","beishida");
VERSION_MAP.put("PEP","renjiao");
VERSION_MAP.put("YUEJIAOHUKE","yuejiaohuke");
VERSION_MAP.put("YUE_RENMIN","yuerenmin");
VERSION_MAP.put("XIANG_JIAO","xiangjiao");
VERSION_MAP.put("YUEJIAOKEXUE","yuejiaokexue");
VERSION_MAP.put("JIANGSU_EDUCATION_PRESS","sujiaoban");
VERSION_MAP.put("YUE_JIAO","yuejiao");
VERSION_MAP.put("JIJIAO_EDITION","jijiao");
VERSION_MAP.put("XINAN_SHIDA","xishida");
VERSION_MAP.put("BUBIAN","bubian");
VERSION_MAP.put("HUJIAOBAN","hujiao");
VERSION_MAP.put("RENJIAO_PEP","renjiaopep");
VERSION_MAP.put("RENJIAO_XINQIDIAN","renjiaoxinqidian");
VERSION_MAP.put("WAI_YAN","waiyan");
VERSION_MAP.put("XIANG_SHAO","xiangshao");
VERSION_MAP.put("RENJIAOJINGTONG","renjiaojingtong");
//学年
SCHOOL_YEAR_MAP.put("ALL_BOOKS",5);
SCHOOL_YEAR_MAP.put("LAST_SEMESTER",1);
SCHOOL_YEAR_MAP.put("NEXT_SEMESTER",2);
}
}
package ws.schild.jave;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class FfmpegFileInfo {
private static final Log LOG = LogFactory.getLog(FfmpegFileInfo.class);
private static final Pattern SIZE_PATTERN = Pattern.compile("(\\d+)x(\\d+)", 2);
private static final Pattern FRAME_RATE_PATTERN = Pattern.compile("([\\d.]+)\\s+(?:fps|tbr)", 2);
private static final Pattern BIT_RATE_PATTERN = Pattern.compile("(\\d+)\\s+kb/s", 2);
private static final Pattern SAMPLING_RATE_PATTERN = Pattern.compile("(\\d+)\\s+Hz", 2);
private static final Pattern CHANNELS_PATTERN = Pattern.compile("(mono|stereo|quad)", 2);
private final FFMPEGLocator locator;
private File inputFile;
public FfmpegFileInfo() {
this.locator = new DefaultFFMPEGLocator();
this.inputFile = new File("");
}
public File getFile() {
return this.inputFile;
}
public void setFile(File file) {
this.inputFile = file;
}
public FfmpegFileInfo(File input, FFMPEGLocator locator) {
this.locator = locator;
this.inputFile = input;
}
public MultimediaInfo getInfo(String url) throws InputFormatException, EncoderException {
FFMPEGExecutor ffmpeg = this.locator.createExecutor();
ffmpeg.addArgument("-i");
ffmpeg.addArgument(url);
try {
ffmpeg.execute();
} catch (IOException var9) {
throw new EncoderException(var9);
}
MultimediaInfo var3;
try {
RBufferedReader reader = new RBufferedReader(new InputStreamReader(ffmpeg.getErrorStream()));
var3 = this.parseMultimediaInfo(this.inputFile, reader);
} finally {
ffmpeg.destroy();
}
return var3;
}
private MultimediaInfo parseMultimediaInfo(File source, RBufferedReader reader) throws InputFormatException, EncoderException {
Pattern p1 = Pattern.compile("^\\s*Input #0, (\\w+).+$\\s*", 2);
Pattern p2 = Pattern.compile("^\\s*Duration: (\\d\\d):(\\d\\d):(\\d\\d)\\.(\\d\\d).*$", 2);
Pattern p3 = Pattern.compile("^\\s*Stream #\\S+: ((?:Audio)|(?:Video)|(?:Data)): (.*)\\s*$", 2);
Pattern p4 = Pattern.compile("^\\s*Metadata:", 2);
MultimediaInfo info = null;
try {
int step = 0;
while(true) {
String line = reader.readLine();
LOG.debug("Output line: " + line);
if (line == null) {
break;
}
String type;
String token;
Matcher m;
switch (step) {
case 0:
token = source.getAbsolutePath() + ": ";
if (line.startsWith(token)) {
String message = line.substring(token.length());
throw new InputFormatException(message);
}
m = p1.matcher(line);
if (m.matches()) {
type = m.group(1);
info = new MultimediaInfo();
info.setFormat(type);
++step;
}
break;
case 1:
m = p2.matcher(line);
if (m.matches()) {
long hours = (long)Integer.parseInt(m.group(1));
long minutes = (long)Integer.parseInt(m.group(2));
long seconds = (long)Integer.parseInt(m.group(3));
long dec = (long)Integer.parseInt(m.group(4));
long duration = dec * 10L + seconds * 1000L + minutes * 60L * 1000L + hours * 60L * 60L * 1000L;
info.setDuration(duration);
++step;
}
break;
case 2:
m = p3.matcher(line);
p4.matcher(line);
if (m.matches()) {
type = m.group(1);
String specs = m.group(2);
StringTokenizer st;
int i;
boolean parsed;
Matcher m2;
int bitRate;
if (!"Video".equalsIgnoreCase(type)) {
if ("Audio".equalsIgnoreCase(type)) {
AudioInfo audio = new AudioInfo();
st = new StringTokenizer(specs, ",");
i = 0;
for(; st.hasMoreTokens(); ++i) {
token = st.nextToken().trim();
if (i == 0) {
audio.setDecoder(token);
} else {
parsed = false;
m2 = SAMPLING_RATE_PATTERN.matcher(token);
if (!parsed && m2.find()) {
bitRate = Integer.parseInt(m2.group(1));
audio.setSamplingRate(bitRate);
parsed = true;
}
m2 = CHANNELS_PATTERN.matcher(token);
if (!parsed && m2.find()) {
String ms = m2.group(1);
if ("mono".equalsIgnoreCase(ms)) {
audio.setChannels(1);
} else if ("stereo".equalsIgnoreCase(ms)) {
audio.setChannels(2);
} else if ("quad".equalsIgnoreCase(ms)) {
audio.setChannels(4);
}
parsed = true;
}
m2 = BIT_RATE_PATTERN.matcher(token);
if (!parsed && m2.find()) {
bitRate = Integer.parseInt(m2.group(1));
audio.setBitRate(bitRate * 1000);
parsed = true;
}
}
}
info.setAudio(audio);
}
} else {
VideoInfo video = new VideoInfo();
st = new StringTokenizer(specs, ",");
for(i = 0; st.hasMoreTokens(); ++i) {
token = st.nextToken().trim();
if (i == 0) {
video.setDecoder(token);
} else {
parsed = false;
m2 = SIZE_PATTERN.matcher(token);
if (!parsed && m2.find()) {
bitRate = Integer.parseInt(m2.group(1));
int height = Integer.parseInt(m2.group(2));
video.setSize(new VideoSize(bitRate, height));
parsed = true;
}
m2 = FRAME_RATE_PATTERN.matcher(token);
if (!parsed && m2.find()) {
try {
float frameRate = Float.parseFloat(m2.group(1));
video.setFrameRate(frameRate);
} catch (NumberFormatException var23) {
LOG.info("Invalid frame rate value: " + m2.group(1), var23);
}
parsed = true;
}
m2 = BIT_RATE_PATTERN.matcher(token);
if (!parsed && m2.find()) {
bitRate = Integer.parseInt(m2.group(1));
video.setBitRate(bitRate * 1000);
parsed = true;
}
}
}
info.setVideo(video);
}
}
}
if (line.startsWith("frame=")) {
reader.reinsertLine(line);
break;
}
}
} catch (IOException var24) {
throw new EncoderException(var24);
}
if (info == null) {
throw new InputFormatException();
} else {
return info;
}
}
}
spring:
datasource:
#测试环境数据库
url: jdbc:mysql://10.22.0.2/wbyb_tbx_0?useUnicode=true&useSSL=false&characterEncoding=utf8
username: banxiaoer
password: wbyb@2018
driver-class-name: com.mysql.cj.jdbc.Driver
\ No newline at end of file \ No newline at end of file
package cn.bxe.updatevideo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class UpdateVideoApplicationTests {
@Test
void contextLoads() {
}
}
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!