From 679af677193a8698eac5e46a158cac7a038c352e Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Wed, 17 Jul 2024 17:38:23 +0200 Subject: [PATCH] Added 2 new command line options --- README.md | 2 + pom.xml | 7 +- src/main/java/module-info.java | 2 + .../org/nanoboot/youtubedlfrontend/Main.java | 326 ++++++++++-------- .../org/nanoboot/youtubedlfrontend/Utils.java | 15 + 5 files changed, 215 insertions(+), 137 deletions(-) diff --git a/README.md b/README.md index 05de5d3..d443751 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # youtubedl-frontend +ffmpeg -i "$video"mkv -preset slow -crf 18 "$video"webm + diff --git a/pom.xml b/pom.xml index 5e291e9..c7233d3 100644 --- a/pom.xml +++ b/pom.xml @@ -119,7 +119,12 @@ org.nanoboot.powerframework - power-random + power-utils + ${power.version} + + + org.nanoboot.powerframework + power-io ${power.version} diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index f1d5c4f..e0ca0d8 100755 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -26,4 +26,6 @@ module youtubedlfrontend { requires humble.video.all; requires com.fasterxml.jackson.databind; requires java.desktop; + requires powerframework.io; + requires powerframework.utils; } diff --git a/src/main/java/org/nanoboot/youtubedlfrontend/Main.java b/src/main/java/org/nanoboot/youtubedlfrontend/Main.java index a68f6c5..6bccdaf 100755 --- a/src/main/java/org/nanoboot/youtubedlfrontend/Main.java +++ b/src/main/java/org/nanoboot/youtubedlfrontend/Main.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; @@ -42,6 +43,8 @@ public class Main { private static int internalStaticVariableVideoNumberPerRow = 0; public static boolean argAlwaysGenerateMetadata = true; public static boolean argAlwaysGenerateHtmlFiles = true; + public static boolean thumbnailAsBase64 = false; + public static boolean thumbnailLinksToYoutube = false; public static int argVideosPerRow = 4; public static int THUMBNAIL_WIDTH = 250; public static String argVideo; @@ -50,12 +53,13 @@ public class Main { public static void main(String[] args) throws IOException, InterruptedException { System.out.println("youtubedlfrontend - HTML generator\n"); - //args = "/rv/databig/youtube --_video UDpsz1yIwiw --always-generate-metadata 1 --always-generate-html-files 1 --videos-per-row 4".split(" "); - if (args.length < 1) { //System.err.println("At least one argument is expected, but the count of arguments is: " + args.length + "."); - args = "/rv/blupi/archivebox --_video UDpsz1yIwiw --always-generate-metadata 0 --always-generate-html-files 1 --videos-per-row 4".split(" "); + String argsS = "/rv/blupi/archivebox --_video UDpsz1yIwiw --always-generate-metadata 0 " + + " --always-generate-html-files 1 --videos-per-row 4 --thumbnail-links-to-youtube 1" + + " --thumbnail-as-base64 1"; + args = argsS.split(" "); //System.exit(1); } argVideo = ""; @@ -98,22 +102,12 @@ public class Main { throw new YoutubedlFrontendException("Fatal error: missing value for --always-generate-metadata"); } String s = args[i]; - switch (s) { - case "1": - argAlwaysGenerateMetadata = true; - break; - case "true": - argAlwaysGenerateMetadata = true; - break; - case "0": - argAlwaysGenerateMetadata = false; - break; - case "false": - argAlwaysGenerateMetadata = false; - break; - default: - throw new YoutubedlFrontendException("Invalid value for --always-generate-metadata"); - }; + + try { + argAlwaysGenerateMetadata = Utils.convertStringToBoolean(s); + } catch (Exception e) { + throw new YoutubedlFrontendException("Invalid value for --always-generate-metadata"); + } } if (arg.equals("--always-generate-html-files")) { @@ -122,24 +116,41 @@ public class Main { throw new YoutubedlFrontendException("Fatal error: missing value for --always-generate-html-files"); } String s = args[i]; - switch (s) { - case "1": - argAlwaysGenerateHtmlFiles = true; - break; - case "true": - argAlwaysGenerateHtmlFiles = true; - break; - case "0": - argAlwaysGenerateHtmlFiles = false; - break; - case "false": - argAlwaysGenerateHtmlFiles = false; - break; - default: + try {argAlwaysGenerateHtmlFiles = Utils.convertStringToBoolean(s);} catch(Exception e) { throw new YoutubedlFrontendException("Invalid value for --always-generate-html-files"); - }; + } } + + if (arg.equals("--thumbnail-as-base64")) { + i++; + if (i >= args.length) { + throw new YoutubedlFrontendException("Fatal error: missing value for --thumbnail-as-base64"); + } + String s = args[i]; + try {thumbnailAsBase64 = Utils.convertStringToBoolean(s);} catch(Exception e) { + throw new YoutubedlFrontendException("Invalid value for --thumbnail-as-base64"); + } + + + } + + if (arg.equals("--thumbnail-links-to-youtube")) { + i++; + if (i >= args.length) { + throw new YoutubedlFrontendException("Fatal error: missing value for --thumbnail-links-to-youtube"); + } + String s = args[i]; + try { + thumbnailLinksToYoutube = Utils.convertStringToBoolean(s); + } catch (Exception e) { + throw new YoutubedlFrontendException("Invalid value for --thumbnail-links-to-youtube"); + } + + } + + + } } String workingDirectory = args.length > 0 && !args[0].startsWith(TWO_DASHES) ? args[0] : new File(".").getAbsolutePath(); @@ -168,13 +179,13 @@ public class Main { i++; System.out.println("\n\nFound video #" + i); - for(File f:new File(archiveBoxArchiveDirectory + "/" +youtubeVideo.getSnapshot() + "/media/" + youtubeVideo.getVideoFileName()).getParentFile().listFiles()) { - if(f.getName().endsWith(".webm")) { + for (File f : new File(archiveBoxArchiveDirectory + "/" + youtubeVideo.getSnapshot() + "/media/" + youtubeVideo.getVideoFileName()).getParentFile().listFiles()) { + if (f.getName().endsWith(".webm")) { //mkv file was manually converted to webm youtubeVideo.setVideoFileName(f.getName()); break; } - + } System.out.println("id = " + youtubeVideo.getId()); System.out.println("snapshot = " + youtubeVideo.getSnapshot()); @@ -256,7 +267,7 @@ public class Main { iii = 0; internalStaticVariableVideoNumberPerRow = 0; sb.append("\n"); - youtubeVideos.stream().filter(v -> c.equals(v.getChannelName())).forEach(z -> { + youtubeVideos.stream().filter(v -> c.equals(v.getChannelName())).forEach(youtubeVideo -> { iii++; if (internalStaticVariableVideoNumberPerRow == 0) { sb.append(""); @@ -264,41 +275,58 @@ public class Main { internalStaticVariableVideoNumberPerRow++; sb.append("\n"); if (internalStaticVariableVideoNumberPerRow == argVideosPerRow) { sb.append(""); internalStaticVariableVideoNumberPerRow = 0; } - File videoHtmlFile = new File(videosDirectory, z.getId() + ".html"); - if(!videoHtmlFile.exists() || argAlwaysGenerateHtmlFiles) { - + File videoHtmlFile = new File(videosDirectory, youtubeVideo.getId() + ".html"); + if (!videoHtmlFile.exists() || argAlwaysGenerateHtmlFiles) { - { - StringBuilder sb2 = new StringBuilder(""" + { + StringBuilder videoHtml = new StringBuilder(""" """ - + z.getTitle() - + """ + + youtubeVideo.getTitle() + + """
\n\n"); - sb.append("\n"); - String uploadDate = z.getUploadDate(); + sb.append("\n"); + String uploadDate = youtubeVideo.getUploadDate(); uploadDate = uploadDate.substring(0, 4) + "-" + uploadDate.substring(4, 6) + "-" + uploadDate.substring(6, 8); - sb.append("\n"); - z.setNumber(iii); + youtubeVideo.setNumber(iii); sb.append("
\n
").append(z.getTitle()).append("
").append(youtubeVideo.getTitle()).append("
").append(uploadDate).append(" •︎ ").append(z.getVideoDuration()) + sb.append("
").append(uploadDate).append(" •︎ ").append(youtubeVideo.getVideoDuration()) .append(" •︎ ") .append("#").append(iii) .append("