mirror of
https://github.com/openeggbert/youtubedl-frontend.git
synced 2025-03-25 17:17:46 +01:00
Some fixes and improvements
This commit is contained in:
parent
43d4bcf927
commit
7318598d8d
@ -38,24 +38,26 @@ public class Main {
|
|||||||
|
|
||||||
private static int iii = 0;
|
private static int iii = 0;
|
||||||
private static int videoNumberPerRow = 0;
|
private static int videoNumberPerRow = 0;
|
||||||
public static final boolean ALWAYS_COMPUTE_METADATA = true;
|
public static final boolean ALWAYS_COMPUTE_METADATA = false;
|
||||||
public static final int VIDEOS_PER_ROW = 4;
|
public static final int VIDEOS_PER_ROW = 4;
|
||||||
private static int THUMBNAIL_WIDTH = 250;
|
private static int THUMBNAIL_WIDTH = 250;
|
||||||
|
public static String argVideo;
|
||||||
|
public static String argChannel;
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, InterruptedException {
|
public static void main(String[] args) throws IOException, InterruptedException {
|
||||||
System.out.println("archiveboxyoutubehelper - HTML generator\n");
|
System.out.println("archiveboxyoutubehelper - HTML generator\n");
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
args = new String[]{"/rv/blupi/archivebox"
|
args = new String[]{"/rv/blupi/archivebox"
|
||||||
//, "--video", "eVqgt6s4h30"
|
//, "--video", "gPU_onaTzXs"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
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);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
String argVideo = "";
|
argVideo = "";
|
||||||
String argChannel = "";
|
argChannel = "";
|
||||||
if(args.length > 1) {
|
if(args.length > 1) {
|
||||||
for(int i = 1;i<args.length;i++) {
|
for(int i = 1;i<args.length;i++) {
|
||||||
String s = args[i];
|
String s = args[i];
|
||||||
@ -88,7 +90,9 @@ public class Main {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
YoutubeVideo youtubeVideo = new YoutubeVideo(mediaDirectory);
|
YoutubeVideo youtubeVideo = new YoutubeVideo(mediaDirectory);
|
||||||
|
if(!Main.argVideo.isBlank() && !youtubeVideo.getId().equals(Main.argVideo)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if(!argVideo.isBlank() && !youtubeVideo.getId().equals(argVideo)) {
|
if(!argVideo.isBlank() && !youtubeVideo.getId().equals(argVideo)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -200,6 +204,9 @@ public class Main {
|
|||||||
videoNumberPerRow = 0;
|
videoNumberPerRow = 0;
|
||||||
}
|
}
|
||||||
File videoHtmlFile = new File(videosDirectory, z.getId() + ".html");
|
File videoHtmlFile = new File(videosDirectory, z.getId() + ".html");
|
||||||
|
// if(videoHtmlFile.exists()) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
{
|
{
|
||||||
StringBuilder sb2 = new StringBuilder("""
|
StringBuilder sb2 = new StringBuilder("""
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
@ -4,7 +4,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.nanoboot.archiveboxyoutubehelper;
|
package org.nanoboot.archiveboxyoutubehelper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,7 +16,9 @@ import org.json.JSONObject;
|
|||||||
* @author robertvokac
|
* @author robertvokac
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class YoutubeComment implements Comparable<YoutubeComment>{
|
@NoArgsConstructor
|
||||||
|
public class YoutubeComment implements Comparable<YoutubeComment> {
|
||||||
|
|
||||||
private String id, parentId, text, author;
|
private String id, parentId, text, author;
|
||||||
private long timestamp;
|
private long timestamp;
|
||||||
|
|
||||||
@ -23,18 +29,42 @@ public class YoutubeComment implements Comparable<YoutubeComment>{
|
|||||||
author = jsonObject.getString("author");
|
author = jsonObject.getString("author");
|
||||||
timestamp = jsonObject.getInt("timestamp");
|
timestamp = jsonObject.getInt("timestamp");
|
||||||
}
|
}
|
||||||
|
public static List<YoutubeComment> sort(List<YoutubeComment> list) {
|
||||||
|
|
||||||
|
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) {
|
||||||
|
final List<YoutubeComment> children = all.stream().filter(c -> c.getParentId().equals(parentId)).sorted().toList();
|
||||||
|
List<YoutubeComment> result = new ArrayList<>();
|
||||||
|
children.stream().forEach(c -> {
|
||||||
|
result.add(c);
|
||||||
|
result.addAll(getChildren(all, c.getId()));
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@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() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(char ch:getId().toCharArray()) {
|
for (char ch : getId().toCharArray()) {
|
||||||
if(ch == '.') {
|
if (ch == '.') {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,22 +4,26 @@
|
|||||||
*/
|
*/
|
||||||
package org.nanoboot.archiveboxyoutubehelper;
|
package org.nanoboot.archiveboxyoutubehelper;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.humble.video.Demuxer;
|
import io.humble.video.Demuxer;
|
||||||
import io.humble.video.DemuxerFormat;
|
import io.humble.video.DemuxerFormat;
|
||||||
import io.humble.video.Global;
|
import io.humble.video.Global;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Properties;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@ -29,6 +33,7 @@ import org.json.JSONObject;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class YoutubeVideo implements Comparable<YoutubeVideo> {
|
public class YoutubeVideo implements Comparable<YoutubeVideo> {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
@ -50,34 +55,66 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
|
|||||||
private String nextVideoId = null;
|
private String nextVideoId = null;
|
||||||
private String ext = null;
|
private String ext = null;
|
||||||
private int number;
|
private int number;
|
||||||
|
//
|
||||||
public static final List<String> missingYoutubeVideos = new ArrayList<>();
|
public static final List<String> missingYoutubeVideos = new ArrayList<>();
|
||||||
|
|
||||||
YoutubeVideo(File mediaDirectory) throws InterruptedException, IOException {
|
public YoutubeVideo(File mediaDirectory) throws InterruptedException, IOException {
|
||||||
File metadataFile = new File(mediaDirectory, "metadata");
|
File metadataFile = new File(mediaDirectory, "metadata");
|
||||||
if (!Main.ALWAYS_COMPUTE_METADATA && metadataFile.exists()) {
|
if (!Main.ALWAYS_COMPUTE_METADATA && metadataFile.exists()) {
|
||||||
|
|
||||||
YoutubeVideo yv = new ObjectMapper().readValue(Utils.readTextFromFile(metadataFile), YoutubeVideo.class);
|
YoutubeVideo yv = new YoutubeVideo();
|
||||||
|
//new ObjectMapper().readValue(Utils.readTextFromFile(metadataFile), YoutubeVideo.class);
|
||||||
|
|
||||||
id = yv.id;
|
Properties properties = new Properties();
|
||||||
snapshot = yv.snapshot;
|
properties.load(new FileInputStream(metadataFile));
|
||||||
title = yv.title;
|
|
||||||
videoFileName = yv.videoFileName;
|
id = properties.getProperty("id");
|
||||||
videoFileSizeInBytes = yv.videoFileSizeInBytes;
|
|
||||||
videoFileSha512HashSum = yv.videoFileSha512HashSum;
|
if (!Main.argVideo.isBlank() && !id.equals(Main.argVideo)) {
|
||||||
videoDuration = yv.videoDuration;
|
return;
|
||||||
channelName = yv.channelName;
|
}
|
||||||
channelUrl = yv.channelUrl;
|
snapshot = properties.getProperty("snapshot");
|
||||||
channelId = yv.channelId;
|
title = properties.getProperty("title");
|
||||||
uploadDate = yv.uploadDate;
|
videoFileName = properties.getProperty("videoFileName");
|
||||||
description = yv.description;
|
videoFileSizeInBytes = Long.valueOf(properties.getProperty("videoFileSizeInBytes"));
|
||||||
thumbnail = yv.thumbnail;
|
videoFileSha512HashSum = properties.getProperty("videoFileSha512HashSum");
|
||||||
comments = yv.comments;
|
videoDuration = properties.getProperty("videoDuration");
|
||||||
|
channelName = properties.getProperty("channelName");
|
||||||
|
channelUrl = properties.getProperty("channelUrl");
|
||||||
|
channelId = properties.getProperty("channelId");
|
||||||
|
uploadDate = properties.getProperty("uploadDate");
|
||||||
|
timestamp = Long.parseLong(properties.getProperty("timestamp"));
|
||||||
|
description = properties.getProperty("description");
|
||||||
|
thumbnail = properties.getProperty("thumbnail");
|
||||||
|
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);
|
||||||
|
comments.add(new ObjectMapper().readValue(toString, YoutubeComment.class));
|
||||||
|
} catch (JsonProcessingException ex) {
|
||||||
|
|
||||||
|
throw new ArchiveBoxYoutubeHelperException(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
previousVideoId = properties.getProperty("previousVideoId");
|
||||||
|
nextVideoId = properties.getProperty("nextVideoId");
|
||||||
|
ext = properties.getProperty("ext");
|
||||||
|
number = Integer.valueOf(properties.getProperty("number"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<File> files = Arrays.asList(mediaDirectory.listFiles());
|
List<File> files = Arrays.asList(mediaDirectory.listFiles());
|
||||||
Optional<File> jsonFile = files.stream().filter(f -> f.getName().endsWith(".json")).findFirst();
|
Optional<File> jsonFile = files.stream().filter(f -> f.getName().endsWith(".json")).findFirst();
|
||||||
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");
|
||||||
|
// if(!Main.argVideo.isBlank() && !id.equals(Main.argVideo)) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
thumbnail = jsonObject.getString("thumbnail");
|
thumbnail = jsonObject.getString("thumbnail");
|
||||||
if (thumbnail == null) {
|
if (thumbnail == null) {
|
||||||
thumbnail = "";
|
thumbnail = "";
|
||||||
@ -98,28 +135,29 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
|
|||||||
Optional<File> descriptionFile = files.stream().filter(f -> f.getName().endsWith(".description")).findFirst();
|
Optional<File> descriptionFile = files.stream().filter(f -> f.getName().endsWith(".description")).findFirst();
|
||||||
|
|
||||||
ext = jsonObject.getString("ext");
|
ext = jsonObject.getString("ext");
|
||||||
|
|
||||||
Optional<File> videoFile = files
|
Optional<File> videoFile = files
|
||||||
.stream()
|
.stream()
|
||||||
.filter(f ->
|
.filter(f
|
||||||
(f.getName().endsWith("." + ext)) ||
|
-> (f.getName().endsWith("." + ext))
|
||||||
(f.getName().endsWith(".mp4")) ||
|
|| (f.getName().endsWith(".mp4"))
|
||||||
(f.getName().endsWith(".mkv"))
|
|| (f.getName().endsWith(".mkv"))
|
||||||
)
|
)
|
||||||
// .filter(
|
// .filter(
|
||||||
// f -> !f.getName().endsWith(".description")
|
// f -> !f.getName().endsWith(".description")
|
||||||
// && !f.getName().endsWith(".json")
|
// && !f.getName().endsWith(".json")
|
||||||
// && !f.getName().equals("metadata")
|
// && !f.getName().equals("metadata")
|
||||||
// && !f.getName().endsWith(thumbnail)
|
// && !f.getName().endsWith(thumbnail)
|
||||||
// )
|
// )
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
snapshot = mediaDirectory.getParentFile().getName();
|
snapshot = mediaDirectory.getParentFile().getName();
|
||||||
id = jsonObject.getString("id");
|
|
||||||
if(videoFile.isEmpty())missingYoutubeVideos.add(id);
|
if (videoFile.isEmpty()) {
|
||||||
|
missingYoutubeVideos.add(id);
|
||||||
|
}
|
||||||
this.description = descriptionFile.isPresent() ? Utils.readTextFromFile(descriptionFile.get()) : "";
|
this.description = descriptionFile.isPresent() ? Utils.readTextFromFile(descriptionFile.get()) : "";
|
||||||
|
|
||||||
|
|
||||||
title = jsonObject.getString("title");
|
title = jsonObject.getString("title");
|
||||||
if (videoFile.isPresent() && !videoFile.get().getName().endsWith(".part")) {
|
if (videoFile.isPresent() && !videoFile.get().getName().endsWith(".part")) {
|
||||||
final File videoFileGet = videoFile.get();
|
final File videoFileGet = videoFile.get();
|
||||||
@ -133,7 +171,6 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
|
|||||||
channelId = jsonObject.getString("channel_id");
|
channelId = jsonObject.getString("channel_id");
|
||||||
uploadDate = jsonObject.getString("upload_date");
|
uploadDate = jsonObject.getString("upload_date");
|
||||||
timestamp = jsonObject.getLong("timestamp");
|
timestamp = jsonObject.getLong("timestamp");
|
||||||
|
|
||||||
|
|
||||||
if (jsonObject.has("comments")) {
|
if (jsonObject.has("comments")) {
|
||||||
final JSONArray jsonArray = jsonObject.getJSONArray("comments");
|
final JSONArray jsonArray = jsonObject.getJSONArray("comments");
|
||||||
@ -143,22 +180,44 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
|
|||||||
comments.add(new YoutubeComment((JSONObject) o));
|
comments.add(new YoutubeComment((JSONObject) o));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(this.comments);
|
this.comments = YoutubeComment.sort(this.comments);
|
||||||
Utils.writeTextToFile(new JSONObject(this).toString(), metadataFile);
|
//
|
||||||
|
Properties properties = new Properties();
|
||||||
|
|
||||||
|
properties.put("id", id);
|
||||||
|
properties.put("snapshot", snapshot);
|
||||||
|
properties.put("title", title);
|
||||||
|
properties.put("videoFileName", videoFileName);
|
||||||
|
properties.put("videoFileSizeInBytes", String.valueOf(videoFileSizeInBytes));
|
||||||
|
properties.put("videoFileSha512HashSum", videoFileSha512HashSum);
|
||||||
|
properties.put("videoDuration", videoDuration);
|
||||||
|
properties.put("channelName", channelName);
|
||||||
|
properties.put("channelUrl", channelUrl);
|
||||||
|
properties.put("channelId", channelId);
|
||||||
|
properties.put("uploadDate", uploadDate);
|
||||||
|
properties.put("timestamp", String.valueOf(timestamp));
|
||||||
|
properties.put("description", description);
|
||||||
|
properties.put("thumbnail", thumbnail);
|
||||||
|
properties.put("comments", new JSONArray(comments).toString());
|
||||||
|
if (previousVideoId != null) {
|
||||||
|
properties.put("previousVideoId", previousVideoId);
|
||||||
|
}
|
||||||
|
if (nextVideoId != null) {
|
||||||
|
properties.put("nextVideoId", nextVideoId);
|
||||||
|
}
|
||||||
|
properties.put("ext", ext);
|
||||||
|
properties.put("number", String.valueOf(number));
|
||||||
|
|
||||||
|
//Utils.writeTextToFile(new JSONObject(this).toString(), metadataFile);
|
||||||
|
properties.store(new FileWriter(metadataFile), "store to properties file");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getVideoFormattedDuration(String arg) throws InterruptedException, IOException {
|
private static String getVideoFormattedDuration(String arg) throws InterruptedException, IOException {
|
||||||
// In Humble, all objects have special contructors named 'make'.
|
|
||||||
|
|
||||||
// A Demuxer opens up media containers, parses and de-multiplexes the streams
|
|
||||||
// of media data without those containers.
|
|
||||||
final Demuxer demuxer = Demuxer.make();
|
final Demuxer demuxer = Demuxer.make();
|
||||||
|
|
||||||
// We open the demuxer by pointing it at a URL.
|
|
||||||
demuxer.open(arg, null, false, true, null, null);
|
demuxer.open(arg, null, false, true, null, null);
|
||||||
|
|
||||||
// Once we've opened a demuxer, Humble can make a guess about the
|
|
||||||
// DemuxerFormat. Humble supports over 100+ media container formats.
|
|
||||||
final DemuxerFormat format = demuxer.getFormat();
|
final DemuxerFormat format = demuxer.getFormat();
|
||||||
|
|
||||||
final long duration = demuxer.getDuration();
|
final long duration = demuxer.getDuration();
|
||||||
@ -189,10 +248,10 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
|
|||||||
@Override
|
@Override
|
||||||
public int compareTo(YoutubeVideo o) {
|
public int compareTo(YoutubeVideo o) {
|
||||||
if (this.channelName != null && o.channelName != null && this.channelName.contentEquals(o.channelName)) {
|
if (this.channelName != null && o.channelName != null && this.channelName.contentEquals(o.channelName)) {
|
||||||
if(this.uploadDate.equals(o.uploadDate)) {
|
if (this.uploadDate.equals(o.uploadDate)) {
|
||||||
return Long.valueOf(timestamp).compareTo(o.timestamp);
|
return Long.valueOf(timestamp).compareTo(o.timestamp);
|
||||||
} else {
|
} else {
|
||||||
return this.uploadDate.compareTo(o.uploadDate);
|
return this.uploadDate.compareTo(o.uploadDate);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.channelName != null && o.channelName != null) {
|
if (this.channelName != null && o.channelName != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user