const puppeteer = require('puppeteer-core'); const request = require('request'); const…
- User
const puppeteer = require('puppeteer-core'); const request = require('request');
const url = process.argv[2]; playVideo(url).catch(error => { console.error('Error:', error); });
async function playVideo(url) { const browser = await puppeteer.launch({ executablePath: './chrome-linux/chrome', headless: true, args: [ '--no-sandbox', '--disable-gpu', '--ignore-certificate-errors', ], });
const page = await browser.newPage(); const retryErrorConfigUrls = [];
try { // Step 1: Get firstResult before loading newUrl let firstResult = 'Null'; await page.goto(url, { timeout: 60000, waitUntil: 'networkidle0', });
const firstElement = await page.$('b.api-key-text'); if (firstElement) { firstResult = await page.evaluate(element => element.textContent, firstElement); } // Step 2: Get the current page URL const currentUrl = page.url(); // Step 3: Create a new URL by replacing 'UI/Dashboard' with 'api/v2.0/indexers?configured=true' const newUrl = currentUrl.replace('UI/Dashboard', 'api/v2.0/indexers?configured=true'); // Step 4: Load the new URL and get its response as pretty JSON await page.goto(newUrl, { timeout: 60000, waitUntil: 'networkidle0', }); // Step 5: Get cookies from the page const cookies = await page.cookies(); const response = await page.evaluate(() => { return JSON.parse(document.body.innerText); }); // Step 6: Filter the array to keep only elements where the value of the 'type' key contains 'private' and 'configured' is true (case-insensitive) const privateItems = response.filter(item => { const isPrivate = item.type.toLowerCase().includes('private'); const isConfigured = String(item.configured).toLowerCase() === 'true'; return isPrivate && isConfigured; }); if (privateItems.length > 0) { console.log(`\nTorznab key: ${firstResult}\n`); // Print the Torznab key only if privateItems is not zero } else { process.exit(0); // Exit the script with zero exit code as there are no private items to process } // Step 7: Modify each element to keep only the 'id' and construct the 'config_url' const finalResult = privateItems.map(item => { const { id } = item; const config_url = currentUrl.replace('UI/Dashboard', `api/v2.0/indexers/${id}/config`); return { id, config_url }; }); // Step 8: Process each config_url using request module with cookies and timeout for (const item of finalResult) { try { const configResponse = await getConfigResponseWithCookies(item.config_url, cookies); // Step 9: Parsing and filtering the response const filteredElements = configResponse.filter(element => { return ( element.type === 'inputstring' && typeof element.value !== 'boolean' && element.value !== null ); }); const groupedValues = filteredElements.map(element => element.value).join(' | '); const prefixedGroupedValues = item.id + ' | ' + groupedValues; console.log(prefixedGroupedValues); } catch (error) { console.log(`##${item.id} | ${item.config_url} | ${error.message}`); // Print errored URLs to stdout retryErrorConfigUrls.push(item.config_url); } } // Step 10: Retry error config_urls with increasing timeout let retryTimeout = 3000; // Initial retry timeout is 15 seconds while (retryErrorConfigUrls.length > 0 && retryTimeout <= 30000) { const retryResults = []; for (const configUrl of retryErrorConfigUrls) { try { const configResponse = await getConfigResponseWithCookies(configUrl, cookies, retryTimeout); retryResults.push({ configUrl, response: configResponse }); } catch (error) { console.log(`##Retry ${retryTimeout}ms | ${configUrl}|${error.message}`); // Print errored URLs to stdout } } // Remove successfully processed config_urls from retryErrorConfigUrls retryErrorConfigUrls.length = 0; for (const retryResult of retryResults) { const configUrl = retryResult.configUrl; const configResponse = retryResult.response; if (!configResponse.error) { // Step 11: Parsing and filtering the response (same as in Step 9) const filteredElements = configResponse.filter(element => { return ( element.type === 'inputstring' && typeof element.value !== 'boolean' && element.value !== null ); }); const groupedValues = filteredElements.map(element => element.value).join(' | '); const prefixedGroupedValues = configUrl + ' | ' + groupedValues; console.log(prefixedGroupedValues); } else { // Config url still encounters an error, add it back to retryErrorConfigUrls retryErrorConfigUrls.push(configUrl); } } retryTimeout *= 2; // Double the retry timeout for the next retry } - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.