1
0
mirror of https://github.com/openeggbert/youtubedl-frontend.git synced 2025-03-14 21:23:27 +01:00

Added 2 new command line options II

This commit is contained in:
Robert Vokac 2024-07-17 18:07:57 +02:00
parent 679af67719
commit 7e65b4363e
No known key found for this signature in database
GPG Key ID: C459E1E4B4A986BB
2 changed files with 28 additions and 2 deletions

View File

@ -18,6 +18,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////
package org.nanoboot.youtubedlfrontend;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@ -289,7 +290,15 @@ public class Main {
.append(youtubeVideo.getMiniThumbnailFormat()).toString();
if (thumbnailAsBase64) {
try {
byte[] bytes= Files.readAllBytes(new File(archiveBoxRootDirectory + "/" + thumbnailPath).toPath());
byte[] bytes = Files.readAllBytes(new File(archiveBoxRootDirectory + "/" + thumbnailPath).toPath());
System.out.println("###=" + archiveBoxRootDirectory + "/" + thumbnailPath);
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
try {
bytes = Utils.resizeImage(bais, 25, (int) (9d / 16d * 25d), youtubeVideo.getThumbnailFormat());
} catch (Exception e) {
//bytes = Utils.resizeImage(bais, 125, (int) (9d / 16d * 125d), "webp");
}
String bytesS = "data:image/jpg;base64, " + org.nanoboot.powerframework.io.bit.base64.Base64Coder.encode(bytes);
sb.append(bytesS);
} catch (IOException ex) {

View File

@ -19,8 +19,12 @@
package org.nanoboot.youtubedlfrontend;
import dev.mccue.guava.hash.Hashing;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
@ -33,6 +37,7 @@ import java.nio.file.StandardCopyOption;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.imageio.ImageIO;
/**
*
@ -182,5 +187,17 @@ public class Utils {
throw new YoutubedlFrontendException("Could not create boolean from String: " + s);
}
}
public static byte[] resizeImage(InputStream inputStream, int width, int height, String formatName) throws IOException {
BufferedImage sourceImage = ImageIO.read(inputStream);
Image thumbnail = sourceImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
BufferedImage bufferedThumbnail = new BufferedImage(thumbnail.getWidth(null),
thumbnail.getHeight(null),
BufferedImage.TYPE_INT_RGB);
bufferedThumbnail.getGraphics().drawImage(thumbnail, 0, 0, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedThumbnail, formatName, baos);
return baos.toByteArray();
}
}