mirror of
https://github.com/jely2002/youtube-dl-gui.git
synced 2021-11-01 22:46:21 +03:00
feat: get the video filename from the youtube-dl log (#126)
This commit is contained in:
@@ -351,32 +351,37 @@ class QueryManager {
|
||||
|
||||
async openVideo(args) {
|
||||
let video = this.getVideo(args.identifier);
|
||||
let file = video.filename;
|
||||
let fallback = false;
|
||||
if(video.type === "playlist") {
|
||||
shell.openPath(video.downloadedPath);
|
||||
return;
|
||||
}
|
||||
fs.readdir(video.downloadedPath, (err, files) => {
|
||||
for(const file of files) {
|
||||
if(file.substr(0, file.lastIndexOf(".")) === video.getFilename()) {
|
||||
if(args.type === "folder") {
|
||||
shell.showItemInFolder(path.join(video.downloadedPath, file));
|
||||
} else if(args.type === "item") {
|
||||
shell.openPath(path.join(video.downloadedPath, file));
|
||||
} else {
|
||||
console.error("Wrong openVideo type specified.")
|
||||
if(file == null) {
|
||||
fs.readdir(video.downloadedPath, (err, files) => {
|
||||
for (const searchFile of files) {
|
||||
if (file.substr(0, file.lastIndexOf(".")) === video.getFilename()) {
|
||||
file = searchFile;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
//Fallback
|
||||
if(args.type === "folder") {
|
||||
if(file == null) {
|
||||
fallback = true;
|
||||
file = video.getFilename() + ".mp4";
|
||||
}
|
||||
});
|
||||
}
|
||||
if(args.type === "folder") {
|
||||
if(fallback) {
|
||||
shell.openPath(video.downloadedPath);
|
||||
} else if(args.type === "item") {
|
||||
shell.openPath(path.join(video.downloadedPath, video.getFilename()) + ".mp4");
|
||||
} else {
|
||||
console.error("Wrong openVideo type specified.")
|
||||
shell.showItemInFolder(path.join(video.downloadedPath, file));
|
||||
}
|
||||
});
|
||||
} else if(args.type === "item") {
|
||||
shell.openPath(path.join(video.downloadedPath, file));
|
||||
} else {
|
||||
console.error("Wrong openVideo type specified.")
|
||||
}
|
||||
}
|
||||
|
||||
getUnifiedAvailableSubtitles(videos) {
|
||||
|
||||
@@ -89,6 +89,7 @@ class DownloadQuery extends Query {
|
||||
let result = null;
|
||||
try {
|
||||
result = await this.environment.downloadLimiter.schedule(() => this.start(this.url, args, (liveData) => {
|
||||
this.video.setFilename(liveData);
|
||||
if (!liveData.includes("[download]")) return;
|
||||
if (!initialReset) {
|
||||
initialReset = true;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const Utils = require("../Utils");
|
||||
const path = require("path");
|
||||
|
||||
class Video {
|
||||
constructor(url, type, environment) {
|
||||
@@ -17,9 +18,24 @@ class Video {
|
||||
this.hasMetadata = false;
|
||||
this.downloaded = false;
|
||||
this.error = false;
|
||||
this.filename = null;
|
||||
this.identifier = Utils.getRandomID(32);
|
||||
}
|
||||
|
||||
setFilename(liveData) {
|
||||
console.log(liveData)
|
||||
if(liveData.includes("[download] Destination: ")) {
|
||||
this.filename = path.basename(liveData.replace("[download] Destination: ", ""));
|
||||
} else if(liveData.includes("[ffmpeg] Merging formats into \"")) {
|
||||
const noPrefix = liveData.replace("[ffmpeg] Merging formats into \"", "");
|
||||
this.filename = path.basename(noPrefix.trim().slice(0, -1));
|
||||
} else if(liveData.includes("[ffmpeg] Adding metadata to '")) {
|
||||
const noPrefix = liveData.replace("[ffmpeg] Adding metadata to '", "");
|
||||
this.filename = path.basename(noPrefix.trim().slice(0, -1));
|
||||
}
|
||||
console.log(this.filename)
|
||||
}
|
||||
|
||||
getFilename() {
|
||||
if(this.hasMetadata) {
|
||||
let sanitizeRegex = /(?:[/<>:"|\\?*]|[\s.]$)/g;
|
||||
|
||||
Reference in New Issue
Block a user