Skip to content

Instantly share code, notes, and snippets.

@Asbra
Created April 11, 2017 09:37
Show Gist options
  • Save Asbra/63d307f11c7edfce2c1d7a0e9aae2985 to your computer and use it in GitHub Desktop.
Save Asbra/63d307f11c7edfce2c1d7a0e9aae2985 to your computer and use it in GitHub Desktop.
Download videos from MerlTV9.com using YouTube-DL
<?php
/*
Pre-requisites:
youtube-dl ( https://github.com/rg3/youtube-dl/ )
*/
if (empty($argv[1])) {
die("merltv9.php url\n");
}
$url = $argv[1];
$data = file_get_contents($url);
$result = preg_match('/var list\s*=\s*([^;]+);/', $data, $matches);
if (!$result) { die("Failed to get data\n"); }
$json = json_decode($matches[1]);
$files = [];
foreach ($json as $item) {
if (isset($item->idGD)) {
$files = explode('0!?^0!?A', $item->idGD);
} else if (isset($item->file)) {
$files[] = $item->file;
}
}
$result = preg_match("/\(\s*list,\s*[\"']([^\"']+)[\"']\s*\);/", $data, $matches);
if ($result == 1) {
$format = $matches[1];
foreach ($files as $i => $file) {
switch ($format) {
case 'GD': // Google Drive
$files[$i] = 'https://docs.google.com/file/d/'.$file;
break;
case 'VI': // Vimeo
$files[$i] = 'http://www.vimeo.com/api/oembed.json?url='.$file;
break;
case 'YT': // YouTube
default:
break;
}
}
}
$cmd = "youtube-dl ".implode(' ', $files);
system($cmd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment