misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux
Rust bittorrent-clientdebriddownload-acceleratordownload-managerdownloadmanagereguifile-downloadergallery-dlidmidm-alternativeinternet-download-managerm3u8-downloadermagnetplaylist-downloaderreal-debridrusttorrent-clientvideo-downloaderyoutube-downloaderyt-dlp
Website: download links follow the latest published release (#3)
Ahmed Nefzaoui55c4e3a74bac
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 19cdb842..2d534afb 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -168,6 +168,9 @@ jobs:path: target/dist/*publish:+ permissions:+ contents: write # the release+ actions: write # rebuilding the websiteif: >-always() && startsWith(github.ref, 'refs/tags/') && needs.windows.result == 'success' &&needs.extension.result == 'success'@@ -216,3 +219,6 @@ jobs:Set-Content -Encoding utf8 notes.md $invitegh release create "${{ github.ref_name }}" --latest --title $title --notes-file notes.md --generate-notes $all}+ # The website links to the latest published release: rebuild it now that the files are+ # there (a release made with this token starts no workflow by itself).+ gh workflow run pages.yml --ref maindiff --git a/tools/website/build.py b/tools/website/build.pyindex 76aae7b4..72656883 100644--- a/tools/website/build.py+++ b/tools/website/build.py@@ -39,7 +39,32 @@ OUT = ROOT / "target" / "site"SITE = "https://misterdownloadmanager.com"REPO = "https://github.com/anefzaoui/misterdownloadmanager"NAME = "Mister Download Manager"-VERSION = re.search(r'(?m)^version\s*=\s*"([^"]+)"', (ROOT / "Cargo.toml").read_text("utf-8")).group(1)+CARGO_VERSION = re.search(r'(?m)^version\s*=\s*"([^"]+)"', (ROOT / "Cargo.toml").read_text("utf-8")).group(1)+++def github(path: str):+ """GET api.github.com/<path> as JSON, or None (offline, rate-limited)."""+ req = urllib.request.Request(f"https://api.github.com/{path}", headers={+ "Accept": "application/vnd.github+json", "User-Agent": "misterdownloadmanager-site"})+ if os.environ.get("GITHUB_TOKEN"):+ req.add_header("Authorization", f"Bearer {os.environ['GITHUB_TOKEN']}")+ try:+ with urllib.request.urlopen(req, timeout=15) as r:+ return json.load(r)+ except Exception as e: # noqa: BLE001 — the site builds without the numbers+ print(f"github {path}: {e}", file=sys.stderr)+ return None+++def published_version() -> str:+ """The latest published release's version: what the download links and the version shown+ point at. Cargo.toml's is ahead of it between a merged version bump and its release's+ files (release.yml rebuilds the site once they are published); used offline."""+ latest = github(f"repos/{REPO.split('github.com/')[1]}/releases/latest")+ return (latest or {}).get("tag_name", "").lstrip("v") or CARGO_VERSION+++VERSION = published_version()TODAY = datetime.date.today().isoformat()RELEASE = f"{REPO}/releases/download/v{VERSION}/MisterDownloadManager-{VERSION}"FILES = {@@ -87,20 +112,6 @@ def stats_code() -> str:return "" if os.environ.get("MDM_SITE_NO_STATS") == "1" else STATCOUNTER-def github(path: str):- """GET api.github.com/<path> as JSON, or None (offline, rate-limited)."""- req = urllib.request.Request(f"https://api.github.com/{path}", headers={- "Accept": "application/vnd.github+json", "User-Agent": "misterdownloadmanager-site"})- if os.environ.get("GITHUB_TOKEN"):- req.add_header("Authorization", f"Bearer {os.environ['GITHUB_TOKEN']}")- try:- with urllib.request.urlopen(req, timeout=15) as r:- return json.load(r)- except Exception as e: # noqa: BLE001 — the site builds without the numbers- print(f"github {path}: {e}", file=sys.stderr)- return None--def short_num(n: int) -> str:return f"{n / 1000:.1f}k".replace(".0k", "k") if n >= 1000 else str(n)