Anyone would know how frustrating 🤯 it is when you are learning something 🧐 and your internet connection drops or is not stable, it takes away your flow of study 📚
An automated downloader that downloads ⬇️ course videos (Live and Recorded) directly from GeeksforGeeks.
- Session Caching: Saves your login status via
auth.jsonto prevent repeated logins. - User Inputs Caching: Remembers your previous preferences out of convenience (
user_inputs.json). - Headless Browser Navigation: Uses Playwright (Firefox) to simulate real human clicks.
- Network Interception: Captures master M3U8 playlists triggered by "Play" buttons.
- Multi-threaded Downloading: Offloads the heavy downloading and decrypting process to a background Worker Thread.
- Concurrent Segments: Downloads multiple
.tsvideo chunks simultaneously usingp-queueto speed up the process.
- Node.js installed
- Dependencies installed:
npm install - Playwright browsers installed:
npx playwright install firefox
Run the main script:
node down2.jsUpon running, the script will ask you for:
- Quality: Choose from
highest,secondHighest,medium,lowest. - Simultaneous Downloads: Number of videos to download at the exact same time (e.g.,
4). - Concurrency: Number of
.tssegments to download concurrently per video (e.g.,20). - Course Name: The exact name of your course listed in your "My Courses" tab.
- Primary Tab: "Live" or "Chapters".
- Chapter Selection: Choose whether to download "All Chapters" or specify a range.
The general architecture flows in 3 phases: Setup & Navigation, Scraping & Interception, and Queueing & Downloading.
- Initialization: Loads cached inputs and asks for user preferences via
inquirer. - Authentication: Launches a Playwright Firefox browser. If
auth.jsonis present, it uses that session. Otherwise, it prompts for a username and password, logs in, and saves the new session. - Navigation: Clicks to "My Courses", searches for your course, navigates to the specified tab, and figures out how many chapters exist.
- Iterates over the selected range of chapters and recordings.
- For each recording, the script clicks the "Play" button.
- It attaches a network listener to the page to scan outgoing requests for
.m3u8or.mp4URLs. - It intercepts the master playlist URL, attaches the title/folder structure, and groups this metadata securely.
- As URLs are successfully intercepted, they are added to an
ObservableQueue. - Worker Thread: A background worker is spun up
Worker/worker.js. - The worker uses
p-queueto cap the number of active video downloads. - Processing (
utils/m3u8Downloader.js):- MP4: If the captured link is
.mp4, it streams it directly. - M3U8 (HLS): It fetches the playlist file to find the available resolutions, selects the one matching your
Qualitypreference, and parses the.tssegment list. - It fetches the AES decryption key (if applicable).
- It downloads the
.tssegments concurrently based on yourConcurrencysetting, decrypts them viacrypto, and merges them into a final.ts(or.mp4) file on completion.
- MP4: If the captured link is
- The
auth.jsonfile generated contains your active GeeksforGeeks login session and live JWT tokens. It is ignored in.gitignore, but never share this file publicly.
