From c4dc2f650f4666bbc615421ff318558031f40ceb Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Fri, 5 Jul 2024 14:17:22 +0200 Subject: [PATCH] Renamed to youtubedl-frontend. Added many improvements --- README.md | 2 +- pom.xml | 30 ++- src/main/java/module-info.java | 5 +- .../Main.java | 240 ++++++++++++------ .../Utils.java | 16 +- .../YoutubeComment.java | 2 +- .../YoutubeVideo.java | 119 ++++++++- .../YoutubedlFrontendException.java} | 10 +- .../lombok.config | 0 9 files changed, 317 insertions(+), 107 deletions(-) rename src/main/java/org/nanoboot/{archiveboxyoutubehelper => youtubedlfrontend}/Main.java (57%) rename src/main/java/org/nanoboot/{archiveboxyoutubehelper => youtubedlfrontend}/Utils.java (86%) rename src/main/java/org/nanoboot/{archiveboxyoutubehelper => youtubedlfrontend}/YoutubeComment.java (97%) rename src/main/java/org/nanoboot/{archiveboxyoutubehelper => youtubedlfrontend}/YoutubeVideo.java (68%) rename src/main/java/org/nanoboot/{archiveboxyoutubehelper/ArchiveBoxYoutubeHelperException.java => youtubedlfrontend/YoutubedlFrontendException.java} (75%) rename src/main/java/org/nanoboot/{archiveboxyoutubehelper => youtubedlfrontend}/lombok.config (100%) diff --git a/README.md b/README.md index 88d6076..05de5d3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# archivebox-youtube-helper +# youtubedl-frontend diff --git a/pom.xml b/pom.xml index e1163af..5e291e9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ @@ -201,6 +216,11 @@ nanoboot-snapshots-repository https://maven.nanoboot.org/snapshots + + AsposeJavaAPI + Aspose Java API + https://repository.aspose.com/repo/ + diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index e3edb27..f1d5c4f 100755 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////////////////////// -// archiveboxyoutubehelper: +// youtubedlfrontend: // Copyright (C) 2024 the original author or authors. // // This program is free software; you can redistribute it and/or @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. /////////////////////////////////////////////////////////////////////////////////////////////// -module archiveboxyoutubehelper { +module youtubedlfrontend { requires lombok; requires org.apache.logging.log4j; requires org.json; @@ -25,4 +25,5 @@ module archiveboxyoutubehelper { requires humble.video.noarch; requires humble.video.all; requires com.fasterxml.jackson.databind; + requires java.desktop; } diff --git a/src/main/java/org/nanoboot/archiveboxyoutubehelper/Main.java b/src/main/java/org/nanoboot/youtubedlfrontend/Main.java similarity index 57% rename from src/main/java/org/nanoboot/archiveboxyoutubehelper/Main.java rename to src/main/java/org/nanoboot/youtubedlfrontend/Main.java index a55045e..28f1d0b 100755 --- a/src/main/java/org/nanoboot/archiveboxyoutubehelper/Main.java +++ b/src/main/java/org/nanoboot/youtubedlfrontend/Main.java @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////////////////////// -// archivebox-youtube-helper: Tool generating html pages for Archive Box. +// youtubedl-frontend: Tool generating html pages for Archive Box. // Copyright (C) 2024 the original author or authors. // // This program is free software; you can redistribute it and/or @@ -16,7 +16,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. /////////////////////////////////////////////////////////////////////////////////////////////// -package org.nanoboot.archiveboxyoutubehelper; +package org.nanoboot.youtubedlfrontend; import java.io.File; import java.io.IOException; @@ -37,48 +37,111 @@ import java.util.Map; public class Main { private static int iii = 0; - private static int videoNumberPerRow = 0; - public static final boolean ALWAYS_COMPUTE_METADATA = false; - public static final int VIDEOS_PER_ROW = 4; - private static int THUMBNAIL_WIDTH = 250; + private static int internalStaticVariableVideoNumberPerRow = 0; + public static boolean argAlwaysGenerateMetadata = true; + public static boolean argAlwaysGenerateHtmlFiles = true; + public static int argVideosPerRow = 4; + public static int THUMBNAIL_WIDTH = 250; public static String argVideo; public static String argChannel; public static void main(String[] args) throws IOException, InterruptedException { - System.out.println("archiveboxyoutubehelper - HTML generator\n"); + System.out.println("youtubedlfrontend - HTML generator\n"); + + args = "/rv/blupi/archivebox --_video UDpsz1yIwiw --always-generate-metadata 1 --always-generate-html-files 1 --videos-per-row 4".split(" "); + //args = "/rv/databig/youtube --_video UDpsz1yIwiw --always-generate-metadata 1 --always-generate-html-files 1 --videos-per-row 4".split(" "); - if (args.length == 0) { - args = new String[]{"/rv/blupi/archivebox" - //, "--video", "gPU_onaTzXs" - }; - } if (args.length < 1) { System.err.println("At least one argument is expected, but the count of arguments is: " + args.length + "."); System.exit(1); } argVideo = ""; argChannel = ""; - if(args.length > 1) { - for(int i = 1;i 0) { + for (int i = 0; i < args.length; i++) { + String arg = args[i]; + if (i == 0 && !arg.startsWith(TWO_DASHES)) { + continue; + } + if (arg.equals("--video")) { i++; - if(i >= args.length) { - throw new ArchiveBoxYoutubeHelperException("Fatal error: missing value for --video"); + if (i >= args.length) { + throw new YoutubedlFrontendException("Fatal error: missing value for --video"); } argVideo = args[i]; } - if(s.equals("--channel")) { + if (arg.equals("--channel")) { i++; - if(i >= args.length) { - throw new ArchiveBoxYoutubeHelperException("Fatal error: missing value for --channel"); + if (i >= args.length) { + throw new YoutubedlFrontendException("Fatal error: missing value for --channel"); } argChannel = args[i]; } + + if (arg.equals("--videos-per-row")) { + i++; + if (i >= args.length) { + throw new YoutubedlFrontendException("Fatal error: missing value for --videos-per-row"); + } + argVideosPerRow = Integer.parseInt(args[i]); + if (argVideosPerRow < 2) { + argVideosPerRow = 0; + } + } + + if (arg.equals("--always-generate-metadata")) { + i++; + if (i >= args.length) { + 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"); + }; + } + + if (arg.equals("--always-generate-html-files")) { + i++; + if (i >= args.length) { + 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: + throw new YoutubedlFrontendException("Invalid value for --always-generate-html-files"); + }; + + } } } - - File archiveBoxRootDirectory = new File(args[0]); + String workingDirectory = args.length > 0 && !args[0].startsWith(TWO_DASHES) ? args[0] : new File(".").getAbsolutePath(); + + File archiveBoxRootDirectory = new File(workingDirectory); File archiveBoxArchiveDirectory = new File(archiveBoxRootDirectory, "archive"); int i = 0; List youtubeVideos = new ArrayList<>(); @@ -90,13 +153,13 @@ public class Main { continue; } YoutubeVideo youtubeVideo = new YoutubeVideo(mediaDirectory); - if(!Main.argVideo.isBlank() && !youtubeVideo.getId().equals(Main.argVideo)) { - continue; - } - if(!argVideo.isBlank() && !youtubeVideo.getId().equals(argVideo)) { + if (!Main.argVideo.isBlank() && !youtubeVideo.getId().equals(Main.argVideo)) { continue; } - if(!argChannel.isBlank() && !youtubeVideo.getChannelId().equals(argChannel)) { + if (!argVideo.isBlank() && !youtubeVideo.getId().equals(argVideo)) { + continue; + } + if (!argChannel.isBlank() && !youtubeVideo.getChannelId().equals(argChannel)) { continue; } i++; @@ -121,14 +184,18 @@ public class Main { YoutubeVideo previousVideo = null; YoutubeVideo nextVideo = null; YoutubeVideo currentVideo = null; - for(int j = 0; j channelUrls = new HashMap<>(); List channels = new ArrayList<>(); @@ -173,21 +240,24 @@ public class Main { channels.forEach(c -> { sb.append("

