]> git.donarmstrong.com Git - bin.git/blob - get_tweekin
added get_tweekn, parsebanlist and modified svnfix for gaim
[bin.git] / get_tweekin
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use IO::File;
7 use IO::Handle;
8 use POSIX qw(strftime);
9 use HTML::Entities qw(decode_entities);
10 use File::Basename qw(basename);
11 use DB_File;
12 use Storable qw(freeze);
13
14 my $OUTDIR=q(/home/don/records/tweekin);
15
16 my $DATE=strftime(q(%Y_%m_%d),localtime(time));
17
18 my %tw_db;
19 tie %tw_db, 'DB_File', "$OUTDIR/tweekin.db" or die "Unable to tie file: $!";
20
21 system('mkdir','-p',"$OUTDIR/tweekin_$DATE") == 0 or die "Unable to mkdir: $!";
22
23 chdir qq($OUTDIR/tweekin_$DATE);
24
25 # get weekly summary
26 system('wget','--quiet','-c','http://www.tweekin.com/weeklysummary.htm');
27
28 my $summary_fh = new IO::File q(weeklysummary.htm),'r';
29
30 my @files_to_get;
31
32 local $/ = undef;
33 my @summary = split m#\s*</tr>\s*<tr>#s, <$summary_fh>;
34
35 for my $entry (@summary) {
36      next unless $entry =~ m#<a\s+href=".+\.mp3">#;
37      my %entry;
38      @entry{qw(catnum mp3 artist title label price genre country format)}
39           = map {s#</?td[^>]*>##;
40                  if (m#<a\s+href="([^\"]+)">#) {
41                       $_ = $1;
42                  }
43                  $_ = decode_entities($_);
44                  s/^\s*//s;
45                  s/\s*$//s;
46                  $_;
47             } split m#</td>\s*<td[^>]*>#, $entry;
48      next if exists $tw_db{$entry{catnum}};
49      push @files_to_get, $entry{mp3};
50      $entry{mp3} = qq(tweekin_$DATE/).basename($entry{mp3});
51      $tw_db{$entry{catnum}} = freeze({%entry});
52 }
53
54 untie %tw_db;
55
56 my $wget = new IO::Handle;
57 open $wget, '|-',qw(wget -i - -nH -nd);
58 print {$wget} join("\n",@files_to_get);
59 close $wget;