mirror of
https://github.com/TheBeastLT/torrentio-scraper.git
synced 2026-04-21 19:21:55 +00:00
add os_hash and size for tb cached entries stream responses
This commit is contained in:
parent
8ae31eaca4
commit
bbb2696c54
2 changed files with 21 additions and 12 deletions
|
|
@ -189,7 +189,7 @@ function populateCachedLinks(streams, mochResult, config) {
|
||||||
name: `[${mochResult.moch.shortName}+] ${stream.name}`,
|
name: `[${mochResult.moch.shortName}+] ${stream.name}`,
|
||||||
title: stream.title,
|
title: stream.title,
|
||||||
url: `${config.host}/resolve/${mochResult.moch.key}/${cachedEntry.url}/${streamFilename(stream)}`,
|
url: `${config.host}/resolve/${mochResult.moch.key}/${cachedEntry.url}/${streamFilename(stream)}`,
|
||||||
behaviorHints: stream.behaviorHints
|
behaviorHints: { ...stream.behaviorHints, ...cachedEntry.behaviorHints }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return stream;
|
return stream;
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,15 @@ import { Type } from '../lib/types.js';
|
||||||
import { isVideo } from '../lib/extension.js';
|
import { isVideo } from '../lib/extension.js';
|
||||||
import StaticResponse from './static.js';
|
import StaticResponse from './static.js';
|
||||||
import { getMagnetLink } from '../lib/magnetHelper.js';
|
import { getMagnetLink } from '../lib/magnetHelper.js';
|
||||||
import { chunkArray, sameFilename, streamFilename, BadTokenError, AccessDeniedError } from './mochHelper.js';
|
import { sameFilename, streamFilename, BadTokenError, AccessDeniedError } from './mochHelper.js';
|
||||||
|
|
||||||
const KEY = 'torbox';
|
const KEY = 'torbox';
|
||||||
const timeout = 30000;
|
const timeout = 30000;
|
||||||
const baseUrl = 'https://api.torbox.app/v1'
|
const baseUrl = 'https://api.torbox.app/v1'
|
||||||
|
|
||||||
export async function getCachedStreams(streams, apiKey) {
|
export async function getCachedStreams(streams, apiKey) {
|
||||||
const hashBatches = chunkArray(streams.map(stream => stream.infoHash), 150)
|
const available = await getAvailabilityResponse(apiKey, streams.map(stream => stream.infoHash))
|
||||||
.map(hashes => getAvailabilityResponse(apiKey, hashes));
|
.then(results => new Map(results.map(result => [result.hash, result])))
|
||||||
const available = await Promise.all(hashBatches)
|
|
||||||
.then(results => results
|
|
||||||
.map(data => data.map(entry => entry.hash))
|
|
||||||
.reduce((all, result) => all.concat(result), []))
|
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log('Failed TorBox cached torrent availability request: ', JSON.stringify(error.message || error));
|
console.log('Failed TorBox cached torrent availability request: ', JSON.stringify(error.message || error));
|
||||||
if (toCommonError(error)) {
|
if (toCommonError(error)) {
|
||||||
|
|
@ -25,11 +21,23 @@ export async function getCachedStreams(streams, apiKey) {
|
||||||
});
|
});
|
||||||
return available && streams
|
return available && streams
|
||||||
.reduce((mochStreams, stream) => {
|
.reduce((mochStreams, stream) => {
|
||||||
const isCached = available.includes(stream.infoHash);
|
const cachedEntry = available.get(stream.infoHash);
|
||||||
const fileName = streamFilename(stream);
|
const fileName = streamFilename(stream);
|
||||||
|
const targetFileName = decodeURIComponent(fileName);
|
||||||
|
const videos = (cachedEntry?.files || [])
|
||||||
|
.filter(file => isVideo(file.short_name))
|
||||||
|
.sort((a, b) => b.size - a.size);
|
||||||
|
const targetVideo = Number.isInteger(stream.fileIdx)
|
||||||
|
&& videos.find(video => sameFilename(video.name, targetFileName))
|
||||||
|
|| videos[0];
|
||||||
mochStreams[`${stream.infoHash}@${stream.fileIdx}`] = {
|
mochStreams[`${stream.infoHash}@${stream.fileIdx}`] = {
|
||||||
url: `${apiKey}/${stream.infoHash}/${fileName}/${stream.fileIdx}`,
|
url: `${apiKey}/${stream.infoHash}/${fileName}/${stream.fileIdx}`,
|
||||||
cached: isCached
|
cached: !!cachedEntry,
|
||||||
|
behaviorHints: targetVideo?.opensubtitles_hash &&
|
||||||
|
{
|
||||||
|
videoSize: targetVideo.size,
|
||||||
|
videoHash: targetVideo.opensubtitles_hash
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return mochStreams;
|
return mochStreams;
|
||||||
}, {})
|
}, {})
|
||||||
|
|
@ -180,8 +188,9 @@ async function _unrestrictLink(apiKey, infoHash, torrent, cachedEntryInfo, fileI
|
||||||
async function getAvailabilityResponse(apiKey, hashes) {
|
async function getAvailabilityResponse(apiKey, hashes) {
|
||||||
const url = `${baseUrl}/api/torrents/checkcached`;
|
const url = `${baseUrl}/api/torrents/checkcached`;
|
||||||
const headers = getHeaders(apiKey);
|
const headers = getHeaders(apiKey);
|
||||||
const params = { hash: hashes.join(','), format: 'list' };
|
const params = { format: 'list', list_files: true };
|
||||||
return axios.get(url, { params, headers, timeout })
|
const data = { hashes }
|
||||||
|
return axios.post(url, data, { params, headers, timeout })
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.data?.success) {
|
if (response.data?.success) {
|
||||||
return Promise.resolve(response.data.data || []);
|
return Promise.resolve(response.data.data || []);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue