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