Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/perl
- ###############################################################################
- ## requires wget as an executable program
- ## for windows users: to make sure wget is in the %PATH%, download
- ## http://users.ugent.be/~bpuype/cgi-bin/fetch.pl?dl=wget/wget.exe
- ## to the %windir% folder
- ###############################################################################
- ## kelleni fog a wget is, mint futtathato file
- ## windows felhasznaloknak: hogy biztos elerheto legyen a wget, toltsd le a
- ## http://users.ugent.be/~bpuype/cgi-bin/fetch.pl?dl=wget/wget.exe -t
- ## a %windir% mappaba
- ###############################################################################
- ##### INCLUDES ##############################################################
- use strict;
- use warnings;
- ##### CONFIGS ###############################################################
- my $MAGAZIN_NUMBER; # hanyas szamu magazinrol van szo?
- # hordominta = 27
- # vilagszam = 13
- # tovabbi magazinok itt: http://inforadio.hu/magazinok/
- my $out = 'links.bat'; # ebbe a bat-ba fogja generalni a letolto scriptet.
- my $out2 = 'links_mar_letoltott.bat'; # ebbe a bat-ba fogja generalni a letolto scriptet.
- ##### GLOBALS ###############################################################
- my $fn = 'index.html@p=';
- my $FH;
- my $OUT;
- my $LAST_PAGE_NUMER = 0;
- my @commands = ();
- my @commands2 = ();
- my $basename = (split('/', $0))[-1];
- ##### SUB ###################################################################
- sub ekezetKiller($)
- {
- my $txt = shift;
- $txt =~ s/á/a/g;
- $txt =~ s/Á/A/g;
- $txt =~ s/í/i/g;
- $txt =~ s/Í/I/g;
- $txt =~ s/é/e/g;
- $txt =~ s/É/E/g;
- $txt =~ s/ö|ó|ő/o/g;
- $txt =~ s/Ö|Ő|Ó/O/g;
- $txt =~ s/ü|ú|ű/u/g;
- $txt =~ s/Ű|Ú|Ü/U/g;
- return $txt;
- }
- ##### PROGRAM CODE #########################################################
- $MAGAZIN_NUMBER = $ARGV[0];
- die "$basename <Magazin Szam>\n" unless defined($MAGAZIN_NUMBER);
- #---- search for downloaded archives ----------------------------------------
- my @downloaded;
- my $DH;
- my $dir = '.';
- opendir($DH, $dir) || die "can't opendir $dir: $!";
- while(readdir $DH)
- {
- chomp($_);
- next if (!(-f $_) || ($_ !~ m/\.mp3\z/) );
- push(@downloaded, $_);
- }
- closedir $DH;
- #---- search for the bigest archive page number ------------------------------
- `wget -q http://inforadio.hu/magazinarchivum/$MAGAZIN_NUMBER -O MN`;
- open($FH, '<', 'MN') or die $!;
- my @a = <$FH>;
- close($FH) or die $!;
- undef($FH);
- unlink 'MN' or die $!;
- chomp(@a);
- my $flag = 0;
- my $max = 0;
- foreach my $ln (@a)
- {
- $flag |= 1 if ($ln =~ m/<select id="lapozo">/);
- $flag |= 2 if ( $flag && ($ln =~ m{</select>}) );
- if ($flag == 1)
- {
- if ($ln =~ m{<option value="(\d+)">\d+</option>})
- {
- $max = $1 if $1 > $max;
- }
- }
- elsif ($flag == 3)
- {
- last;
- }
- }
- $flag = 0;
- $LAST_PAGE_NUMER = $max;
- #---- Get magazin archive and Grep the archive .mp3 -------------------------
- foreach my $n (1 .. $LAST_PAGE_NUMER)
- {
- `wget -q "http://inforadio.hu/magazinarchivum/$MAGAZIN_NUMBER/?p=$n"`;
- my $tempFile = $fn.$n;
- open($FH, '<', $tempFile) or die "$tempFile : $!";
- my @cont = <$FH>;
- close($FH) or die $!;
- undef($FH);
- unlink $tempFile or die $!;
- chomp(@cont);
- my $title;
- foreach my $ln (@cont)
- {
- if ($ln =~ m{<h4.*?>(.*?magazin) (\d+)\.? ?([^\. ]*?) (\d+)-?.*?sa,? (\d+)\.? r.*?</h4>})
- {
- my ($MAG, $y, $m, $d, $r) = ($1, $2, $3, $4, $5);
- $MAG = ekezetKiller($MAG);
- if ($m =~ m/jan/i) { $m = '01'; }
- elsif ($m =~ m/rcius/i) { $m = '02'; }
- elsif ($m =~ m/febru/i) { $m = '03'; }
- elsif ($m =~ m/prilis/i) { $m = '04'; }
- elsif ($m =~ m/jus/i) { $m = '05'; }
- elsif ($m =~ m/nius/i) { $m = '06'; }
- elsif ($m =~ m/lius/i) { $m = '07'; }
- elsif ($m =~ m/augusz/i) { $m = '08'; }
- elsif ($m =~ m/szepte/i) { $m = '09'; }
- elsif ($m =~ m/okt/i) { $m = 10; }
- elsif ($m =~ m/novem/i) { $m = 11; }
- elsif ($m =~ m/decem/i) { $m = 12; }
- $d = "0$d" if length($d) == 1;
- $title = "$MAG - ${y}_${m}_${d} - ${r}.mp3";
- print $title . "\n";
- }
- if (($title) && ($ln =~ m{playaudio\('/audio/([0-9a-f]+)/([^']+)'}i))
- {
- my ($num, $name) = ($1, $2);
- my $url = 'http://inforadio.hu/audio/' . $num . '/' . $name;
- if (grep {$title eq $_} @downloaded)
- {
- push(@commands2, "wget -c $url -O \"$title\"");
- }
- else
- {
- push(@commands, "wget -c $url -O \"$title\"");
- }
- $title = '';
- }
- }
- }
- #---- write out downloader scripts ------------------------------------------
- # hianyzo reszek
- if (@commands)
- {
- @commands = sort {$b cmp $a} @commands;
- my $command = join("\n", @commands);
- open($OUT, '>', $out) or die $!;
- print $OUT $command or die $!;
- close($OUT);
- undef($OUT);
- }
- # mar meglevo reszek
- if (@commands2 && $ARGV[1])
- {
- @commands2 = sort {$b cmp $a} @commands2;
- my $command2 = join("\n", @commands2);
- open($OUT, '>', $out2) or die $!;
- print $OUT $command2 or die $!;
- close($OUT);
- undef($OUT);
- }
Advertisement
Add Comment
Please, Sign In to add comment