Skip to content

Instantly share code, notes, and snippets.

@tlikai
Created October 9, 2013 08:23
Show Gist options
  • Save tlikai/6898004 to your computer and use it in GitHub Desktop.
Save tlikai/6898004 to your computer and use it in GitHub Desktop.
网易公开课批量下载
#!/usr/bin/env php
<?php
require 'simple_html_dom.php'; // http://sourceforge.net/projects/simplehtmldom/
if (empty($argv[1])) {
echo 'Give me download url please.', PHP_EOL;
exit;
}
foreach(find($argv[1]) as list($name, $url)) {
$fileName = $name . '.mp4';
if (file_exists($fileName)) {
continue;
}
exec("wget '$url' -O '$name.mp4'");
}
function find($url)
{
$result = array();
$dom = file_get_html($url);
$key = 0;
foreach ($dom->find('td[class=u-ctitle]') as $td) {
$name = preg_replace('/\s+/', '', strip_tags($td->outertext));
$result[$key][0] = iconv('gbk', 'utf-8', $name);
$key++;
}
$key = 0;
foreach($dom->find('a[class=downbtn]') as $link) {
$result[$key][1] = $link->href;
$key++;
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment