8 use POSIX qw(strftime);
9 use HTML::Entities qw(decode_entities);
10 use File::Basename qw(basename);
12 use Storable qw(freeze);
16 my $OUTDIR=q(/home/don/records/tweekin);
18 my %options = (skip => 1);
19 GetOptions(\%options,'skip|s!','debug|d+','help|h|?','man|m');
23 my $DATE=strftime(q(%Y_%m_%d),localtime(time));
26 tie %tw_db, 'DB_File', "$OUTDIR/tweekin.db" or die "Unable to tie file: $!";
28 system('mkdir','-p',"$OUTDIR/tweekin_$DATE") == 0 or die "Unable to mkdir: $!";
30 chdir qq($OUTDIR/tweekin_$DATE);
33 system('wget','--quiet','-c','http://www.tweekin.com/weeklysummary.htm');
35 my $summary_fh = new IO::File q(weeklysummary.htm),'r';
40 my @summary = split m#\s*</tr>\s*<tr>#s, <$summary_fh>;
42 for my $entry (@summary) {
43 next unless $entry =~ m#<a\s+href=".+\.mp3">#;
45 @entry{qw(catnum mp3 artist title label price genre country format)}
46 = map {s#</?td[^>]*>##;
47 if (m#<a\s+href="([^\"]+)">#) {
50 $_ = decode_entities($_);
54 } split m#</td>\s*<td[^>]*>#, $entry;
55 next if (exists $tw_db{$entry{catnum}} and $options{skip});
56 push @files_to_get, $entry{mp3};
57 $entry{mp3} = qq(tweekin_$DATE/).basename($entry{mp3});
58 $tw_db{$entry{catnum}} = freeze({%entry});
63 my $wget = new IO::Handle;
64 open $wget, '|-',qw(wget -i - -nH -nd);
65 print {$wget} join("\n",@files_to_get);