Subscription TV

Obviously you’ll have to change some directories around, but this should be the gist of it. Just put this in a crontab to run every half hour or so, and tell your torrent client (I recommend deluge) to auto-add everything in torrents directory and you should be good to go. Of course I don’t advocate doing anything illegal.  Works a little better if you make a ~/lib/autodownload/schedule/[dayofweek].txt file for each day, which contain eztv show page htmls, but append showname.html to the end line.

use strict;

my $lib = "/home/username/lib/autodownload";
my $debug = 0;
my $doublequote = "\"";
my $exclude = "zoink|torrage|720|ppv|DOCTYPE";
my $last_n = "5";
my $newline = "\n";
my $noerrors = "2>/dev/null";
my $quiet = "--quiet";
my $sd = "\\.";#slashdot
my $singlequote = "\47";
my $useragent = "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110323 Ubuntu/10.10 (maverick) Firefox/3.6.16";
my $wget_timeout = 10;
my $wget_opts = "-N --timeout=$wget_timeout --tries=1 $quiet";
my $wget_threads = 5;
my $xargs_opts = "-n 3 -P $wget_threads --no-run-if-empty";

my $today = `date +"%A"`;
my $yesterday = `date --date="-1 day" +"%A"`;
my $bash_cmd = "sed 's/\\\"/\\n/g' {}.html | /bin/grep \\\"\\\\.torrent\\\$\\\" | /bin/grep -Eiv \\\"$exclude\\\" | head -n $last_n";

system("mkdir -p ${lib}/htmls ${lib}/torrents ${lib}/torrents-work; find ${lib}/htmls -type f|xargs -r /bin/rm;");

if($debug){print "shows from eztv\n";}
system("cat ${lib}/schedule/$today.txt ${lib}/schedule/$yesterday.txt|xargs $xargs_opts wget $wget_opts --directory-prefix=${lib}/htmls;
ls ${lib}/htmls/*.html $noerrors | sed 's/${sd}html//'|xargs -n 1 -P 6 -I{} bash -c \"$bash_cmd\" | grep -Eiv \"$exclude\" | sort --random-sort | xargs $xargs_opts wget $wget_opts --directory-prefix=${lib}/torrents-work/;");

my $shows = "how i met your mother";
$shows .= "|big bang";
$shows .= "|burn notice";
$shows .= "|camelot";
$shows .= "|game thrones";
$shows .= "|glee";
$shows .= "|royal pains";
$shows .= "|spartacus";
$shows .= "|top gear";
$shows .= "|true blood";
$shows .= "|white collar";
$shows =~ s/ /./g;#what if there are no characters between words? or the words change order?

if($debug){print "shows from tpb\n";}
system("wget $wget_opts -O ${lib}/htmls/vtv.html;
perl -pe 's/$doublequote/$newline/g' ${lib}/htmls/vtv.html|grep \"${sd}torrent\"|grep -Ei \"$shows\"|grep -Eiv \"$exclude\"|xargs $xargs_opts wget $wget_opts --directory-prefix=${lib}/torrents-work");

$shows = "rip";
if($debug){print "movies from tpb\n";}
my @torrents_list = `wget $wget_opts -O ${lib}/htmls/movies.html;
perl -pe 's/$doublequote/$newline/g' ${lib}/htmls/movies.html|grep \"\\${sd}\"|grep -Eiv \"|comment|magnet|icon_image|dl\\\.gif\"|grep -Ei -B 1 \"trusted|vip\"|grep -Ei \"dvdr|bdr\"`;

while(my $title = <@torrents_list>)
	if($title eq ""){next;}
	if($debug){print "\n\n";}

system("cp -u ${lib}/torrents-work/* ${lib}/torrents $noerrors; /bin/rm -f ${lib}/torrents/*.invalid $noerrors");

sub download_film
	my $torrent = $_[0];
	my $title = $torrent;
	$title =~ s/.*\/(.*)[_\.].*rip.*/$1/ig;
	$title =~ s/\'//g;
	$title =~ s/[^A-Za-z0-9]/ /g;#cut out the crazy stuff
	$title =~ s/  / /g;
	$title =~ s/  / /g;
	$title =~ s/  / /g;
	$title =~ s/^ //g;
	$title =~ s/ $//g;
	if($debug){print "title = $title\n";}
	$title =~ s/ /%20/g;
	system ("wget $wget_opts -O ${lib}/htmls/film.html --user-agent=\"$useragent\" -e robots=off\\&q=imdb%20$title
	perl -pe 's/[${doublequote}${singlequote}]/$newline/g' ${lib}/htmls/film.html|grep -E \"\/genre\/|users have given an average vote\"|grep -Eiv \"images\"|sort --unique > ${lib}/htmls/film2.txt");
	my $rating = 0;
	my $cutoff = 7.2;#download any film at or above this rating
	my %genrecuts = (
		Action => 10,
		Adventure => 10,
		Animation => 10,
		Biography => 10,
		Comedy => 6.2,
		Crime => 10,
		Documentary => 10,
		Drama => 10,
		Family => 6.2,
		Fantasy => 6.2,
		Horror => 10,
		Mystery => 10,
		Romance => 6.2,
		SciFi => 10,
		Sport => 10,
		Thriller => 10,
		War => 10,
		);#download film in genre if above the least
		# restrictive genre score
	my @genres;
	my $genre;
	open FILE, "${lib}/htmls/film2.txt" or die $!;
	while(my $line = <FILE>)
		if($line =~ m/\/genre\/(.*)/)
			$genre = $1;
			$genre =~ s/[^A-Za-z]//;
			push(@genres, "$genre\n");
			my $tempcut = $genrecuts{$genre};
			if(! $tempcut){$tempcut = 10;}#if undefined genre, don't give benefit
			$cutoff = min($cutoff, $tempcut);
			$line =~ m/IMDb users have given an average vote of ([0-9.]*)\/10/;
			$rating = $1;
	close FILE;
	system("/bin/rm ${lib}/htmls/film.html ${lib}/htmls/film2.txt");
	if($debug){print "rating = $rating\n"; print @genres;}
	if($rating >= $cutoff)
		#print "$rating > $cutoff\n";
		#actually wget the torrent file
		if($debug){print "Downloading\n";}
		if($debug){print "title = |$torrent|\n";}
		$torrent =~ s/([\(\)])/\\$1/g;
		system("wget $wget_opts --directory-prefix=${lib}/torrents-work $torrent");
	}#else do nothing
		if($debug){print "Skipping\n";}
		#print "$rating < $cutoff\n";

sub min
	if($_[0] < $_[1]){ return $_[0];}
	return $_[1];

sub max
	if($_[0] < $_[1]){ return $_[1];}
	return $_[0];

Posted in Tech. Tags: , . 1 Comment »

Downloading flash videos on ubuntu (or anything else for that matter) using a firefox addon

Can’t get enough of those xtranormal videos of weird cgi people talking to each other? Worry no more, try this firefox addon.

Starting Deluge through SSH

I had some trouble starting an instance of deluge on a remote machine and directing the x output of deluge to that remote machine.  My solution:

export DISPLAY=:0.0 && deluge

As a sidenote combining deluge with an rss feed makes it more or less into a very clever dvr.  I recommend flexrss, which is installable as a plugin to deluge.