xvideo-dll 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +110 -65
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,89 +1,134 @@
1
- # xvideo-download
1
+ # xvideo-dll
2
2
 
3
- Librería para Node.js que obtiene la información y las resoluciones disponibles de un video y lo descarga.
3
+ A Node.js library that reads a video page, lists the available qualities and downloads the one you choose.
4
4
 
5
- - Lee los datos básicos de la página (título, miniatura, descripción).
6
- - Detecta todas las calidades: MP4 directo (`mp4-low`, `mp4-high`) y HLS (`hls-480p`, `hls-720p`, ...).
7
- - Descarga HLS en paralelo y lo convierte a un **MP4 real** (reproducible en navegador, VS Code, etc.).
8
- - **No necesita ffmpeg.**
9
- - Si la URL firmada caduca a mitad de la descarga, puede renovarla automáticamente.
5
+ - Reads the basic page data (title, thumbnail, description).
6
+ - Detects every quality: direct MP4 (`mp4-low`, `mp4-high`) and HLS (`hls-480p`, `hls-720p`, ...).
7
+ - Downloads HLS in parallel and converts it to a **real MP4** (plays in browsers, VS Code, etc.).
8
+ - **No ffmpeg required.**
9
+ - If the signed URL expires mid-download, it can refresh it automatically.
10
10
 
11
- ## Requisitos
11
+ ## Requirements
12
12
 
13
- - Node.js 18 o superior.
13
+ - Node.js 18 or higher.
14
14
 
15
- ## Instalación
15
+ ## Install
16
16
 
17
17
  ```bash
18
- npm install xvideo-download
18
+ npm install xvideo-dll
19
19
  ```
20
20
 
21
- ## Uso rápido
21
+ ## Quick start
22
22
 
23
- ```ts
24
- import { fetchPageHtml, parseVideo, getResolutions, download } from "xvideo-download";
23
+ 1. Create a folder and install the package:
25
24
 
26
- const pageUrl = "https://sitio.com/video/xxxx";
25
+ ```bash
26
+ mkdir test && cd test
27
+ npm init -y
28
+ npm install xvideo-dll
29
+ ```
27
30
 
28
- // 1. Descargar la página (siempre en vivo: las URLs caducan)
29
- const html = await fetchPageHtml(pageUrl);
31
+ 2. Create a file named `example.mjs` (the `.mjs` extension lets you use `import` and top-level `await` with no extra setup):
30
32
 
31
- // 2. Información básica
32
- console.log(parseVideo(html));
33
- // { title, thumbnail, description, jsonLd }
33
+ ```js
34
+ import { fetchPageHtml, parseVideo, getResolutions, download } from "xvideo-dll";
34
35
 
35
- // 3. Resoluciones disponibles
36
- const resolutions = await getResolutions(html);
37
- console.log(Object.keys(resolutions));
38
- // [ "mp4-low", "mp4-high", "hls-250p", "hls-480p", ... ]
36
+ // Usage: node example.mjs "PAGE_URL" [quality] [--list | -F]
37
+ const args = process.argv.slice(2);
38
+ const listOnly = args.includes("--list") || args.includes("-F");
39
+ const [pageUrl, quality = "mp4-low"] = args.filter((a) => !a.startsWith("-"));
39
40
 
40
- // 4. Descargar una
41
- const key = "hls-480p";
42
- const result = await download(
43
- resolutions[key],
44
- "video.mp4",
45
- (p) => console.log(`${Math.round(p * 100)}%`), // progreso (0 a 1)
46
- 8, // conexiones en paralelo (solo HLS)
47
- async () => { // opcional: renovar la URL si caduca
48
- const fresh = await getResolutions(await fetchPageHtml(pageUrl));
49
- return fresh[key];
50
- }
51
- );
41
+ if (!pageUrl) {
42
+ console.error('Usage: node example.mjs "PAGE_URL" [quality] [--list | -F]');
43
+ process.exit(1);
44
+ }
52
45
 
