// 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);
}