resolve infoHash for offcloud and premiumize debrid metas
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import OffcloudClient from 'offcloud-api';
|
import OffcloudClient from 'offcloud-api';
|
||||||
|
import magnet from 'magnet-uri';
|
||||||
import { Type } from '../lib/types.js';
|
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';
|
||||||
@@ -45,7 +46,6 @@ export async function getCatalog(apiKey, offset = 0) {
|
|||||||
return OC.cloud.history()
|
return OC.cloud.history()
|
||||||
.then(torrents => torrents)
|
.then(torrents => torrents)
|
||||||
.then(torrents => (torrents || [])
|
.then(torrents => (torrents || [])
|
||||||
.filter(torrent => torrent && statusReady(torrent))
|
|
||||||
.map(torrent => ({
|
.map(torrent => ({
|
||||||
id: `${KEY}:${torrent.requestId}`,
|
id: `${KEY}:${torrent.requestId}`,
|
||||||
type: Type.OTHER,
|
type: Type.OTHER,
|
||||||
@@ -58,12 +58,14 @@ export async function getItemMeta(itemId, apiKey, ip) {
|
|||||||
const OC = new OffcloudClient(apiKey, options);
|
const OC = new OffcloudClient(apiKey, options);
|
||||||
const torrents = await OC.cloud.history();
|
const torrents = await OC.cloud.history();
|
||||||
const torrent = torrents.find(torrent => torrent.requestId === itemId)
|
const torrent = torrents.find(torrent => torrent.requestId === itemId)
|
||||||
|
const infoHash = torrent && magnet.decode(torrent.originalLink).infoHash
|
||||||
const createDate = torrent ? new Date(torrent.createdOn) : new Date();
|
const createDate = torrent ? new Date(torrent.createdOn) : new Date();
|
||||||
return _getFileUrls(OC, torrent)
|
return _getFileUrls(OC, torrent)
|
||||||
.then(files => ({
|
.then(files => ({
|
||||||
id: `${KEY}:${itemId}`,
|
id: `${KEY}:${itemId}`,
|
||||||
type: Type.OTHER,
|
type: Type.OTHER,
|
||||||
name: torrent.name,
|
name: torrent.name,
|
||||||
|
infoHash: infoHash,
|
||||||
videos: files
|
videos: files
|
||||||
.filter(file => isVideo(file))
|
.filter(file => isVideo(file))
|
||||||
.map((file, index) => ({
|
.map((file, index) => ({
|
||||||
|
|||||||
@@ -61,11 +61,13 @@ export async function getItemMeta(itemId, apiKey, ip) {
|
|||||||
const options = await getDefaultOptions();
|
const options = await getDefaultOptions();
|
||||||
const PM = new PremiumizeClient(apiKey, options);
|
const PM = new PremiumizeClient(apiKey, options);
|
||||||
const rootFolder = await PM.folder.list(itemId, null);
|
const rootFolder = await PM.folder.list(itemId, null);
|
||||||
|
const infoHash = await _findInfoHash(PM, itemId);
|
||||||
return getFolderContents(PM, itemId, ip)
|
return getFolderContents(PM, itemId, ip)
|
||||||
.then(contents => ({
|
.then(contents => ({
|
||||||
id: `${KEY}:${itemId}`,
|
id: `${KEY}:${itemId}`,
|
||||||
type: Type.OTHER,
|
type: Type.OTHER,
|
||||||
name: rootFolder.name,
|
name: rootFolder.name,
|
||||||
|
infoHash: infoHash,
|
||||||
videos: contents
|
videos: contents
|
||||||
.map((file, index) => ({
|
.map((file, index) => ({
|
||||||
id: `${KEY}:${file.id}:${index}`,
|
id: `${KEY}:${file.id}:${index}`,
|
||||||
@@ -96,7 +98,7 @@ export async function resolve({ ip, isBrowser, apiKey, infoHash, cachedEntryInfo
|
|||||||
return _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser)
|
return _getCachedLink(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser)
|
||||||
.catch(() => _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser))
|
.catch(() => _resolve(PM, infoHash, cachedEntryInfo, fileIndex, ip, isBrowser))
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error && error.message && error.message.includes('Account not premium.')) {
|
if (error?.message?.includes('Account not premium.')) {
|
||||||
console.log(`Access denied to Premiumize ${infoHash} [${fileIndex}]`);
|
console.log(`Access denied to Premiumize ${infoHash} [${fileIndex}]`);
|
||||||
return StaticResponse.FAILED_ACCESS;
|
return StaticResponse.FAILED_ACCESS;
|
||||||
}
|
}
|
||||||
@@ -151,6 +153,12 @@ async function _findTorrent(PM, infoHash) {
|
|||||||
return foundTorrent || Promise.reject('No recent torrent found');
|
return foundTorrent || Promise.reject('No recent torrent found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function _findInfoHash(PM, itemId) {
|
||||||
|
const torrents = await PM.transfer.list().then(response => response.transfers);
|
||||||
|
const foundTorrent = torrents.find(torrent => `${torrent.file_id}` === itemId || `${torrent.folder_id}` === itemId);
|
||||||
|
return foundTorrent?.src ? magnet.decode(foundTorrent.src).infoHash : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
async function _createTorrent(PM, infoHash) {
|
async function _createTorrent(PM, infoHash) {
|
||||||
const magnetLink = await getMagnetLink(infoHash);
|
const magnetLink = await getMagnetLink(infoHash);
|
||||||
return PM.transfer.create(magnetLink).then(() => _findTorrent(PM, infoHash));
|
return PM.transfer.create(magnetLink).then(() => _findTorrent(PM, infoHash));
|
||||||
|
|||||||
Reference in New Issue
Block a user