|
@@ -1,5 +1,10 @@
|
|
|
package cn.reghao.tnb.content.app.vod.service;
|
|
package cn.reghao.tnb.content.app.vod.service;
|
|
|
|
|
|
|
|
|
|
+import cn.reghao.jutil.jdk.converter.DateTimeConverter;
|
|
|
|
|
+import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
|
|
|
+import cn.reghao.jutil.jdk.text.TextFile;
|
|
|
|
|
+import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
|
|
|
+import cn.reghao.tnb.content.api.constant.PostScope;
|
|
|
import cn.reghao.tnb.content.api.dto.VideoCard;
|
|
import cn.reghao.tnb.content.api.dto.VideoCard;
|
|
|
import cn.reghao.tnb.content.app.ContentApplication;
|
|
import cn.reghao.tnb.content.app.ContentApplication;
|
|
|
import cn.reghao.tnb.content.app.vod.db.mapper.*;
|
|
import cn.reghao.tnb.content.app.vod.db.mapper.*;
|
|
@@ -10,14 +15,20 @@ import cn.reghao.tnb.content.app.util.redis.ds.RedisSortedSet;
|
|
|
import cn.reghao.tnb.content.app.vod.model.vo.BannerVideoVO;
|
|
import cn.reghao.tnb.content.app.vod.model.vo.BannerVideoVO;
|
|
|
import cn.reghao.tnb.content.app.vod.service.rcmd.RedisKeys;
|
|
import cn.reghao.tnb.content.app.vod.service.rcmd.RedisKeys;
|
|
|
import cn.reghao.tnb.content.app.vod.service.rcmd.UserInterestBased;
|
|
import cn.reghao.tnb.content.app.vod.service.rcmd.UserInterestBased;
|
|
|
|
|
+import com.google.gson.JsonElement;
|
|
|
|
|
+import com.google.gson.JsonObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.concurrent.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -173,4 +184,222 @@ public class VideoPostTest {
|
|
|
List<BannerVideoVO> list1 = bannerVideoMapper.findBannerVideos();
|
|
List<BannerVideoVO> list1 = bannerVideoMapper.findBannerVideos();
|
|
|
System.out.println();
|
|
System.out.println();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ VideoCategoryPostMapper videoCategoryPostMapper;
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void videoCategoryPostTest() {
|
|
|
|
|
+ List<VideoCategoryPost> videoCategoryPostList = new ArrayList<>();
|
|
|
|
|
+ int categoryPid = 11;
|
|
|
|
|
+ List<VideoPost> list = videoPostMapper.findGroupByUserAndCategory(categoryPid);
|
|
|
|
|
+ for (VideoPost videoPost : list) {
|
|
|
|
|
+ long publishBy = videoPost.getPublishBy();
|
|
|
|
|
+ int categoryId = videoPost.getCategoryId();
|
|
|
|
|
+ VideoPost videoPost1 = videoPostMapper.findUserAndCategory(publishBy, categoryId);
|
|
|
|
|
+ videoCategoryPostList.add(new VideoCategoryPost(videoPost1));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!videoCategoryPostList.isEmpty()) {
|
|
|
|
|
+ videoCategoryPostMapper.deleteByCategoryPid(categoryPid);
|
|
|
|
|
+ videoCategoryPostMapper.saveAll(videoCategoryPostList);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void videoPostTagTest() {
|
|
|
|
|
+ Map<String, List<VideoPost>> map = new ConcurrentHashMap<>();
|
|
|
|
|
+ Set<String> tagList = new HashSet<>();
|
|
|
|
|
+ List<VideoPost> videoPostList = videoPostMapper.findAll();
|
|
|
|
|
+
|
|
|
|
|
+ for (VideoPost videoPost : videoPostList) {
|
|
|
|
|
+ String title = videoPost.getTitle();
|
|
|
|
|
+ /*List<VideoPost> list = map.computeIfAbsent(title, v -> new ArrayList<>());
|
|
|
|
|
+ if (!list.isEmpty()) {
|
|
|
|
|
+ VideoPost videoPost1 = list.get(0);
|
|
|
|
|
+ if (videoPost1.getDuration() == videoPost.getDuration() &&
|
|
|
|
|
+ videoPost1.getHorizontal() == videoPost.getHorizontal()) {
|
|
|
|
|
+ list.add(videoPost);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ list.add(videoPost);
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
+ String videoId = videoPost.getVideoId();
|
|
|
|
|
+ List<String> tags = videoTagMapper.findVideoTags(videoId);
|
|
|
|
|
+ tagList.addAll(tags);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /*List<String> urls = new ArrayList<>();
|
|
|
|
|
+ map.forEach((k, v) -> {
|
|
|
|
|
+ if (v.size() <= 1) {
|
|
|
|
|
+ map.remove(k);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
|
+ boolean contain = false;
|
|
|
|
|
+ for (VideoPost videoPost : v) {
|
|
|
|
|
+ long publishBy = videoPost.getPublishBy();
|
|
|
|
|
+ if (publishBy == 11002) {
|
|
|
|
|
+ contain = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (contain) {
|
|
|
|
|
+ for (VideoPost videoPost : v) {
|
|
|
|
|
+ String url = String.format("https://reghao.cn/video/%s", videoPost.getVideoId());
|
|
|
|
|
+ sb.append(url).append(" - ");
|
|
|
|
|
+ }
|
|
|
|
|
+ urls.add(sb.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < urls.size(); i++) {
|
|
|
|
|
+ System.out.printf("%s -> %s\n", i, urls.get(i));
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void videoTest() throws IOException, InterruptedException {
|
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
|
+ File dir = new File("/home/reghao/Downloads/tele/1");
|
|
|
|
|
+ for (File file : dir.listFiles()) {
|
|
|
|
|
+ parseJson(file, list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Set<String> set = new HashSet<>(list);
|
|
|
|
|
+ Queue<String> queue = new ArrayDeque<>(set);
|
|
|
|
|
+ ExecutorService threadPool = ThreadPoolWrapper.threadPool("search-pool", 20);
|
|
|
|
|
+ ThreadPoolExecutor tpe = (ThreadPoolExecutor) threadPool;
|
|
|
|
|
+ while (!Thread.interrupted()) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (tpe.getActiveCount() < 20) {
|
|
|
|
|
+ String line = queue.poll();
|
|
|
|
|
+ if (line != null) {
|
|
|
|
|
+ String title = "";
|
|
|
|
|
+ if (line.endsWith(".mp4")) {
|
|
|
|
|
+ title = line.replace(".mp4", "");
|
|
|
|
|
+ } else if (line.endsWith(".MP4")) {
|
|
|
|
|
+ title = line.replace(".MP4", "");
|
|
|
|
|
+ } else if (line.endsWith(".mov")) {
|
|
|
|
|
+ title = line.replace(".mov", "");
|
|
|
|
|
+ } else if (line.endsWith(".MOV")) {
|
|
|
|
|
+ title = line.replace(".MOV", "");
|
|
|
|
|
+ } else if (line.endsWith(".m4v")) {
|
|
|
|
|
+ title = line.replace(".m4v", "");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ title = StringUtils.trimAllWhitespace(line);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ threadPool.submit(new SearchTask(title));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("queue is empty");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //log.info("当前线程队列有 {} 个线程, 其中 {} 个活跃线程, 休眠 1s 等待线程池空闲...", tpe.getQueue().size(), tpe.getActiveCount());
|
|
|
|
|
+ Thread.sleep(1_000);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ class SearchTask implements Runnable {
|
|
|
|
|
+ private String title;
|
|
|
|
|
+
|
|
|
|
|
+ public SearchTask(String title) {
|
|
|
|
|
+ this.title = title;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ List<VideoPost> list1 = videoPostMapper.findByTitle(title);
|
|
|
|
|
+ if (list1.isEmpty()) {
|
|
|
|
|
+ log.info("notexist {}", title);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ List<String> videoIds = list1.stream().map(VideoPost::getVideoId).collect(Collectors.toList());
|
|
|
|
|
+ log.info("exist {} videoId {}", title, videoIds);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void parseJson(File jsonFile, List<String> list) {
|
|
|
|
|
+ JsonObject jsonObject = JsonConverter.jsonFileToObject(jsonFile, JsonObject.class);
|
|
|
|
|
+ for (JsonElement jsonElement : jsonObject.get("messages").getAsJsonArray()) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ JsonObject jsonObject1 = jsonElement.getAsJsonObject();
|
|
|
|
|
+ String filename = jsonObject1.get("file_name").getAsString();
|
|
|
|
|
+ if (filename.isBlank()) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ long dateUnixtime = jsonObject1.get("date_unixtime").getAsLong();
|
|
|
|
|
+ DateTimeConverter.localDateTime(dateUnixtime*1000);
|
|
|
|
|
+ list.add(filename);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ //e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void vodTest() {
|
|
|
|
|
+ File dir = new File("/home/reghao/disk/2/vod/tg/");
|
|
|
|
|
+ for (File file : dir.listFiles()) {
|
|
|
|
|
+ if (file.isDirectory()) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String filename = file.getName();
|
|
|
|
|
+ String title = "";
|
|
|
|
|
+ if (filename.endsWith(".mp4")) {
|
|
|
|
|
+ title = filename.replace(".mp4", "");
|
|
|
|
|
+ } else if (filename.endsWith(".mov")) {
|
|
|
|
|
+ title = filename.replace(".mov", "");
|
|
|
|
|
+ } else if (filename.endsWith(".MP4")) {
|
|
|
|
|
+ title = filename.replace(".MP4", "");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<VideoPost> list1 = videoPostMapper.findByTitle(title);
|
|
|
|
|
+ if (list1.isEmpty()) {
|
|
|
|
|
+ //log.info("notexist {}", title);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ List<String> videoIds = list1.stream().map(VideoPost::getVideoId).collect(Collectors.toList());
|
|
|
|
|
+ log.info("exist {} videoId {}", title, videoIds);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void test1() {
|
|
|
|
|
+ String tagId = "77d4093c54aa4e568ea58788e5b1bfaa";
|
|
|
|
|
+ int scope = PostScope.PROTECT.getCode();
|
|
|
|
|
+ //videoPostTagMapper.saveAll(list1);
|
|
|
|
|
+
|
|
|
|
|
+ TextFile textFile = new TextFile();
|
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
|
+ String filePath = "/home/reghao/Downloads/1_fyt91.txt";
|
|
|
|
|
+ //filePath = "/home/reghao/Downloads/1_fytgc.txt";
|
|
|
|
|
+
|
|
|
|
|
+ List<VideoPostTag> list = new ArrayList<>();
|
|
|
|
|
+ for (String line : textFile.read(filePath)) {
|
|
|
|
|
+ if (line.startsWith("exist")) {
|
|
|
|
|
+ String videoIdsStr = line.split(" videoId ")[1];
|
|
|
|
|
+ String[] videoIds = videoIdsStr.replace("[", "")
|
|
|
|
|
+ .replace("]", "")
|
|
|
|
|
+ .split(", ");
|
|
|
|
|
+
|
|
|
|
|
+ for (String videoId : videoIds) {
|
|
|
|
|
+ /*VideoPost videoPost = videoPostMapper.findByVideoId(videoId);
|
|
|
|
|
+ long publishBy = videoPost.getPublishBy();*/
|
|
|
|
|
+ sb.append("'").append(videoId).append("',");
|
|
|
|
|
+ list.add(new VideoPostTag(videoId, scope, tagId));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ videoPostTagMapper.saveAll(list);
|
|
|
|
|
+ System.out.println(sb.toString());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|