6 die "Missing machine (first argument on the command line)" if (!defined($machine));
8 # Parses songlist from ddrfreak.com
13 while (not m/<tr bgcolor=\#CFDCF8>/) {
19 next if /<td bgcolor=\#DFECF8>Beginner<\/td>/;
20 m/ <td \s* align=center> .*? <\/td> /x or die "Parse error, line 1";
22 m/ <td> (?: <font \s* color=.*?> )? (.*?) (?: <\/font> )? <\/td> /x or die "Parse error, line 2";
27 m/ <td \s* align=center> (.*?) <\/td> \s* # artist
28 <td \s* align=center \s* bgcolor=\#DFECF8>
29 (?: <a \s* href=" .*? "> ([0-9-] | 10) <\/a>)? # beginner single
31 /x or die "Parse error, line 3";
33 my ($artist, $sb) = ($1, $2);
37 m/ <td \s* align=center \s* bgcolor=\#CFDCF8> (?: <a \s* href=" .*? "> )? (\d*) ( ?: <\/a> )? <\/td> /x
38 or die "Parse error, line 4";
43 m/ <td \s* align=center \s* bgcolor=\#BFCCF8> (?: <a \s* href=" .*? "> )? (\d*) ( ?: <\/a> )? <\/td> /x
44 or die "Parse error, line 5";
49 m/ <td \s* align=center \s* bgcolor=\#AFBCF8> (?: <a \s* href=" .*? "> )? (\d*) ( ?: <\/a> )? <\/td> /x
50 or die "Parse error, line 6";
55 m/ <td \s* align=center \s* bgcolor=\#9FACF8> (?: <a \s* href=" .*? "> )? (\d*) ( ?: <\/a> )? <\/td> /x
56 or die "Parse error, line 7";
61 m/ <td \s* align=center \s* bgcolor=\#CFDCF8> (?: <a \s* href=" .*? "> )? (\d*) ( ?: <\/a> )? <\/td> /x
62 or die "Parse error, line 8";
67 m/ <td \s* align=center \s* bgcolor=\#BFCCF8> (?: <a \s* href=" .*? "> )? (\d*) ( ?: <\/a> )? <\/td> /x
68 or die "Parse error, line 9";
73 m/ <td \s* align=center \s* bgcolor=\#AFBCF8> (?: <a \s* href=" .*? "> )? (\d*) ( ?: <\/a> )? <\/td> /x
74 or die "Parse error, line 10";
79 m/ <td \s* align=center \s* bgcolor=\#9FACF8> (?: <a \s* href=" .*? "> )? (\d*) ( ?: <\/a> )? <\/td> /x
80 or die "Parse error, line 11";
84 if ($songname eq 'FANTASY') {
85 $songname = "$songname ($artist)";
88 # minimal SQL escaping
89 $songname =~ s/'/\\'/g;
92 # Insert the song only if it doesn't already exist
93 printf "INSERT INTO songs SELECT nextval('songs_song_seq') AS song, '%s' AS title, '%s' AS artist, 0 AS minbpm, 0 AS maxbpm WHERE '%s' NOT IN ( SELECT title FROM songs );\n",
94 $songname, $artist, $songname;
95 printf "INSERT INTO machinesongs SELECT ( SELECT song FROM songs WHERE title='%s' ), ( SELECT machine FROM machines WHERE machinename='%s' );\n",
98 for my $t (['single', 'beginner', $sb],
99 ['single', 'standard', $ss],
100 ['single', 'difficult', $sd],
101 ['single', 'expert', $se],
102 ['single', 'challenge', $sc],
103 ['double', 'standard', $ds],
104 ['double', 'difficult', $dd],
105 ['double', 'expert', $de],
106 ['double', 'challenge', $dc]) {
107 next if (!defined($t->[2]) || $t->[2] eq '');
108 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",
109 $songname, $machine, $t->[0], $t->[1], $t->[2];