3 ms·
// yy078 part 1 of 2 #include <time.h> int fileno (FILE *); int t,u,w,x,y,z; char ch; int itag; int lenh(int n){int h,s;s=n
by 1vuio0pswjnm7 3y ago
// yy078 part 1 of 2
#include <time.h>
int fileno (FILE *);
int t,u,w,x,y,z;
char ch;
int itag;
int lenh(int n){int h,s;s=n%(24*3600);h=s/3600 ;return(h);}
int lenm(int n){int m,s;s=n%(24*3600);s=s%3600;m=s/60;return(m);}
int lens(int n){int s;s=n%(24*3600);s=s%3600;s=s%60;return(s);}
time_t xt;
struct tm *yt;
char zt[100];
int len, views;
int csv, sql, append;
int ins(){fwrite("INSERT INTO t1(ts,utc,itag,vid,title,dur,len,cid,views,author) VALUES(",1,70,stdout);return(0);}
int on(){fwrite("') ON CONFLICT(vid) DO UPDATE SET views=excluded.views;\n",1,56,stdout);return(0);}
%option nounput noinput noyywrap
%%
^HTTP\/1.1[ ]200[ ]OK\r itag = 0;u = 0;len = 0;views = 0;
\42lastModified\42:[ ]\42[0-9]{10} {
if(itag>0)
{
if(t==1)
{
y=0;for(x=17;x<yyleng;x++){if(yytext[x])yytext[y]=yytext[x];y++;};
if(sql)if(!csv)ins();
fwrite(yytext,1,10,yyout);putc(44,stdout);
xt=atoi(yytext);
yt=localtime(&xt);
if(strftime(zt,sizeof(zt),"%d %b %Y %H:%M:%S %Z",yt)!=0)
{
if(sql)putchar(39);
fwrite(zt,24,1,stdout);
if(sql)putchar(39);
putc(44,stdout);
}
}
t = 0;
}
}
\42itag\42:[ ]18, {
itag=18;t = 1;
}
\42itag\42:[ ]22, {
itag=22;
}
^[ ]{4}\42videoId\42:[ ]\42[^\n]{11}\42, {
if(itag>0)
{
fprintf(stdout,"%02d,",itag);
if(sql)putchar(39);
for(x=16;x<yyleng-1;x++)if(yytext[x]!=34)putc(yytext[x],stdout);
if(sql)putchar(39);
putc(44,stdout);
}
}
\42title\42:[ ]\42[^\n]+\42, {
if(itag>0)
if(csv)
{
ch = 0;
for(x=9;x<yyleng-1;x++)
{
if(yytext[x]==92)ch=yytext[x];
if(yytext[x]==34&&ch!=0){putc(34,stdout);ch = 0;};
if(yytext[x]!=34&&yytext[x]!=92&&ch!=0){putc(ch,stdout);putc(yytext[x],stdout);ch = 0;};
if(ch==0&&yytext[x]!=92)putc(yytext[x],stdout);
}
u = 1;
putc(44,stdout);
}
if(itag>0)
if(sql)
{
ch = 0;
putchar(39);
for(x=10;x<yyleng-2;x++)
{
if(yytext[x]==92)ch=yytext[x];
if(yytext[x]==34&&ch!=0){ch = 0;};
if(yytext[x]==39){putc(39,stdout);};
if(ch==0&&yytext[x]!=92)putc(yytext[x],stdout);
}
u = 1;
putchar(39);
putc(44,stdout);
}
}
\42lengthSeconds\42:[ ]\42[^\42\n]+ {
if(itag>0)
if(len==0)
{
y=0;for(x=18;x<yyleng;x++){if(yytext[x])yytext[y]=yytext[x];y++;};
if(yytext[yyleng-18])yytext[yyleng-18]=0;
w=atoi(yytext);
if(sql)putchar(39);
fprintf(stdout,"%02d:%02d:%02d",lenh(w),lenm(w),lens(w));
if(sql)putchar(39);