-
Notifications
You must be signed in to change notification settings - Fork 1
/
arte.pl
executable file
·214 lines (199 loc) · 4.49 KB
/
arte.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/perl
# Mar
# Download for arte files
# wget http://arte.tv/papi/tvguide/videos/livestream/player/D/
# v0.8.3
use strict;
use warnings;
my $file=" "; # filename to write
my $ogfolder="/arte/stream"; # folder to store
my $old=" "; # old filename to fetch the change of the mega data
my $pid;
my $meta;
my $json;
my $date;
my $startdate;
my $offset;
my $ID=0; # ID to seperate the screens and kill them
my $URL;
my $OLDURL=" ";
my $first=1;
my $rechte=0;
my $pass=0;
my $plus=0;
my $notlive=0;
my $pjson="";
my $path="";
my $purl="";
my ($mp4,$seite);
# url from arte !
my $url="http://arte.tv/papi/tvguide/videos/livestream/player/D/";
my $rtmp="rtmp://artestras.fcod.llnwd.net/a3903/o35/";
# get init url
my $text;
my $filename;
if ( `cat /var/lock/arte` )
{
print "arte collector runs !!\n";
exit 1;
}
else
{
`echo "runs" > /var/lock/arte`;
}
if ( @ARGV )
{
print "No Arguments NEEDED\n arte.pl v0.8.2\n\n";
exit 1;
}
`mkdir -p $ogfolder`;
while (1)
{
&urlparse();
if ( $file ne $old )
{
if ( $first || $file eq " " )
{
print "INPUT1 File: $file || ID: $ID || orgfile: $filename\n";
$first=0;
}
if ( `find $ogfolder -name "*$ID*.mp4" 2> /dev/null` )
{
print "exists\n";
sleep 1;
$old = $file; # for the next round
# check if rtmpdump runs
&killoldpid();
next;
}
# Wenn keine fehler oder doppelungen aufgetreten sind , dann wird aufgenommen
print "INPUT2 File: $file || ID: $ID || orgfile: $filename || ??Plus = $plus\n";
print "gotopidcheck: R:$rechte, P:$pass, PLUS:$plus, L:$notlive\n";
&killoldpid();
if ( $plus == 0 && $rechte )
{
`echo "rtmpdump -v -r \\\"rtmp://artestras.fc.llnwd.net/artestras/s_artestras_scst_geoFRDE_de?s=1320220800&h=878865258ebb8eaa437b99c3c7598998\\\" -o \\\"$ogfolder/$file\\\"" > /tmp/run.sh`;
system("screen -dmS $ID-rtmp bash /tmp/run.sh"); # start the ffmpeg dump detached
# write Metadata
chomp($meta);
print "get meta and record !! \n";
`echo \"$meta\n\n\" > $ogfolder/$file.meta.txt`;
`echo $json >> $ogfolder/$file.meta.txt`;
# debug output
print "\nruned: PID $pid ,ID $ID \n";
}
$old = $file; # for the next round
$first=1;
}
sleep 1;
}
sub killoldpid()
{
#print "get the current screen pid";
$pid = `ps aux | grep rtmpdump | grep -v grep | grep 1320220800 | sed 's/root\\s\\+//g' | cut -d " " -f1`;
chomp($pid);
if ( $pid )
{
`killall -2 rtmpdump`;
sleep 2;
if ( `ps aux | grep rtmpdump | grep -v grep | grep 1320220800 | sed 's/root\\s\\+//g' | cut -d " " -f1` )
{
#killardly
`killall rtmpdump`;
}
print "\nkilled rtmpdump with pid $pid\n";
}
}
sub urlparse()
{
$date = `date +"%Y%m%d"`;
# rest values
$rechte=0;
$pass=0;
$plus=0;
$notlive=0;
chomp($date);
$text=`wget --timeout=5 $url -qO-`;
# Json dump , debug
$json = $text;
#$path = " ";
# Prüfung ob Live rechte da sind ?
$URL = $text;
$URL =~ s/.*VUP":"//;
$URL =~ s/".*//;
$URL =~ s/{/dummy/;
if ( $URL ne $OLDURL && $URL && $URL ne "dummy" )
{
# debug url # nicht einkomentiern !!!
#$URL = "http://www.arte.tv/guide/de/016992-000/breaking-the-waves";
print "New URL : $URL\n";
$seite = `wget $URL -qO - | tail -n +630`;
print "getpage";
if ( grep{/Als Live verfügbar: nein/}$seite)
{
# wenn nicht live verfügbar
print "!KeineRechte!";
$rechte=0;
}
else
{
$rechte=1;
}
if ( grep{/Arte\+7: nein/}$seite )
{
print "!7N!\n";
$plus = 0;
}
else
{
print "!7+!\n";
$plus=1;
}
$OLDURL=$URL;
}
# text umbau so das keine probleme enstehen beim parsen
$text =~ s/ /_/g;
$text =~ s/\(/_/g;
$text =~ s/\)/_/g;
$text =~ s/\//_/g;
$text =~ s/\?//g;
$text =~ s/!//g;
$text =~ s/&//g;
#$text =~ s/\'//g;
#$text =~ s/\://g;
#$text =~ s/\"//g;
# get Arte ID
$ID = $text;
$ID =~ s/.*VPI":"//;
$ID =~ s/".*//;
if ( $ID eq "{" || !$ID )
{
$ID = 0;
}
$ID =~ s/-/_/;
# dateinamen erzeugung
$file = $text;
#print "==FILEIST:$file==";
$file =~ s/.*"VTI":"//;
$file =~ s/,.*/.mp4/;
$file =~ s/'//g;
$file =~ s/://g;
$file =~ s/"//g;
#print "==FILEIST:$file==";
$filename=$file;
$file = "$date-$ID-$file";
# Meta daten
$meta = $text;
$meta =~ s/.*"VDE":"//;
$meta =~ s/",".*//;
$meta =~ s/_/ /g;
# file backup
if (!$file)
{
$date = `date +"%Y%m%d_%H"`;
chomp($date);
$file = "$date.mp4";
print "1";
}
print ".";
}