Esempio n. 1
0
function download_folder($basedir, $folder, $start = 0, $end = null, $list = null, $downloader = "wget")
{
    if (isset($folder["index"])) {
        $dir = $basedir . DIRECTORY_SEPARATOR . $folder["index"] . "_" . $folder["title"];
    } else {
        $dir = $basedir . DIRECTORY_SEPARATOR . $folder["title"];
    }
    if (!file_exists($dir)) {
        mkdir($dir);
    }
    foreach ($folder["contents"] as $content) {
        if ($content["type"] == "folder") {
            download_folder($dir, $content, $start, $end, $list, $downloader);
        } elseif ($content["type"] == "file") {
            $curr_index = $content['lindex'] ? $content['lindex'] : $content['index'];
            if (!empty($list) && in_array($curr_index, $list) || empty($list) && ((empty($start) || $curr_index >= $start) && (empty($end) || $curr_index <= $end))) {
                $outputfile = $dir . DIRECTORY_SEPARATOR . convert_to_filename($content['index'] . "_" . $content['title'] . "." . $content['extension']);
                if (!file_exists($outputfile)) {
                    if ($content["data"] == "link") {
                        switch ($downloader) {
                            case 'idm':
                                exec("idman /d \"" . $content['contents'] . "\" /p \"" . $dir . "\" /a /n /f \"" . convert_to_filename($content['index'] . "_" . $content['title'] . "." . $content['extension']) . "\" & ping 127.0.0.1 -n 2 > nul");
                                break;
                            default:
                                exec("wget -O " . $outputfile . " \"" . $content['contents'] . "\"");
                                break;
                        }
                    } else {
                        if ($content["data"] == "text") {
                            file_put_contents($outputfile, $content['contents']);
                        }
                    }
                }
            }
        }
    }
}
Esempio n. 2
0
$course['options']['headers'] = array_merge($course['options']['headers'], ['X-Udemy-Bearer-Token: ' . $user['accesstoken']]);
$course['link'] = str_replace(':courseId', $courseId, $urls['course']['link']);
$course['response'] = common_curl($course['link'], $urls['course']['method'], $course['options']);
$course['extras'] = true;
if ($course['response']['status'] != 200) {
    $course['response'] = common_curl(str_replace('extras,', '', $course['link']), $urls['course']['method'], $course['options']);
    $course['extras'] = false;
}
if ($course['response']['status'] != 200) {
    die("Error fetching course details");
}
$course['decoded_response'] = json_decode($course['response']['body'], true);
echo "Parsing links....\n";
$course['download_links'] = parse_links($courseId, $course['decoded_response'], $course['extras']);
// ***********************************************
//                Download Course
// ***********************************************
echo "Downloading course....\n";
if (!file_exists($basedir)) {
    mkdir($basedir);
}
download_folder($basedir, $course['download_links'], $start, $end, $list, $downloader);
switch ($downloader) {
    case 'idm':
        exec("idman /s");
        echo "Course added to IDM and downloading started.\n";
        break;
    default:
        echo "Course download complete.\n";
        break;
}