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

Changes, improvements and fixes

This commit is contained in:
Robert Vokac 2024-12-27 17:01:38 +01:00
parent 56ee178ec3
commit e5210a8c88
Signed by: robertvokac
GPG Key ID: FB9CE8E20AADA55F
2 changed files with 41 additions and 20 deletions

View File

@ -47,8 +47,8 @@ public class Main {
if (args.length < 1) {
//System.err.println("At least one argument is expected, but the count of arguments is: " + args.length + ".");
String argsS = "/rv/blupi/archivebox --video_ 7qKUtn76q30 --always-generate-metadata 0"
+ " --always-generate-html-files 1 --videos-per-row 4 --thumbnail-links-to-youtube 1"
String argsS = "/rv/blupi/archivebox --video_ 5rGd2VQz3mo --always-generate-metadata 0"
+ " --always-generate-html-files 1 --videos-per-row 4 --thumbnail-links-to-youtube 0"
+ " --thumbnail-as-base64 1"
+ " --channel_ UCqBpgfXap7cZOYkAC34u8Lg ";
args = argsS.split(" ");
@ -150,6 +150,7 @@ public class Main {
iii = 0;
internalStaticVariableVideoNumberPerRow = 0;
oneChannelStringBuilder.append("<table>\n");
long countOfVideosInChannel = youtubeVideos.stream().filter(v -> channel.equals(v.getChannelName())).count();
youtubeVideos.stream().filter(v -> channel.equals(v.getChannelName())).forEach(youtubeVideo -> {
iii++;
if (internalStaticVariableVideoNumberPerRow == 0) {
@ -209,8 +210,10 @@ public class Main {
if (!videoHtmlFile.exists() || argsInstance.getBoolean(ArgType.ALWAYS_GENERATE_HTML_FILES).get()) {
{
String singleVideo = new YoutubeVideoHtml(youtubeVideo, archiveBoxRootDirectory, archiveBoxArchiveDirectory).toString();
String singleVideo = new YoutubeVideoHtml(youtubeVideo, archiveBoxRootDirectory, archiveBoxArchiveDirectory, countOfVideosInChannel).toString();
Utils.writeTextToFile(singleVideo, videoHtmlFile);
processedVideos++;
System.out.println("Processed " + processedVideos + " from " + archiveBoxArchiveDirectory.list().length);
}
}
});
@ -229,6 +232,6 @@ public class Main {
return oneChannelStringBuilder;
}
private static int processedVideos = 0;
}

View File

@ -21,6 +21,8 @@ package com.openeggbert.utils.youtubedlfrontend;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Date;
@ -35,7 +37,7 @@ public class YoutubeVideoHtml {
@Getter
private String singleVideo;
public YoutubeVideoHtml(YoutubeVideo youtubeVideo, File archiveBoxRootDirectory, File archiveBoxArchiveDirectory) {
public YoutubeVideoHtml(YoutubeVideo youtubeVideo, File archiveBoxRootDirectory, File archiveBoxArchiveDirectory, long countOfVideosInChannel) {
StringBuilder videoHtml = new StringBuilder("""
<!DOCTYPE html>
@ -62,9 +64,11 @@ public class YoutubeVideoHtml {
videoHtml.append("<input type=\"text\" id=\"youtube_url\" name=\"youtube_url\" size=\"60\" width=\"60\" style=\"margint-bottom:20px;margin-right:10px;font-size:110%;padding:5px;\" value=\"" + finalUrl + "\"><br>\n<br>\n");
videoHtml.append("<a target=\"_blank\" href=\"").append(finalUrl).append("\">");
videoHtml.append(finalUrl).append("</a>").append("<br>\n");
String videoLocalFileEncoded = null;
String videoLocalUrl = "";
try {
videoLocalUrl = "file:///" + archiveBoxRootDirectory.getAbsolutePath() + "/archive/" + youtubeVideo.getSnapshot() + "/media/" + URLEncoder.encode(youtubeVideo.getVideoFileName(), StandardCharsets.UTF_8.toString()).replace("+", "%20");
videoLocalFileEncoded = URLEncoder.encode(youtubeVideo.getVideoFileName(), StandardCharsets.UTF_8.displayName()).replace("+", "%20").replace("#", "%23");
videoLocalUrl = "file:///" + archiveBoxRootDirectory.getAbsolutePath() + "/archive/" + youtubeVideo.getSnapshot() + "/media/" + videoLocalFileEncoded;
} catch (UnsupportedEncodingException ex) {
throw new YoutubedlFrontendException(ex.getMessage());
}
@ -72,11 +76,22 @@ public class YoutubeVideoHtml {
//try {
videoHtml.append("<video src=\"");
String videoFileName = youtubeVideo.getVideoFileName();
// if (!videoFileName.contains(""))
{
try {
videoFileName = URLEncoder.encode(youtubeVideo.getVideoFileName(), StandardCharsets.UTF_8.displayName()).replace("+", "%20").replace("#", "%23");
} catch (UnsupportedEncodingException ex) {
System.out.println("File name does not contain : " + videoFileName);
System.err.println(ex.getMessage());
throw new YoutubedlFrontendException(ex.getMessage());
}
}
videoHtml.append("../archive/").append(youtubeVideo.getSnapshot()).append("/media/").append(// URLEncoder.encode(
youtubeVideo.getVideoFileName());
videoFileName);
videoHtml.append("""
" controls height=\"500px\">
" controls autoplay height=\"440px\">
Your browser does not support the video tag.
</video><br>
""");
@ -92,26 +107,29 @@ public class YoutubeVideoHtml {
.append(youtubeVideo.getThumbnailFormat())
.append("\"></a><br>\n");
}
videoHtml.append("<span style=\"font-size:160%;font-weight:bold;\">").append(youtubeVideo.getTitle()).append("</span>");
videoHtml.append("<span style=\"font-size:200%;font-weight:bold;\">").append(youtubeVideo.getTitle()).append("</span>");
videoHtml.append("<br>\n<br>\n");
videoHtml.append("#").append(youtubeVideo.getNumber()).append("&nbsp;&nbsp;&nbsp;");
if (youtubeVideo.getPreviousVideoId() != null) {
boolean backEnabled = youtubeVideo.getNumber() > 1 && youtubeVideo.getPreviousVideoId() != null;
{
// videoHtml.append("<a href=\"./").append(youtubeVideo.getPreviousVideoId()).append(".html\">");
videoHtml.append("<button style=\"font-size:150%;\" onclick=\"window.location ='").append("./").append(youtubeVideo.getPreviousVideoId()).append(".html'\">");
videoHtml.append("<button ").append(backEnabled ? "" : "disabled").append(" style=\"").append(backEnabled ? "" : "visibility:hidden;").append("font-size:200%;\" onclick=\"window.location ='").append("./").append(youtubeVideo.getPreviousVideoId()).append(".html'\">");
//<button class="link" onclick="alert(1)">Click</button>
}
videoHtml.append("Back");
if (youtubeVideo.getPreviousVideoId() != null) {
//videoHtml.append("</a>");
videoHtml.append("</button>");
}
videoHtml.append("&nbsp;&nbsp;&nbsp;");
if (youtubeVideo.getNextVideoId() != null) {
boolean nextEnabled = youtubeVideo.getNumber() < countOfVideosInChannel && youtubeVideo.getNextVideoId() != null;
{
//videoHtml.append("<a href=\"./").append(youtubeVideo.getNextVideoId()).append(".html\">");
videoHtml.append("<button style=\"font-size:150%;\" onclick=\"window.location ='").append("./").append(youtubeVideo.getNextVideoId()).append(".html'\">");
}
videoHtml.append("<button ").append(nextEnabled ? "" : "disabled").append(" style=\"").append(nextEnabled ? "" : "visibility:hidden;").append("font-size:200%;\" onclick=\"window.location ='").append("./").append(youtubeVideo.getNextVideoId()).append(".html'\">");
videoHtml.append("Next");
if (youtubeVideo.getNextVideoId() != null) {
//videoHtml.append("</a>");
videoHtml.append("</button>");
@ -121,7 +139,7 @@ videoHtml.append("<button style=\"font-size:150%;\" onclick=\"window.location ='
.append("<br><br><a href=\"../archive/")
.append(youtubeVideo.getSnapshot())
.append("/media/")
.append(youtubeVideo.getVideoFileName())
.append(videoLocalFileEncoded)
.append("\">Download</a> ");
videoHtml.append(Utils.TWO_DECIMAL_POINTS_FORMATTER.format(((double) youtubeVideo.getVideoFileSizeInBytes()) / 1024d / 1024d)).append(" MB ");
if (youtubeVideo.getVideoFileName().endsWith(".mkv")) {
@ -143,7 +161,7 @@ videoHtml.append("<button style=\"font-size:150%;\" onclick=\"window.location ='
videoHtml.append("\"><br>");
}
videoHtml.append("<a target=\"_blank\" href=\"file://").append(archiveBoxArchiveDirectory).append("/").append(youtubeVideo.getSnapshot()).append("/media\">Directory</a>").append("<br>");
// videoHtml.append("<a target=\"_blank\" href=\"file://").append(archiveBoxArchiveDirectory).append("/").append(youtubeVideo.getSnapshot()).append("/media\">Directory</a>").append("<br>");
videoHtml.append("<br>\n<br>\n");
videoHtml.append("<br>\n");
videoHtml.append("<pre style=\"white-space: pre-wrap; border:1px solid black;max-width:600px;padding:10px;min-height:50px;\">");