Enabling video trim support

pull/9/head
aandrew-me 3 years ago
parent 4e91c55aac
commit 850c020d2d

2
.gitignore vendored

@ -5,3 +5,5 @@ test.js
.* .*
!/.gitignore !/.gitignore
todo.txt todo.txt
ffmpeg
ffmpeg.exe

@ -82,7 +82,7 @@
<br> <br>
<input type="hidden" name="url" class="url" id="url"> <input type="hidden" name="url" class="url" id="url">
<button class="submitBtn" id="videoDownload">Download</button> <button class="submitBtn" id="videoDownload">Download</button>
<!-- <button id="advancedToggle" onClick ="advancedToggle()">Advanced</button> --> <button id="advancedToggle" onClick ="advancedToggle()">Advanced</button>
</div> </div>
<div id="audioList"> <div id="audioList">
@ -92,7 +92,7 @@
<br> <br>
<input type="hidden" name="url" class="url"> <input type="hidden" name="url" class="url">
<button class="submitBtn" id="audioDownload">Download</button> <button class="submitBtn" id="audioDownload">Download</button>
<!-- <button id="advancedToggle" onClick ="advancedToggle()">Advanced</button> --> <button id="advancedToggle" onClick ="advancedToggle()">Advanced</button>
</div> </div>

@ -0,0 +1,10 @@
#!/bin/bash
# Script to download the latest x64 linux version of custom ffmpeg build for yt-dlp
# The binary will be placed in the root dir of the app
wget "https://github.com/yt-dlp/FFmpeg-Builds/releases/latest/download/ffmpeg-n5.1-latest-linux64-gpl-5.1.tar.xz"
tar xvf ffmpeg-n5.1-latest-linux64-gpl-5.1.tar.xz
cp ffmpeg-n5.1-latest-linux64-gpl-5.1/bin/ffmpeg ffmpeg
chmod 777 ffmpeg
rm -rf ffmpeg-n5.1-latest-linux64-gpl-5.1
rm ffmpeg-n5.1-latest-linux64-gpl-5.1.tar.xz

