]> git.donarmstrong.com Git - bin.git/blobdiff - get_tweekin
added get_tweekn, parsebanlist and modified svnfix for gaim
[bin.git] / get_tweekin
diff --git a/get_tweekin b/get_tweekin
new file mode 100755 (executable)
index 0000000..68be38f
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use IO::File;
+use IO::Handle;
+use POSIX qw(strftime);
+use HTML::Entities qw(decode_entities);
+use File::Basename qw(basename);
+use DB_File;
+use Storable qw(freeze);
+
+my $OUTDIR=q(/home/don/records/tweekin);
+
+my $DATE=strftime(q(%Y_%m_%d),localtime(time));
+
+my %tw_db;
+tie %tw_db, 'DB_File', "$OUTDIR/tweekin.db" or die "Unable to tie file: $!";
+
+system('mkdir','-p',"$OUTDIR/tweekin_$DATE") == 0 or die "Unable to mkdir: $!";
+
+chdir qq($OUTDIR/tweekin_$DATE);
+
+# get weekly summary
+system('wget','--quiet','-c','http://www.tweekin.com/weeklysummary.htm');
+
+my $summary_fh = new IO::File q(weeklysummary.htm),'r';
+
+my @files_to_get;
+
+local $/ = undef;
+my @summary = split m#\s*</tr>\s*<tr>#s, <$summary_fh>;
+
+for my $entry (@summary) {
+     next unless $entry =~ m#<a\s+href=".+\.mp3">#;
+     my %entry;
+     @entry{qw(catnum mp3 artist title label price genre country format)}
+         = map {s#</?td[^>]*>##;
+                if (m#<a\s+href="([^\"]+)">#) {
+                     $_ = $1;
+                }
+                $_ = decode_entities($_);
+                s/^\s*//s;
+                s/\s*$//s;
+                $_;
+           } split m#</td>\s*<td[^>]*>#, $entry;
+     next if exists $tw_db{$entry{catnum}};
+     push @files_to_get, $entry{mp3};
+     $entry{mp3} = qq(tweekin_$DATE/).basename($entry{mp3});
+     $tw_db{$entry{catnum}} = freeze({%entry});
+}
+
+untie %tw_db;
+
+my $wget = new IO::Handle;
+open $wget, '|-',qw(wget -i - -nH -nd);
+print {$wget} join("\n",@files_to_get);
+close $wget;