Progmar Marcin Załęczny

Language:
We are using cookies in the page. If you use the page you agree for the cookies.      Close

How to download video courses from Udemy

  1. Python Installation.

    Download the newest Pythona 3.x from https://www.python.org and install it in c:\python3 folder.

    Important: In the last window of installation process click "Disable path length limit" option (screen below), to make it possible for windows to store long paths in PATH variable.

    After successful installation, directory containing Python binaries should be added to the path.

    Open "cmd" console (hotkey WINR+R, type "cmd" and press Enter eky) and type in following command:

    pip install youtube-dl

    to intstall application youtube-dl. This works as video downloader from the web.
    It is very likely, that after having issued command above youtube-dl will not be installed because pip asks to upgrade.
    Issue command then:

    python.exe -m pip install --upgrade pip

    This makes pip - Python packages manager - to upgrade. Next reissue command:

    pip install youtube-dl
    It is very likely that this time youtube-dl will not install too because of it has been installed together with Python installation. You should following message:
    Requirement already satisfied: youtube-dl in c:\python3\lib\site-packages (2021.12.17)
    If not, youtube-dl should install properly.
    Now following command:
    youtube-dl --version
    displays youtube-dl current version.
  2. XAMPP installation.

    Download the newest version of XAMPP package from https://www.apachefriends.org/pl/download.html (for the time of writing this tutorial it is: 8.1.10 / PHP 8.1.10 64 bit). We need only command line php.exe from the package. Next screen presents applications available during installation:

    You may deselect all if you want or if you do not know what the XAMPP is because PHP is installed by default and cannot be turned off. I have selected all because I use all the tools available there. But for the requirements of the tutorial PHP installation is completely sufficient. Change destination to C:\xampp directory. Next choose your language (english by default) and start installation process:

    At the end check off option:
    "Do you want to start Control Panel now?"
    because we do not need to run XAMPP control panel.

    Now you have to add path to the PHP to the system settings, because installer did not do it for us. So open Start menu (Windows 11) and click "Settings" button:

    On the list that will be presented choose "System Information":

    Next click "Advanced System Information":

    The "System properties" dialog box will pop-up, navigate to "Advanced" tab and click "Environment variables..." button:

    In the upper list select Path item and click "Edit..." button below:

    In the next dialog box click "New" button and type in "c:\xampp\php" path as the value:

    Click "OK" button in all opened dialog boxes to apply the changes to the system. If you open "Cmd" console now and executes following comman:

    php --version

    then you should see PHP version printed out.

  3. ffmpeg installation

    Essential programs for creating mp4 movies you can download from: https://ffmpeg.org/download.html. On the website click big windows icon and choose "Windows builds by BtbN" option. In the list that apears click ffmpeg-master-latest-win64-gpl.zip to get the file. Extract downloaded file and copy programs ffmpeg.exe, ffplay.exe, ffprobe.exe to c:\bin directory. Finally add the directory to system PATH variable as described in the previous paragraph (regarding c:\xampp\php path).

  4. Creating scripts for dowloading lectures from the udemy website.

    In the folder that you use as a lecture's download destination create following scripts:
    dl.bat and fill it with the content:

    youtube-dl -v --ignore-config -a "%1"

    and convert2mp4.php and fill it with the content:

    <?php
    
    $files = scandir(".");
    $base = "";
    $counter = 0;
    for ($i = 0; $i < count($files); $i++) {
        $ext = pathinfo($files[$i], PATHINFO_EXTENSION);
        if ($ext == 'm3u8') {
            $base = str_replace(".$ext", "", pathinfo($files[$i], PATHINFO_BASENAME));
        }
        if ($ext == 'ts') {
            $counter++;
        }
    }
    
    
    for ($i = 0; $i < $counter; $i++) {
        $fn = $base . $i . "-" . $base . $i . ".ts";
        if (!is_file($fn)) {
            echo "ERROR: $fn not exists\n";
            exit(0);
        }
        echo "$fn\n";
        $c = file_get_contents($fn);
        file_put_contents("$base.ts", $c, FILE_APPEND);
    }
    
    system("ffmpeg -i $base.ts -acodec copy -vcodec copy $base.mp4");
    
    if (is_file("$base.mp4")) {
        for ($i = 0; $i < $counter; $i++) {
            $fn = $base . $i . "-" . $base . $i . ".ts";
            if (is_file($fn)) {
                unlink($fn);
            }
        }
        unlink("$base.ts");
        unlink("$base.m3u8");
    }
  5. Downloading lectures

    Run Firefox webbrowser, press F12 key, to open developer's panel, navigate to "Network" tab and in searchbar type in "m3u8" phrase. Next open the page containing course in the browser:

    On the list at the bottom there are links matching searched phrase. Localize the one referencing to the video of the best quality. To do that hover mouse cursor over each item and in the tooltip look for "1920x1080" substring. Alternatively you can click each of the items and examine panel that appears to the right for the "1920x1080" occurence:

    Click localized item and from the context menu choose option: "Open in new tab". "Save as" dialogs pops up:

    navigate to the directory containing scripts dl.bat and convert2mp4.php and save the file not changing its default name. Important! If you save with different name the result mp4 file could not be created properly.
    Next open "Cmd" console, go to the directory with downloaded file and issue command (the filename after dl.bat should match yours saved file):

    dl.bat aa0080ab0c89fc2e25fc3a77e1548856cef2.m3u8

    As a result ther will be downloaded fragment files in format of *.ts extension. Now execute command:

    php convert2mp4.php
    After that there will be created result of *.mp4 with lecture you requested. Now you can rename the file to more meaningfull ame and copy to your folder containing course files.