dr3v

tracklistr

Oct 2nd, 2020
1,614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.89 KB | None | 0 0
  1. # Grab txt tracklist from various sites and formats it for f2k
  2. # Supported sites:
  3.     # Bandcamp
  4.     # Genius
  5.     # RYM
  6.     # Wiki
  7.  
  8. # Get raw text
  9. open(FILE,"<","input.txt");
  10.  
  11.     while(<FILE>){
  12.         chomp $_;
  13.         push(@lines,$_);
  14.     }
  15.  
  16. close FILE;
  17.  
  18. $data = join("",@lines);
  19. chomp $data;
  20.  
  21. #######################################################################
  22. # Determine where the list came from and send to appropriate subroutine
  23. if ($data =~ m/\d+:\d+\t+/){
  24.     # copied from bandcamp tracklist
  25.     print("\nMatched Bandcamp!\n\n");
  26.     bandcamp();
  27.  
  28. } elsif ($lines[0] =~ m/ \d+:\d+$/){
  29.     # copied from RYM tracklist
  30.     print("\nMatched RateYourMusic!\n\n");
  31.     rym();
  32.  
  33. } elsif ($lines[0] =~ m/^\d+\.\t"/){
  34.     # copied from wiki tracklist
  35.     print("\nMatched wiki!\n\n");
  36.     wiki();
  37.  
  38. } elsif ($data =~ m/ Lyrics\d+/g){
  39.     # copied from Genius album tracklist
  40.     print("\nMatched Genius!\n\n");
  41.     genius();
  42.  
  43. } elsif ($data =~ m/fkbreak/g){
  44.     # tracklist, composer, producer data formatted from libreoffice calc
  45.     print("\nMatched LibreOffice Calc!\n\n");
  46.     calc();
  47. }
  48.  
  49. ############
  50. # Bandcamp #
  51. ############
  52. sub bandcamp
  53. {
  54.  
  55.     @tracks = grep {m/ \d+:\d+$/} @lines;
  56.  
  57.     foreach(@tracks){
  58.         $line = $_; chomp $line;
  59.  
  60.         $line =~ s/ \d+:\d+$//g;
  61.         push(@output,$line);
  62.     }
  63.  
  64.     $tracklist = join("\n",@output);
  65.  
  66.     chomp $tracklist;
  67.     print $tracklist;
  68.  
  69.     open(OUT,">","output.txt");
  70.     print OUT ($tracklist);
  71.     close OUT;
  72.  
  73. }
  74.  
  75. ############
  76. #   RYM    #
  77. ############
  78. sub rym
  79. {
  80.  
  81.     @tracks = grep {m/^\d+ |\w\d /} @lines;
  82.  
  83.     foreach(@tracks){
  84.         $line = $_; chomp $line;
  85.  
  86.         $line =~ s/^\d+ |\w\d //g;
  87.         $line =~ s/ \d+:\d*$//g;
  88.         push(@output,$line);
  89.     }
  90.  
  91.     $tracklist = join("\n",@output);
  92.  
  93.     chomp $tracklist;
  94.     print $tracklist;
  95.  
  96.     open(OUT,">","output.txt");
  97.     print OUT ($tracklist);
  98.     close OUT;
  99.  
  100. }
  101.  
  102. ############
  103. #   Wiki   #
  104. ############
  105. sub wiki
  106. {
  107.  
  108.     foreach(@lines){
  109.         chomp $_;
  110.         $title = $_;
  111.         $title =~ s/^\d+\.\t|\t\d+:\d+$//g;
  112.  
  113.         @notesep = split('" \(',$title);
  114.         $title = $notesep[0];
  115.         $title =~ s/^"|"$//g;
  116.  
  117.         $note = $notesep[1];
  118.         $note =~ s/^\(|\)$//g;
  119.        
  120.         push(@output,"$title|$note");
  121.     }
  122.  
  123.     $tracklist = join("\n",@output);
  124.  
  125.     chomp $tracklist;
  126.     print $tracklist;
  127.  
  128.     open(OUT,">","output.txt");
  129.     print OUT ($tracklist);
  130.     close OUT;
  131.  
  132. }
  133.  
  134.  
  135. ############
  136. #  Genius  #
  137. ############
  138. sub genius
  139. {
  140.  
  141.     @tracks = grep {m/ Lyrics$/} @lines;
  142.     $tracklist = join("\n",@tracks);
  143.  
  144.     $tracklist =~ s/ Lyrics//g;
  145.     $tracklist =~ s/ \(Ft\. / \| /g;
  146.     $tracklist =~ s/(\|.*)\)/\1/g;
  147.     $tracklist =~ s/&/and/g;
  148.     $tracklist =~ s/(\|.*,.*) and (.*)/\1, and \2/g;
  149.  
  150.     print $tracklist;
  151.  
  152.     open(OUT,">","output.txt");
  153.     print OUT ($tracklist);
  154.     close OUT;
  155.  
  156. }
  157.  
  158. ############
  159. #   Calc   #
  160. ############
  161. # For this one, you need to have 1) tracklist copied from calc, followed by composer list (not separated by \n\n), and if there's another column, add that to the bottom of composers with an extra space inbetween (\n\n)
  162. sub calc
  163. {
  164.  
  165.     binmode(STDOUT, ":utf8");
  166.  
  167.     $numline = @lines;
  168.     $numline -= 1;
  169.  
  170.     @tracklist = grep {m/^"/} @lines;
  171.  
  172.     # remove tracklist from @lines
  173.     $numtracks = @tracklist;
  174.     $ct = 0;
  175.  
  176.     while($ct < $numtracks){
  177.         shift @lines;
  178.         $ct += 1;
  179.     }
  180.  
  181.     $data = join("\n",@lines);
  182.     @calc = split("\n\n",$data);
  183.  
  184.     # format each column from calc
  185.     $ct = 0;
  186.     foreach(@calc){
  187.         $col = $_;
  188.         chomp $col;
  189.  
  190.         $col =~ s/\n(?!fkbreak)/, /g;
  191.         $col =~ s/fkbreak/\n/g;
  192.         $col =~ s/\[[a-z]+\]//g;
  193.         $col =~ s/,\n/\n/g;
  194.  
  195.         @$ct = split(/\n/,$col);
  196.  
  197.         $ct += 1;
  198.     }
  199.  
  200.     # Push final tracklist
  201.     $num = 0;
  202.     foreach(@tracklist){
  203.         chomp $_;
  204.         $title = $_;
  205.        
  206.         @notesep = split('" \(',$title);
  207.         $title = $notesep[0];
  208.         $title =~ s/^"|"$//g;
  209.  
  210.         $note = $notesep[1];
  211.         $note =~ s/^\(|\)$//g;
  212.        
  213.         push(@final,"$title|$note|$0[$num]|$1[$num]");
  214.         $num += 1;
  215.     }
  216.  
  217.     $data = join("\n",@final);
  218.  
  219.     # print $data;
  220.  
  221.     open (OUT,">","output.txt");
  222.     print OUT ($data);
  223.     close OUT;
  224.  
  225. }
Advertisement