x=https://news.ycombinator.com/item?id
links -dump $x=37060497|sed -n '8,139s/.\{6\}//p' > 076.l
links -dump $x=37061215|sed -n '5,99s/.\{6\}//p' > 082.l
links -dump $x=37061227|sed -n '5,148s/.\{6\}//p' >> 082.l
for x in 076 082;do
flex -8Crf $x.l
cc -O3 -std=c89 -W -Wall -pedantic -pipe lex.yy.c -static -o yy$x
strip -s yy$x
done {
if(videoid)fputc(yytext[c],stdout);
}
if(videoid)putchar(10);
}
\"videoId\":[ ]\"[^\"\12]+ {
if(videoid)
for(c=12;yytext[c]!=13&&yytext[c]!=34&&yytext[c]!=44&&yytext[c]!=93&&yytext[c]!=125&&c<24;++c)
if(yytext[c]!=0)
{
if(videoid)fputc(yytext[c],stdout);
}
if(videoid)putchar(10);
}
"i.ytimg.com/vi/"[^\/]{11}\/[mh]qdefault.jpg {
if(videoid)
for(c=15;yytext[c]!=13&&yytext[c]!=34&&yytext[c]!=44&&yytext[c]!=93&&yytext[c]!=125&&c<26;++c)
if(yytext[c]!=0)
{
if(videoid)fputc(yytext[c],stdout);
}
if(videoid)putchar(10);
}
/* --------------------- canonicalbaseurls ------------------------- */
\"canonicalBaseUrl\":\"\/@[^\"\12]+\" {
if(canonicalbaseurl)
{
for(c=20;yytext[c]!=32&&yytext[c]!=34&&yytext[c]!=44&&yytext[c]!=92&&yytext[c]!=93&&yytext[c]!=125;++c)
if(yytext[c]!=0)
fputc(yytext[c],stdout);
putc(10,stdout);
}
}
\"canonicalBaseUrl\":[ ]\"\/@[^\"\12]+\" {
if(canonicalbaseurl)
{
for(c=21;yytext[c]!=32&&yytext[c]!=34&&yytext[c]!=44&&yytext[c]!=92&&yytext[c]!=93&&yytext[c]!=125;++c)
if(yytext[c]!=0)
fputc(yytext[c],stdout);
putc(10,stdout);
}
}
/* ------------------------ channelids ------------------------------- */
\"channelId\":\"UC[^\"\12]+ {
if(channelid)
{
for(c=13;c!=yyleng+1;++c)
if(yytext[c]!=0)
fputc(yytext[c],stdout);
putchar(10);
}
}
\"channelId\":[ ]\"UC[^\"\12]+ {
if(channelid)
{
for(c=14;c!=yyleng+1;++c)
if(yytext[c]!=0)
fputc(yytext[c],stdout);
putchar(10);
}
}
\"browseId\":[ ]\"UC[^\"\12]+ {
if(channelid)
{
for(c=13;c!=yyleng+1;++c)
if(yytext[c]!=0)
fputc(yytext[c],stdout);
putchar(10);
}
}
\"browseId\":\"UC[^\"\12]+ {
if(channelid)
{
for(c=12;c!=yyleng+1;++c)
if(yytext[c]!=0)
fputc(yytext[c],stdout);
putchar(10);
}
}
,UC[^\"\12,]{22} {
if(channelid)
{
for(c=1;c!=yyleng+1;++c)
if(yytext[c]!=0)
fputc(yytext[c],stdout);
putchar(10);
}
}
/* --------------------- tokens ---------------------- */
\"token\":[ ]\"[^\"\12]+ {
if(token)
{
for(c=10;yytext[c]!=34&&yytext[c]!=44&&yytext[c]!=93&&yytext[c]!=125;++c)
if(yytext[c]!=0)
fputc(yytext[c],stdout);
putchar(10);
}
}
\"continuationAction\":\"[^\"\12]+ {
if(token)
{
for(c=22;yytext[c]!=34&&yytext[c]!=44&&yytext[c]!=93&&yytext[c]!=125;++c)
if(yytext[c]!=0)
fputc(yytext[c],stdout);
putchar(10);
}
}
\"continuationCommand\":\{\"token\":\"[^\"\12]+ {
if(token)
{
for(c=32;yytext[c]!=34&&yytext[c]!=44&&yytext[c]!=93&&yytext[c]!=125;++c)
if(yytext[c]!=0)
fputc(yytext[c],stdout);
putchar(10);
}
}
.|\n
%%
int main(int argc,char* argv[]){
if((!argc)||(!argv[1]))goto help;
if((argv[1][0]!=98)&&
(argv[1][0]!=99)&&
(argv[1][0]!=104)&&
(argv[1][0]!=112)&&
(argv[1][0]!=116)&&
(argv[1][0]!=118))goto help;
if(argv[1][0]==98)canonicalbaseurl++;
if(argv[1][0]==99)channelid++;
if(argv[1][0]==104)http++;;
if(argv[1][0]==112)playlistid++;;
if(argv[1][0]==116)token++;;
if(argv[1][0]==118)videoid++;;
yylex();
exit(0);
help:
fputs("usage: yy082 {b,c,h,p,t,v}\12",stderr);
fputs("b canonicalBaseUrls\n",stderr);
fputs("c channelIds\n",stderr);
fputs("h watchUrls\n",stderr);
fputs("p playlistIds\n",stderr);
fputs("t continuation tokens\n",stderr);
fputs("v videoIds\n",stderr);
exit(1);
} /* yy082 part 1 of 2 */
int fileno (FILE *);
int channelid,videoid,canonicalbaseurl,token,http,playlistid;
int c;
%option nounput noinput noyywrap
%s xa xb xc
%%
/* --------------- watchurls -------------------- */
"https://www.youtube.com/watch?v="[-0-9_A-Za-z]{11} {
if(http)puts(yytext);
if(videoid)
{
for(c=32;c<43;++c)
if(yytext[c]!=0)fputc(yytext[c],stdout);
if(videoid)putchar(10);
}
}
"https://www.youtube.com/embed/"[-0-9_A-Za-z]{11} {
if(http)puts(yytext);
if(videoid)
{
for(c=30;c<41;++c)
if(yytext[c]!=0)fputc(yytext[c],stdout);
if(videoid)putchar(10);
}
}
"https://www.youtube.com/shorts/"[-0-9_A-Za-z]{11} {
if(http)puts(yytext);
if(videoid)
{
for(c=31;c<42;++c)
if(yytext[c]!=0)fputc(yytext[c],stdout);
if(videoid)putchar(10);
}
}
"https://youtu.be/"[-0-9_A-Za-z]{11} {
if(http)puts(yytext);
if(videoid)
{
for(c=17;c<28;++c)
if(yytext[c]!=0)fputc(yytext[c],stdout);
if(videoid)putchar(10);
}
}
/* --------------------- playlistids ------------------------- */
\"shareUrl\":[ ]\"[^\"\12]+\", {
if(playlistid)
{
for(c=51;yytext[c]!=32&&yytext[c]!=34&&yytext[c]!=44&&yytext[c]!=92&&yytext[c]!=93&&yytext[c]!=125;++c)
if(yytext[c]!=0)
fputc(yytext[c],stdout);
putc(10,stdout);
}
}
"https://www.youtube.com/playlist?list="[-0-9_A-Za-z]{18,34} {
if(http)puts(yytext);
if(playlistid)
{
for(c=38;c<74;++c)
if(yytext[c]!=0)fputc(yytext[c],stdout);
if(playlistid)putchar(10);
}
}
\"playlistId\":[ ]\"[^\"\12]+ {
if(playlistid)
for(c=15;yytext[c]!=13&&yytext[c]!=34&&yytext[c]!=44&&yytext[c]!=93&&yytext[c]!=125&&c<50;++c)
if(yytext[c]!=0)
{
if(playlistid)fputc(yytext[c],stdout);
}
if(playlistid)putchar(10);
}
/* --------------- videoids -------------------- */
"target=_blank>"[-_A-Za-z0-9]{11} {
if(videoid)
for(c=14;yytext[c]!=13&&yytext[c]!=34&&yytext[c]!=44&&yytext[c]!=93&&yytext[c]!=125&&c<25;++c)
if(yytext[c]!=0)
{
if(videoid)fputc(yytext[c],stdout);
}
if(videoid)putchar(10);
}
[,'][-_A-Za-z0-9]{11}[,'] {
if(videoid)
for(c=1;yytext[c]!=13&&yytext[c]!=34&&yytext[c]!=44&&yytext[c]!=93&&yytext[c]!=125&&c<12;++c)
if(yytext[c]!=0)
{
if(videoid)fputc(yytext[c],stdout);
}
if(videoid)putchar(10);
}
\"videoId\":\"[^\"\12]+ {
if(videoid)
for(c=11;yytext[c]!=13&&yytext[c]!=34&&yytext[c]!=44&&yytext[c]!=93&&yytext[c]!=125&&c<23;++c)
if(yytext[c]!=0) // yy076
int yy_get_next_buffer();
int fileno(FILE *);
int h,s,x,y;
int search,playlist,videoId,canonicalBaseUrl,channelId,token1,token2;
SEARCH ^=[^\n]+
URL1 ^https:\/\/www.youtube.com\/watch\?v=[0-9A-Za-z\55\137]{11}$
URL2 ^https:\/\/youtu.be\/[0-9A-Za-z\55\137]{11}$
URL3 ^https:\/\/www.youtube.com\/embed\/[0-9A-Za-z\55\137]{11}$
URL4 ^https:\/\/www.youtube.com\/playlist\?list=[0-9A-Za-z\55\137]{18}$
URL5 ^https:\/\/www.youtube.com\/playlist\?list=[0-9A-Za-z\55\137]{34}$
VIDEOID ^[0-9A-Za-z\55\137]{11}$
PLAYLISTID ^PL[0-9A-Za-z\55\137]+$
CHANNELNAME ^\57\100[0-9a-zA-Z\55\137]+$
CHANNELID ^\125\103[0-9A-Za-z_\55\137]{22}$
TOKEN ^[A-Za-z0-9]+(%3D)*$
int http()
{
if(token1)fwrite("POST /youtubei/v1/search?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8 HTTP/1.1\n",1,78,yyout);
if(token2)fwrite("POST /youtubei/v1/browse?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8 HTTP/1.1\n",1,78,yyout);
if(videoId)fwrite("POST /youtubei/v1/player?key=AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w HTTP/1.1\n",1,78,yyout);
if(canonicalBaseUrl)
{
fwrite("GET ",1,4,yyout);
fwrite(yytext,1,yyleng,yyout);
fwrite("/videos HTTP/1.1\r\n",1,18,yyout);
}
if(channelId)
{
fwrite("GET /channel/",1,13,yyout);
fwrite(yytext,1,yyleng,yyout);
fwrite("/videos HTTP/1.1\r\n",1,18,yyout);
}
if(search)
{
fwrite("GET /results?search_query",1,25,yyout);
fwrite(yytext,1,yyleng,yyout);
fwrite(" HTTP/1.1\r\n",1,11,yyout);
}
if(playlist)
{
fwrite("GET /playlist?list=",1,19,yyout);
fwrite(yytext,1,yyleng,yyout);
fwrite(" HTTP/1.1\r\n",1,11,yyout);
}
fwrite("Host: www.youtube.com\n",1,22,yyout);
if(videoId||token1||token2)fwrite("Content-Type: appllication/json\n",1,32,yyout);
if(videoId)fwrite("Content-Length: 287\n",1,20,yyout);
if(token1||token2)fprintf(stdout,"Content-Length: %d\n",yyleng+121);
if(videoId)fwrite("cookie: PREF=hl=en&tz=UTC; CONSENT=YES+cb.20210328-17-p0.en+FX+994; GPS=1; YSC=vhWkc-LLQ2w; VISITOR_INFO1_LIVE=RaHngNUvOzk\n",1,123,stdout);
fwrite("Connection: keep-alive\n\n",1,24,yyout);
if(videoId)
{
fwrite("{\"context\": {\"client\": {\"clientName\": \"ANDROID\", \"clientVersion\": \"17.31.35\", \"androidSdkVersion\": 30 }}, \"videoId\": \"",1,118,yyout);
fwrite(yytext,1,11,yyout);
fwrite("\", \"params\": \"CgIQBg==\", \"playbackContext\": {\"contentPlaybackContext\": {\"html5Preference\": \"HTML5_PREF_WANTS\"}}, \"contentCheckOk\": true, \"racyCheckOk\": true}\n",1,158,yyout);
}
if(token1||token2)
{
fwrite("{\"context\":{\"client\":{\"hl\":\"en-US\",\"gl\":\"US\",\"clientName\":\"MWEB\",\"clientVersion\":\"2.20210916.06.01\"}},",1,102,yyout);
fwrite("\"continuation\":\"",1,16,yyout);
fwrite(yytext,1,yyleng,yyout);
fwrite("\"}\n",1,3,yyout);
}
videoId = 0,canonicalBaseUrl = 0,channelId = 0,token1 = 0,token2 = 0;
return(0);
}
%option nounput noinput noyywrap
%%
\"yt_web_search\" s++;
{URL1} {
videoId++;
y=0;for(x=32;x<yyleng;x++)
{if(yytext[x])yytext[y]=yytext[x];y++;}
if(yytext[yyleng-32])yytext[yyleng-32]=0;
h++;http();
}
{URL2} {
videoId++;
y=0;for(x=17;x<yyleng;x++)
{if(yytext[x])yytext[y]=yytext[x];y++;}
if(yytext[yyleng-17])yytext[yyleng-17]=0;
h++;http();
}
{URL3} {
videoId++;
y=0;for(x=30;x<yyleng;x++)
{if(yytext[x])yytext[y]=yytext[x];y++;}
if(yytext[yyleng-30])yytext[yyleng-30]=0;
h++;http();
}
{URL4} {
playlist++;
y=0;for(x=38;x<57;x++)
{if(yytext[x])yytext[y]=yytext[x];y++;}
if(yytext[57])yytext[57]=0;
h++;http();
}
{URL5} {
playlist++;
y=0;for(x=38;x<72;x++)
{if(yytext[x])yytext[y]=yytext[x];y++;}
if(yytext[72])yytext[72]=0;
h++;http();
}
{SEARCH} {
search++;
y=0;for(x=0;x<yyleng;x++)
{if(x!=yyleng-1)if(yytext[x]==32)yytext[x]=43;if(yytext[x])yytext[y]=yytext[x];y++;}
if(yytext[yyleng])yytext[yyleng]=0;
h++;http();
}
{CHANNELID} channelId++; h++;http();
{CHANNELNAME} canonicalBaseUrl++; h++;http();
{VIDEOID} videoId++; h++;http();
{PLAYLISTID} playlist++; h++;http();
{TOKEN} {
for(x=0;x<yyleng;x++)
{if(yytext[0]==52&&yytext[1]==113&&yytext[2]==109)token2++;else token1++;}
h++;http();
}
.|\n
%%
int main()
{
yylex();
/* do not need if using bssl */
if(h)fprintf(stdout,"\r\n%s\r\n%s\r\n\r\n",
"GET /robots.txt HTTP/1.0","Host: www.youtube.com");
exit(0);
}