]> git.sesse.net Git - ccbs/blob - parse/parse-wiki-songlist.pl
Added a front end for setting the active tournament.
[ccbs] / parse / parse-wiki-songlist.pl
1 #! /usr/bin/perl
2 use strict;
3 use warnings;
4
5 my $machine = shift;
6 die "Missing machine (first argument on the command line)" if (!defined($machine));
7
8 # Parses songlist from the DDRNO wiki
9
10 print "begin;\n";
11
12 while (<>) {
13         m/
14           \|   \s* \[\[ (.*?) \]\] \s*    # song name
15           \|\| \s* \[\[ (.*?) \]\] \s*    # artist
16           \|\| \s*      (\d+(?:-(\d+))?)  \s*    # bpm
17           \|\| \s*      (\d+)      \s*    # single beginner
18           \|\| \s*      (\d+)      \s*    # single standard
19           \|\| \s*      (\d+)      \s*    # single difficult 
20           \|\| \s*      (\d+)      \s*    # single expert
21           \|\| \s*
22           \|\| \s*      (\d+)      \s*    # double standard
23           \|\| \s*      (\d+)      \s*    # double difficult
24           \|\| \s*      (\d+)      \s*    # double expert
25          /x or next;
26          
27         my ($songname, $artist, $minbpm, $maxbpm, $sb, $ss, $sd, $se, $ds, $dd, $de) = 
28            ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);
29
30         # fix some wikisyntax ickyness :-)
31         $artist =~ s/\]\]//g;
32         $artist =~ s/\[\[//g;
33
34         # minimal SQL escaping
35         $songname =~ s/'/\\'/g;
36         $artist =~ s/'/\\'/g;
37
38         $maxbpm = $minbpm if (!defined($maxbpm));
39         ($maxbpm,$minbpm) = ($minbpm,$maxbpm) if ($maxbpm < $minbpm);
40
41         printf "INSERT INTO songs (title,artist,minbpm,maxbpm) VALUES ('%s','%s',%u,%u);\n",
42                 $songname, $artist, $minbpm, $maxbpm;
43         
44         for my $t (['single', 'beginner', $sb],
45                    ['single', 'standard', $ss],
46                    ['single', 'difficult', $sd],
47                    ['single', 'expert', $se],
48                    ['double', 'standard', $ds],
49                    ['double', 'difficult', $dd],
50                    ['double', 'expert', $de]) {
51                 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",
52                         $songname, $machine, $t->[0], $t->[1], $t->[2];
53         }
54 }
55
56 printf "commit;\n";