Unable to add start and end time to my YouTube downloader app Project using ytdl library

88 Views Asked by At

I am working on creating an application that can be used to download videos on YouTube. From my research, All available applications doesn't allow you to specify the start time and the end time of the video duration you wish to download instead of the full videos as usual.

So I embarked on using NodeJs and a library called ytdl-core.

Below is my code so far, my challenge is I can't still implement the start and end time for the app to download. Am only able to download the full application. Is there a way out?

const express = require('express');
const cors = require('cors');
const ytdl = require('ytdl-core');
const app = express();
app.use(cors());
app.listen(4000, () => {
    console.log('Server Works !!! At port 4000');
});
app.get('/download', (req,res) => {
var URL = req.query.URL;
res.header('Content-Disposition', 'attachment; filename="video.mp4"');
ytdl(URL, {
    format: 'mp4'
    }).pipe(res);
});

Frontend

var convertBtn = document.querySelector('.convert-button');
var URLinput = document.querySelector('.URL-input');
var start= document.querySelector('.startValue');
var end= document.querySelector('.endValue');

convertBtn.addEventListener('click', () => {
    console.log(`URL: ${URLinput.value}`);
    sendURL(URLinput.value);
});
function sendURL(URL) {
    window.location.href = `http://localhost:4000/download?URL=${URL}?startTime=${start}?endTime=${end}`;
}

I got the URL submitted by the user and passed via a query and used the package to download the video from YouTube.

app.get('/download', (req,res) => {
var URL = req.query.URL;
var startTime = req.query.startTime;
var endTime =  req.query.startTime;

res.header('Content-Disposition', 'attachment; filename="video.mp4"');
ytdl(URL, {
    format: 'mp4'
    }).pipe(res);
});

0

There are 0 best solutions below