X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=inline;f=parse%2Fparse-ddrfreak-songlist.pl;fp=parse%2Fparse-ddrfreak-songlist.pl;h=7c02865f3dd21f6552d7a1db001ccd30aee892e5;hb=0997a092b47e38af5eedff8e3c5493c55fd6e472;hp=0000000000000000000000000000000000000000;hpb=7becac72ea9ef34a7b43d65fe8461d0b2ce602e6;p=ccbs
diff --git a/parse/parse-ddrfreak-songlist.pl b/parse/parse-ddrfreak-songlist.pl
new file mode 100644
index 0000000..7c02865
--- /dev/null
+++ b/parse/parse-ddrfreak-songlist.pl
@@ -0,0 +1,105 @@
+#! /usr/bin/perl
+use strict;
+use warnings;
+
+my $machine = shift;
+die "Missing machine (first argument on the command line)" if (!defined($machine));
+
+# Parses songlist from ddrfreak.com
+
+print "begin;\n";
+
+while (<>) {
+ while (not m/
/) {
+ $_ = <>;
+ last if not $_;
+ }
+ $_ = <>;
+ last if not $_;
+ next if /Beginner<\/td>/;
+ m/ | .*? <\/td> /x or die "Parse error, line 1";
+ $_ = <>;
+ m/ | (?: )? (.*?) (?: <\/font> )? <\/td> /x or die "Parse error, line 2";
+
+ my $songname = $1;
+
+ $_ = <>;
+ m/ | (.*?) <\/td> \s* # artist
+ |
+ (?: ([0-9-] | 10) <\/a>)? # beginner single
+ <\/td>
+ /x or die "Parse error, line 3";
+
+ my ($artist, $sb) = ($1, $2);
+
+ # single standard
+ $_ = <>;
+ m/ | (?: )? (\d*) ( ?: <\/a> )? <\/td> /x
+ or die "Parse error, line 4";
+ my $ss = $1;
+
+ # single difficult
+ $_ = <>;
+ m/ | (?: )? (\d*) ( ?: <\/a> )? <\/td> /x
+ or die "Parse error, line 5";
+ my $sd = $1;
+
+ # single expert
+ $_ = <>;
+ m/ | (?: )? (\d*) ( ?: <\/a> )? <\/td> /x
+ or die "Parse error, line 6";
+ my $se = $1;
+
+ # single challenge
+ $_ = <>;
+ m/ | (?: )? (\d*) ( ?: <\/a> )? <\/td> /x
+ or die "Parse error, line 7";
+ my $sc = $1;
+
+ # double standard
+ $_ = <>;
+ m/ | (?: )? (\d*) ( ?: <\/a> )? <\/td> /x
+ or die "Parse error, line 8";
+ my $ds = $1;
+
+ # double difficult
+ $_ = <>;
+ m/ | (?: )? (\d*) ( ?: <\/a> )? <\/td> /x
+ or die "Parse error, line 9";
+ my $dd = $1;
+
+ # double expert
+ $_ = <>;
+ m/ | (?: )? (\d*) ( ?: <\/a> )? <\/td> /x
+ or die "Parse error, line 10";
+ my $de = $1;
+
+ # double challenge
+ $_ = <>;
+ m/ | (?: )? (\d*) ( ?: <\/a> )? <\/td> /x
+ or die "Parse error, line 11";
+ my $dc = $1;
+
+ # minimal SQL escaping
+ $songname =~ s/'/\\'/g;
+ $artist =~ s/'/\\'/g;
+
+ printf "INSERT INTO songs (title,artist,minbpm,maxbpm) VALUES ('%s','%s',0,0);\n",
+ $songname, $artist;
+
+ for my $t (['single', 'beginner', $sb],
+ ['single', 'standard', $ss],
+ ['single', 'difficult', $sd],
+ ['single', 'expert', $se],
+ ['single', 'challenge', $sc],
+ ['double', 'standard', $ds],
+ ['double', 'difficult', $dd],
+ ['double', 'expert', $de],
+ ['double', 'challenge', $dc]) {
+ next if (!defined($t->[2]) || $t->[2] eq '');
+ 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",
+ $songname, $machine, $t->[0], $t->[1], $t->[2];
+ }
+}
+
+printf "commit;\n";
|