Stream filename scan updates and add provider fallback in v1.3.5
This commit is contained in:
+28
-7
@@ -551,21 +551,34 @@ export class DebridService {
|
||||
this.allDebridClient = new AllDebridClient(next.allDebridToken);
|
||||
}
|
||||
|
||||
public async resolveFilenames(links: string[]): Promise<Map<string, string>> {
|
||||
public async resolveFilenames(
|
||||
links: string[],
|
||||
onResolved?: (link: string, fileName: string) => void
|
||||
): Promise<Map<string, string>> {
|
||||
const unresolved = links.filter((link) => looksLikeOpaqueFilename(filenameFromUrl(link)));
|
||||
if (unresolved.length === 0) {
|
||||
return new Map<string, string>();
|
||||
}
|
||||
|
||||
const clean = new Map<string, string>();
|
||||
const reportResolved = (link: string, fileName: string): void => {
|
||||
const normalized = fileName.trim();
|
||||
if (!normalized || looksLikeOpaqueFilename(normalized) || normalized.toLowerCase() === "download.bin") {
|
||||
return;
|
||||
}
|
||||
if (clean.get(link) === normalized) {
|
||||
return;
|
||||
}
|
||||
clean.set(link, normalized);
|
||||
onResolved?.(link, normalized);
|
||||
};
|
||||
|
||||
const token = this.settings.allDebridToken.trim();
|
||||
if (token) {
|
||||
try {
|
||||
const infos = await this.allDebridClient.getLinkInfos(unresolved);
|
||||
for (const [link, fileName] of infos.entries()) {
|
||||
if (fileName.trim() && !looksLikeOpaqueFilename(fileName.trim())) {
|
||||
clean.set(link, fileName.trim());
|
||||
}
|
||||
reportResolved(link, fileName);
|
||||
}
|
||||
} catch {
|
||||
// ignore and continue with host page fallback
|
||||
@@ -573,10 +586,18 @@ export class DebridService {
|
||||
}
|
||||
|
||||
const remaining = unresolved.filter((link) => !clean.has(link) && isRapidgatorLink(link));
|
||||
await runWithConcurrency(remaining, 3, async (link) => {
|
||||
await runWithConcurrency(remaining, 6, async (link) => {
|
||||
const fromPage = await resolveRapidgatorFilename(link);
|
||||
if (fromPage && !looksLikeOpaqueFilename(fromPage)) {
|
||||
clean.set(link, fromPage);
|
||||
reportResolved(link, fromPage);
|
||||
});
|
||||
|
||||
const stillUnresolved = unresolved.filter((link) => !clean.has(link));
|
||||
await runWithConcurrency(stillUnresolved, 4, async (link) => {
|
||||
try {
|
||||
const unrestricted = await this.unrestrictLink(link);
|
||||
reportResolved(link, unrestricted.fileName || "");
|
||||
} catch {
|
||||
// ignore final fallback errors
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -497,22 +497,21 @@ export class DownloadManager extends EventEmitter {
|
||||
|
||||
private async resolveQueuedFilenames(unresolvedByLink: Map<string, string[]>): Promise<void> {
|
||||
try {
|
||||
const resolved = await this.debridService.resolveFilenames(Array.from(unresolvedByLink.keys()));
|
||||
if (resolved.size === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let changed = false;
|
||||
for (const [link, itemIds] of unresolvedByLink.entries()) {
|
||||
const fileName = resolved.get(link);
|
||||
const applyResolvedName = (link: string, fileName: string): void => {
|
||||
const itemIds = unresolvedByLink.get(link);
|
||||
if (!itemIds || itemIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (!fileName || fileName.toLowerCase() === "download.bin") {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
const normalized = sanitizeFilename(fileName);
|
||||
if (!normalized || normalized.toLowerCase() === "download.bin") {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
let changedForLink = false;
|
||||
for (const itemId of itemIds) {
|
||||
const item = this.session.items[itemId];
|
||||
if (!item) {
|
||||
@@ -528,8 +527,16 @@ export class DownloadManager extends EventEmitter {
|
||||
item.targetPath = path.join(this.session.packages[item.packageId]?.outputDir || this.settings.outputDir, normalized);
|
||||
item.updatedAt = nowMs();
|
||||
changed = true;
|
||||
changedForLink = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changedForLink) {
|
||||
this.persistSoon();
|
||||
this.emitState();
|
||||
}
|
||||
};
|
||||
|
||||
await this.debridService.resolveFilenames(Array.from(unresolvedByLink.keys()), applyResolvedName);
|
||||
|
||||
if (changed) {
|
||||
this.persistSoon();
|
||||
|
||||
Reference in New Issue
Block a user