Enabling video trim support

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

4
.gitignore vendored

@ -4,4 +4,6 @@ package-lock.json
test.js
.*
!/.gitignore
todo.txt
todo.txt
ffmpeg
ffmpeg.exe

@ -82,7 +82,7 @@
<br>
<input type="hidden" name="url" class="url" id="url">
<button class="submitBtn" id="videoDownload">Download</button>
<!-- <button id="advancedToggle" onClick ="advancedToggle()">Advanced</button> -->
<button id="advancedToggle" onClick ="advancedToggle()">Advanced</button>
</div>
<div id="audioList">
@ -92,7 +92,7 @@
<br>
<input type="hidden" name="url" class="url">
<button class="submitBtn" id="audioDownload">Download</button>
<!-- <button id="advancedToggle" onClick ="advancedToggle()">Advanced</button> -->
<button id="advancedToggle" onClick ="advancedToggle()">Advanced</button>
</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": {
"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",
"version": "3.0.2",
"version": "3.1.0",
"main": "main.js",
"scripts": {
"start": "electron .",
"watch": "nodemon --exec electron .",
"debug": "electron --inspect=5858 .",
"windows": "rm -rf ./node_modules && electron-builder -w",
"linux": "rm -rf ./node_modules && electron-builder -l",
"mac": "rm -rf ./node_modules && electron-builder -m",
"publish-linux": "rm -rf ./node_modules && electron-builder -l --publish=always",
"publish-windows": "rm -rf ./node_modules && electron-builder -w --publish=always"
"windows": "./windows.sh && electron-builder -w",
"linux": "./linux.sh && electron-builder -l",
"publish-linux": "./linux.sh && electron-builder -l --publish=always",
"publish-windows": "./windows.sh && electron-builder -w --publish=always"
},
"author": {
"name": "Andrew",

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

@ -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