wollte gestern was aus der ARD-Mediathek herunterladen. Vor einiger Zeit gab es dazu dieses Skript. Der Autor schreibt, das sei nicht mehr nötig, weil man mit einer ID aus der URL einfach so herunterladen könne. Genauer geht das so:
Code: Alles auswählen
1. URL Mediathek, z.B. "http://www.ardmediathek.de/tv/Der-Blaue-Planet/Der-Blaue-Planet-1/Das-Erste/Video?bcastId=49529922&documentId=50144564".
2. Man braucht die documentId, hier also 50144564.
3. Dann lädt man eine Textdatei im JSON-Format herunter:
wget 'http://www.ardmediathek.de/play/media/50144564'
4. In dieser Datei hält man nach .mp4-Dateien Ausschau.
Code: Alles auswählen
show_ardstreams.pl 'http://www.ardmediathek.de/tv/Der-Blaue-Planet/Der-Blaue-Planet-1/Das-Erste/Video?bcastId=49529922&documentId=50144564'
Code: Alles auswählen
#!/usr/bin/perl
use warnings;
use strict;
# show_ardstreams.pl, abgdf@gmx.net
# GNU GPL, V.2, 2018
use LWP::Simple;
use Cwd;
my $MEDIATHEKURL = "http://www.ardmediathek.de/tv/Der-Blaue-Planet/Der-Blaue-Planet-1/Das-Erste/Video?bcastId=49529922&documentId=50144564";
if ($#ARGV < 0) {
print "\nUsage: show_ardstreams.pl MEDIATHEKURL\n\n";
exit 1;
};
$MEDIATHEKURL = $ARGV[0];
chomp($MEDIATHEKURL);
if ($MEDIATHEKURL !~ /documentId=/) {
print "\nError: '/documentId=' has to be in MEDIATHEKURL. Aborting.\n\n";
exit 2;
}
my $thisdir = getcwd();
my $tempdir = "$thisdir/temp";
sub getDocumentId {
my $mediathekurl = shift;
my @a = split(/documentId=/, $mediathekurl);
my $b = $a[1];
chomp($b);
return $b;
}
sub getBcastId {
my $mediathekurl = shift;
my @a = split(/bcastId=/, $mediathekurl);
my $b = $a[1];
@a = split(/\&documentId=/, $b);
$b = $a[0];
return $b;
}
sub disruptJson {
my $json = shift;
$json =~ s/https\://g;
$json =~ s/http\://g;
my @a = split(/\n/, $json);
my $i; my $u; my @b; my @c; my @d; my @e;
my $streamurl;
@b = ();
# Split the Json at ":" and put the elements into a list:
for $i (@a) {
@c = split(/\:/, $i);
for $u (@c) {
push(@b, $u);
}
}
# Split the broken elements at "," and put the remains into a list:
for $i (@b) {
@c = split(/\,/, $i);
for $u (@c) {
push(@d, $u);
}
}
# Only keep elements with ".mp4":
@e = grep(/\.mp4/, @d);
@b = ();
# Extract element-parts between quotes, "........":
for $i (@e) {
if ($i =~ m/"([^"]*)\.mp4/) {
$streamurl = "http:$1.mp4";
push(@b, $streamurl);
}
}
return @b;
}
my $documentid = getDocumentId($MEDIATHEKURL);
my $bcastid = getBcastId($MEDIATHEKURL);
# The JSON with the streams is found at this URL:
my $json = get("http://www.ardmediathek.de/play/media/$documentid");
my @streamlist = disruptJson($json);
if ($#streamlist == -1) {
print "Error: No streams found. Something's wrong.\n";
exit 3;
}
print "\n";
print "Stream-list:\n";
for my $i (@streamlist) {
print "$i\n";
}
print "\n";