@dominevo/series-scraper-core 0.0.89 → 0.0.90
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.
- package/dist/ports/paths.d.ts +7 -0
- package/dist/services/download-paths.d.ts +3 -0
- package/dist/services/download-paths.js +41 -0
- package/dist/services/download.service.js +10 -13
- package/dist/services/ffmpeg-hls-args.d.ts +26 -0
- package/dist/services/ffmpeg-hls-args.js +59 -0
- package/package.json +1 -1
package/dist/ports/paths.d.ts
CHANGED
|
@@ -2,4 +2,11 @@
|
|
|
2
2
|
export interface Paths {
|
|
3
3
|
/** Chrome profiles, plugins and captcha dumps live under it. */
|
|
4
4
|
dataDir: string;
|
|
5
|
+
/**
|
|
6
|
+
* What a RELATIVE `downloadPath` in the settings is resolved against (nothing resolves `bookDownloadPath`). Absent: `dataDir`,
|
|
7
|
+
* so a host whose working directory is not its own (an embedded one) never writes under it. The Docker
|
|
8
|
+
* image sets it to its working directory, where `./downloads` is a mounted volume. The sonarr and radarr
|
|
9
|
+
* roots still resolve against the working directory, on purpose: they are absolute in practice.
|
|
10
|
+
*/
|
|
11
|
+
relativeBaseDir?: string;
|
|
5
12
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.resolveDownloadDir = resolveDownloadDir;
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
/** A configured download directory as an absolute path: relative ones resolve against the host's base, never `process.cwd()`. */
|
|
39
|
+
function resolveDownloadDir(configured, paths) {
|
|
40
|
+
return path.resolve(paths.relativeBaseDir ?? paths.dataDir, configured);
|
|
41
|
+
}
|
|
@@ -73,6 +73,7 @@ const sort_links_1 = require("./sort-links");
|
|
|
73
73
|
const cloudflare_detect_1 = require("./cloudflare-detect");
|
|
74
74
|
const media_url_1 = require("./media-url");
|
|
75
75
|
const media_headers_1 = require("./media-headers");
|
|
76
|
+
const download_paths_1 = require("./download-paths");
|
|
76
77
|
const ffmpeg_hls_args_1 = require("./ffmpeg-hls-args");
|
|
77
78
|
const hls_progress_1 = require("./hls-progress");
|
|
78
79
|
const describe_error_1 = require("../utils/describe-error");
|
|
@@ -718,7 +719,7 @@ let DownloadService = DownloadService_1 = class DownloadService {
|
|
|
718
719
|
const seasonFolder = `Season ${String(seasonNumber).padStart(2, '0')}`;
|
|
719
720
|
return path.join(path.resolve(settings.sonarrRootPath), cachedFinalDirBase, seasonFolder);
|
|
720
721
|
};
|
|
721
|
-
const tempDir =
|
|
722
|
+
const tempDir = (0, download_paths_1.resolveDownloadDir)(settings.downloadPath, this.paths);
|
|
722
723
|
const scheduler = this.getEpisodeScheduler();
|
|
723
724
|
const forced = opts?.forced ?? false;
|
|
724
725
|
// A scan leaves a recently not-available episode alone; an operator action re-checks it.
|
|
@@ -1311,7 +1312,7 @@ let DownloadService = DownloadService_1 = class DownloadService {
|
|
|
1311
1312
|
const movieFolder = path.basename(movie.path);
|
|
1312
1313
|
finalDir = path.join(path.resolve(settings.radarrRootPath), movieFolder);
|
|
1313
1314
|
}
|
|
1314
|
-
const tempDir =
|
|
1315
|
+
const tempDir = (0, download_paths_1.resolveDownloadDir)(settings.downloadPath, this.paths);
|
|
1315
1316
|
notify({
|
|
1316
1317
|
type: 'episode_start',
|
|
1317
1318
|
title: 'Movie Downloading',
|
|
@@ -1420,7 +1421,7 @@ let DownloadService = DownloadService_1 = class DownloadService {
|
|
|
1420
1421
|
}
|
|
1421
1422
|
async _runDirectDownload(trackId, link, fileName) {
|
|
1422
1423
|
const settings = this.settings.get();
|
|
1423
|
-
const targetDir =
|
|
1424
|
+
const targetDir = (0, download_paths_1.resolveDownloadDir)(settings.downloadPath, this.paths);
|
|
1424
1425
|
const startedAt = new Date().toISOString();
|
|
1425
1426
|
// Create history entry immediately with 'downloading' status
|
|
1426
1427
|
const historyEntry = this.history.add({
|
|
@@ -2091,7 +2092,7 @@ let DownloadService = DownloadService_1 = class DownloadService {
|
|
|
2091
2092
|
*/
|
|
2092
2093
|
async listLocalFiles() {
|
|
2093
2094
|
const settings = this.settings.get();
|
|
2094
|
-
const dir =
|
|
2095
|
+
const dir = (0, download_paths_1.resolveDownloadDir)(settings.downloadPath, this.paths);
|
|
2095
2096
|
try {
|
|
2096
2097
|
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
2097
2098
|
const files = [];
|
|
@@ -2122,7 +2123,7 @@ let DownloadService = DownloadService_1 = class DownloadService {
|
|
|
2122
2123
|
*/
|
|
2123
2124
|
async deleteLocalFile(fileName) {
|
|
2124
2125
|
const settings = this.settings.get();
|
|
2125
|
-
const dir =
|
|
2126
|
+
const dir = (0, download_paths_1.resolveDownloadDir)(settings.downloadPath, this.paths);
|
|
2126
2127
|
const filePath = path.join(dir, fileName);
|
|
2127
2128
|
// Prevent directory traversal
|
|
2128
2129
|
if (!filePath.startsWith(dir))
|
|
@@ -2681,11 +2682,7 @@ let DownloadService = DownloadService_1 = class DownloadService {
|
|
|
2681
2682
|
headers: (0, media_headers_1.toFfmpegHeaderBlock)((0, media_headers_1.buildMediaHeaders)({ referer: effectiveReferer, userAgent })),
|
|
2682
2683
|
proxyUrl: this.vpn.getFfmpegProxyUrl(url, egressId),
|
|
2683
2684
|
}),
|
|
2684
|
-
...audioMaps,
|
|
2685
|
-
'-c', 'copy',
|
|
2686
|
-
'-bsf:a', 'aac_adtstoasc',
|
|
2687
|
-
'-y',
|
|
2688
|
-
outputPath,
|
|
2685
|
+
...(0, ffmpeg_hls_args_1.buildHlsOutputArgs)(audioMaps, outputPath),
|
|
2689
2686
|
];
|
|
2690
2687
|
const proc = (0, child_process_1.spawn)(ffmpegPath, args, { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
2691
2688
|
let stderr = '';
|
|
@@ -2827,7 +2824,7 @@ let DownloadService = DownloadService_1 = class DownloadService {
|
|
|
2827
2824
|
return [];
|
|
2828
2825
|
}
|
|
2829
2826
|
this.logger.log(`HLS audio: pinning track LANGUAGE="${matchedLang}" (preferred="${preferred}", available=${langs.join(',')})`);
|
|
2830
|
-
return
|
|
2827
|
+
return (0, ffmpeg_hls_args_1.buildAudioLanguageMaps)(matchedLang, (0, ffmpeg_hls_args_1.highestBandwidthVariant)(body));
|
|
2831
2828
|
}
|
|
2832
2829
|
catch (err) {
|
|
2833
2830
|
this.logger.debug?.(`HLS audio pre-parse failed: ${err?.message || err}`);
|
|
@@ -3075,7 +3072,7 @@ let DownloadService = DownloadService_1 = class DownloadService {
|
|
|
3075
3072
|
finalDir = path.join(path.resolve(settings.sonarrRootPath), seriesFolder, seasonFolder);
|
|
3076
3073
|
}
|
|
3077
3074
|
}
|
|
3078
|
-
const tempDir =
|
|
3075
|
+
const tempDir = (0, download_paths_1.resolveDownloadDir)(settings.downloadPath, this.paths);
|
|
3079
3076
|
const linkErrors = [];
|
|
3080
3077
|
const linkFailures = [];
|
|
3081
3078
|
const tag = this.epTag(entry.title, epLabel);
|
|
@@ -3138,7 +3135,7 @@ let DownloadService = DownloadService_1 = class DownloadService {
|
|
|
3138
3135
|
if (settings.moveEp && settings.radarrRootPath) {
|
|
3139
3136
|
finalDir = path.join(path.resolve(settings.radarrRootPath), path.basename(movie.path));
|
|
3140
3137
|
}
|
|
3141
|
-
const tempDir =
|
|
3138
|
+
const tempDir = (0, download_paths_1.resolveDownloadDir)(settings.downloadPath, this.paths);
|
|
3142
3139
|
const linkErrors = [];
|
|
3143
3140
|
const linkFailures = [];
|
|
3144
3141
|
for (const rawLink of candidates) {
|
|
@@ -17,3 +17,29 @@ export interface HlsInputArgsOptions {
|
|
|
17
17
|
readonly proxyUrl?: string;
|
|
18
18
|
}
|
|
19
19
|
export declare function buildHlsInputArgs({ url, headers, proxyUrl }: HlsInputArgsOptions): string[];
|
|
20
|
+
/**
|
|
21
|
+
* ffmpeg output arguments for an HLS download into mp4, as a stream copy.
|
|
22
|
+
*
|
|
23
|
+
* Without `audioMaps` nothing is mapped: ffmpeg's own selection keeps the best video and one audio
|
|
24
|
+
* stream, which is what a download wants. `-sn` and `-dn` keep subtitle and data streams out whatever
|
|
25
|
+
* the selection would do, because mp4 cannot hold a webvtt subtitle or timed ID3 and the muxer dies
|
|
26
|
+
* with "Could not write header (incorrect codec parameters ?)".
|
|
27
|
+
*
|
|
28
|
+
* `audioMaps` (see `buildAudioLanguageMaps`) pins one video variant and one audio rendition.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildHlsOutputArgs(audioMaps: readonly string[], outputPath: string): string[];
|
|
31
|
+
/**
|
|
32
|
+
* Exactly one video variant plus the audio rendition tagged with `language`.
|
|
33
|
+
*
|
|
34
|
+
* The audio selector is an AUDIO one (`0:a:m:...`): a subtitle tagged with the same language must not
|
|
35
|
+
* match. ffmpeg's HLS demuxer makes one program per variant, numbered in playlist order, so
|
|
36
|
+
* `0:p:<variantIndex>:v` is that variant's video and nothing else. Without a variant index the first
|
|
37
|
+
* video stream is taken.
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildAudioLanguageMaps(language: string, variantIndex?: number): string[];
|
|
40
|
+
/**
|
|
41
|
+
* Position, among the `#EXT-X-STREAM-INF` entries of a master playlist, of the one with the highest
|
|
42
|
+
* BANDWIDTH (the best quality). A variant that declares a RESOLUTION is preferred over one that does
|
|
43
|
+
* not, so an audio-only variant is never the video pick. Undefined when the playlist lists none.
|
|
44
|
+
*/
|
|
45
|
+
export declare function highestBandwidthVariant(masterBody: string): number | undefined;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildHlsInputArgs = buildHlsInputArgs;
|
|
4
|
+
exports.buildHlsOutputArgs = buildHlsOutputArgs;
|
|
5
|
+
exports.buildAudioLanguageMaps = buildAudioLanguageMaps;
|
|
6
|
+
exports.highestBandwidthVariant = highestBandwidthVariant;
|
|
4
7
|
const RW_TIMEOUT_US = '15000000';
|
|
5
8
|
const RECONNECT_DELAY_MAX_S = '5';
|
|
6
9
|
function buildHlsInputArgs({ url, headers, proxyUrl }) {
|
|
@@ -15,3 +18,59 @@ function buildHlsInputArgs({ url, headers, proxyUrl }) {
|
|
|
15
18
|
'-i', url,
|
|
16
19
|
];
|
|
17
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* ffmpeg output arguments for an HLS download into mp4, as a stream copy.
|
|
23
|
+
*
|
|
24
|
+
* Without `audioMaps` nothing is mapped: ffmpeg's own selection keeps the best video and one audio
|
|
25
|
+
* stream, which is what a download wants. `-sn` and `-dn` keep subtitle and data streams out whatever
|
|
26
|
+
* the selection would do, because mp4 cannot hold a webvtt subtitle or timed ID3 and the muxer dies
|
|
27
|
+
* with "Could not write header (incorrect codec parameters ?)".
|
|
28
|
+
*
|
|
29
|
+
* `audioMaps` (see `buildAudioLanguageMaps`) pins one video variant and one audio rendition.
|
|
30
|
+
*/
|
|
31
|
+
function buildHlsOutputArgs(audioMaps, outputPath) {
|
|
32
|
+
return [
|
|
33
|
+
...audioMaps,
|
|
34
|
+
'-dn',
|
|
35
|
+
'-sn',
|
|
36
|
+
'-c', 'copy',
|
|
37
|
+
'-bsf:a', 'aac_adtstoasc',
|
|
38
|
+
'-y',
|
|
39
|
+
outputPath,
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Exactly one video variant plus the audio rendition tagged with `language`.
|
|
44
|
+
*
|
|
45
|
+
* The audio selector is an AUDIO one (`0:a:m:...`): a subtitle tagged with the same language must not
|
|
46
|
+
* match. ffmpeg's HLS demuxer makes one program per variant, numbered in playlist order, so
|
|
47
|
+
* `0:p:<variantIndex>:v` is that variant's video and nothing else. Without a variant index the first
|
|
48
|
+
* video stream is taken.
|
|
49
|
+
*/
|
|
50
|
+
function buildAudioLanguageMaps(language, variantIndex) {
|
|
51
|
+
return [
|
|
52
|
+
'-map', variantIndex === undefined ? '0:v:0' : `0:p:${variantIndex}:v`,
|
|
53
|
+
'-map', `0:a:m:language:${language}`,
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Position, among the `#EXT-X-STREAM-INF` entries of a master playlist, of the one with the highest
|
|
58
|
+
* BANDWIDTH (the best quality). A variant that declares a RESOLUTION is preferred over one that does
|
|
59
|
+
* not, so an audio-only variant is never the video pick. Undefined when the playlist lists none.
|
|
60
|
+
*/
|
|
61
|
+
function highestBandwidthVariant(masterBody) {
|
|
62
|
+
const variants = masterBody
|
|
63
|
+
.split(/\r?\n/)
|
|
64
|
+
.filter((line) => line.startsWith('#EXT-X-STREAM-INF:'))
|
|
65
|
+
.map((line, index) => ({
|
|
66
|
+
index,
|
|
67
|
+
bandwidth: Number(line.match(/(?:^|[:,])BANDWIDTH=(\d+)/i)?.[1] ?? 0),
|
|
68
|
+
hasResolution: /[:,]RESOLUTION=/i.test(line),
|
|
69
|
+
}));
|
|
70
|
+
const candidates = variants.some((v) => v.hasResolution) ? variants.filter((v) => v.hasResolution) : variants;
|
|
71
|
+
let best;
|
|
72
|
+
for (const v of candidates)
|
|
73
|
+
if (!best || v.bandwidth > best.bandwidth)
|
|
74
|
+
best = v;
|
|
75
|
+
return best?.index;
|
|
76
|
+
}
|
package/package.json
CHANGED