53
- console.log(result); // { path: "video.mp4", bytes: 13967360 }
54
- ```
46
+ // 1. Fetch the page (always live: signed URLs expire)
47
+ const html = await fetchPageHtml(pageUrl);
48
+
49
+ // 2. Basic info
50
+ console.log(parseVideo(html));
51
+
52
+ // 3. Available qualities
53
+ const resolutions = await getResolutions(html);
54
+ const keys = Object.keys(resolutions);
55
+
56
+ if (listOnly) {
57
+ console.log("\nAvailable qualities:");
58
+ for (const key of keys) console.log(` ${key}`);
59
+ process.exit(0);
60
+ }
61
+
62
+ // 4. Download the chosen quality (default: "mp4-low", the lightest)
63
+ if (!resolutions[quality]) {
64
+ console.error(`Quality "${quality}" not found. Available: ${keys.join(", ")}`);
65
+ process.exit(1);
66
+ }
67
+
68
+ const result = await download(
69
+ resolutions[quality],
70
+ `video-${quality}.mp4`,
71
+ (p) => process.stdout.write(`\r${Math.round(p * 100)}%`), // progress (0 to 1)
72
+ 8, // parallel connections (HLS only)
73
+ async () => { // optional: refresh the URL if it expires
74
+ const fresh = await getResolutions(await fetchPageHtml(pageUrl));
75
+ return fresh[quality];
76
+ }
77
+ );
55
78
 
56
- También funciona con `require`:
79
+ console.log(`\nSaved to ${result.path} (${(result.bytes / 1024 / 1024).toFixed(1)} MB)`);
80
+ ```
81
+
82
+ 3. Run it:
83
+
84
+ ```bash
85
+ node example.mjs "PAGE_URL" --list # list the available qualities
86
+ node example.mjs "PAGE_URL" # download mp4-low (the fastest)
87
+ node example.mjs "PAGE_URL" hls-480p # download a specific quality
88
+ ```
89
+
90
+ The quality names (`mp4-low`, `hls-480p`, ...) are the keys returned by `getResolutions`, so always list them first: they change from video to video.
91
+
92
+ It also works with `require`, inside an `async` function (CommonJS does not allow top-level `await`):
57
93
 
58
94
  ```js
59
- const { fetchPageHtml, getResolutions, download } = require("xvideo-download");
95
+ const { fetchPageHtml, getResolutions, download } = require("xvideo-dll");
96
+
97
+ async function main() {
98
+ const html = await fetchPageHtml(process.argv[2]);
99
+ const resolutions = await getResolutions(html);
100
+ console.log(Object.keys(resolutions)); // see the qualities
101
+ await download(resolutions["mp4-low"], "video.mp4");
102
+ }
103
+
104
+ main();
60
105
  ```
61
106
 
62
107
  ## API
63
108
 
64
- | Función | Qué hace |
109
+ | Function | What it does |
65
110
  |---|---|
