some improvement

This commit is contained in:
Meghdad committed 2026-08-02 21:44:40 +03:30
1 parent bd92689d4a
commit 187878a774
12 files changed
+215 -22

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
# Copy this file to .env. Never commit real values.
RAVIN_USERNAME=""
RAVIN_PASSWORD=""
RAVIN_USER_AGENT=""
RAVIN_COOKIE=""
+4
View File
@@ -0,0 +1,4 @@
* text=auto eol=lf
*.py text eol=lf
*.md text eol=lf
*.toml text eol=lf
+44
View File
@@ -0,0 +1,44 @@
name: CI
on:
push:
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.12", "3.14"]
steps:
- name: Check out repository
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Run tests
run: python -m unittest -v
- name: Check syntax
run: python -m py_compile ravin_downloader.py
- name: Confirm secrets stay untracked
run: |
if git ls-files --error-unmatch .env >/dev/null 2>&1; then
echo "error: .env must never be tracked"
exit 1
fi
- name: Verify package installation
run: |
python -m pip install .
ravin-downloader --version
+11
View File
@@ -0,0 +1,11 @@
# Changelog
All notable changes to this project will be documented here.
## 0.1.0 - 2026-08-02
- List enrolled Moodle courses through the mobile API or authenticated AJAX fallback.
- List and download accessible course resources with safe partial-file handling.
- Support Cloudflare-protected sites through a user-provided browser session.
- Load and securely update credentials and browser-session values in a Git-ignored `.env` file.
- Provide JSON output for scripting.
+19
View File
@@ -0,0 +1,19 @@
# Contributing
Contributions are welcome. Keep changes focused, dependency-free where practical, and compatible with Python 3.10 or newer.
## Development workflow
1. Fork the repository and create a branch for the change.
2. Do not commit `.env`, browser cookies, passwords, downloaded course files, or private LMS responses.
3. Add or update tests for behavioral changes.
4. Run:
```bash
python3 -m unittest -v
python3 -m py_compile ravin_downloader.py
```
5. Open a pull request describing the problem, approach, and test coverage.
Tests must use synthetic data. Do not include real course content, account identifiers, session values, or credentials in fixtures or issue reports.
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 Meghdad Fadaee
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+6
View File
@@ -0,0 +1,6 @@
include LICENSE
include README.md
include CONTRIBUTING.md
include SECURITY.md
include CHANGELOG.md
include .env.example
+53 -18
View File
@@ -1,34 +1,56 @@
# Ravin Academy course downloader
# Ravin Moodle Downloader
This small, dependency-free command-line tool lists the Moodle courses available to your account and downloads the files in a selected course. It first tries Moodle's official mobile web-service API and automatically falls back to a normal web login plus Moodle's own authenticated AJAX interface.
A dependency-free command-line client that lists your enrolled Moodle courses and downloads accessible course files. It defaults to Ravin Academy, but accepts another Moodle base URL through `--site`.
Your password is read with a hidden prompt and is never written to disk.
The client first tries Moodle's official mobile web-service API and falls back to a normal web login plus Moodle's authenticated AJAX interface. For sites protected by Cloudflare, it can reuse request headers from a browser session.
## Usage
> [!IMPORTANT]
> Use this tool only for courses and files your account is authorized to access. Respect the LMS terms, instructor permissions, and applicable copyright rules. This project does not bypass enrollment, DRM, or access controls.
Python 3.10 or newer is recommended.
## Requirements
- Python 3.10 or newer
- An active enrollment on the target Moodle site
The runtime has no third-party Python dependencies.
## Installation
After cloning or downloading the repository, install the command from its root directory:
```bash
python3 ravin_downloader.py --username YOUR_USERNAME courses
python3 ravin_downloader.py --username YOUR_USERNAME files 44
python3 ravin_downloader.py --username YOUR_USERNAME download 44
python3 -m pip install .
```
You can then use `ravin-downloader` from any shell. Running `python3 ravin_downloader.py` directly from the repository remains supported.
## Quick start
```bash
ravin-downloader courses
ravin-downloader files COURSE_ID
ravin-downloader download COURSE_ID
```
Files are saved under `downloads/<course-id>/...`. Existing completed files are skipped; interrupted downloads use a temporary `.part` suffix. Use `--overwrite` if you want to replace existing files.
For scripting, credentials can be supplied for the current shell process and output can be JSON:
For scripting, use JSON output:
```bash
RAVIN_USERNAME='your-user' RAVIN_PASSWORD='your-password' \
python3 ravin_downloader.py --json courses
ravin-downloader --json courses
ravin-downloader --json files COURSE_ID
```
Avoid putting the password directly in shell history. Prefer the normal hidden password prompt when working interactively.
## Configuration
On first use, missing values are requested interactively and saved in `.env` in the current directory. Copy [`.env.example`](.env.example) if you prefer to configure it manually. The file is Git-ignored and written with owner-only permissions.
Never commit or share `.env`. It may contain both account credentials and a temporary authenticated browser session.
If the academy disables its mobile token service, the fallback is automatic. You can force that path for troubleshooting:
```bash
python3 ravin_downloader.py --web-only --username YOUR_USERNAME courses
ravin-downloader --web-only --username YOUR_USERNAME courses
```
## When Cloudflare blocks terminal login
@@ -42,7 +64,7 @@ Ravin Academy currently puts a Cloudflare browser check in front of both Moodle
5. Run the browser-session mode:
```bash
python3 ravin_downloader.py --browser-session courses
ravin-downloader --browser-session courses
```
Paste the User-Agent normally and the Cookie header into the hidden prompt. After the headers are validated, they are saved in `.env` with owner-only permissions and ignored by Git. The same file can contain all four values:
@@ -57,16 +79,29 @@ RAVIN_COOKIE="the complete browser Cookie header"
Values entered at the script's prompts are written or updated automatically. Later commands reuse `.env`, so you can simply run:
```bash
python3 ravin_downloader.py files 44
python3 ravin_downloader.py download 44
ravin-downloader files 44
ravin-downloader download 44
```
The saved session is checked on every run. When it expires or Cloudflare rejects it, the tool asks for fresh headers and replaces the saved copy. You can force that refresh yourself with:
```bash
python3 ravin_downloader.py --refresh-session courses
ravin-downloader --refresh-session courses
```
Never send `.env`, your password, or its Cookie value to another person; they grant access to your LMS account or signed-in session.
The tool only requests content that the supplied account is already authorized to view. It does not bypass enrollment, permissions, DRM, or access controls.
## Development
Run the test suite without installing additional packages:
```bash
python3 -m unittest -v
python3 -m py_compile ravin_downloader.py
```
See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidance and [SECURITY.md](SECURITY.md) for reporting security issues.
## License and disclaimer
Released under the [MIT License](LICENSE). This is an independent community project and is not affiliated with or endorsed by Ravin Academy or Moodle HQ.
+13
View File
@@ -0,0 +1,13 @@
# Security policy
## Reporting a vulnerability
Please report vulnerabilities privately through GitHub's **Security advisories → Report a vulnerability** feature when it is available for this repository. Do not open a public issue containing exploit details, credentials, cookies, private course URLs, or personal information.
Include the affected version, a minimal reproduction using synthetic data, and the expected impact. Remove all real LMS secrets before attaching logs.
## Credential handling
The downloader may store `RAVIN_USERNAME`, `RAVIN_PASSWORD`, `RAVIN_USER_AGENT`, and `RAVIN_COOKIE` in a local `.env` file. That file is excluded from Git and created with owner-only permissions, but users are still responsible for protecting it. Browser cookies should be treated like passwords and refreshed if exposed.
Only download content your account is authorized to access. This project does not support bypassing authentication, enrollment, DRM, or other access controls.
+33
View File
@@ -0,0 +1,33 @@
[build-system]
requires = ["setuptools>=77"]
build-backend = "setuptools.build_meta"
[project]
name = "ravin-moodle-downloader"
version = "0.1.0"
description = "List and download authorized course files from Ravin Academy or another Moodle site"
readme = "README.md"
requires-python = ">=3.10"
license = "MIT"
authors = [{name = "Meghdad Fadaee"}]
keywords = ["moodle", "downloader", "lms", "education"]
classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: Education",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Topic :: Education",
]
dependencies = []
[project.scripts]
ravin-downloader = "ravin_downloader:main"
[tool.setuptools]
py-modules = ["ravin_downloader"]
+4 -2
View File
@@ -31,9 +31,10 @@ from typing import Any, Iterable
DEFAULT_SITE = "https://training.ravinacademy.com"
USER_AGENT = "RavinCourseDownloader/1.0 (+personal Moodle client)"
__version__ = "0.1.0"
USER_AGENT = f"RavinMoodleDownloader/{__version__} (+personal Moodle client)"
DOWNLOADABLE_MODULES = {"resource", "folder", "page", "book"}
DEFAULT_ENV_FILE = Path(__file__).resolve().with_name(".env")
DEFAULT_ENV_FILE = Path.cwd() / ".env"
ENV_KEYS = {
"username": "RAVIN_USERNAME",
"password": "RAVIN_PASSWORD",
@@ -809,6 +810,7 @@ def _format_size(size: int | None) -> str:
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="List and download your Ravin Academy Moodle course files.")
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
parser.add_argument("--site", default=DEFAULT_SITE, help=f"Moodle base URL (default: {DEFAULT_SITE})")
parser.add_argument("--username", help="LMS username; password is prompted securely")
parser.add_argument("--web-only", action="store_true", help="skip the Moodle mobile API and use a normal web session")
+2 -2
View File
@@ -69,7 +69,7 @@ class ParserTests(unittest.TestCase):
{
"RAVIN_USERNAME": "0935",
"RAVIN_PASSWORD": 'pass"word',
"RAVIN_COOKIE": "MoodleSession=secret; cf_clearance=value",
"RAVIN_COOKIE": "example_session=synthetic-value",
},
)
self.assertEqual(
@@ -78,7 +78,7 @@ class ParserTests(unittest.TestCase):
"UNRELATED": "keep me",
"RAVIN_USERNAME": "0935",
"RAVIN_PASSWORD": 'pass"word',
"RAVIN_COOKIE": "MoodleSession=secret; cf_clearance=value",
"RAVIN_COOKIE": "example_session=synthetic-value",
},
)
self.assertEqual(os.stat(path).st_mode & 0o777, 0o600)