1
0
mirror of https://github.com/openeggbert/youtubedl-frontend.git synced 2025-03-25 17:17:46 +01:00
This commit is contained in:
Robert Vokac 2024-12-27 17:26:22 +01:00
parent e5210a8c88
commit 66c89e1c72
Signed by: robertvokac
GPG Key ID: FB9CE8E20AADA55F
5 changed files with 23 additions and 65 deletions

View File

@ -34,9 +34,9 @@ public enum ArgType {
THUMBNAIL_AS_BASE64("thumbnail-as-base64", "false"), THUMBNAIL_AS_BASE64("thumbnail-as-base64", "false"),
THUMBNAIL_LINKS_TO_YOUTUBE("thumbnail-links-to-youtube", "false"); THUMBNAIL_LINKS_TO_YOUTUBE("thumbnail-links-to-youtube", "false");
@Getter @Getter
private String name; private final String name;
@Getter @Getter
private String defaultValue; private final String defaultValue;
ArgType(String name, String defaultValue) { ArgType(String name, String defaultValue) {
this.name = name; this.name = name;

View File

@ -64,12 +64,12 @@ public class Main {
List<YoutubeVideo> youtubeVideos = YoutubeVideo.loadYoutubeVideos(archiveBoxArchiveDirectory, argsInstance); List<YoutubeVideo> youtubeVideos = YoutubeVideo.loadYoutubeVideos(archiveBoxArchiveDirectory, argsInstance);
Map<String, String> channelUrls = new HashMap<>(); Map<String, String> channelUrls = new HashMap<>();
List<String> channels = new ArrayList<>(); List<String> channels = new ArrayList<>();
youtubeVideos.stream().forEach(c -> { youtubeVideos.stream().forEach(v -> {
final String channelName_ = c.getChannelName(); final String channelName = v.getChannelName();
if (channelName_ != null && !channelUrls.containsKey(c.getChannelName())) { if (channelName != null && !channelUrls.containsKey(v.getChannelName())) {
channelUrls.put(channelName_, c.getChannelUrl()); channelUrls.put(channelName, v.getChannelUrl());
channels.add(channelName_); channels.add(channelName);
} }
}); });
Collections.sort(channels, (String o1, String o2) -> o1.toLowerCase().compareTo(o2.toLowerCase())); Collections.sort(channels, (String o1, String o2) -> o1.toLowerCase().compareTo(o2.toLowerCase()));
@ -94,21 +94,11 @@ public class Main {
System.out.println("[Warning] Snapshots without videos:"); System.out.println("[Warning] Snapshots without videos:");
YoutubeVideo.missingYoutubeVideos.forEach(s -> System.out.println(s)); YoutubeVideo.missingYoutubeVideos.forEach(s -> System.out.println(s));
System.out.println("Total duration: " + ((int)((((double)YoutubeVideo.totalDurationInMilliseconds) / 1000d / 60d / 60d))) + " hours"); System.out.println("Total duration: " + ((int)((((double)YoutubeVideo.totalDurationInMilliseconds) / 1000d / 60d / 60d))) + " hours");
youtubeVideos.sort(new Comparator<YoutubeVideo>() { youtubeVideos.stream().sorted((YoutubeVideo o1, YoutubeVideo o2) -> Long.valueOf(o1.getVideoDurationInMilliseconds()).compareTo(o2.getVideoDurationInMilliseconds()))
@Override .forEach(y-> {System.out.println(y.getVideoDurationInMinutes() + " = minutes \t" + "https://youtube.com/watch?v=" + y.getId() + "\t" + y.getTitle());});
public int compare(YoutubeVideo o1, YoutubeVideo o2) {
return Long.valueOf(o1.getVideoDurationInMilliseconds()).compareTo(o2.getVideoDurationInMilliseconds());
}
});
youtubeVideos.forEach(y-> {System.out.println(y.getVideoDurationInMinutes() + " = minutes \t" + "https://youtube.com/watch?v=" + y.getId() + "\t" + y.getTitle());});
System.out.println("\n\n\n\n"); System.out.println("\n\n\n\n");
youtubeVideos.sort(new Comparator<YoutubeVideo>() { youtubeVideos.stream().sorted((YoutubeVideo o1, YoutubeVideo o2) -> Long.valueOf(o1.getVideoFileSizeInBytes()).compareTo(o2.getVideoFileSizeInBytes()))
@Override .forEach(y-> {System.out.println(y.getVideoFileSizeInMegaBytes()+ " MB \t" + "https://youtube.com/watch?v=" + y.getId() + "\t" + y.getTitle());});
public int compare(YoutubeVideo o1, YoutubeVideo o2) {
return Long.valueOf(o1.getVideoFileSizeInBytes()).compareTo(o2.getVideoFileSizeInBytes());
}
});
youtubeVideos.forEach(y-> {System.out.println(y.getVideoFileSizeInMegaBytes()+ " MB \t" + "https://youtube.com/watch?v=" + y.getId() + "\t" + y.getTitle());});
} }
private static StringBuilder createChannelHtml(String wantedChannelName, List<String> channels, Args argsInstance, Map<String, String> channelUrls, List<YoutubeVideo> youtubeVideos, File archiveBoxRootDirectory, File videosDirectory, File archiveBoxArchiveDirectory) { private static StringBuilder createChannelHtml(String wantedChannelName, List<String> channels, Args argsInstance, Map<String, String> channelUrls, List<YoutubeVideo> youtubeVideos, File archiveBoxRootDirectory, File videosDirectory, File archiveBoxArchiveDirectory) {

View File

@ -50,7 +50,6 @@ public class YoutubeComment implements Comparable<YoutubeComment> {
List<YoutubeComment> root = getChildren(list, "root"); List<YoutubeComment> root = getChildren(list, "root");
Collections.sort(root); Collections.sort(root);
return list; return list;
//return sort(list, new ArrayList<>(), "root");
} }
private static List<YoutubeComment> getChildren(List<YoutubeComment> all, String parentId) { private static List<YoutubeComment> getChildren(List<YoutubeComment> all, String parentId) {
@ -65,13 +64,7 @@ public class YoutubeComment implements Comparable<YoutubeComment> {
@Override @Override
public int compareTo(YoutubeComment o) { public int compareTo(YoutubeComment o) {
//if(this.timestamp != o.timestamp) {
// return this.id.compareTo(o.id);
return Long.valueOf(this.timestamp).compareTo(o.timestamp); return Long.valueOf(this.timestamp).compareTo(o.timestamp);
//}
// else {
// return this.id.compareTo(o.id);
// }
} }
public int dotCount() { public int dotCount() {

View File

@ -81,9 +81,6 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
File metadataFile = new File(mediaDirectory, "metadata"); File metadataFile = new File(mediaDirectory, "metadata");
if (!argAlwaysGenerateMetadata && metadataFile.exists()) { if (!argAlwaysGenerateMetadata && metadataFile.exists()) {
YoutubeVideo yv = new YoutubeVideo();
//new ObjectMapper().readValue(Utils.readTextFromFile(metadataFile), YoutubeVideo.class);
Properties properties = new Properties(); Properties properties = new Properties();
var input = new FileInputStream(metadataFile); var input = new FileInputStream(metadataFile);
properties.load(new InputStreamReader(input, Charset.forName("UTF-8"))); properties.load(new InputStreamReader(input, Charset.forName("UTF-8")));
@ -96,7 +93,7 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
snapshot = properties.getProperty("snapshot"); snapshot = properties.getProperty("snapshot");
title = properties.getProperty("title"); title = properties.getProperty("title");
videoFileName = properties.getProperty("videoFileName"); videoFileName = properties.getProperty("videoFileName");
videoFileSizeInBytes = Long.valueOf(properties.getProperty("videoFileSizeInBytes")); videoFileSizeInBytes = Long.parseLong(properties.getProperty("videoFileSizeInBytes"));
videoFileSha512HashSum = properties.getProperty("videoFileSha512HashSum"); videoFileSha512HashSum = properties.getProperty("videoFileSha512HashSum");
videoDuration = properties.getProperty("videoDuration"); videoDuration = properties.getProperty("videoDuration");
channelName = properties.getProperty("channelName"); channelName = properties.getProperty("channelName");
@ -110,7 +107,6 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
comments = new ArrayList<>(); comments = new ArrayList<>();
JSONArray ja = new JSONArray(properties.getProperty("comments")); JSONArray ja = new JSONArray(properties.getProperty("comments"));
ja.forEach(o -> { ja.forEach(o -> {
JSONObject jo = (JSONObject) o;
try { try {
final String toString = o.toString(); final String toString = o.toString();
System.out.println(toString); System.out.println(toString);
@ -124,7 +120,7 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
previousVideoId = properties.getProperty("previousVideoId"); previousVideoId = properties.getProperty("previousVideoId");
nextVideoId = properties.getProperty("nextVideoId"); nextVideoId = properties.getProperty("nextVideoId");
ext = properties.getProperty("ext"); ext = properties.getProperty("ext");
number = Integer.valueOf(properties.getProperty("number")); number = Integer.parseInt(properties.getProperty("number"));
return; return;
} }
List<File> files = Arrays.asList(mediaDirectory.listFiles()); List<File> files = Arrays.asList(mediaDirectory.listFiles());
@ -132,9 +128,6 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
String json = jsonFile.isPresent() ? Utils.readTextFromFile(jsonFile.get()) : ""; String json = jsonFile.isPresent() ? Utils.readTextFromFile(jsonFile.get()) : "";
JSONObject jsonObject = new JSONObject(json); JSONObject jsonObject = new JSONObject(json);
id = jsonObject.getString("id"); id = jsonObject.getString("id");
// if(!Main.argVideo.isBlank() && !id.equals(Main.argVideo)) {
// return;
// }
thumbnail = jsonObject.getString("thumbnail"); thumbnail = jsonObject.getString("thumbnail");
if (thumbnail == null) { if (thumbnail == null) {
@ -143,9 +136,7 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
JSONArray thumbnails = jsonObject.getJSONArray("thumbnails"); JSONArray thumbnails = jsonObject.getJSONArray("thumbnails");
for (int i = 0; i < thumbnails.length(); i++) { for (int i = 0; i < thumbnails.length(); i++) {
JSONObject o = (JSONObject) thumbnails.get(i); JSONObject o = (JSONObject) thumbnails.get(i);
if (!o.has("width")) { if (o.has("width")) {
continue;
} else {
int width = o.getInt("width"); int width = o.getInt("width");
if (width < (((double) Main.THUMBNAIL_WIDTH) * 0.8d)) { if (width < (((double) Main.THUMBNAIL_WIDTH) * 0.8d)) {
continue; continue;
@ -159,10 +150,6 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
File thumbnailFile = new File(mediaDirectory, "thumbnail." + getThumbnailFormat()); File thumbnailFile = new File(mediaDirectory, "thumbnail." + getThumbnailFormat());
File miniThumbnailFile = new File(mediaDirectory, "mini-thumbnail." + getMiniThumbnailFormat()); File miniThumbnailFile = new File(mediaDirectory, "mini-thumbnail." + getMiniThumbnailFormat());
// new File(mediaDirectory, "thumbnail.jpg").delete();
// new File(mediaDirectory, "mini-thumbnail.jpg").delete();
// new File(mediaDirectory, "thumbnail.webp").delete();
// new File(mediaDirectory, "mini-thumbnail.webp").delete();
if (thumbnail != null) { if (thumbnail != null) {
if (!thumbnailFile.exists()) { if (!thumbnailFile.exists()) {
try (BufferedInputStream in = new BufferedInputStream(new URL(thumbnail).openStream()); FileOutputStream fileOutputStream = new FileOutputStream(thumbnailFile.getAbsolutePath())) { try (BufferedInputStream in = new BufferedInputStream(new URL(thumbnail).openStream()); FileOutputStream fileOutputStream = new FileOutputStream(thumbnailFile.getAbsolutePath())) {
@ -200,7 +187,6 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
|| (f.getName().endsWith(".mp4")) || (f.getName().endsWith(".mp4"))
|| (f.getName().endsWith(".mkv")) || (f.getName().endsWith(".webm")) || (f.getName().endsWith(".mkv")) || (f.getName().endsWith(".webm"))
) )
.findFirst(); .findFirst();
snapshot = mediaDirectory.getParentFile().getName(); snapshot = mediaDirectory.getParentFile().getName();
@ -353,10 +339,10 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
continue; continue;
} }
YoutubeVideo youtubeVideo = new YoutubeVideo(mediaDirectory, argsInstance.getBoolean(ArgType.ALWAYS_GENERATE_METADATA).get(), argsInstance.getString(ArgType.VIDEO).orElse("")); YoutubeVideo youtubeVideo = new YoutubeVideo(mediaDirectory, argsInstance.getBoolean(ArgType.ALWAYS_GENERATE_METADATA).get(), argsInstance.getString(ArgType.VIDEO).orElse(""));
if (argsInstance.getString(ArgType.VIDEO).isPresent() && !argsInstance.getString(ArgType.VIDEO).equals(youtubeVideo.getId())) { if (argsInstance.getString(ArgType.VIDEO).isPresent() && !argsInstance.getString(ArgType.VIDEO).get().equals(youtubeVideo.getId())) {
continue; continue;
} }
if (argsInstance.getString(ArgType.CHANNEL).isPresent() && !argsInstance.getString(ArgType.CHANNEL).equals(youtubeVideo.getChannelId())) { if (argsInstance.getString(ArgType.CHANNEL).isPresent() && !argsInstance.getString(ArgType.CHANNEL).get().equals(youtubeVideo.getChannelId())) {
continue; continue;
} }

View File

@ -21,8 +21,6 @@ package com.openeggbert.utils.youtubedlfrontend;
import java.io.File; import java.io.File;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
@ -35,7 +33,7 @@ import lombok.Getter;
public class YoutubeVideoHtml { public class YoutubeVideoHtml {
@Getter @Getter
private String singleVideo; private final String singleVideo;
public YoutubeVideoHtml(YoutubeVideo youtubeVideo, File archiveBoxRootDirectory, File archiveBoxArchiveDirectory, long countOfVideosInChannel) { public YoutubeVideoHtml(YoutubeVideo youtubeVideo, File archiveBoxRootDirectory, File archiveBoxArchiveDirectory, long countOfVideosInChannel) {
@ -61,7 +59,7 @@ public class YoutubeVideoHtml {
""" """
); );
String finalUrl = "https://www.youtube.com/watch?v=" + youtubeVideo.getId(); String finalUrl = "https://www.youtube.com/watch?v=" + youtubeVideo.getId();
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("<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=\"").append(finalUrl).append("\"><br>\n<br>\n");
videoHtml.append("<a target=\"_blank\" href=\"").append(finalUrl).append("\">"); videoHtml.append("<a target=\"_blank\" href=\"").append(finalUrl).append("\">");
videoHtml.append(finalUrl).append("</a>").append("<br>\n"); videoHtml.append(finalUrl).append("</a>").append("<br>\n");
String videoLocalFileEncoded = null; String videoLocalFileEncoded = null;
@ -73,12 +71,10 @@ public class YoutubeVideoHtml {
throw new YoutubedlFrontendException(ex.getMessage()); throw new YoutubedlFrontendException(ex.getMessage());
} }
if (!youtubeVideo.getVideoFileName().endsWith(".mkv")) { if (!youtubeVideo.getVideoFileName().endsWith(".mkv")) {
//try {
videoHtml.append("<video src=\""); videoHtml.append("<video src=\"");
String videoFileName = youtubeVideo.getVideoFileName(); String videoFileName = youtubeVideo.getVideoFileName();
// if (!videoFileName.contains(""))
{ {
try { try {
videoFileName = URLEncoder.encode(youtubeVideo.getVideoFileName(), StandardCharsets.UTF_8.displayName()).replace("+", "%20").replace("#", "%23"); videoFileName = URLEncoder.encode(youtubeVideo.getVideoFileName(), StandardCharsets.UTF_8.displayName()).replace("+", "%20").replace("#", "%23");
@ -95,9 +91,7 @@ public class YoutubeVideoHtml {
Your browser does not support the video tag. Your browser does not support the video tag.
</video><br> </video><br>
"""); """);
// } catch (UnsupportedEncodingException ex) {
// throw new YoutubedlFrontendException(ex.getMessage());
// }
} else { } else {
videoHtml.append("<a target=\"_blank\" href=\"").append(videoLocalUrl).append("\">"); videoHtml.append("<a target=\"_blank\" href=\"").append(videoLocalUrl).append("\">");
@ -113,24 +107,21 @@ public class YoutubeVideoHtml {
boolean backEnabled = youtubeVideo.getNumber() > 1 && youtubeVideo.getPreviousVideoId() != null; boolean backEnabled = youtubeVideo.getNumber() > 1 && youtubeVideo.getPreviousVideoId() != null;
{ {
// videoHtml.append("<a href=\"./").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'\">"); 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"); videoHtml.append("Back");
//videoHtml.append("</a>");
videoHtml.append("</button>"); videoHtml.append("</button>");
} }
videoHtml.append("&nbsp;&nbsp;&nbsp;"); videoHtml.append("&nbsp;&nbsp;&nbsp;");
boolean nextEnabled = youtubeVideo.getNumber() < countOfVideosInChannel && youtubeVideo.getNextVideoId() != null; boolean nextEnabled = youtubeVideo.getNumber() < countOfVideosInChannel && youtubeVideo.getNextVideoId() != null;
{ {
//videoHtml.append("<a href=\"./").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("<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"); videoHtml.append("Next");
//videoHtml.append("</a>");
videoHtml.append("</button>"); videoHtml.append("</button>");
} }
@ -161,7 +152,7 @@ videoHtml.append("<button ").append(backEnabled ? "" : "disabled").append(" styl
videoHtml.append("\"><br>"); videoHtml.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<br>\n");
videoHtml.append("<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;\">"); videoHtml.append("<pre style=\"white-space: pre-wrap; border:1px solid black;max-width:600px;padding:10px;min-height:50px;\">");
@ -170,8 +161,6 @@ videoHtml.append("<button ").append(backEnabled ? "" : "disabled").append(" styl
videoHtml.append("<h2>Comments</h2>"); videoHtml.append("<h2>Comments</h2>");
youtubeVideo.getComments().forEach(co -> { youtubeVideo.getComments().forEach(co -> {
// private String id, parentId, text, author;
// private int timestamp;
videoHtml.append("<div style=\"margin-left:") videoHtml.append("<div style=\"margin-left:")
.append(co.dotCount() * 50) .append(co.dotCount() * 50)
.append("px;\">"); .append("px;\">");