Update app.js
Browse files
app.js
CHANGED
|
@@ -205,7 +205,7 @@ app.get('/cookie', async (req, res) => {
|
|
| 205 |
});
|
| 206 |
|
| 207 |
app.get('/welcome', async (req, res) => {
|
| 208 |
-
const { name, info } = req.query;
|
| 209 |
|
| 210 |
// Ensure all required query parameters are present
|
| 211 |
if (!name || !info) {
|
|
@@ -514,7 +514,7 @@ body {
|
|
| 514 |
</span>
|
| 515 |
</div>
|
| 516 |
<h6>${info}</h6>
|
| 517 |
-
<h2>
|
| 518 |
<button class="btn">Continue</button>
|
| 519 |
</div>
|
| 520 |
</div>
|
|
@@ -600,6 +600,33 @@ close_btn.addEventListener('click', () => {
|
|
| 600 |
}
|
| 601 |
});
|
| 602 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 603 |
const PORT = process.env.PORT || 7860;
|
| 604 |
|
| 605 |
app.listen(PORT, async () => {
|
|
|
|
| 205 |
});
|
| 206 |
|
| 207 |
app.get('/welcome', async (req, res) => {
|
| 208 |
+
const { name, info, desc } = req.query;
|
| 209 |
|
| 210 |
// Ensure all required query parameters are present
|
| 211 |
if (!name || !info) {
|
|
|
|
| 514 |
</span>
|
| 515 |
</div>
|
| 516 |
<h6>${info}</h6>
|
| 517 |
+
<h2>${desc}</h2>
|
| 518 |
<button class="btn">Continue</button>
|
| 519 |
</div>
|
| 520 |
</div>
|
|
|
|
| 600 |
}
|
| 601 |
});
|
| 602 |
|
| 603 |
+
async function getYouTubeChannelDetails(channelName) {
|
| 604 |
+
const browser = await chromium.launch({ headless: true });
|
| 605 |
+
const page = await browser.newPage();
|
| 606 |
+
const url = `https://www.youtube.com/@${channelName}/videos`;
|
| 607 |
+
await page.goto(url);
|
| 608 |
+
const name = await page.locator('yt-dynamic-text-view-model h1').textContent();
|
| 609 |
+
const username = await page.locator('yt-content-metadata-view-model-wiz__metadata-text').first().textContent();
|
| 610 |
+
const subscriberCount = await page.locator('yt-content-metadata-view-model-wiz__metadata-row').nth(1).textContent();
|
| 611 |
+
const videoCount = await page.locator('yt-content-metadata-view-model-wiz__metadata-row').last().textContent();
|
| 612 |
+
await browser.close();
|
| 613 |
+
return { name, username, subscriberCount, videoCount };
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
app.get('/yt-info-channel', async (req, res) => {
|
| 617 |
+
const { name } = req.query;
|
| 618 |
+
if (!name) {
|
| 619 |
+
return res.status(400).send({ error: 'Channel name parameter is required.' });
|
| 620 |
+
}
|
| 621 |
+
try {
|
| 622 |
+
const channelDetails = await getYouTubeChannelDetails(name);
|
| 623 |
+
res.json(channelDetails);
|
| 624 |
+
} catch (error) {
|
| 625 |
+
console.error(error);
|
| 626 |
+
res.status(500).send({ error: 'Failed to retrieve channel details.' });
|
| 627 |
+
}
|
| 628 |
+
});
|
| 629 |
+
|
| 630 |
const PORT = process.env.PORT || 7860;
|
| 631 |
|
| 632 |
app.listen(PORT, async () => {
|