Skip to main content
Glama
test-captions.jsβ€’1.86 kB
#!/usr/bin/env node console.log('πŸŽ₯ Testing Video ID Extraction from URLs'); console.log(''); // Function to extract video ID (simplified version for testing) function extractVideoId(input) { console.log(`Processing input: ${input}`); // If it's already a video ID (doesn't contain http/https), return as-is if (!input.includes('http')) { console.log(' β†’ Direct video ID detected'); return input; } // Extract video ID from various JW.org URL formats try { const url = new URL(input); console.log(` β†’ Parsed URL: ${url.href}`); // Check for 'lank' parameter (most common format) const lank = url.searchParams.get('lank'); if (lank) { console.log(` β†’ Found 'lank' parameter: ${lank}`); return lank; } // Check for 'docid' parameter (alternative format) const docid = url.searchParams.get('docid'); if (docid) { console.log(` β†’ Found 'docid' parameter: ${docid}`); return docid; } // Check if video ID is in the pathname const pathMatch = url.pathname.match(/\/(pub-[^\/]+)/); if (pathMatch) { console.log(` β†’ Found video ID in path: ${pathMatch[1]}`); return pathMatch[1]; } console.log(' β†’ No video ID found in URL'); return input; } catch (error) { console.log(` β†’ URL parsing failed: ${error.message}`); return input; } } // Test cases const testCases = [ 'pub-jwbvod25_17_VIDEO', 'https://www.jw.org/finder?srcid=jwlshare&wtlocale=E&lank=pub-jwbvod25_17_VIDEO', 'https://www.jw.org/en/library/videos/?docid=pub-jwbvod25_17_VIDEO', 'https://www.jw.org/en/library/videos/pub-jwbvod25_17_VIDEO/' ]; testCases.forEach((testCase, index) => { console.log(`\nπŸ“‹ Test ${index + 1}:`); const result = extractVideoId(testCase); console.log(`βœ… Result: ${result}`); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/advenimus/jw-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server