66
- | `fetchPageHtml(url)` | Descarga el HTML de la página (sigue redirecciones). |
67
- | `getVideoInfo(url)` | Descarga la página y devuelve `parseVideo` de su HTML. |
68
- | `parseVideo(html)` | Extrae `title`, `thumbnail`, `description` y `jsonLd` de un HTML. |
69
- | `parsePlayerUrls(html)` | Extrae las URLs `low`, `high` y `hls` del script del reproductor. |
70
- | `parseHlsMaster(m3u8, masterUrl)` | Convierte una lista maestra `.m3u8` en `{ "hls-720p": url, ... }`. |
71
- | `getResolutions(html)` | Devuelve todas las calidades disponibles. |
72
- | `download(url, outPath, onProgress?, threads?, refreshUrl?)` | Descarga una resolución. Elige solo el método según la URL. |
73
- | `downloadHlsFast(...)` | Descarga HLS en paralelo y lo convierte a MP4. |
74
- | `downloadFile(url, outPath, onProgress?)` | Descarga un MP4 directo. |
75
-
76
- Todas las funciones y los tipos `VideoInfo` y `Resolutions` se exportan.
77
-
78
- ## Cosas a tener en cuenta
79
-
80
- - **Las URLs caducan.** Contienen un token con tiempo limitado. Pide siempre la página con `fetchPageHtml` justo antes de descargar y no guardes las URLs para usarlas después.
81
- - **Descarga HLS:** se baja en segmentos a una carpeta temporal (`.hls_temp_*`, junto al archivo de salida), se unen y se convierten a MP4. La carpeta se borra al terminar, incluso si hay un error.
82
- - **Memoria:** en HLS el video completo pasa por la memoria durante la conversión. Es cómodo para videos de decenas de MB; con archivos muy grandes consumirá bastante RAM.
83
- - **MP4 directo:** se descarga con una sola conexión (el parámetro `threads` no aplica).
84
- - **Compatibilidad:** está pensada para páginas cuyo reproductor expone `setVideoUrlLow`, `setVideoUrlHigh` y `setVideoHLS`. Si el sitio cambia ese código, hay que ajustar `parsePlayerUrls`.
85
- - **Uso responsable:** respeta los términos de uso del sitio y los derechos de autor del contenido, y no hagas muchas peticiones seguidas.
86
-
87
- ## Licencia
88
-
89
- ISC
111
+ | `fetchPageHtml(url)` | Downloads the page HTML (follows redirects). |
112
+ | `getVideoInfo(url)` | Downloads the page and returns `parseVideo` of its HTML. |
113
+ | `parseVideo(html)` | Extracts `title`, `thumbnail`, `description` and `jsonLd` from an HTML string. |
114
+ | `parsePlayerUrls(html)` | Extracts the `low`, `high` and `hls` URLs from the player script. |
115
+ | `parseHlsMaster(m3u8, masterUrl)` | Turns an HLS master playlist into `{ "hls-720p": url, ... }`. |
116
+ | `getResolutions(html)` | Returns every available quality. |
117
+ | `download(url, outPath, onProgress?, threads?, refreshUrl?)` | Downloads one quality. Picks the right method from the URL. |
118
+ | `downloadHlsFast(...)` | Downloads HLS in parallel and converts it to MP4. |
119
+ | `downloadFile(url, outPath, onProgress?)` | Downloads a direct MP4. |
120
+
121
+ All functions and the `VideoInfo` and `Resolutions` types are exported.
122
+
123
+ ## Things to keep in mind
124
+
125
+ - **URLs expire.** They carry a time-limited token. Always fetch the page with `fetchPageHtml` right before downloading, and never store URLs to use later.
126
+ - **HLS download:** segments are saved to a temporary folder (`.hls_temp_*`, next to the output file), joined and converted to MP4. The folder is deleted when finished, even if an error occurs.
127
+ - **Memory:** for HLS, the whole video goes through memory during conversion. This is fine for videos of tens of MB; very large files will use a lot of RAM.
128
+ - **Direct MP4:** downloaded with a single connection (the `threads` parameter does not apply).
129
+ - **Compatibility:** built for pages whose player exposes `setVideoUrlLow`, `setVideoUrlHigh` and `setVideoHLS`. If the site changes that code, `parsePlayerUrls` has to be adjusted.
130
+ - **Responsible use:** respect the site's terms of use and the copyright of the content, and do not send many requests in a row.
131
+
132
+ ## License
133
+
134
+ ISC
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "xvideo-dll",
3
- "version": "1.0.0",
4
- "description": "Obtiene la info y las resoluciones de un video y lo descarga (MP4 directo o HLS convertido a MP4 real) sin necesitar ffmpeg.",
3
+ "version": "1.0.2",
4
+ "description": "Lists the qualities of a video page and downloads it (direct MP4 or HLS converted to a real MP4) without ffmpeg.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",