commit 0e1328750078df6cd0ffd6de26d82fe2ffd1e95b
Author: spesk1 <spesk@pm.me>
Date: Sat Jun 29 18:36:55 2019 -0400
Download tracks from archive.org streaming pages (mp3 only)
diff --git a/download_archive_dot_org.pl b/download_archive_dot_org.pl
new file mode 100755
index 0000000..e3f779d
--- /dev/null
+++ b/download_archive_dot_org.pl
@@ -0,0 +1,54 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+# Try and find .mp3 links in archive.org pages
+
+if ( ! defined $ARGV[0] ) {
+ print "Need to pass archive.org URL\n";
+ exit 1;
+}
+
+my $page_url = shift(@ARGV);
+my $page_content = `curl -s $page_url`;
+my @names;
+my @links;
+
+my $counter = 1;
+foreach my $line ( split("\n",$page_content) ) {
+ chomp $line;
+ if ( $line =~ m/<meta itemprop="name" content="(.*)"/ ) {
+ my $name = $counter . "_" . $1;
+ push(@names,$name);
+ $counter++;
+ } elsif ( $line =~ m/<link itemprop="associatedMedia" href="(.*\.mp3)"/ ) {
+ push(@links,$1);
+ }
+}
+
+my %link_map;
+@link_map{@names} = @links;
+
+sub make_filename($) {
+ my $name = shift;
+ my $filename;
+ open(my $fh, ">>", \$filename);
+ foreach my $char ( split("",$name) ) {
+ if ( $char =~ m/[\s->']/ ) {
+ print $fh "";
+ } else {
+ print $fh "$char";
+ }
+ }
+
+ return $filename;
+}
+
+foreach my $key ( keys %link_map ) {
+ #print "$key : $link_map{$key}\n";
+ my $filename = make_filename($key) . ".mp3";
+ #print "wget -q $link_map{$key} -O $filename\n";
+ print "Downloading $key\n";
+ system("wget -q $link_map{$key} -O $filename");
+}