File size: 2,385 Bytes
c892026
 
78dd2f3
f407186
c892026
f407186
 
 
cd07850
f407186
 
c892026
f407186
 
c892026
f407186
c892026
095adeb
0cef924
1b61f26
0cef924
1b61f26
095adeb
cd07850
1910190
 
 
c892026
 
0cef924
095adeb
1910190
095adeb
 
1910190
0cef924
41f915d
0cef924
41f915d
 
 
 
 
 
0cef924
f407186
095adeb
41f915d
095adeb
c892026
095adeb
c400431
c892026
f407186
c892026
 
 
78dd2f3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const puppeteer = require('puppeteer-core');

async function getPinterestVideos(query) {
    let browser;
    try {
        browser = await puppeteer.launch({
            executablePath: '/usr/bin/chromium',
            headless: 'new',
            args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage']
        });

        const page = await browser.newPage();
        await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36');

        const searchUrl = `https://www.pinterest.com/search/pins/?q=${encodeURIComponent(query)}&rs=typed`;
        await page.goto(searchUrl, { waitUntil: 'networkidle2', timeout: 30000 });

        await page.evaluate(async () => {
            for (let i = 0; i < 3; i++) {
                window.scrollBy(0, window.innerHeight * 2);
                await new Promise(r => setTimeout(r, 1500));
            }
        });

        const pinUrls = await page.evaluate(() => {
            return Array.from(document.querySelectorAll('a[href*="/pin/"]'))
                .map(a => a.href).filter(href => href.includes('/pin/'));
        });

        const uniquePins = [...new Set(pinUrls)].slice(0, 60);

        for (const pinUrl of uniquePins) {
            const pPage = await browser.newPage();
            try {
                await pPage.goto(pinUrl, { waitUntil: 'domcontentloaded', timeout: 10000 });
                const content = await pPage.content();
                const videoRegex = /https:\/\/v1\.pinimg\.com\/videos\/mc\/[^\s"']+/g;
                const matches = content.match(videoRegex);

                if (matches) {
                    let rawUrl = matches[0].replace(/\\u002F/g, '/').replace(/[奖励"']/g, '');
                    const hashMatch = rawUrl.match(/([a-f0-9]{32})/);
                    if (hashMatch) {
                        const h = hashMatch[1];
                        process.stdout.write(`https://v1.pinimg.com/videos/mc/720p/${h.substring(0,2)}/${h.substring(2,4)}/${h.substring(4,6)}/${h}.mp4\n`);
                    }
                }
            } catch (e) {} 
            await pPage.close();
        }
    } catch (error) {
        process.stderr.write(error.message);
    } finally {
        if (browser) await browser.close();
    }
}

getPinterestVideos(process.argv.slice(2).join(' '));