]> git.donarmstrong.com Git - bin.git/blob - get_tweekin
add reset usb bus command
[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 use Getopt::Long;
15
16 my $OUTDIR=q(/home/don/records/tweekin);
17
18 my %options = (skip => 1);
19 GetOptions(\%options,'skip|s!','debug|d+','help|h|?','man|m');
20
21
22
23 my $DATE=strftime(q(%Y_%m_%d),localtime(time));
24
25 my %tw_db;
26 tie %tw_db, 'DB_File', "$OUTDIR/tweekin.db" or die "Unable to tie file: $!";
27
28 system('mkdir','-p',"$OUTDIR/tweekin_$DATE") == 0 or die "Unable to mkdir: $!";
29
30 chdir qq($OUTDIR/tweekin_$DATE);
31
32 # get weekly summary
33 system('wget','--quiet','-c','http://www.tweekin.com/weeklysummary.htm');
34
35 my $summary_fh = new IO::File q(weeklysummary.htm),'r';
36
37 my @files_to_get;
38
39 local $/ = undef;
40 my @summary = split m#\s*</tr>\s*<tr>#s, <$summary_fh>;
41
42 for my $entry (@summary) {
43      next unless $entry =~ m#<a\s+href=".+\.mp3">#;
44      my %entry;
45      @entry{qw(catnum mp3 artist title label price genre country format)}
46           = map {s#</?td[^>]*>##;
47                  if (m#<a\s+href="([^\"]+)">#) {
48                       $_ = $1;
49                  }
50                  $_ = decode_entities($_);
51                  s/^\s*//s;
52                  s/\s*$//s;
53                  $_;
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});
59 }
60
61 untie %tw_db;
62
63 my $wget = new IO::Handle;
64 open $wget, '|-',qw(wget -i - -nH -nd);
65 print {$wget} join("\n",@files_to_get);
66 close $wget;