A command-line tool to download course materials from Moodle (IIT Bombay).
- Download all course materials automatically
- Automatic cookie extraction from your browser (Chrome, Firefox, Brave, Edge, etc.)
- Track downloaded files to avoid re-downloading
- Support for multiple file types (PDFs, videos, documents, etc.)
- Resume interrupted downloads
- Organize files by course and section
- Cross-platform support: Windows, Linux, and macOS
- Multi-browser support: Chrome, Edge, Brave, Firefox, Opera, Vivaldi, Chromium
- Python 3.7 or higher
- pipx (recommended for installation)
- A supported browser with an active Moodle session
This project requires the following Python packages (automatically installed via pipx):
requests- HTTP library for API callsbeautifulsoup4- HTML parsingpyyaml- YAML configuration file handlingtqdm- Progress bars for downloadspycryptodome- Cookie decryption for automatic extraction
These are listed in requirements.txt and will be installed automatically when you install the CLI tool.
On Linux/macOS:
python3 -m pip install --user pipx
python3 -m pipx ensurepathOn Windows:
python -m pip install --user pipx
python -m pipx ensurepathAfter installation, close and reopen your terminal for the PATH changes to take effect.
To verify pipx is installed correctly:
pipx --versionNavigate to the project directory and install:
cd /path/to/moodle
pipx install . --forceThis will automatically install all dependencies from requirements.txt. The --force flag ensures a clean installation if you're reinstalling.
Alternative: Install with pip (not recommended)
pip install -r requirements.txt
pip install -e .Note: Using pipx is recommended as it creates an isolated environment.
moodle --helpYou should see the help menu with available commands.
The tool requires authentication with Moodle. You have two options:
-
Open Moodle in your browser and log in: https://moodle.iitb.ac.in
-
Open Developer Tools:
- Chrome/Edge/Brave: Press
F12orCtrl+Shift+I(Windows/Linux) /Cmd+Option+I(Mac) - Firefox: Press
F12orCtrl+Shift+I(Windows/Linux) /Cmd+Option+I(Mac) - Safari: Enable Developer menu in Preferences, then press
Cmd+Option+I
- Chrome/Edge/Brave: Press
-
Go to the Application/Storage tab:
- Chrome/Edge/Brave: Click on "Application" tab → "Cookies" → "https://moodle.iitb.ac.in"
- Firefox: Click on "Storage" tab → "Cookies" → "https://moodle.iitb.ac.in"
- Safari: Click on "Storage" tab → "Cookies" → "moodle.iitb.ac.in"
-
Find the MoodleSession cookie:
- Look for a cookie named
MoodleSession - Copy its Value (typically a 26-character alphanumeric string
- Validate and use it
- Look for a cookie named
Requirements:
- Linux/macOS: No special permissions needed for most browsers
- Windows: Administrator privileges required for Chromium browsers (Chrome, Edge, Brave), but not for Firefox
If extraction fails, the tool will automatically try other browsers and provide manual instructions as a fallback.
If automatic extraction doesn't work, you can manually extract the cookie:
To authenticate with Moodle, you need to extract your session cookie:
-
Open Moodle in your browser and log in: https://moodle.iitb.ac.in
-
Open Developer Tools:
- Chrome/Edge: Press
F12orCtrl+Shift+I(Windows/Linux) /Cmd+Option+I(Mac) - Firefox: Press
F12orCtrl+Shift+I(Windows/Linux) /Cmd+Option+I(Mac) - Safari: Enable Developer menu in Preferences, then press
Cmd+Option+I
- Chrome/Edge: Press
-
Go to the Application/Storage tab:
- Chrome/Edge: Click on "Application" tab → "Cookies" → "https://moodle.iitb.ac.in"
- Firefox: Click on "Storage" tab → "Cookies" → "https://moodle.iitb.ac.in"
- Safari: Click on "Storage" tab → "Cookies" → "moodle.iitb.ac.in"
-
Find the MoodleSession cookie:
- Look for a cookie named
MoodleSession - Copy its Value (a long string of random characters)
- Look for a cookie named
-
Install a browser extension to export cookies:
- Chrome: "Get cookies.txt LOCALLY" or "EditThisCookie"
- Firefox: "cookies.txt"
-
Export cookies for
moodle.iitb.ac.inin Netscape format -
Save the exported file as
.envin the project directory
Note: If you're using automatic extraction, skip this step - the .env file is created automatically.
For manual configuration, create a file named .env in your working directory:
Recommended format:
MOODLE_SESSION=your_session_cookie_value_here
Alternative format (Netscape cookies):
# Netscape HTTP Cookie File
.moodle.iitb.ac.in TRUE / TRUE 1234567890 MoodleSession your_session_cookie_value_here
Replace your_session_cookie_value_here with the actual cookie value you copied (should be alphanumeric, about 26 characters).
is created automatically if you use automatic cookie extraction
- The file must be in the directory where you run the
moodlecommand - Keep this file secure and don't share it (it contains your authentication token)
- The session expires periodically; the tool will automatically re-extract when needed
- Add
.envto your.gitignoreif using version control
Run the init command to discover and configure your courses:
moodle initWhat happens:
- The tool checks if your cookie is valid
- If invalid or missing, it automatically extracts a fresh cookie from your browser
- Connects to Moodle using your cookie
- Discovers all enrolled courses
- Createst to Moodle using your cookie
- Discover all enrolled courses
- Create a
courses.yamlfile with your courses
Edit courses.yaml to customize which courses to download:
- name: Course Name
id: 1234
status: enabled # Change to 'disabled' to skip this course
local_folder: Course Name- Set
status: enabledfor courses you want to download - Set
status: disabledfor courses you want to skip - Customize
local_folderto change the download directory name
Download all enabled courses:
**What happens:**
- The tool validates your session cookie
- If expired, automatically extracts a fresh cookie from your browser
- Downloads all files from enabled courses
- Skips files that have already been downloaded
- Organizes files by course and section
- Shows progress for each downloadourses
- Skip files that have already been downloaded
- Organize files by course and section
- Show progress with a progress bar
### Reinitialize Courses
If you need to refresh your course list:
```bash
moodle initTo update to the latest version:
cd /path/to/moodle
git pull # if using git
pipx install . --forceAfter running the tool, your directory structure will look like:
your-working-directory/
├── .env # Your Moodle session cookie (keep secure!)
├── courses.yaml # Course configuration
├── manifest.json # Tracks downloaded files
└── Course Name/ # Downloaded course materials
├── Section 1/
│ ├── lecture1.pdf
│ └── notes.pdf
└── Section 2/
└── assignment.pdf
"Session Expired" ErrorThe tool should automatically re-extract it from your browser. If automatic extraction fails:
Solution 1: Make sure you're logged into Moodle in one of the supported browsers, then run the command again.
Solution 2: Manually extract a new cookie (see Configuration section) and update your .env file.
The tool couldn't find a valid cookie in any browser.
Solutions:
- Make sure you're logged into https://moodle.iitb.ac.in in your browser
- Try a different browser from the supported list
- Close and reopen your browser, then log in again
- Use manual cookie extraction (see Configuration section)
The tool found browsers but couldn't extract a valid cookie.
Common causes:
- Not logged into Moodle in any browser
- Browser encryption on Windows
On Windows, automatic extraction from Chromium browsers (Chrome, Edge, Brave) requires administrator privileges.
Solutions:
- Run Command Prompt/PowerShell as Administrator, then run
moodle pull - Use Firefox instead (doesn't require admin privileges)
- Use manual cookie extraction method
Ensure the installation directory has proper permissions:
chmod +x ~/.local/bin/moodleIf browser database access fails:
- Close the browser completely
- Some snap-installed browsers may have restricted access
- Try Firefox or manually extract the cookie
If you see ModuleNotFoundError: No module named 'Crypto':
pipx install --force .
# or
pipx inject moodle-cli pycryptodombrowser: https://moodle.iitb.ac.in
2. Close your browser completely and try again
3. Try a different browser (Firefox is often easiest on Linux)
4. Use manual extraction method
- Contains the `MoodleSession` cookie
- Has the correct format (see Configuration se (auto-generated or manual)
- `courses.yaml` - Course configuration (generated by `moodle init`)
- `manifest.json` - Tracks downloaded files (auto-generated)
## How Automatic Cookie Extraction Works
### Linux/macOS (Chromium browsers)
- Uses v10 AES-CBC encryption with PBKDF2
- Key derived from password "peanuts" (Chrome's default)
- The tool validates and refreshes cookies automatically
- Cookies are extracted locally and never sent to third parties
- The cookie typically expires after a period of inactivity
- On Windows, administrator privileges are used only for local decryption
### Windows (Chromium browsers)
- Uses v20 app-bound encryption with DPAPI
- Requires SYSTEM privileges for decryption
- Needs administrator rights
- Uses Windows Cryptography APIs
### Firefox (All platforms)
- Cookies often stored unencrypted
- Simple SQLite database access
- No special permissions needed
- Works as fallback option
### Fallback Chain
1. Try all Chromium browsers (Chrome, Edge, Brave, etc.)
2. Try Firefox if Chromium extraction fails
3. Show manual extraction instructions if all fail
If `moodle` command is not found after installation:
1. Run `pipx ensurepath` again
2. Close and reopen your terminal
3. Check if pipx bin directory is in PATH:
```bash
echo $PATH # Linux/macOS
echo %PATH% # WindowsOn Linux/macOS, ensure the installation directory has proper permissions:
chmod +x ~/.local/bin/moodleThe tool looks for these files in the current working directory:
.env- Contains your Moodle session cookiecourses.yaml- Course configuration (generated bymoodle init)manifest.json- Tracks downloaded files (auto-generated)
- Never commit your
.envfile to version control - Add
.envto your.gitignorefile - The session cookie grants access to your Moodle account
- Regenerate your cookie if you suspect it has been compromised
- The cookie typically expires after a period of inactivity
This tool is for educational purposes. Use responsibly and in accordance with your institution's policies.
For issues or questions:
- Check the Troubleshooting section above
- Ensure you're using the latest version
- Verify your
.envfile is configured correctly