Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Grab txt tracklist from various sites and formats it for f2k
- # Supported sites:
- # Bandcamp
- # Genius
- # RYM
- # Wiki
- # Get raw text
- open(FILE,"<","input.txt");
- while(<FILE>){
- chomp $_;
- push(@lines,$_);
- }
- close FILE;
- $data = join("",@lines);
- chomp $data;
- #######################################################################
- # Determine where the list came from and send to appropriate subroutine
- if ($data =~ m/\d+:\d+\t+/){
- # copied from bandcamp tracklist
- print("\nMatched Bandcamp!\n\n");
- bandcamp();
- } elsif ($lines[0] =~ m/ \d+:\d+$/){
- # copied from RYM tracklist
- print("\nMatched RateYourMusic!\n\n");
- rym();
- } elsif ($lines[0] =~ m/^\d+\.\t"/){
- # copied from wiki tracklist
- print("\nMatched wiki!\n\n");
- wiki();
- } elsif ($data =~ m/ Lyrics\d+/g){
- # copied from Genius album tracklist
- print("\nMatched Genius!\n\n");
- genius();
- } elsif ($data =~ m/fkbreak/g){
- # tracklist, composer, producer data formatted from libreoffice calc
- print("\nMatched LibreOffice Calc!\n\n");
- calc();
- }
- ############
- # Bandcamp #
- ############
- sub bandcamp
- {
- @tracks = grep {m/ \d+:\d+$/} @lines;
- foreach(@tracks){
- $line = $_; chomp $line;
- $line =~ s/ \d+:\d+$//g;
- push(@output,$line);
- }
- $tracklist = join("\n",@output);
- chomp $tracklist;
- print $tracklist;
- open(OUT,">","output.txt");
- print OUT ($tracklist);
- close OUT;
- }
- ############
- # RYM #
- ############
- sub rym
- {
- @tracks = grep {m/^\d+ |\w\d /} @lines;
- foreach(@tracks){
- $line = $_; chomp $line;
- $line =~ s/^\d+ |\w\d //g;
- $line =~ s/ \d+:\d*$//g;
- push(@output,$line);
- }
- $tracklist = join("\n",@output);
- chomp $tracklist;
- print $tracklist;
- open(OUT,">","output.txt");
- print OUT ($tracklist);
- close OUT;
- }
- ############
- # Wiki #
- ############
- sub wiki
- {
- foreach(@lines){
- chomp $_;
- $title = $_;
- $title =~ s/^\d+\.\t|\t\d+:\d+$//g;
- @notesep = split('" \(',$title);
- $title = $notesep[0];
- $title =~ s/^"|"$//g;
- $note = $notesep[1];
- $note =~ s/^\(|\)$//g;
- push(@output,"$title|$note");
- }
- $tracklist = join("\n",@output);
- chomp $tracklist;
- print $tracklist;
- open(OUT,">","output.txt");
- print OUT ($tracklist);
- close OUT;
- }
- ############
- # Genius #
- ############
- sub genius
- {
- @tracks = grep {m/ Lyrics$/} @lines;
- $tracklist = join("\n",@tracks);
- $tracklist =~ s/ Lyrics//g;
- $tracklist =~ s/ \(Ft\. / \| /g;
- $tracklist =~ s/(\|.*)\)/\1/g;
- $tracklist =~ s/&/and/g;
- $tracklist =~ s/(\|.*,.*) and (.*)/\1, and \2/g;
- print $tracklist;
- open(OUT,">","output.txt");
- print OUT ($tracklist);
- close OUT;
- }
- ############
- # Calc #
- ############
- # 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)
- sub calc
- {
- binmode(STDOUT, ":utf8");
- $numline = @lines;
- $numline -= 1;
- @tracklist = grep {m/^"/} @lines;
- # remove tracklist from @lines
- $numtracks = @tracklist;
- $ct = 0;
- while($ct < $numtracks){
- shift @lines;
- $ct += 1;
- }
- $data = join("\n",@lines);
- @calc = split("\n\n",$data);
- # format each column from calc
- $ct = 0;
- foreach(@calc){
- $col = $_;
- chomp $col;
- $col =~ s/\n(?!fkbreak)/, /g;
- $col =~ s/fkbreak/\n/g;
- $col =~ s/\[[a-z]+\]//g;
- $col =~ s/,\n/\n/g;
- @$ct = split(/\n/,$col);
- $ct += 1;
- }
- # Push final tracklist
- $num = 0;
- foreach(@tracklist){
- chomp $_;
- $title = $_;
- @notesep = split('" \(',$title);
- $title = $notesep[0];
- $title =~ s/^"|"$//g;
- $note = $notesep[1];
- $note =~ s/^\(|\)$//g;
- push(@final,"$title|$note|$0[$num]|$1[$num]");
- $num += 1;
- }
- $data = join("\n",@final);
- # print $data;
- open (OUT,">","output.txt");
- print OUT ($data);
- close OUT;
- }
Advertisement