Skip to content
This repository was archived by the owner on Aug 16, 2025. It is now read-only.
This repository was archived by the owner on Aug 16, 2025. It is now read-only.

Suggestion to make it fast #208

@Shashwat-CODING

Description

@Shashwat-CODING

use this method to get data from youtube this will make it fast

const express = require('express');
const axios = require('axios');
const app = express();
const port = 3000;

// Define the YouTube video ID (the ID from the URL you provided)
const videoId = 'MtR0iiSRCck'; // This is just an example. You can make it dynamic.

// Endpoint to fetch data from YouTube's player API
app.get('/data', async (req, res) => {
try {
// Prepare the request to YouTube's API endpoint
const response = await axios.post(
'https://www.youtube.com/youtubei/v1/player?prettyPrint=false',
{
context: {
client: {
clientName: 'WEB',
clientVersion: '2.20230310.02.00',
hl: 'en',
},
},
videoId: videoId, // Use the dynamic videoId if needed
},
{
headers: {
'Content-Type': 'application/json',
'X-Youtube-Client-Name': '1',
'X-Youtube-Client-Version': '2.20230310.02.00',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
'Accept-Language': 'en-US,en;q=0.9',
}
}
);

    // Send the response back to the client
    res.json(response.data);
} catch (error) {
    // Handle any errors
    console.error('Error fetching data from YouTube API:', error);
    res.status(500).json({ error: 'Failed to fetch data' });
}

});

// Start the server
app.listen(port, () => {
console.log(Server running at http://localhost:${port});
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions