Node.JS YouTube-DL Express Example to Extract YouTube Video Meta Info (Title, Description) In JS

You are currently viewing Node.JS YouTube-DL Express Example to Extract YouTube Video Meta Info (Title, Description) In JS

Node.js Youtube-DL Express Example to Extract Youtube Video Meta Info (Title, Description) in JS

const express = require('express')
 
const app = express()
 
const bodyParser = require('body-parser')
const {exec} = require('child_process')
 
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.set('view engine', 'ejs')
 
app.get('/', (req, res) => {
    res.render('index',{description:''})
})
 
app.post('/getinfo', (req, res) => {
    exec(`youtube-dl --get-description ${req.body.url} --skip-download`, (err, stdout, stderr) => {
        if (err) {
            console.log(err)
        } else {
            console.log(stdout)
            res.render('index',{description:stdout})
        }
    })
})
 
app.listen(5000, () => {
    console.log("App is listening on port 5000")
})

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
 
</head>
<body>
    <div class="container">
        <h1 class="text-center">
            Youtube Meta Description Title Generator
        </h1>
        <form action="/getinfo" method="post">
            <div class="form-group">
                 <label for="url">Enter Youtube Video URL:</label>
                <input type="text" name="url" required class="form-control" placeholder="Enter Youtube Video URL" id="">
            </div>
            <div class="form-group">
                <button class="btn btn-danger btn-block">
                    Get Info
                </button>
            </div>
        </form>
        <div class="form-group">
            <textarea class="form-control" name="" id="" cols="30" rows="10">
                <%if(description){%>
                    <%=description%>
                <%}%>
            </textarea>
        </div>
    </div>
</body>
</html>

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply