1
0
mirror of https://github.com/openeggbert/youtubedl-frontend.git synced 2025-03-25 17:17:46 +01:00

Added some improvements

This commit is contained in:
Robert Vokac 2024-07-10 21:23:20 +02:00
parent c716abb127
commit 66ed2445b2
No known key found for this signature in database
GPG Key ID: C459E1E4B4A986BB
2 changed files with 42 additions and 12 deletions

View File

@ -23,6 +23,8 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
@ -48,12 +50,13 @@ public class Main {
public static void main(String[] args) throws IOException, InterruptedException { public static void main(String[] args) throws IOException, InterruptedException {
System.out.println("youtubedlfrontend - HTML generator\n"); System.out.println("youtubedlfrontend - HTML generator\n");
args = "/rv/blupi/archivebox --_video UDpsz1yIwiw --always-generate-metadata 1 --always-generate-html-files 0 --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(" "); //args = "/rv/databig/youtube --_video UDpsz1yIwiw --always-generate-metadata 1 --always-generate-html-files 1 --videos-per-row 4".split(" ");
if (args.length < 1) { if (args.length < 1) {
System.err.println("At least one argument is expected, but the count of arguments is: " + args.length + "."); //System.err.println("At least one argument is expected, but the count of arguments is: " + args.length + ".");
System.exit(1); args = "/rv/blupi/archivebox --_video UDpsz1yIwiw --always-generate-metadata 0 --always-generate-html-files 1 --videos-per-row 4".split(" ");
//System.exit(1);
} }
argVideo = ""; argVideo = "";
argChannel = ""; argChannel = "";
@ -165,6 +168,14 @@ public class Main {
i++; i++;
System.out.println("\n\nFound video #" + 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")) {
//mkv file was manually converted to webm
youtubeVideo.setVideoFileName(f.getName());
break;
}
}
System.out.println("id = " + youtubeVideo.getId()); System.out.println("id = " + youtubeVideo.getId());
System.out.println("snapshot = " + youtubeVideo.getSnapshot()); System.out.println("snapshot = " + youtubeVideo.getSnapshot());
System.out.println("title = " + youtubeVideo.getTitle()); System.out.println("title = " + youtubeVideo.getTitle());
@ -238,7 +249,7 @@ public class Main {
</head> </head>
<body> <body>
"""); """);
NumberFormat formatter = new DecimalFormat("#0.00");
channels.forEach(c -> { channels.forEach(c -> {
sb.append("<h1>").append(c).append("</h1>\n"); sb.append("<h1>").append(c).append("</h1>\n");
sb.append("<div style=\"max-width:").append((Main.THUMBNAIL_WIDTH + 20) * Main.argVideosPerRow).append("px\"><a href =\"").append(channelUrls.get(c)).append("\">").append(channelUrls.get(c)).append("</a><div class=\"videos\">"); sb.append("<div style=\"max-width:").append((Main.THUMBNAIL_WIDTH + 20) * Main.argVideosPerRow).append("px\"><a href =\"").append(channelUrls.get(c)).append("\">").append(channelUrls.get(c)).append("</a><div class=\"videos\">");
@ -283,6 +294,7 @@ public class Main {
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="UTF-8">
<link rel="icon" type="image/x-icon" href="../favicon.ico" sizes="16x16"> <link rel="icon" type="image/x-icon" href="../favicon.ico" sizes="16x16">
<title>""" <title>"""
+ z.getTitle() + z.getTitle()
@ -311,22 +323,29 @@ public class Main {
throw new YoutubedlFrontendException(ex.getMessage()); throw new YoutubedlFrontendException(ex.getMessage());
} }
if(!z.getVideoFileName().endsWith(".mkv")) { if(!z.getVideoFileName().endsWith(".mkv")) {
try { //try {
sb2.append("<video src=\""); sb2.append("<video src=\"");
sb2.append("../archive/" + z.getSnapshot() + "/media/" + URLEncoder.encode(z.getVideoFileName(), StandardCharsets.UTF_8.toString()).replace("+", "%20")); sb2.append("../archive/" + z.getSnapshot() + "/media/"
+
// URLEncoder.encode(
z.getVideoFileName()
// , StandardCharsets.UTF_8.toString()
// )
// .replace("+", "%20")
);
sb2.append(""" sb2.append("""
" controls width=\"800\"> " controls height=\"500px\">
Your browser does not support the video tag. Your browser does not support the video tag.
</video><br> </video><br>
"""); """);
} catch (UnsupportedEncodingException ex) { // } catch (UnsupportedEncodingException ex) {
throw new YoutubedlFrontendException(ex.getMessage()); // throw new YoutubedlFrontendException(ex.getMessage());
} // }
} else { } else {
sb2.append("<a target=\"_blank\" href=\"").append(videoLocalUrl).append("\">"); sb2.append("<a target=\"_blank\" href=\"").append(videoLocalUrl).append("\">");
sb2.append("<img style=\"margin:10px;width:600px;\" src=\"../archive/") sb2.append("<img style=\"margin:10px;height:500px;\" src=\"../archive/")
.append(z.getSnapshot()) .append(z.getSnapshot())
.append("/media/thumbnail.") .append("/media/thumbnail.")
.append(z.getThumbnailFormat()) .append(z.getThumbnailFormat())
@ -351,6 +370,14 @@ public class Main {
sb2.append("</a>"); sb2.append("</a>");
} }
sb2.append(" "); sb2.append(" ");
sb2
.append("<br><br><a href=\"../archive/")
.append(z.getSnapshot())
.append("/media/")
.append(z.getVideoFileName())
.append("\">Download</a> ");
sb2.append(formatter.format(((double)z.getVideoFileSizeInBytes()) / 1024d / 1024d)).append(" MB");
sb2.append("<br>\n"); sb2.append("<br>\n");
sb2.append("<pre style=\"white-space: pre-wrap; border:1px solid black;max-width:600px;padding:10px;min-height:50px;\">"); sb2.append("<pre style=\"white-space: pre-wrap; border:1px solid black;max-width:600px;padding:10px;min-height:50px;\">");
sb2.append(z.getDescription().isBlank() ? "No description" : z.getDescription()); sb2.append(z.getDescription().isBlank() ? "No description" : z.getDescription());

View File

@ -15,7 +15,9 @@ import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -68,7 +70,8 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
//new ObjectMapper().readValue(Utils.readTextFromFile(metadataFile), YoutubeVideo.class); //new ObjectMapper().readValue(Utils.readTextFromFile(metadataFile), YoutubeVideo.class);
Properties properties = new Properties(); Properties properties = new Properties();
properties.load(new FileInputStream(metadataFile)); var input = new FileInputStream(metadataFile);
properties.load(new InputStreamReader(input, Charset.forName("UTF-8")));
id = properties.getProperty("id"); id = properties.getProperty("id");