Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Add support for http://tv.zing.vn (simple mp4 in source code) #12505
Comments
|
meanwhile, here is an implementation in PHP-cli, maybe it'll help speed up development of a youtube-dl python implementation #!/usr/bin/env php
<?php
declare (strict_types = 1);
if ($argc !== 2 && $argc !== 3) {
die("usage: {$argv[0]} url {int_version}\n");
}
$url = $argv[1];
$quality = (int)($argv[2] ?? -1);
class HC
{
public $ch;
public function __construct()
{
$this->ch = curl_init();
curl_setopt_array($this->ch, array(
CURLOPT_ENCODING => '',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_COOKIEFILE => '',
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_VERBOSE => false
));
}
public function __destruct()
{
curl_close($this->ch);
}
public function fetch(string $url)
{
curl_setopt($this->ch, CURLOPT_URL, $url);
return curl_exec($this->ch);
}
};
$hc = new HC();
$html = $hc->fetch($url);
// playlist.source = "https://ztv-mcloud-mpl-s3.zadn.vn/9aVVgQFDDxU/whls/vod/480/lxgx4OHaPMKb9IVNfG/HaoLanTruyen_10_muxed.m3u8?authen=exp=1548875226~acl=/9aVVgQFDDxU/*~hmac=8c1864f2bcfe04c9bb306a2b1651acb5";
$domd = @DOMDocument::loadHTML($html);
$xp = new DOMXPath($domd);
$title = $xp->query("//div[@class='box-description']//strong")->item(0)->getAttribute("alt");
echo "title: {$title}\n";
$versions = array();
/*
playlist.sources.push({
label: "720p(VIP)",
disabled: true,
isHD: true,
index: 100
});
playlist.sources.push({
label: "480p",
source: "https://ztv-mcloud-bf-s3.zadn.vn/mq1rFE38Xsc/635908c4cc8025de7c91/156b34621027f979a036/480/HaoLanTruyen_10_muxed.mp4?authen=exp=1549188788~acl=/mq1rFE38Xsc/*~hmac=3b0f9e0cfdc0ccf043f08b43d5dc3541",
index: 1
});
*/
preg_match_all("/playlist\.sources\.push\s*\(\s*(\{[\s\S]*?\}\s*)\s*\)\s*\;/", $html, $matches);
if (!empty($matches)) {
$matches = $matches[1];
$matches = array_filter(array_map(function (string $str) {
$str = preg_replace('/(\S+)\:([\s\"0-9]|(?:null))/', '"${1}":${2}', $str);
return (json_decode($str, true) ?? []);
}, $matches), function (array $data) {
return (empty($data['disabled']) && !empty($data['label']) && !empty($data['source']));
});
foreach ($matches as $match) {
$versions[] = array(
'type' => 'direct',
'quality' => $match['label'],
'url' => $match['source'],
);
}
}
// playlist.source = "https://ztv-mcloud-mpl-s3.zadn.vn/9aVVgQFDDxU/whls/vod/480/lxgx4OHaPMKb9IVNfG/HaoLanTruyen_10_muxed.m3u8?authen=exp=1548875226~acl=/9aVVgQFDDxU/*~hmac=8c1864f2bcfe04c9bb306a2b1651acb5";
preg_match("/playlist\.source\s*\=\s*\"([^\"]*)/", $html, $matches);
$versionsURL = $matches[1];
$versions_raw = $hc->fetch($versionsURL);
$versions_raw = preg_split("/\r?\n/", $versions_raw, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 1; $i < count($versions_raw); $i += 2) {
preg_match('/NAME\=\"(.*?)\"/', $versions_raw[$i], $q);
$q = $q[1];
$u = 'https:' . $versions_raw[$i + 1];
$versions[] = ['type' => 'm3u8', 'quality' => $q, 'url' => $u];
}
if (!isset($versions[$quality])) {
echo "available version: \n";
print_r($versions);
echo "you must chose a version, as a number, add it as the last argument.\n";
die(1);
}
if ($versions[$quality]["type"] === 'direct') {
$cmd = "wget " . escapeshellarg($versions[$quality]['url']) . " -O " . escapeshellarg($title . "." . $versions[$quality]["quality"] . ".mp4");
echo "{$cmd}\n";
system($cmd);
} elseif ($versions[$quality]['type'] === 'm3u8') {
$urls_raw = $hc->fetch($versions[$quality]['url']);
$fname = $title . ".mp4";
echo " saving to \"{$fname}\"\n";
$fp = fopen($title . ".mp4", 'wb');
$urls_raw = array_values(array_filter(preg_split("/\r?\n/", $urls_raw), function ($str) {
return ('//' === substr($str, 0, 2));
}));
//var_dump($urls_raw);
for ($i = 0, $max = count($urls_raw); $i < $max; ++$i) {
echo "\rdownloading: " . ($i + 1) . "/{$max}";
fwrite($fp, $hc->fetch('https:' . $urls_raw[$i]));
}
echo " done!\n";
fclose($fp);
}(license, if you're looking for one: https://unlicense.org/UNLICENSE ) examples:
$ php vdl.php 'https://tv.zing.vn/video/Hao-Lan-Truyen-Tap-10/IWZEUOD7.html' 1 Hạo Lan Truyện - Tập 10 Vietsub.480p.mp4 1%[=> ] 3.81M 534KB/s eta 9m 29s```
|
Description of your issue, suggested solution and other information
Please add support for tv.zing.vn. The video URL is a mp4 in the source code:
Example: http://tv.zing.vn/video/Sien-Nhan-Perman-Tap-130/IWZBEEEF.html