SimpleSyntax
SimpleSyntax is a lightweight, CSS-selector-inspired Python library for downloading media and extracting metadata from various platforms. It provides a clean, declarative API for handling complex downloading tasks, including automatic fallback mechanisms, cookie management, and metadata extraction.
Requirements
- Python >= 3.9
- yt-dlp
- gallery-dl
ffmpeg(required for merging audio/video streams)
Installation
SimpleSyntax is designed to be used as a drop-in library. Ensure you have the required dependencies installed:
pip install yt-dlp gallery-dl
Basic Usage
The library provides a single entry point, rz, which allows you to define the operations you want to perform using a selector-based syntax.
from SimpleSyntax import rz
url = "https://example.com/video"
# Perform operations and bind results to variables in your current scope
rz({
"video[3]": "my_video",
"title": "video_title"
}, url)
print(f"Downloaded: {my_video}")
print(f"Title: {video_title}")
Selector Syntax
SimpleSyntax uses a CSS-inspired selector syntax to define tasks.
Media Selectors
Media selectors support a quality index from 0 to 6:
video[N]: Downloads video content.media[N]: Attempts to download as video; falls back to image downloading if the video engine fails.
Quality Index (N):
0: Audio only1: 360p2: 480p3: 720p4: 1080p5: 1440p6: Best quality
Metadata Selectors
Extract information without downloading the media:
titlecreatorurlviews(formatted)likes(formatted)comments(formatted)duration(formatted)thumbnaildate(YYYY/MM/DD)live(True/False)
Fallback & Cookie Management
SimpleSyntax includes a resilient fallback system:
- No-Cookie Attempt: Every operation is first attempted without cookies.
- Ranked Cookie Fallback: If the first attempt fails, SimpleSyntax ranks user-supplied cookie files by calculating the similarity between the target URL and the cookie filename (using host/path matching).
- Automatic Retry: It sequentially retries the operation using the ranked cookies, stopping at the first successful attempt.
- History: Successful cookie-URL associations are cached to improve future ranking.
To enable cookie support, define a ReiZyuki list/tuple in your caller's scope containing paths to your cookie files:
ReiZyuki = ["/path/to/cookies.txt"]
Playlist Handling
SimpleSyntax supports downloading segments of playlists.
Note: Usage requires providing a string value in the format QUALITY:SKIP:COUNT.
rz({"playlist": "3:0:5"}, url)- Download 5 videos starting from index 0, in 720p quality.
Author: ReiZyuki
Metadata
Release files for simplesyntax 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| simplesyntax-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Release files / simplesyntax-0.1.2-py3-none-any.whl
| Download URL | simplesyntax-0.1.2-py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e57bfb6b3fd103387a0b5e470770350b59941a8212c9dcff41b54fbed7e391ff
|
|
BLAKE2b-256 checksum How to use checksums |
63742943ef0bdae178644c2da30021e6036144cfbc1c9583838dd18c380ee0df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|