Comments (1)
const express = require('express');
const ytdl = require('ytdl-core');
const app = express();
app.get('/', async (req, res) => {
res.sendFile('index.html', { root: './' });
});
app.get('/videoInfo', async (req, res) => {
const { videoUrl } = req.query;
if (!videoUrl) {
return res.status(400).json({ error: 'Please provide a video URL.' });
}
try {
const info = await ytdl.getInfo(videoUrl);
console.log('Video Info:', info); // Log the entire 'info' object to the console
const title = info.videoDetails.title;
const uploadDate = info.videoDetails.uploadDate;
const views = info.videoDetails.viewCount;
const duration = parseInt(info.videoDetails.lengthSeconds) / 60;
// Fetching likes and dislikes with default values of 0
const likes = info.videoDetails && info.videoDetails.likes ;
const dislikes = info.videoDetails && info.videoDetails.dislikes ? parseInt(info.videoDetails.dislikes) : 0;
const separateVideoCounter = info.videoDetails.isLiveContent ? 'Live Stream' : 'Single Video';
const videoInfo = {
title,
uploadDate,
views,
duration: duration.toFixed(2),
likes,
dislikes, // Adding dislikes to the videoInfo object
separateVideoCounter,
};
res.json(videoInfo);
} catch (error) {
res.status(500).json({ error: 'Could not fetch video information.' });
}
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
from node-ytdl-core.
Related Issues (20)
- SyntaxError: Invalid or unexpected token HOT 19
- Timeout error starting -- no code change, no change in payload length HOT 1
- Is this repository no longer being maintained? HOT 2
- Downloaded has no sounds @latest version HOT 3
- Question HOT 1
- Error in audio stream for xxxx: MinigetError: Status code: 403 HOT 2
- Method getInfo(url) with most of the hasVideo or hasAudio false and download only audio or video. Not a proper video. HOT 1
- MP3 id3 tag issue?
- [YouTube] Itag 18 not loading anymore HOT 7
- FFMPEG Get FileStream rather than writing straight to a file HOT 2
- Handling stream error events
- Banned dependency HOT 1
- Proxy not working HOT 1
- MinigetError: Status code: 573 HOT 2
- `audioTrack` not in typescript type for `formats`, `lang` parameter ignored
- Problem with duration
- Download a private video youtube HOT 1
- status code 410
- 410 status error HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-ytdl-core.