-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmms.pl
112 lines (104 loc) · 2.79 KB
/
mms.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
#!/usr/bin/perl
# Récupération des liens mms ou autres à partir d'une page web
use Coro::LWP;
use strict;
use v5.10;
my $debug = 0;
sub get_mms {
my $url = shift;
return $url if ($url =~ /(mp4|mp3|avi|mov|asf|m4a|\d\d)$/);
my $useragt = "Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0";
my $browser = LWP::UserAgent->new(keep_alive => 0,
agent =>$useragt);
$browser->timeout(5);
$browser->default_header(
[ 'Accept-Language' => "fr-fr"
# 'Accept-Encoding' => "gzip,deflate",
# 'Accept-Charset' => "ISO-8859-15,utf-8"
]
);
$browser->max_size(65000);
my ($page,$type);
if (!$debug) {
my $response = $browser->head($url);
$type = $response->header("Content-type");
if (!$response->is_success) {
say "get_mms error : ",$response->status_line;
say "trying get (max size = 65000)...";
$response = $browser->get($url);
$type = $response->header("Content-type");
}
return undef if (!$response->is_success);
if ($type =~ /(audio|video)/ && $type !~ /charset/) {
# audio/xxx est quand même prenable !
print "url is not text : $type\n";
$browser->max_size(5000);
$page = $response->content;
if ($page !~ /^(\#EXTM3U|http|\[playlist)/) {
# Evitez les crétins qui gèrent le m3u en audio !!!
return $url;
} else {
print "crétin de m3u évité\n";
}
} else {
if (!$type) {
print "mms: pas de content-type: $type\n";
}
$page = $response->content;
}
} else {
open(F,"<yt.html") || die "can't open yt.html\n";
@_ = <F>;
close(F);
$page = join("",@_);
}
if (!$page) {
print STDERR "could not get $url\n";
} elsif ($page =~ /^(\#EXTM3U|http)/) {
# m3u, on interprête d'après le contenu et pas l'extension
foreach (split /\r?\n/,$page) {
next if (/^\#/);
return $_ if (/^http/);
}
print "could not find url in m3u $page from $url\n";
return undef;
} elsif ($page =~ /^\[playlist/) {
foreach (split /\r?\n/,$page) {
return $1 if (/^File\d*\=(http.+)/);
}
print "pls impossible à traiter $page from $url\n";
exit(1);
} elsif ($page =~ /"(mms.+?)"/) {
print "mms url : $1 from $url\n";
return $1;
} elsif ($page =~ /yt.preload.start\(/) { # Youtube
while ($page =~ s/yt.preload.start\("(.+?)"\)//) {
next if ($1 =~ /xml$/);
my $url = $1;
$url =~ s/\\\//\//g;
$url =~ s/%(..)/chr(hex($1))/ge;
$url =~ s/generate_204/videoplayback/g;
$url =~ s/\\u(....)/chr(hex($1))/ge;
print "youtube url $url\n";
return $url;
}
} else {
# open(F,">dump");
# print F $page;
# close(F);
while ($page =~ s/iframe src\="(.+?)"//m) {
print "trying iframe $1\n";
my $r = get_mms($1);
return $r if ($r);
}
print "did not find mms from $url\n";
if (!$type) {
return $url;
} else {
return undef;
}
}
return $url;
}
get_mms() if ($debug);
1;