-
Notifications
You must be signed in to change notification settings - Fork 1
/
play.pl
executable file
·95 lines (76 loc) · 2.26 KB
/
play.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env perl
use LWP::Simple;
use HTML::TreeBuilder::XPath;
use feature "switch";
sub pageRequest {
my ($url) = @_;
my $content = get $url;
die "Can't fetch url $url\n" unless defined $content;
return $content;
}
sub findXPath {
my ($xml,$xpath) = @_;
my $tree = HTML::TreeBuilder::XPath->new;
$tree->parse($xml);
my @nodeset = $tree->findnodes($xpath);
return @nodeset;
}
sub extractWebmStream {
my ($content) = @_;
my @playercontrol = findXPath($content, '//ul[@id="downloadBox"]/li[position()=4]/a');
my $streampath = @playercontrol[0]->attr('href');
return $streampath;
}
sub getMainPageContent {
my $tagesschaumain = 'http://www.tagesschau.de';
my $content = pageRequest($tagesschaumain);
return $content;
}
sub findLast20Url {
my $content = getMainPageContent();
my @nodes = findXPath($content, '//select[@id="navSendungen"]');
my $url = @nodes[0]->content()->[0]->attr('value');
return $url;
}
sub findLast20Stream {
my $flashpageurl = findLast20Url();
my $flashpage = pageRequest($flashpageurl);
my $streampath = extractWebmStream($flashpage);
return $streampath;
}
sub findLiveStream {
return "http://www.tagesschau.de/commons/include/multimedia/style_video_wmv_live_cover.jsp?res=high&typ=1"
}
sub findRecentUrl {
my $content = getMainPageContent();
my @lastshownode = findXPath($content,'//div[@id="sendungenLeft"]/ul/li[position()=3]/a');
my $lastshowurl = @lastshownode[0]->attr('href');
return $lastshowurl;
}
sub findRecentStream {
my $recentpageurl = findRecentUrl();
my $recentpage = pageRequest($recentpageurl);
my $streampath = extractWebmStream($recentpage);
return $streampath;
}
sub mplayerPlay {
my ($url) = @_;
exec("mplayer '$url'");
}
my ($toplay) = @ARGV;
if (!$toplay) {
print "How to use:\n";
print "play.pl <streamDescription>\n";
print "Possible stream Descriptions:\n";
print "20 : recent 20:00 show\n";
print "live : livestream\n";
print "recent : most recent show recorded\n";
} else {
my $url;
given ($toplay) {
$url = findLast20Stream() when "20";
$url = findLiveStream() when "live";
$url = findRecentStream() when "recent";
}
mplayerPlay($url);
}