Convert YouTube JSON to TSV
<p><pre><code>     sed &#x27;s&#x2F;.\{4\}&#x2F;&#x2F;&#x27; &lt;&lt; eof|flex -8iCrf 
     &#x2F;* youtube json to tsv *&#x2F;
    
     int fileno (FILE *);
     int setenv (const char *, const char *, int);
     #define echo do{if(fwrite(yytext,(size_t)yyleng,1,yyout)){}}while(0)
     #define jmp (yy_start) = 1 + 2 *
     #define pc(x) putchar(x)
     int request_type;
     int count_text;
     int count_simpletext;
     int count_baseurl;
     int count_videoid;
     void save_request(){setenv(&quot;request&quot;,yytext,1);}
     void save_channel(){setenv(&quot;channel&quot;,yytext,1);}
     void print_saved_channel(){fprintf(stdout,&quot;\t%s&quot;,getenv(&quot;channel&quot;));}
     void print_saved_request(){fprintf(stdout,&quot;\t%s&quot;,getenv(&quot;request&quot;));}
     void print_saved_request_type(){pc(9);if(request_type==1)pc(115);if(request_type==2)pc(99);}
     void try_to_omit_premieres(){if(yytext[0]==&#x27;*&#x27;)jmp 0;} 
    
    pattern_initial_baseurl \&quot;canonicalBaseUrl\&quot;:\&quot;
    pattern_continuation_baseurl \&quot;canonicalBaseUrl\&quot;:\40\&quot;
    pattern_originalurl \&quot;originalUrl\&quot;:\&quot;https:\&#x2F;\&#x2F;www.youtube.com
    pattern_initial_video \&quot;videoRenderer\&quot;:
    pattern_initial_grid \&quot;gridVideoRenderer\&quot;:
    pattern_initial_movie \&quot;movieRenderer\&quot;:
    pattern_continuation_compact\&quot;compactVideoRenderer\&quot;:\40\173
    pattern_initial_videoid \&quot;videoId\&quot;:\&quot;
    pattern_continuation_videoid \&quot;videoId\&quot;:\40\&quot; 
    pattern_initial_text \&quot;text\&quot;:\&quot;
    pattern_continuation_text \&quot;text\&quot;:\40\&quot;
    pattern_initial_simpletext \&quot;simpleText\&quot;:\&quot;
    pattern_channel_name &quot;&#x2F;c&#x2F;&quot;
    pattern_channel_id &quot;&#x2F;channel&#x2F;&quot; 
    pattern_search_query &quot;&#x2F;results?search_query&quot;.{6} 
    
    %option nounput noinput noyywrap
    %s state_print_column1
    %s state_print_column2
    %s state_print_column4
    %s state_save_request_type1
    %s state_save_request_type2
    %s state_save_request
    %s state_save_channel
    %%
    
      &#x2F;* 
      originalUrl 
      *&#x2F;
    {pattern_originalurl} jmp state_save_request;
     &#x2F;* 
      will use as cols 5,6 
      *&#x2F;
    &lt;state_save_request&gt;\&quot; jmp 0;
    &lt;state_save_request&gt;{pattern_channel_name}|{pattern_channel_id} jmp state_save_request_type2;
    &lt;state_save_request&gt;{pattern_search_query} jmp state_save_request_type1;
    &lt;state_save_request_type2&gt;[^&#x2F;]* request_type=2;save_request();jmp 0;
    &lt;state_save_request_type1&gt;[^\&quot;]* request_type=1;save_request();jmp 0;
    
      &#x2F;* 
       videoRenderer gridVideoRenderer movieRenderer compactVideRenderer
       start of record reset counters
       *&#x2F;
    {pattern_initial_video}|{pattern_initial_grid}|{pattern_initial_movie}|{pattern_continuation_compact} {
     count_videoid=0;
     count_text=0;
     count_simpletext=0;
     count_baseurl=0;}
    
      &#x2F;* 
       videoId 
       *&#x2F;
    {pattern_initial_videoid}|{pattern_continuation_videoid} {
     count_videoid++;jmp state_print_column1;}
      &#x2F;*
       print 1
      *&#x2F;
    &lt;state_print_column1&gt;\&quot; jmp 0; 
    &lt;state_print_column1&gt;[^\&quot;]* if(count_videoid==1){echo;pc(9);}
    
      &#x2F;* 
       canonicalBaseUrl 
      *&#x2F;
    {pattern_initial_baseurl}|{pattern_continuation_baseurl} {
     count_baseurl++;jmp state_save_channel;}
     &#x2F;* 
       print 3 if search json
     *&#x2F;
    &lt;state_save_channel&gt;\&quot; jmp 0;
    &lt;state_save_channel&gt;[^\&quot;]* {
      save_channel();
      if(request_type==1)
      if(count_baseurl==1)
      print_saved_channel();} 
    
      &#x2F;* 
       text 
      *&#x2F;
    {pattern_initial_text} {
     count_text++;
     if(count_text==1)
     jmp state_print_column2;}
     &#x2F;* 
       print 2 if search json
       print 2 plus 3 if channel json
     *&#x2F; 
    &lt;state_print_column2&gt;\&quot; jmp 0;
    &lt;state_print_column2&gt;[^\&quot;]* {
     echo; 
     if(request_type==2)
     print_saved_channel();}   
     &#x2F;*
       also print 4 if continuation json
     *&#x2F;
    {pattern_continuation_text} {
     count_text++; 
     if(count_text==1)
     jmp state_print_column2; 
     if(request_type==2)
     if(count_text==4)
     jmp state_print_column4;  
     if(request_type==1)
     if(count_text==5)
     jmp state_print_column4;} 
    
     &#x2F;* 
       simpleText 
       print 4 if initial json 
     *&#x2F;
    {pattern_initial_simpletext} {
     count_simpletext++; 
     if(request_type==1)
     if(count_simpletext==2)
     jmp state_print_column4; 
     if(request_type==2)
     if(count_simpletext==4)
     jmp state_print_column4;} 
    
     &#x2F;* 
       print 4 plus 5,6 
     *&#x2F;
    &lt;state_print_column4&gt;\&quot; jmp 0;
    &lt;state_print_column4&gt;[^\&quot;]* {
     try_to_omit_premieres();
     if(yytext[0]&gt;57)fprintf(stdout,&quot;\t%s&quot;,&quot;No_views&quot;);else {pc(9);echo;};
     print_saved_request();
     print_saved_request_type();pc(10);jmp 0;} 
    
    \n|.
    %%
    int main(){ yylex();exit(0);}
    
    &#x2F;* ----------------------------------------------------------
    
       initial json and continuation json differ
       continuation json has space after the colon
    
       columns:
       1 video ID 
       2 description (may contain unicode)
       3 channel name or channel ID
       4 running time (NB. missing for videos with No views) 
       5 search query_string or channel name&#x2F;ID
       6 search or channel (&quot;s&quot; or &quot;c&quot;)
       
       do meta tags from video page html allow unicode
    
       search_query retrieval is &quot;request type 1&quot;
       channel retrieval is &quot;request type 2&quot;
    
    
    ------------------------------------------------------------ *&#x2F;
   
</code></pre>
eof<p><pre><code>   cc -std=c89 -pedantic -Wall -static lex.yy.cc -o yy062</code></pre>