@ -1,21 +1,20 @@
{ {
"dependencies": { "dependencies": {
"electron-updater": "^5.2.1", "electron-updater": "^5.2.1",
"ffmpeg-static": "^5.1.0", "yt-dlp-wrap": "^2.3.11",
"yt-dlp-wrap": "^2.3.11" "yt-dlp-wrap-extended": "^2.3.12"
}, },
"name": "ytdownloader", "name": "ytdownloader",
"version": "3.0.2", "version": "3.1.0",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"start": "electron .", "start": "electron .",
"watch": "nodemon --exec electron .", "watch": "nodemon --exec electron .",
"debug": "electron --inspect=5858 .", "debug": "electron --inspect=5858 .",
"windows": "rm -rf ./node_modules && electron-builder -w", "windows": "./windows.sh && electron-builder -w",
"linux": "rm -rf ./node_modules && electron-builder -l", "linux": "./linux.sh && electron-builder -l",
"mac": "rm -rf ./node_modules && electron-builder -m", "publish-linux": "./linux.sh && electron-builder -l --publish=always",
"publish-linux": "rm -rf ./node_modules && electron-builder -l --publish=always", "publish-windows": "./windows.sh && electron-builder -w --publish=always"
"publish-windows": "rm -rf ./node_modules && electron-builder -w --publish=always"
}, },
"author": { "author": {
"name": "Andrew", "name": "Andrew",

@ -1,10 +1,10 @@
const fs = require("fs"); const fs = require("fs");
const cp = require("child_process"); const cp = require("child_process");
const os = require("os"); const os = require("os");
const ffmpeg = require("ffmpeg-static"); const ffmpeg = __dirname + "/../ffmpeg"
const path = require("path"); const path = require("path");
const { shell, ipcRenderer, clipboard } = require("electron"); const { shell, ipcRenderer, clipboard } = require("electron");
const { default: YTDlpWrap } = require("yt-dlp-wrap"); const { default: YTDlpWrap } = require("yt-dlp-wrap-extended");
// Directories // Directories
const homedir = os.homedir(); const homedir = os.homedir();
@ -357,46 +357,46 @@ getId("audioDownload").addEventListener("click", (event) => {
// Time formatting // Time formatting
// function timeFormat(duration) { function timeFormat(duration) {
// // Hours, minutes and seconds // Hours, minutes and seconds
// var hrs = ~~(duration / 3600); var hrs = ~~(duration / 3600);
// var mins = ~~((duration % 3600) / 60); var mins = ~~((duration % 3600) / 60);
// var secs = ~~duration % 60; var secs = ~~duration % 60;
// // Ouput like "1:01" or "4:03:59" or "123:03:59" // Ouput like "1:01" or "4:03:59" or "123:03:59"
// var ret = ""; var ret = "";
// if (hrs > 0) { if (hrs > 0) {
// ret += "" + hrs + ":" + (mins < 10 ? "0" : ""); ret += "" + hrs + ":" + (mins < 10 ? "0" : "");
// } }
// ret += "" + mins + ":" + (secs < 10 ? "0" : ""); ret += "" + mins + ":" + (secs < 10 ? "0" : "");
// ret += "" + secs; ret += "" + secs;
// return ret; return ret;
// } }
// Manage advanced options, needs to be called // Manage advanced options, needs to be called
// function manageAdvanced(duration) { function manageAdvanced(duration) {
// let startTime = getId("startTime").value; let startTime = getId("startTime").value;
// let endTime = getId("endTime").value; let endTime = getId("endTime").value;
// if (startTime && !endTime) {
// rangeCmd = `*${startTime}-${timeFormat(duration)}`;
// } else if (!startTime && endTime) {
// rangeCmd = `*0-${endTime}`;
// } else if (startTime && endTime) {
// rangeCmd = `*${startTime}-${endTime}`;
// } else {
// rangeOption = "";
// }
// console.log("Range option: " + rangeOption); if (startTime && !endTime) {
// console.log("rangeCmd:" + rangeCmd); rangeCmd = `*${startTime}-${timeFormat(duration)}`;
// } } else if (!startTime && endTime) {
rangeCmd = `*0-${endTime}`;
} else if (startTime && endTime) {
rangeCmd = `*${startTime}-${endTime}`;
} else {
rangeOption = "";
}
console.log("Range option: " + rangeOption);
console.log("rangeCmd:" + rangeCmd);
}
////////////////////////////// //////////////////////////////
// Downloading with yt-dlp // Downloading with yt-dlp
////////////////////////////// //////////////////////////////
function download(type) { function download(type) {
// manageAdvanced(duration); manageAdvanced(duration);
const url = getId("url").value; const url = getId("url").value;
let ext; let ext;
@ -495,8 +495,8 @@ function download(type) {
downloadProcess = ytdlp.exec( downloadProcess = ytdlp.exec(
[ [
url, url,
// rangeOption, rangeOption,
// rangeCmd, rangeCmd,
"-f", "-f",
`${format_id}+${audioFormat}`, `${format_id}+${audioFormat}`,
"-o", "-o",
@ -513,8 +513,8 @@ function download(type) {
downloadProcess = ytdlp.exec( downloadProcess = ytdlp.exec(
[ [
url, url,
// rangeOption, rangeOption,
// rangeCmd, rangeCmd,
"-f", "-f",
format_id, format_id,
"-o", "-o",
@ -533,6 +533,7 @@ function download(type) {
controller.abort(); controller.abort();
}); });
downloadProcess downloadProcess
.on("progress", (progress) => { .on("progress", (progress) => {
getId(randomId + "prog").textContent = `Progress: ${ getId(randomId + "prog").textContent = `Progress: ${
@ -601,9 +602,15 @@ function afterSave(location, filename, progressId) {
body: "File saved successfully.", body: "File saved successfully.",
icon: "../assets/images/icon.png", icon: "../assets/images/icon.png",
}); });
let finalLocation = location
let finalFilename = filename
if (os.platform() === "win32"){
finalLocation = location.split(path.sep).join("\\\\")
finalFilename = filename.split(path.sep).join("\\\\")
}
getId( getId(
progressId progressId
).innerHTML = `<b onClick="showItem('${location}', '${filename}')">File saved. Click to Open</b>`; ).innerHTML = `<b onClick="showItem('${finalLocation}', '${finalFilename}')">File saved. Click to Open</b>`;
} }
function showItem(location, filename) { function showItem(location, filename) {

@ -0,0 +1,11 @@
#!/bin/bash
# Script to download the latest x64 windows version of custom ffmpeg build for yt-dlp
# The binary will be placed in the root dir of the app
wget "https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-n5.1-latest-win64-gpl-5.1.zip"
tar xvf ffmpeg-n5.1-latest-linux64-gpl-5.1.tar.xz
cp ffmpeg-n5.1-latest-linux64-gpl-5.1/bin/ffmpeg ffmpeg.exe
chmod 777 ffmpeg.exe
rm -rf ffmpeg-n5.1-latest-linux64-gpl-5.1
rm ffmpeg-n5.1-latest-linux64-gpl-5.1.tar.xz
Loading…
Cancel
Save