mirror of
https://github.com/openeggbert/youtubedl-frontend.git
synced 2025-03-25 17:17:46 +01:00
Small improvements II
This commit is contained in:
parent
56d14fc21c
commit
43d4bcf927
@ -46,12 +46,36 @@ public class Main {
|
|||||||
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"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (args.length != 1) {
|
if (args.length < 1) {
|
||||||
System.err.println("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 = "";
|
||||||
|
String argChannel = "";
|
||||||
|
if(args.length > 1) {
|
||||||
|
for(int i = 1;i<args.length;i++) {
|
||||||
|
String s = args[i];
|
||||||
|
if(s.equals("--video")) {
|
||||||
|
i++;
|
||||||
|
if(i >= args.length) {
|
||||||
|
throw new ArchiveBoxYoutubeHelperException("Fatal error: missing value for --video");
|
||||||
|
}
|
||||||
|
argVideo = args[i];
|
||||||
|
}
|
||||||
|
if(s.equals("--channel")) {
|
||||||
|
i++;
|
||||||
|
if(i >= args.length) {
|
||||||
|
throw new ArchiveBoxYoutubeHelperException("Fatal error: missing value for --channel");
|
||||||
|
}
|
||||||
|
argChannel = args[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
File archiveBoxRootDirectory = new File(args[0]);
|
File archiveBoxRootDirectory = new File(args[0]);
|
||||||
File archiveBoxArchiveDirectory = new File(archiveBoxRootDirectory, "archive");
|
File archiveBoxArchiveDirectory = new File(archiveBoxRootDirectory, "archive");
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -64,6 +88,13 @@ public class Main {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
YoutubeVideo youtubeVideo = new YoutubeVideo(mediaDirectory);
|
YoutubeVideo youtubeVideo = new YoutubeVideo(mediaDirectory);
|
||||||
|
|
||||||
|
if(!argVideo.isBlank() && !youtubeVideo.getId().equals(argVideo)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(!argChannel.isBlank() && !youtubeVideo.getChannelId().equals(argChannel)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
System.out.println("\n\nFound video #" + i);
|
System.out.println("\n\nFound video #" + i);
|
||||||
|
|
||||||
@ -83,6 +114,18 @@ public class Main {
|
|||||||
youtubeVideos.add(youtubeVideo);
|
youtubeVideos.add(youtubeVideo);
|
||||||
}
|
}
|
||||||
Collections.sort(youtubeVideos);
|
Collections.sort(youtubeVideos);
|
||||||
|
YoutubeVideo previousVideo = null;
|
||||||
|
YoutubeVideo nextVideo = null;
|
||||||
|
YoutubeVideo currentVideo = null;
|
||||||
|
for(int j = 0; j<youtubeVideos.size(); j++) {
|
||||||
|
previousVideo = currentVideo;
|
||||||
|
currentVideo = youtubeVideos.get(j);
|
||||||
|
if(j < (youtubeVideos.size() - 1)) {
|
||||||
|
nextVideo = youtubeVideos.get(j+1);
|
||||||
|
}
|
||||||
|
if(previousVideo != null) currentVideo.setPreviousVideoId(previousVideo.getId());
|
||||||
|
if(nextVideo != null) currentVideo.setNextVideoId(nextVideo.getId());
|
||||||
|
}
|
||||||
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(c -> {
|
||||||
@ -150,6 +193,7 @@ public class Main {
|
|||||||
.append(" •︎ ")
|
.append(" •︎ ")
|
||||||
.append("#").append(iii)
|
.append("#").append(iii)
|
||||||
.append("</td></tr>\n");
|
.append("</td></tr>\n");
|
||||||
|
z.setNumber(iii);
|
||||||
sb.append("</table></div></td>\n");
|
sb.append("</table></div></td>\n");
|
||||||
if (videoNumberPerRow == VIDEOS_PER_ROW) {
|
if (videoNumberPerRow == VIDEOS_PER_ROW) {
|
||||||
sb.append("<tr>");
|
sb.append("<tr>");
|
||||||
@ -195,6 +239,16 @@ public class Main {
|
|||||||
.append("/media/thumbnail.jpg\"></a><br>");
|
.append("/media/thumbnail.jpg\"></a><br>");
|
||||||
sb2.append("<span style=\"font-size:160%;font-weight:bold;\">").append(z.getTitle()).append("</span>");
|
sb2.append("<span style=\"font-size:160%;font-weight:bold;\">").append(z.getTitle()).append("</span>");
|
||||||
sb2.append("<br><br>");
|
sb2.append("<br><br>");
|
||||||
|
sb2.append("#").append(z.getNumber()).append(" ");
|
||||||
|
if(z.getPreviousVideoId() != null) sb2.append("<a href=\"./").append(z.getPreviousVideoId()).append(".html\">");
|
||||||
|
sb2.append("Back");
|
||||||
|
if(z.getPreviousVideoId() != null) sb2.append("</a>");
|
||||||
|
sb2.append(" ");
|
||||||
|
if(z.getNextVideoId()!= null) sb2.append("<a href=\"./").append(z.getNextVideoId()).append(".html\">");
|
||||||
|
sb2.append("Next");
|
||||||
|
if(z.getNextVideoId() != null) sb2.append("</a>");
|
||||||
|
sb2.append(" ");
|
||||||
|
sb2.append("<br>");
|
||||||
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());
|
||||||
sb2.append("</pre>");
|
sb2.append("</pre>");
|
||||||
@ -253,6 +307,8 @@ sb2.append("<div style=\"margin-left:")
|
|||||||
""");
|
""");
|
||||||
Utils.writeTextToFile(sb.toString(), videosHtmlFile);
|
Utils.writeTextToFile(sb.toString(), videosHtmlFile);
|
||||||
|
|
||||||
|
System.out.println("[Warning] Snapshots without videos:");
|
||||||
|
YoutubeVideo.missingYoutubeVideos.forEach(s -> System.out.println(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,16 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
|
|||||||
private String channelUrl;
|
private String channelUrl;
|
||||||
private String channelId;
|
private String channelId;
|
||||||
private String uploadDate;
|
private String uploadDate;
|
||||||
|
private long timestamp;
|
||||||
private String description;
|
private String description;
|
||||||
private String thumbnail;
|
private String thumbnail;
|
||||||
private List<YoutubeComment> comments = new ArrayList<>();
|
private List<YoutubeComment> comments = new ArrayList<>();
|
||||||
|
private String previousVideoId = null;
|
||||||
|
private String nextVideoId = null;
|
||||||
|
private String ext = null;
|
||||||
|
private int number;
|
||||||
|
public static final List<String> missingYoutubeVideos = new ArrayList<>();
|
||||||
|
|
||||||
YoutubeVideo(File mediaDirectory) throws InterruptedException, IOException {
|
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()) {
|
||||||
@ -91,19 +97,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");
|
||||||
|
|
||||||
Optional<File> videoFile = files
|
Optional<File> videoFile = files
|
||||||
.stream()
|
.stream()
|
||||||
.filter(
|
.filter(f ->
|
||||||
f -> !f.getName().endsWith(".description")
|
(f.getName().endsWith("." + ext)) ||
|
||||||
&& !f.getName().endsWith(".json")
|
(f.getName().endsWith(".mp4")) ||
|
||||||
&& !f.getName().equals("metadata")
|
(f.getName().endsWith(".mkv"))
|
||||||
&& !f.getName().endsWith(thumbnail)
|
|
||||||
)
|
)
|
||||||
|
// .filter(
|
||||||
|
// f -> !f.getName().endsWith(".description")
|
||||||
|
// && !f.getName().endsWith(".json")
|
||||||
|
// && !f.getName().equals("metadata")
|
||||||
|
// && !f.getName().endsWith(thumbnail)
|
||||||
|
// )
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
|
snapshot = mediaDirectory.getParentFile().getName();
|
||||||
|
id = jsonObject.getString("id");
|
||||||
|
if(videoFile.isEmpty())missingYoutubeVideos.add(id);
|
||||||
this.description = descriptionFile.isPresent() ? Utils.readTextFromFile(descriptionFile.get()) : "";
|
this.description = descriptionFile.isPresent() ? Utils.readTextFromFile(descriptionFile.get()) : "";
|
||||||
|
|
||||||
id = jsonObject.getString("id");
|
|
||||||
snapshot = mediaDirectory.getParentFile().getName();
|
|
||||||
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();
|
||||||
@ -116,6 +132,8 @@ public class YoutubeVideo implements Comparable<YoutubeVideo> {
|
|||||||
channelUrl = jsonObject.getString("channel_url");
|
channelUrl = jsonObject.getString("channel_url");
|
||||||
channelId = jsonObject.getString("channel_id");
|
channelId = jsonObject.getString("channel_id");
|
||||||
uploadDate = jsonObject.getString("upload_date");
|
uploadDate = jsonObject.getString("upload_date");
|
||||||
|
timestamp = jsonObject.getLong("timestamp");
|
||||||
|
|
||||||
|
|
||||||
if (jsonObject.has("comments")) {
|
if (jsonObject.has("comments")) {
|
||||||
final JSONArray jsonArray = jsonObject.getJSONArray("comments");
|
final JSONArray jsonArray = jsonObject.getJSONArray("comments");
|
||||||
@ -171,7 +189,11 @@ 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)) {
|
||||||
|
return Long.valueOf(timestamp).compareTo(o.timestamp);
|
||||||
|
} 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) {
|
||||||
return this.channelName.compareTo(o.channelName);
|
return this.channelName.compareTo(o.channelName);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user