- // Helper function to generate a standard UUID v4
- function generateUUID() {
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
- var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
- return v.toString(16);
- });
- }
- // Common headers required by the API
- const HEADERS = {
- "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
- "Referer": "https://cinebolt.org/"
- };
- /**
- * Fetches the stream URL for a given TMDB ID.
- * If season and episode are provided, it fetches a TV show, otherwise a Movie.
- */
- async function fetchStreamUrl(tmdbid, season = null, episode = null) {
- const isTV = (season !== null && episode !== null);
- const typeLabel = isTV ? `TV Show (S${season}E${episode})` : `Movie`;
- console.log(`\n--- Fetching ${typeLabel} | TMDB ID: ${tmdbid} ---`);
- // Generate a single session nonce to use across both requests
- let sessionNonce = generateUUID();
- // === STEP 1: Fetch Token ===
- let tokenUrl = `https://cinebolt.org/api/stream-token?tmdb_id=${tmdbid}&nonce=${sessionNonce}`;
- if (isTV) {
- tokenUrl += `&season=${season}&episode=${episode}`;
- }
- let tokenRes;
- try {
- const response = await fetch(tokenUrl, { headers: HEADERS });
- if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
- tokenRes = await response.json();
- } catch (e) {
- throw new Error(`Step 1 (Token) Failed: ${e.message}`);
- }
- let streamId = tokenRes.id || tmdbid;
- let streamToken = tokenRes.token;
- if (!streamToken) {
- throw new Error(`Could not find 'token' in the response: ${JSON.stringify(tokenRes)}`);
- }
- // === STEP 2: Fetch Stream JSON ===
- // Using trailing slash on {streamId}/ and unencoded token '==' to satisfy backend parser constraints
- let streamUrl = `https://cinebolt.org/api/stream/${streamId}/?token=${streamToken}&nonce=${sessionNonce}`;
- if (isTV) {
- streamUrl += `&season=${season}&episode=${episode}`;
- }
- let streamData;
- try {
- const response = await fetch(streamUrl, { headers: HEADERS });
- if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
- streamData = await response.json();
- } catch (e) {
- throw new Error(`Step 2 (Stream Data) Failed: ${e.message}`);
- }
- // === STEP 3: Parse File URL ===
- let fileUrl = streamData?.sources?.[0]?.file;
- if (!fileUrl) {
- throw new Error(`Missing 'file' property. Raw JSON: ${JSON.stringify(streamData)}`);
- }
- return fileUrl;
- }
- // === MAIN EXECUTION ===
- async function runExamples() {
- console.log("=== Cinebolt POC Scraper ===");
- // Example 1: Movie (e.g., Ocean's Eleven - TMDB: 161)
- try {
- const movieUrl = await fetchStreamUrl(161);
- console.log("SUCCESS! Movie Stream URL:");
- console.log(movieUrl);
- } catch (err) {
- console.error("Movie Example Failed:", err.message);
- }
- // Example 2: TV Show (e.g., Breaking Bad - TMDB: 1396, Season 1, Episode 1)
- try {
- const tvUrl = await fetchStreamUrl(1396, 1, 1);
- console.log("SUCCESS! TV Stream URL:");
- console.log(tvUrl);
- } catch (err) {
- console.error("TV Show Example Failed:", err.message);
- }
- console.log("\n============================");
- }
- runExamples();
cinebolt
Posted by Anonymous on Fri 14th Aug 2026 06:34
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
kpaste.net RSS