1
0
mirror of https://github.com/openeggbert/youtubedl-frontend.git synced 2025-03-14 21:23:27 +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_LINKS_TO_YOUTUBE("thumbnail-links-to-youtube", "false");
@Getter
private String name;
private final String name;
@Getter
private String defaultValue;
private final String defaultValue;
ArgType(String name, String defaultValue) {
this.name = name;

View File

@ -64,12 +64,12 @@ public class Main {
List<YoutubeVideo> youtubeVideos = YoutubeVideo.loadYoutubeVideos(archiveBoxArchiveDirectory, argsInstance);
Map<String, String> channelUrls = new HashMap<>();
List<String> channels = new ArrayList<>();
youtubeVideos.stream().forEach(c -> {
final String channelName_ = c.getChannelName();
youtubeVideos.stream().forEach(v -> {
final String channelName = v.getChannelName();
if (channelName_ != null && !channelUrls.containsKey(c.getChannelName())) {
channelUrls.put(channelName_, c.getChannelUrl());
channels.add(channelName_);
if (channelName != null && !channelUrls.containsKey(v.getChannelName())) {
channelUrls.put(channelName, v.getChannelUrl());
channels.add(channelName);
}
});
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:");
YoutubeVideo.missingYoutubeVideos.forEach(s -> System.out.println(s));
System.out.println("Total duration: " + ((int)((((double)YoutubeVideo.totalDurationInMilliseconds) / 1000d / 60d / 60d))) + " hours");
youtubeVideos.sort(new Comparator<YoutubeVideo>() {
@Override
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());});
youtubeVideos.stream().sorted((YoutubeVideo o1, YoutubeVideo o2) -> Long.valueOf(o1.getVideoDurationInMilliseconds()).compareTo(o2.getVideoDurationInMilliseconds()))
.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");
youtubeVideos.sort(new Comparator<YoutubeVideo>() {
@Override
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());});
youtubeVideos.stream().sorted((YoutubeVideo o1, YoutubeVideo o2) -> Long.valueOf(o1.getVideoFileSizeInBytes()).compareTo(o2.getVideoFileSizeInBytes()))
.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) {

View File

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

View File

@ -81,9 +81,6 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
File metadataFile = new File(mediaDirectory, "metadata");
if (!argAlwaysGenerateMetadata && metadataFile.exists()) {
YoutubeVideo yv = new YoutubeVideo();
//new ObjectMapper().readValue(Utils.readTextFromFile(metadataFile), YoutubeVideo.class);
Properties properties = new Properties();
var input = new FileInputStream(metadataFile);
properties.load(new InputStreamReader(input, Charset.forName("UTF-8")));
@ -96,7 +93,7 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
snapshot = properties.getProperty("snapshot");
title = properties.getProperty("title");
videoFileName = properties.getProperty("videoFileName");
videoFileSizeInBytes = Long.valueOf(properties.getProperty("videoFileSizeInBytes"));
videoFileSizeInBytes = Long.parseLong(properties.getProperty("videoFileSizeInBytes"));
videoFileSha512HashSum = properties.getProperty("videoFileSha512HashSum");
videoDuration = properties.getProperty("videoDuration");
channelName = properties.getProperty("channelName");
@ -110,7 +107,6 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
comments = new ArrayList<>();
JSONArray ja = new JSONArray(properties.getProperty("comments"));
ja.forEach(o -> {
JSONObject jo = (JSONObject) o;
try {
final String toString = o.toString();
System.out.println(toString);
@ -124,7 +120,7 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
previousVideoId = properties.getProperty("previousVideoId");
nextVideoId = properties.getProperty("nextVideoId");
ext = properties.getProperty("ext");
number = Integer.valueOf(properties.getProperty("number"));
number = Integer.parseInt(properties.getProperty("number"));
return;
}
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()) : "";
JSONObject jsonObject = new JSONObject(json);
id = jsonObject.getString("id");
// if(!Main.argVideo.isBlank() && !id.equals(Main.argVideo)) {
// return;
// }
thumbnail = jsonObject.getString("thumbnail");
if (thumbnail == null) {
@ -143,9 +136,7 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
JSONArray thumbnails = jsonObject.getJSONArray("thumbnails");
for (int i = 0; i < thumbnails.length(); i++) {
JSONObject o = (JSONObject) thumbnails.get(i);
if (!o.has("width")) {
continue;
} else {
if (o.has("width")) {
int width = o.getInt("width");
if (width < (((double) Main.THUMBNAIL_WIDTH) * 0.8d)) {
continue;
@ -159,10 +150,6 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
File thumbnailFile = new File(mediaDirectory, "thumbnail." + getThumbnailFormat());
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 (!thumbnailFile.exists()) {
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(".mkv")) || (f.getName().endsWith(".webm"))
)
.findFirst();
snapshot = mediaDirectory.getParentFile().getName();
@ -353,10 +339,10 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
continue;
}
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;
}
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;
}

View File

@ -21,8 +21,6 @@ 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 +33,7 @@ import lombok.Getter;
public class YoutubeVideoHtml {
@Getter
private String singleVideo;
private final String singleVideo;
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();
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(finalUrl).append("</a>").append("<br>\n");
String videoLocalFileEncoded = null;
@ -73,12 +71,10 @@ public class YoutubeVideoHtml {
throw new YoutubedlFrontendException(ex.getMessage());
}
if (!youtubeVideo.getVideoFileName().endsWith(".mkv")) {
//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");
@ -95,9 +91,7 @@ public class YoutubeVideoHtml {
Your browser does not support the video tag.
</video><br>
""");
// } catch (UnsupportedEncodingException ex) {
// throw new YoutubedlFrontendException(ex.getMessage());
// }
} else {
videoHtml.append("<a target=\"_blank\" href=\"").append(videoLocalUrl).append("\">");
@ -113,24 +107,21 @@ public class YoutubeVideoHtml {
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'\">");
//<button class="link" onclick="alert(1)">Click</button>
videoHtml.append("Back");
//videoHtml.append("</a>");
videoHtml.append("</button>");
}
videoHtml.append("&nbsp;&nbsp;&nbsp;");
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("Next");
//videoHtml.append("</a>");
videoHtml.append("</button>");
}
@ -161,7 +152,7 @@ videoHtml.append("<button ").append(backEnabled ? "" : "disabled").append(" styl
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");
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>");
youtubeVideo.getComments().forEach(co -> {
// private String id, parentId, text, author;
// private int timestamp;
videoHtml.append("<div style=\"margin-left:")
.append(co.dotCount() * 50)
.append("px;\">");