MOVED!
This site is moved to niranjan.prithviraj.org
This site is no longer maintained.
I got content and money to host it myself.
It’s just better that way for everyone.
Automatic Torrent download from eztv_it
If you live on this side on the Atlantic or the Pacific, TV buffs all face a problem. We do not get the TV shows that air in the US! Even if the show does air here, it’s an ancient season which has been out in Blu Ray since the cave men.
However, thankfully to the internet, we can always torrent download the TV show anytime we want. But wait,
1. there’s keeping track of all the TV shows you watch,
2. remembering to download the episode after it airs,
3. sifting through torrent sites in search for the torrent that actually works.
Thats a lot of work especially since we don’t have TiVo either. But what are computers for?
I present here my solution to automate this entire process of,
1. downloading your tv shows as soon as they are available online,
2. not having to sift through all the torrent sites,
3. have them downloaded even if you forget.
What you will need
1. One laptop running linux.
2. One internet connection.
3. One php5 installation.
4. One crontab
Go to ez_tv’s account on Twitter. You will notice almost every update is a link to a torrent for a tv show. You can find almost every show here, including one’s that don’t air in the US. But the problem is, you would have to search the posts for the TV show you are looking for. This can be hell, especially if you try to use it a couple days after your TV show has aired.
Fortunately, Twitter provides apis, which provide unprotected tweets as RESTful services. This basically means, you can get all those posts as raw text and write a program which will sift through it and get your favorite TV shows.
I used php to write a quick hack on being able to do this. I also used this plugin for making REST calls to twitter.
You can find my code here:
<?php
require_once('rest.php');
$rws = new RestServiceClient('http://twitter.com/statuses/user_timeline.json');
user_id = 37039456;#eztv_it user_id
$rws->count = 20;
$rws->excuteRequest();
$json = $rws->getResponse();
$decodejson = json_decode($json);
#XYZ is the regex that gets the right show name you are looking for.
$shows = array('/XYZ */');
foreach($decodejson as $text){
foreach($shows as $showregx){
if(preg_match($showregx,$text->text,$showarr)){
$stringarr = explode('-',$text->text);
#get the torrent link
$splitter = '/http*/';
$matches = preg_split($splitter,$text->text);
#get filename for downloaded torrent
$filenamecreator = '/.it\//';
$filename = preg_split($filenamecreator,$matches[1]);
#download file and save it. make sure this dir has write permissions
$myFile = '/Downloads/'.$filename[1];
$file_contents = file_get_contents('http'.$matches[1]);
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh,$file_contents);
}
}
}
#add to transmission and start the download! yeayy...
$dir = '/Downloads/twitter';
$dh = opendir($dir);
$filestoaddtotransmission;
while(false !== ($torrfile = readdir($dh))){
if($torrfile != '.' && $torrfile != '..')
$filestoaddtotransmission = $filestoaddtotransmission.' '.$dir.'/'.$torrfile;
}
`transmission $filestoaddtotransmission &`;
closedir($dh);
?>
All you need to do next is to pop this in your crontab.
Open up crontab by typing
your-terminal-prompt:~$crontab -e
You should see like this (if its the first time, it will ask your choice of editor to view it in):
# m h dom mon dow command
Check out crontab on wikipedia to know how to put entries here. You should run the php script from the command line (with php command) and not using wget through your local webserver. This is because, it’s a little trickier to set up backtick operator to run with GUI programs like transmission, when the script is running through a web server.
:wq
Jquery for beginners – 1
This is for jquery beginners.
Recently I was working with jquery for some very simple and straighforward ajax. It was so simple, that i created this post with QuickPress.
One of the fields in my Ajax request was a phone number containing atleast one ‘+’ sign. For some reason, the plus sign was never actually part of the request string I was sending. (I found this out after a good deal of investigation). This cascaded and caused a lot of other problems , server side validation stopped working and such…
The simple and cool thing with Jquery is that, if ‘dataType’ attribute of the ajax request is left blank, a preliminary clean up of the data string/hash is done. Therefore ff you have plus signs in your data string, they will be cleaned up.
To stop this from happening, set the ‘dataType’ attribute to ‘text’ and everything will be fine again.