-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathezrss_downloader.pl
More file actions
41 lines (37 loc) · 1.36 KB
/
ezrss_downloader.pl
File metadata and controls
41 lines (37 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl
#
use strict;
use warnings;
use Data::Dumper;
use XML::FeedPP;
use DBI;
my $url = "http://uk.microft.org/files/tvshows.xml";
my $feed = XML::FeedPP::RSS->new( $url );
my $dbh = DBI->connect( "dbi:SQLite:dbname=/tmp/downloads.db","","", { RaiseError => 1, AutoCommit => 1 });
my $create_query = "create table if not exists downloaded_torrents (filename TEXT);";
$dbh->do($create_query);
while (<>){
chomp;
(my $name, my $quality, undef) = split(/;/,$_);
my @matched = $feed->match_item( 'title' => qr/\b$name\b/i );
for my $match (@matched) {
my $link;
if ( $quality and $match->{'title'} =~ m/$quality/i ) {
$link = $match->{'link'};
} elsif ( not $quality ) {
$link = $match->{'link'};
}
if ($link) {
my $filename = $link;
$filename =~ s!.*/([^/]+.torrent)!$1!;
#print Dumper($filename);
my $downloaded = $dbh->selectall_arrayref("SELECT filename from downloaded_torrents WHERE filename = '$filename' ;");
#print Dumper($downloaded);
my $command = "wget -q -c -P ~/Dropbox/torrents/ \"$link\" ";
my $result = system($command) unless scalar @$downloaded;
$dbh->do("INSERT INTO downloaded_torrents VALUES ('$filename');") unless scalar @$downloaded;
}
}
}
$dbh->commit();
$dbh->disconnect;