فهرست منبع

麻将侠批量上传

licailing 4 سال پیش
والد
کامیت
fc41ae9b5a
1فایلهای تغییر یافته به همراه57 افزوده شده و 10 حذف شده
  1. 57 10
      src/test/java/com/izouma/nineth/service/CollectionServiceTest.java

+ 57 - 10
src/test/java/com/izouma/nineth/service/CollectionServiceTest.java

@@ -12,15 +12,19 @@ import com.izouma.nineth.repo.CollectionRepo;
 import com.izouma.nineth.repo.PrivilegeOptionRepo;
 import com.izouma.nineth.repo.UserRepo;
 import com.izouma.nineth.service.storage.StorageService;
+import com.izouma.nineth.utils.ImageUtils;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang3.RandomStringUtils;
+import org.bytedeco.javacv.FFmpegFrameGrabber;
+import org.bytedeco.javacv.Frame;
+import org.bytedeco.javacv.Java2DFrameConverter;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.*;
 import java.nio.file.Files;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
@@ -52,23 +56,25 @@ class CollectionServiceTest extends ApplicationTests {
 
     @Test
     public void batchUpload() throws IOException {
-        AtomicInteger num = new AtomicInteger(2501);
+        AtomicInteger num = new AtomicInteger(1);
         List<BlindBoxItem> items = new ArrayList<>();
-        String jsonStr = FileUtils.readFileToString(new File("/Users/qiufangchao/Desktop/evo.json"), "UTF-8");
-        Arrays.stream(new File("/Users/qiufangchao/Desktop/evo3").listFiles())
-                .filter(f -> Pattern.matches("^BJ.*\\.png$", f.getName()))
+        String jsonStr = FileUtils.readFileToString(new File("/Users/qiufangchao/Desktop/mj.json"), "UTF-8");
+        Arrays.stream(new File("/Users/qiufangchao/Desktop/mahjong/dong").listFiles())
+                .filter(f -> !f.getName().contains(".DS_Store"))
                 .parallel().forEach(file -> {
                     try {
                         Collection collection = JSON.parseObject(jsonStr, Collection.class);
                         collection.setId(null);
-                        collection.setName(String.format("OASISPUNK.EVO #%04d", num.getAndIncrement()));
+                        collection.setName("MAHJONGMAN 麻将侠: 十三幺 1-" + num.getAndIncrement());
                         collection.setStock(1);
                         collection.setTotal(1);
                         collection.setSale(0);
                         collection.setMinterId(7150L);
                         collection.setOnShelf(false);
                         collection.setSalable(false);
-                        collection.setPic(Collections.singletonList(new FileObject("", "https://raex-meta.oss-cn-shenzhen.aliyuncs.com/image/evos3/" + file.getName(), null, "png")));
+                        String thumbPath = "https://cdn.raex.vip/thumb_image/mahjong/" + file.getName()
+                                .substring(0, file.getName().lastIndexOf(".")) + ".jpg";
+                        collection.setPic(Collections.singletonList(new FileObject("", "https://cdn.raex.vip/video/mahjong/" + file.getName(), thumbPath, "video/mp4")));
 
                         collectionRepo.save(collection);
                         System.out.println("保存成功" + collection.getId());
@@ -91,7 +97,7 @@ class CollectionServiceTest extends ApplicationTests {
     public void createBlindBox() throws IOException {
         List<Collection> items = collectionRepo.findByNameLike("OASISPUNK.EVO #%").stream().filter(i -> {
             int num = Integer.parseInt(i.getName().substring("OASISPUNK.EVO #".length()));
-            return num > 2500 && num <= 3000;
+            return num > 0 && num <= 280;
         }).collect(Collectors.toList());
 
         String jsonStr = FileUtils.readFileToString(new File("/Users/qiufangchao/Desktop/evo.json"), "UTF-8");
@@ -144,4 +150,45 @@ class CollectionServiceTest extends ApplicationTests {
         collectionService.savePoint(3749128L, LocalDateTime.of(2022, 3, 23, 15, 0, 0));
     }
 
+    @Test
+    public void uploadMp4() {
+        Arrays.stream(new File("/Users/qiufangchao/Desktop/majiang").listFiles())
+                .parallel()
+                .filter(f -> !f.getName().contains(".DS_Store"))
+                .forEach(file -> {
+                    System.out.println(file.getName());
+                    try {
+                        String url = storageService.uploadFromInputStream(new FileInputStream(file), "video/mahjong/" + file.getName());
+                        String thumbPath = "thumb_image/mahjong/" + file.getName()
+                                .substring(0, file.getName().lastIndexOf(".")) + ".jpg";
+
+                        FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(file);
+                        Java2DFrameConverter frameConverter = new Java2DFrameConverter();
+                        try {
+                            frameGrabber.start();
+
+                            Frame frame = null;
+                            while (frame == null) {
+                                frame = frameGrabber.grabKeyFrame();
+                            }
+                            Objects.requireNonNull(frame, "获取视频缩略图失败");
+                            BufferedImage thumbBi = frameConverter.convert(frame);
+
+                            BufferedImage thumbResized = ImageUtils.resizeJpg(thumbBi, 1000, 1000, false);
+                            ByteArrayOutputStream os = new ByteArrayOutputStream();
+                            ImageIO.write(thumbResized, "jpg", os);
+                            InputStream is = new ByteArrayInputStream(os.toByteArray());
+                            String thumbUrl = storageService.uploadFromInputStream(is, thumbPath);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        } finally {
+                            frameGrabber.stop();
+                        }
+                    } catch (Exception e) {
+                    }
+                });
+
+
+    }
+
 }