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.9.tar.gz (24.8 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.9-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: java2_extention-1.0.9.tar.gz
  • Upload date:
  • Size: 24.8 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.9.tar.gz
Algorithm Hash digest
SHA256 1da38c30ce615ae3fd2abfc9b95444cbbd711122e600cc4a71d9a4ba0b2fc6fc
MD5 a5bfaee77399aa32b45bffcea05dd6b0
BLAKE2b-256 6914f9e0b04663eb7b2676d4083fb68422ec2ea2287b3324863f44374a93f158

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for java2_extention-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 3f9d4646c61375077fc578913f604fc963fb4cd848a549b02384f6663fd889ef
MD5 8e6933b5946db4eb673f50a874c50544
BLAKE2b-256 b9750d1822e838c8527a483a29f5b222c44cda3f93c82544e12cae6a04baf9b3

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