]> git.sesse.net Git - ccbs/blob - parse/parse-wiki-songlist.pl
169dbd26552cbde95c68eaf7dae5e7958a063256
[ccbs] / parse / parse-wiki-songlist.pl
1 #! /usr/bin/perl
2 use strict;
3 use warnings;
4
5 # Parses songlist from the DDRNO wiki
6
7 while (<>) {
8         m/
9           \|   \s* \[\[ (.*?) \]\] \s*    # song name
10           \|\| \s* \[\[ (.*?) \]\] \s*    # artist
11           \|\| \s*      (\d+(-\d+)?)  \s*    # bpm
12           \|\| \s*      (\d+)      \s*    # single beginner
13           \|\| \s*      (\d+)      \s*    # single standard
14           \|\| \s*      (\d+)      \s*    # single difficult 
15           \|\| \s*      (\d+)      \s*    # single expert
16           \|\| \s*
17           \|\| \s*      (\d+)      \s*    # double standard
18           \|\| \s*      (\d+)      \s*    # double difficult
19           \|\| \s*      (\d+)      \s*    # double expert
20          /x or next;
21          
22         my ($songname, $artist, $minbpm, $maxbpm, $sb, $ss, $sd, $se, $ds, $dd, $de) = 
23            ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);
24
25         # fix some wikisyntax ickyness :-)
26         $artist =~ s/\]\]//g;
27         $artist =~ s/\[\[//g;
28
29         # minimal SQL escaping
30         $songname =~ s/'/\\'/g;
31         $artist =~ s/'/\\'/g;
32
33         $maxbpm = $minbpm if (!defined($maxbpm));
34         ($maxbpm,$minbpm) = ($minbpm,$maxbpm) if ($maxbpm < $minbpm);
35
36         printf "INSERT INTO songs (title,artist,minbpm,maxbpm) VALUES ('%s','%s',%u,%u);\n",
37                 $songname, $artist, $minbpm, $maxbpm;
38         
39         for my $t (['single', 'beginner', $sb],
40                    ['single', 'standard', $ss],
41                    ['single', 'difficult', $sd],
42                    ['single', 'expert', $se],
43                    ['double', 'standard', $ds],
44                    ['double', 'difficult', $dd],
45                    ['double', 'expert', $de]) {
46                 printf "INSERT INTO songratings (song,playmode,difficulty,feetrating) VALUES ((SELECT song FROM songs WHERE title='%s'),'%s','%s',%u);\n",
47                         $songname, $t->[0], $t->[1], $t->[2];
48         }
49         
50 }