").append(c).append("

\n"); - sb.append("
").append(channelUrls.get(c)).append("
"); + sb.append("
").append(channelUrls.get(c)).append("
"); iii = 0; - videoNumberPerRow = 0; + internalStaticVariableVideoNumberPerRow = 0; sb.append("\n"); youtubeVideos.stream().filter(v -> c.equals(v.getChannelName())).forEach(z -> { iii++; - if (videoNumberPerRow == 0) { + if (internalStaticVariableVideoNumberPerRow == 0) { sb.append(""); } - videoNumberPerRow++; + internalStaticVariableVideoNumberPerRow++; sb.append("\n"); - if (videoNumberPerRow == VIDEOS_PER_ROW) { + if (internalStaticVariableVideoNumberPerRow == argVideosPerRow) { sb.append(""); - videoNumberPerRow = 0; + internalStaticVariableVideoNumberPerRow = 0; } File videoHtmlFile = new File(videosDirectory, z.getId() + ".html"); -// if(videoHtmlFile.exists()) { -// -// } + if(!videoHtmlFile.exists() || argAlwaysGenerateHtmlFiles) { + + { StringBuilder sb2 = new StringBuilder(""" @@ -214,8 +284,8 @@ public class Main { """ - +z.getTitle() + - """ + + z.getTitle() + + """
\n\n"); sb.append("\n"); @@ -199,14 +269,14 @@ public class Main { .append("\n"); z.setNumber(iii); sb.append("
").append(z.getTitle()).append("