Created
May 24, 2021 10:32
-
-
Save cloph/b3014ee0daab5414ef32639235658331 to your computer and use it in GitHub Desktop.
perl script to parse the list of Rockmith songs from the Ubisofts website for ease of search/filtering locally
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -CSD | |
use warnings; | |
use strict; | |
use utf8; | |
use File::Slurp; | |
use XML::LibXML; | |
# works with the output as of May 2021 | |
# curl https://rocksmith.ubisoft.com/rocksmith/en-us/music/ > rockmsith_dlc.html | |
my $janky_html = read_file('rocksmith_dlc.html'); | |
my $xml_2014 = my $xml_og = my $xml_dlc = $janky_html; | |
$xml_2014 =~ s#.*<div class="tabPanel rock2014">.*?(<\?xml.*?</songs>).*#$1#s; | |
$xml_og =~ s#.*<div class="tabPanel rock">.*?(<\?xml.*?</songs>).*#$1#s; | |
$xml_dlc =~ s#.*<div class="tabPanel downloads">.*?(<\?xml.*?</songs>).*#$1#s; | |
my %bonus_songs = ( | |
"Bob Marley & The Wailers" => "Three Little Birds", | |
"Elvis Presley" => "Suspicious Minds", | |
"FUN." => "Some Nights", | |
"Jackson 5" => "I Want You Back", | |
"Outkast" => "Hey Ya!", | |
"Train" => "Drops of Jupiter", | |
); | |
my %unlockable_songs = ( | |
"Playground Kings" => "Self Trap", | |
"Versus Them" => "Impossible Dreams", | |
"Disonaur" => "Sea to Swallow", | |
"Matt Montgomery, Brian McCune and Brendan West" => "On Top of the World", | |
"Crimson" => "Don't Stop", | |
"Sabaka" => "Monochromic", | |
"Bedowyn" => "Snarling of Beasts", | |
"Hail the Sun" => "Eight Ball, Coroner's Pocket", | |
"Ubisoft" => "Rocksmith 2012 Theme", | |
"Aching Head" => "Self-Destruct", | |
"Karawan" => "Desolate Motion", | |
); | |
my @songs; | |
my %tags; | |
sub parse_songs($$){ | |
my $xml = shift; | |
my $defaultpack = shift; | |
# inline xml has unescaped ampersands… | |
$xml =~ s#&#&#g; | |
my $dom = XML::LibXML->load_xml(string => $xml); | |
foreach my $song ($dom->getElementsByTagName('song')) { | |
my %entry; | |
foreach my $node ($song->getElementsByTagName('*')) { | |
my $name = $node->nodeName; | |
my $value = $node->textContent; | |
$value =~ s#^\s+|\s+$##g; | |
$tags{$name} = 1; | |
$entry{$name} = $value; | |
} | |
$entry{'song-pack'} = $defaultpack unless($entry{'song-pack'}); | |
push @songs, \%entry; | |
} | |
} | |
sub create_song_xml($) { | |
my $songsref = shift; | |
my $xml = '<?xml version="1.0" encoding="utf-8"?><songs>'; | |
while (my ($artist, $title) = each %$songsref) { | |
$xml .= '<song><track-name>'.$title.'</track-name><artist>'.$artist.'</artist></song>'; | |
} | |
return $xml.'</songs>'; | |
} | |
parse_songs($xml_og, "Rocksmith OG"); | |
parse_songs($xml_2014, "Rocksmith 2014"); | |
parse_songs($xml_dlc, ""); | |
parse_songs(create_song_xml(\%bonus_songs), "Remastered Bonus"); | |
parse_songs(create_song_xml(\%unlockable_songs), "unlockable"); | |
# output as tab separated file | |
my @all_tags = sort(keys %tags); | |
print join("\t", @all_tags)."\n"; | |
foreach my $song (@songs) { | |
my @values = map {$song->{$_} // ""} @all_tags; | |
print join("\t", @values)."\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment