Skip to main content

Async video downloader with Cloudflare bypass, parallel chunked transfers, and multi-source HTML extraction. Termux / ARMv7 optimised.

Project description

java2-extention

Async video downloader with Cloudflare bypass, parallel chunked transfers, and multi-source HTML extraction.
Optimised for Termux / ARMv7 / 2 GB RAM.


Install

pip install java2-extention

With faster optional deps (lxml, aiodns, brotli):

pip install "java2-extention[fast]"

Termux one-liner

pkg update && pkg install python python-pip
pip install java2-extention

CLI usage

# Download from a video page (auto-extracts best quality)
java2dl "https://example.com/some-video-page" ./downloads/

# Download a known direct URL
java2dl "https://cdn.example.com/video.mp4" ./video.mp4

# Skip Cloudflare warmup (clean CDN, no challenge)
java2dl "https://cdn.example.com/video.mp4" . --no-warm

# Verbose debug output
java2dl "https://example.com/page" . --debug

Python API

import asyncio
from java2_extention import (
    VideoExtractor,
    pick_best,
    rank_qualities,
    fetch_html,
    warm_download_url,
    download_to_file,
    ProgressTracker,
)
from java2_extention.downloader import make_session

async def main():
    page_url = "https://example.com/video-page"

    # 1. Fetch the page HTML (Cloudflare-aware, sync → thread)
    html = await asyncio.to_thread(fetch_html, page_url)

    # 2. Extract all video URLs from the page
    extractor = VideoExtractor(base_url=page_url)
    entries = extractor.extract(html)

    # 3. Pick the best direct download
    pick = pick_best(entries)
    if not pick:
        print("No downloadable video found")
        return

    print(f"Best: {pick.url}  quality={pick.quality}")

    # 4. Warm the CDN (solve Cloudflare, harvest cookies)
    final_url, cookies = await warm_download_url(pick.url, page_url)

    # 5. Download with a progress callback
    async def on_progress(downloaded: int, total):
        if total:
            print(f"\r{downloaded/total*100:.1f}%", end="", flush=True)

    tracker = ProgressTracker(callback=on_progress)

    async with make_session(cookies) as session:
        size = await download_to_file(
            session,
            final_url,
            dest=__import__("pathlib").Path("video.mp4"),
            progress=tracker,
            referer=page_url,
            warm=False,   # already warmed above
        )
    print(f"\nDone — {size / 1024 / 1024:.1f} MB")

asyncio.run(main())

How it works

Step What happens
Extract VideoExtractor tries 5 strategies in order: OG video meta, Twitter player meta, <video>/<source> tags, inline <script> JSON scan, <link rel> tags.
Rank Each URL is scored by format (mp4 > webm > m3u8), resolution label, and penalises preview/thumbnail URLs.
Warm warm_download_url runs cloudscraper (HEAD then range probe) to solve Cloudflare challenges and harvest cookies.
Download If the server supports byte ranges and the file is > 2 MB, splits into N parallel chunks. Worker count is capped by available RAM. Falls back to streaming if ranges are unsupported.

Environment variables

Variable Default Purpose
J2_CHUNK_SIZE 524288 (512 KB) Bytes per read chunk
J2_DL_WORKERS 8 Max parallel range workers
J2_PROGRESS_SEC 2 Progress callback interval (seconds)

Lower J2_DL_WORKERS to 2–4 on a 2 GB ARMv7 device if you see OOM.


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

java2_extention-1.0.8.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

java2_extention-1.0.8-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file java2_extention-1.0.8.tar.gz.

File metadata

  • Download URL: java2_extention-1.0.8.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for java2_extention-1.0.8.tar.gz
Algorithm Hash digest
SHA256 e8a61e7b30de02003a82e0f8a83046c4ff434188b3c3902822e94d134756d4b2
MD5 1fbca0c2993e36e2b159f053cbc43689
BLAKE2b-256 b343519ee009faed0273f54435f82547d8aa9cc1d4a07202ccf063bcba2c948d

See more details on using hashes here.

File details

Details for the file java2_extention-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for java2_extention-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 cab74cd2cf1789ebb814dbdf08e785f57ec544f05e3b3e787012becd7ab8a2dc
MD5 839f6912336f259a44cc1f6468d961a0
BLAKE2b-256 129b775dbfccca3e110d7f4f45387b38cab05018d6eeec951eb82b35b888dd54

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page