Skip to content

Instantly share code, notes, and snippets.

@pulsar256
Created May 21, 2015 17:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pulsar256/f5621e85ef50711adc6f to your computer and use it in GitHub Desktop.
Save pulsar256/f5621e85ef50711adc6f to your computer and use it in GitHub Desktop.
Generator for pageTokens for the Youtube API
// workaround for https://code.google.com/p/gdata-issues/issues/detail?id=7163
var d0 = "AEIMQUYcgkosw048";
var d1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var d2 = d1;
var d1c = 0;
var d2c = 0;
var overflowSuffix = "Q";
var direction = "AA";
var d2OverflowCounter = 0;
var pageSize = 50;
for(i = 0; i < 1024; i++) {
if(i % pageSize == 0) console.log("C" + d1.charAt((d1c / d0.length) % d1.length) + d0.charAt(i % d0.length) + overflowSuffix + direction, ":", i);
if(++d1c % (1 << 8) == 0) d1c = 1 << 7;
if(++d2c % (1 << 7) == 0) overflowSuffix = d2.charAt(++d2OverflowCounter) + "E";
}
@alexbenfica
Copy link

Hum... interesting!
How did you find the way tokens work?

@pulsar256
Copy link
Author

by looking at a couple of valid ones and guessing how the algorithm might work.

@bromix
Copy link

bromix commented May 29, 2015

This would be nice in Python with page and max_result as a parameter :)

@bromix
Copy link

bromix commented May 31, 2015

i=400 isn't working. Token should be CJADEAA but calculates CJAAEAA

pageSize = 50
i = 400

@bromix
Copy link

bromix commented May 31, 2015

Further tests reviled that var d1 = "ABCDEFGHIJKLMNOP"; should be correct. After P the iteration starts with I again. So d1 has only a length of 16.

@pulsar256
Copy link
Author

@bromix: the sequence is calculated correctly on my end, just pasted the code into the chrome dev console. gives me CJADEAA : 400. Please keep in mind that the algorithm is not very smart and requires to iterate beginning with 0.

And yes, you are right. d1 might be trimmed to [A..P] but d2 may not. I way lazy. Feel free to fork ;)

@bromix
Copy link

bromix commented May 31, 2015

@Pulsar: thanks for the feedback...already figured it out for python. But your code was inspiring and a lot of help :) no need for iterations on my end now :)

@bromix
Copy link

bromix commented May 31, 2015

@pulsar256
Copy link
Author

awesome! ;)

@chuckstark
Copy link

even with the code examples above, i seem to get stuck at 46 pages (with a max of 50 per page). Can you get more than 46 pages returned?

@p4rnicke
Copy link

I got stuck at page 22, after 1000 position. But it may be a mostake on my porting.@chuckstarl can you give a list of codes until 46?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment