-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdailymotion.class.php
63 lines (60 loc) · 2.63 KB
/
dailymotion.class.php
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
<?php
class dailymotion
{
public $enable_proxies = false;
public $url;
function find_video_id($url)
{
$domain = str_ireplace("www.", "", parse_url($url, PHP_URL_HOST));
switch (true) {
case($domain == "dai.ly"):
$video_id = str_replace('https://dai.ly/', "", $url);
$video_id = str_replace('/', "", $video_id);
return $video_id;
break;
case($domain == "dailymotion.com"):
$url_parts = parse_url($url);
$path_arr = explode("/", rtrim($url_parts['path'], "/"));
$video_id = $path_arr[2];
return $video_id;
break;
}
}
function azf_Video_info($url)
{
$video_id = $this->find_video_id($url);
$web_page = url_get_contents("https://www.dailymotion.com/embed/video/" . $video_id, $this->enable_proxies);
preg_match_all('/var config =(.*);/', $web_page, $match);
if (isset($match[1][0]) != "") {
$data = json_decode($match[1][0], true);
$video["title"] = $data["metadata"]["title"];
$video["source"] = "dailymotion";
$video["thumbnail"] = $data["metadata"]["posters"][max(array_keys($data["metadata"]["posters"]))];
$video["duration"] = format_seconds($data["metadata"]["duration"]);
$streams_m3u8 = url_get_contents($data["metadata"]["qualities"]["auto"][0]["url"], $this->enable_proxies);
preg_match_all('/#EXT-X-STREAM-INF:(.*)/', $streams_m3u8, $streams_raw);
$streams_raw = $streams_raw[1];
$streams = array();
foreach ($streams_raw as $stream) {
$quality = get_string_between($stream, 'NAME="', '"');
if (!isset($streams[$quality])) {
$streams[$quality]["quality"] = $quality;
$streams[$quality]["url"] = get_string_between($stream, 'PROGRESSIVE-URI="', '"');
}
}
$i = 0;
foreach ($streams as $stream){
$video["links"][$i]["url"] = $stream["url"];
$video["links"][$i]["type"] = "mp4";
$video["links"][$i]["size"] = get_file_size($video["links"][$i]["url"], $this->enable_proxies);
$video["links"][$i]["quality"] = $stream["quality"] . "p";
$video["links"][$i]["mute"] = "no";
$i++;
}
usort($video["links"], 'sort_by_quality');
return $video;
} else {
return false;
}
}
}