]> git.sesse.net Git - ccbs/blobdiff - parse/parse-ddrfreak-songlist.pl
DDR Europe tournament parser now by default sets all players to Norway. Syntax fixes...
[ccbs] / parse / parse-ddrfreak-songlist.pl
index 7c02865f3dd21f6552d7a1db001ccd30aee892e5..532c182cc86de7e1bc98e35e767f480ab67f72d5 100644 (file)
@@ -80,12 +80,28 @@ while (<>) {
                or die "Parse error, line 11";
        my $dc = $1;
 
+       # Blarg, hack
+       if ($songname eq 'FANTASY') {
+               $songname = "$songname ($artist)";
+       }
+
+       # Some HTML -> UTF-8 stuff
+       $songname =~ s/&hearts;/\xe2\x9d\xa4/g;
+       $songname =~ s/&forall;/\xe2\x88\x80/g;
+       $songname =~ s/CANDY&#9733;/CANDY\xe2\x98\x86/g;  # white star, not black
+       $songname =~ s/&#9733;/\xe2\x98\x85/g;
+       $songname =~ s/&#233;/\xc3\xa9/g;
+       $songname =~ s/<sup>2<\/sup>/\xc2\xb2/g;
+
        # minimal SQL escaping
        $songname =~ s/'/\\'/g;
        $artist =~ s/'/\\'/g;
 
-       printf "INSERT INTO songs (title,artist,minbpm,maxbpm) VALUES ('%s','%s',0,0);\n",
-               $songname, $artist;
+       # Insert the song only if it doesn't already exist
+       printf "INSERT INTO songs SELECT nextval('songs_song_seq') AS song, '%s' AS title, '%s' AS artist, 0 AS minbpm, 0 AS maxbpm WHERE LOWER('%s') NOT IN ( SELECT LOWER(title) FROM songs );\n",
+               $songname, $artist, $songname;
+       printf "INSERT INTO machinesongs SELECT ( SELECT song FROM songs WHERE LOWER(title)=LOWER('%s') ), ( SELECT machine FROM machines WHERE machinename='%s' );\n",
+               $songname, $machine;
        
        for my $t (['single', 'beginner', $sb],
                    ['single', 'standard', $ss],
@@ -97,7 +113,7 @@ while (<>) {
                    ['double', 'expert', $de],
                    ['double', 'challenge', $dc]) {
                next if (!defined($t->[2]) || $t->[2] eq '');
-               printf "INSERT INTO songratings (song,machine,playmode,difficulty,feetrating) VALUES ((SELECT song FROM songs WHERE title='%s'),(SELECT machine FROM machines WHERE machinename='%s'),'%s','%s',%u);\n",
+               printf "INSERT INTO songratings (song,machine,playmode,difficulty,feetrating) VALUES ((SELECT song FROM songs WHERE LOWER(title)=LOWER('%s')),(SELECT machine FROM machines WHERE machinename='%s'),'%s','%s',%u);\n",
                        $songname, $machine, $t->[0], $t->[1], $t->[2];
        }
 }