/**
* Downloads video from IDNES page.
*
* @param array|string $pages Array with URL on requested pages | URL on requested page
* @param string $destDir Destination directory, the place where the video will be saved.
* @param type $namePattern Pattern of destination filename:
* %S% - source filename
* %C% - counter (according to the count of given pages is counter padded by zeros)
* example:
* 'Piano school - Lesson no. %C%' => returns e.g. 'Piano school - Lesson no. 03'
*/
function download_idnes_videos($pages = array(), $destDir = '', $namePattern = '%S%')
{
// check parameter
if (!is_array($pages)) {
$pages = (array)$pages;
}
// get services from pages
array_walk($pages, function(&$page) {
preg_match('/videoFLV.+data:\s*["\'](.+?)["\']/', @file_get_contents($page), $matches);
$page = (($matches) ? $matches[1] : '');
});
// download videos
$count = count($pages);
$sprintf = (($count < 10) ? '%d' : (($count < 100) ? '%02d' : '%03d'));
$echoSprintf = $sprintf . '. ';
$i = 1;
foreach ($pages as $service) {
if ($service) {
$xml = simplexml_load_file($service);
foreach ($xml->items->item as $item) {
if ($item->type == 'video') {
$video = $item->linkvideo->server . $item->linkvideo->path . $item->linkvideo->file;
$source = @fopen($video, 'r');
if (!$source) {
$server = (($item->linkvideo->server == 'http://stream7p.idnes.cz/') ? 'http://stream6p.idnes.cz/' : 'http://stream7p.idnes.cz/');
$video = $server . $item->linkvideo->path . $item->linkvideo->file;
$source = @fopen($video, 'r');
}
if ($source) {
// check destination
if (!is_dir($destDir)) {
mkdir($destDir, 0777, TRUE);
}
// create destination file
$dotPos = strrpos($item->linkvideo->file, '.');
$filename = substr($item->linkvideo->file, 0, $dotPos);
$ext = substr($item->linkvideo->file, $dotPos);
$destname = str_replace(array('%S%', '%C%'), array($filename, sprintf($sprintf, $i)), $namePattern);
$destfile = rtrim($destDir, '/') . '/' . $destname . $ext;
$dest = fopen($destfile, 'w');
if ($dest) {
echo sprintf($echoSprintf, $i) . 'copying... "' . $video . '" to "' . $destfile . '"<br />';
stream_copy_to_stream($source, $dest);
} else {
echo sprintf($echoSprintf, $i) . 'destination is not writable.<br />';
}
} else {
echo sprintf($echoSprintf, $i) . 'source was not found.<br />';
}
$i++;
// jump to next page
break;
}
}
} else {
echo sprintf($echoSprintf, $i) . 'service was not found.<br />';
$i++;
}
}
}
// example
/*
$pages = array(
'http://hobby.idnes.cz/video-na-klavesy-se-naucite-za-par-tydnu-zacnete-s-nami-od-prvni-lekce-1jg-/hobby-domov.aspx?c=A100514_153649_hobby-domov_bma',
'http://hobby.idnes.cz/video-na-klavir-za-nekolik-tydnu-2-dil-dsk-/hobby-domov.aspx?c=A100522_083145_hobby-domov_bma',
'chybna url'
);
download_idnes_videos($pages, 'test', 'Piano school - Lesson no. %C% (%S%)');
*/
Quote from: 151kbar151 on July 13, 2013, 02:24:43 PMNapiš mi soukromě: http://testtbj.mzf.cz/formular.php
Díky, to je ono. Ale jak jsi tohle udělal? Já jen, abych si dovedl poradit příště.