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 # Some HTML -> UTF-8 stuff
89 $songname =~ s/♥/\xe2\x9d\xa4/g;
90 $songname =~ s/∀/\xe2\x88\x80/g;
91 $songname =~ s/★/\xe2\x98\x85/g;
92 $songname =~ s/é/\xc3\xa9/g;
93 $songname =~ s/<sup>2<\/sup>/\xc2\xb2/g;
95 # minimal SQL escaping
96 $songname =~ s/'/\\'/g;
99 # Insert the song only if it doesn't already exist
100 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",
101 $songname, $artist, $songname;
102 printf "INSERT INTO machinesongs SELECT ( SELECT song FROM songs WHERE LOWER(title)=LOWER('%s') ), ( SELECT machine FROM machines WHERE machinename='%s' );\n",
105 for my $t (['single', 'beginner', $sb],
106 ['single', 'standard', $ss],
107 ['single', 'difficult', $sd],
108 ['single', 'expert', $se],
109 ['single', 'challenge', $sc],
110 ['double', 'standard', $ds],
111 ['double', 'difficult', $dd],
112 ['double', 'expert', $de],
113 ['double', 'challenge', $dc]) {
114 next if (!defined($t->[2]) || $t->[2] eq '');
115 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",
116 $songname, $machine, $t->[0], $t->[1], $t->[2];