Difference between revisions of "Setup Automatic podcast download"

From LinuxMCE
Jump to: navigation, search
(New page: NOTE TO READERS - I have written this article and this has worked for me. I am not a LinuxMCE expert. I suggest someone who is looks over this and removes this message if this method looks...)
 
Line 17: Line 17:
 
I created two php files in the /home/public/data/audio/podcasts directory.  
 
I created two php files in the /home/public/data/audio/podcasts directory.  
 
The first to get the Security Now podcast called get_security_now.php:
 
The first to get the Security Now podcast called get_security_now.php:
<?PHP
+
<?PHP
 
function GetFileName($p) {
 
function GetFileName($p) {
 
return substr($p,strrpos($p,"/")+1);
 
return substr($p,strrpos($p,"/")+1);
Line 31: Line 31:
 
foreach($xml->channel->item as $item){
 
foreach($xml->channel->item as $item){
 
   print "Title:" . $item->title . "\n";
 
   print "Title:" . $item->title . "\n";
// print "Link:" . $item->link . "\n";
+
// print "Link:" . $item->link . "\n";
 
$fn = $fp . GetFileName($item->link);
 
$fn = $fp . GetFileName($item->link);
 
if (file_exists($fn)) {
 
if (file_exists($fn)) {
Line 43: Line 43:
 
}
 
}
 
print "\n";
 
print "\n";
// var_dump($xml->channel->item);
+
// var_dump($xml->channel->item);
 
 
  
 
print "End of get_pod.php\n\n";
 
print "End of get_pod.php\n\n";
  
?>
+
?>
 
The second to get the TWIT podcast called get_twit.php:
 
The second to get the TWIT podcast called get_twit.php:
<?PHP
+
<?PHP
 
function GetFileName($p) {
 
function GetFileName($p) {
 
return substr($p,strrpos($p,"/")+1);
 
return substr($p,strrpos($p,"/")+1);
Line 64: Line 64:
 
foreach($xml->channel->item as $item){
 
foreach($xml->channel->item as $item){
 
   print "Title:" . $item->title . "\n";
 
   print "Title:" . $item->title . "\n";
// print "Link:" . $item->link . "\n";
+
// print "Link:" . $item->link . "\n";
 
$fn = $fp . GetFileName($item->link);
 
$fn = $fp . GetFileName($item->link);
 
if (file_exists($fn)) {
 
if (file_exists($fn)) {
Line 77: Line 77:
 
}
 
}
 
print "\n";
 
print "\n";
// var_dump($xml->channel->item);
+
// var_dump($xml->channel->item);
 
 
  
 
print "End of get_pod.php\n\n";
 
print "End of get_pod.php\n\n";
  
?>
+
?>
 
You can test these scripts.
 
You can test these scripts.
 
Type "php /home/public/data/audio/podcasts/get_security_now.php"
 
Type "php /home/public/data/audio/podcasts/get_security_now.php"
Line 90: Line 90:
 
Now you can manually type these commands at the prompt to download new items but it would be nice for this to happen automatically. To do this you can add this as a daily cron task.
 
Now you can manually type these commands at the prompt to download new items but it would be nice for this to happen automatically. To do this you can add this as a daily cron task.
 
First create a bash script called get_pods.sh into the /home/public/data/audio/podcasts/ directory:
 
First create a bash script called get_pods.sh into the /home/public/data/audio/podcasts/ directory:
#!/bin/sh
+
#!/bin/sh
 
+
php /home/public/data/audio/podcasts/get_security_now.php
+
php /home/public/data/audio/podcasts/get_security_now.php
php /home/public/data/audio/podcasts/get_twit.php
+
php /home/public/data/audio/podcasts/get_twit.php
  
 
Once you have created this file type the following command to make it executable:
 
Once you have created this file type the following command to make it executable:
chmod 777 /home/public/data/audio/podcasts/get_pods.sh
+
chmod 777 /home/public/data/audio/podcasts/get_pods.sh
 
This allows cron to use it.
 
This allows cron to use it.
 
Finally create a link to this in the cron.daily folder to make this run daily:
 
Finally create a link to this in the cron.daily folder to make this run daily:
sudo ln -s /home/public/data/audio/podcasts/get_pods.sh /etc/cron.daily/rjm_get_podcasts
+
sudo ln -s /home/public/data/audio/podcasts/get_pods.sh /etc/cron.daily/rjm_get_podcasts
 
=== Step4 - Add your own podcasts===
 
=== Step4 - Add your own podcasts===

Revision as of 13:55, 16 May 2009

NOTE TO READERS - I have written this article and this has worked for me. I am not a LinuxMCE expert. I suggest someone who is looks over this and removes this message if this method looks ok.

I listen to podcasts and I would like my core to automatically download podcasts when they become availible, for me to listen to later. I didn't want a whole RSS reader program, just something to downlaod podcasts, so I set this up using a php and a bash script. I needed to use php because it has features to phrase xml files. This enables it to read the RSS feed for the podcast. I used bash to create a simple script which cron could run.

Steps to follow

In this example I will set up automatic downloads of two podcases. Security Now and This week in Tech. After the end of the instruction set I show how you can add your own podcasts to this. This method checks if files are already downloaded and only downloads new ones.

Step 1 - Create directory

The first step is to create the relevant directories. I did this on my code. Log in as the linuxmce user cd /home/public/data/audio/ mkdir podcasts cd podcasts mkdir security_now mkdir twit

Step 2 - Create and test PHP catching script

I created two php files in the /home/public/data/audio/podcasts directory. The first to get the Security Now podcast called get_security_now.php:

<?PHP

function GetFileName($p) { return substr($p,strrpos($p,"/")+1); };

print "Starting to get the security now POD Casts\n";

$fp = "/home/public/data/audio/podcasts/security_now/";

$request_url = "http://leoville.tv/podcasts/sn.xml"; $xml = simplexml_load_file($request_url) or die("feed not loading");

foreach($xml->channel->item as $item){

  		print "Title:" . $item->title . "\n";
//		print "Link:" . $item->link . "\n";

$fn = $fp . GetFileName($item->link); if (file_exists($fn)) { print " Already Downloaded\n"; } else { $ds = "wget -P". $fp . " '" . $item->link . "'"; $foo = system($ds,$output); print " Downlaoded\n"; }; // print "FileName:$fn\n"; } print "\n";

//	var_dump($xml->channel->item);


print "End of get_pod.php\n\n";

?>

The second to get the TWIT podcast called get_twit.php:

<?PHP

function GetFileName($p) { return substr($p,strrpos($p,"/")+1); };

print "Starting to get the TWIT (This week in Tech) POD Casts\n";

$fp = "/home/public/data/audio/podcasts/twit/";

$request_url = "http://leoville.tv/podcasts/twit.xml"; $xml = simplexml_load_file($request_url) or die("feed not loading");

foreach($xml->channel->item as $item){

  		print "Title:" . $item->title . "\n";
//		print "Link:" . $item->link . "\n";

$fn = $fp . GetFileName($item->link); if (file_exists($fn)) { print " Already Downloaded\n"; } else { $ds = "wget -P". $fp . " '" . $item->link . "'"; $foo = system($ds,$output); print " Downlaoded\n"; }; // print "FileName:$fn\n"; // die("$ds\nTest End\n"); } print "\n";

//	var_dump($xml->channel->item);


print "End of get_pod.php\n\n";

?>

You can test these scripts. Type "php /home/public/data/audio/podcasts/get_security_now.php" When this is done goto the security_now directory and check the files have appeared Simularly "php /home/public/data/audio/podcasts/get_twit.php" should put the files into the twit directory.

Step 3 - Make corn check for new items daily

Now you can manually type these commands at the prompt to download new items but it would be nice for this to happen automatically. To do this you can add this as a daily cron task. First create a bash script called get_pods.sh into the /home/public/data/audio/podcasts/ directory:

#!/bin/sh

php /home/public/data/audio/podcasts/get_security_now.php
php /home/public/data/audio/podcasts/get_twit.php

Once you have created this file type the following command to make it executable:

chmod 777 /home/public/data/audio/podcasts/get_pods.sh

This allows cron to use it. Finally create a link to this in the cron.daily folder to make this run daily:

sudo ln -s /home/public/data/audio/podcasts/get_pods.sh /etc/cron.daily/rjm_get_podcasts

Step4 - Add your own podcasts