#!/usr/bin/perl # download radio nederland files. $archive_url = "http://download.omroep.nl/rnw/smac"; @day_lists = ( [ 'sp_contra.mp3', 'sp_voz.mp3' ], ['sp_series.mp3', 'sp_archivos.mp3', 'sp_nuestra.mp3', 'sp_presenta.mp3'], ['voces.mp3'], ['sp_interactivo.mp3', 'sp_europahoy.mp3'], ['sp_radioenlace.mp3', 'sp_aler.mp3'], ['sp_radipaz.mp3', 'sp_sintesis.mp3','sp_noticiasnl_sat.mp3'], ['sp_noticiasnl_sun.mp3', 'sp_cartas.mp3', 'esp_ciencia.mp3', 'sp_radionovela.mp3'], ); sub mssg { my $m = shift; print $m,"\n";} sub dosys { my $m = shift; print $m,"\n"; my $ans = system $m; if ($ans == 2) { # user hit ctrl-c mssg("lftp killed, exiting ..."); exit(1); } } $date = `date --iso-8601`; chomp $date; # yyyy-mm-dd # day of week from 1..7 $number_date = `date +'%u'`; chomp $number_date; mssg "weekday number $number_date"; # weekdir is dir for current week starting on monday # lastweekedir is dir for monday before that # determine weekly dir , either last monday or today if its monday if ( $number_date != 1 ) { $weekdir = `date --iso-8601 -d "last Monday"`; $lastweekdir = `date --iso-8601 -d "2 weeks ago monday"`; chomp $weekdir; chomp $lastweekdir; $weekdir = "w-" . $weekdir; $lastweekdir = "w-" . $lastweekdir; } else { # if today is monday $weekdir = "w-" . $date; $lastweekdir = `date --iso-8601 -d "last Monday"`; chomp $lastweekdir; $lastweekdir = "w-" . $lastweekdir; } $daydir = "d-" . $date; mssg "autoradned: today's date $date"; mssg "weekday number $number_date"; mssg "Weekly dir is $weekdir"; mssg "Last week weekly dir is $lastweekdir"; sub create_dirs { if ( not -e $weekdir ) { dosys "mkdir $weekdir"; } if ( not -e $lastweekdir ) { dosys "mkdir $lastweekdir"; } if (not -e $daydir ) { dosys "mkdir $daydir"; } } sub get_file_str { my $file = shift; return "lftp -c \" reget $archive_url/$file \" "; } # get noticias; published daily sub get_noticias { my $file = "noticias.mp3"; if ( not -e "$daydir/$file" ) { mssg("*** $daydir/$file not there. Getting it..."); } dosys "cd $daydir; " . get_file_str($file); } # get files published every weekday sub get_weekday { my @files = ("esp_matinal.mp3", "sp_irn.mp3", "sp_resumen.mp3"); get_list($daydir, @files); } # get files that are specific to a day of week number # 1=monday sub get_day_number { my $day_number = shift; } # get a list of files and put in dir. sub get_list { my $dir = shift; my @files = @_; my $file; foreach $file (@files) { if ( not -e "$dir/$file" ) { mssg("*** $dir/$file not there. Getting it..."); } dosys "cd $dir; " . get_file_str($file); } } # get files published on specific dates, but # not todays because maybe it is not published. sub get_weekly_except_today { my $i; my $dir; for($i=1;$i<=7; $i++) { if ($i == $number_date ) { mssg "Skipping files for today '$i'"; next; } if ( $number_date > $i ) { $dir = $weekdir; } else { $dir = $lastweekdir; } mssg "Getting day $i into $dir"; get_list($dir, @{$day_lists[$i-1]}); } } create_dirs(); get_noticias(); # this file comes out everyday get_weekday(); # only weekdays, every weekday get_weekly_except_today();