Add --extid for crunchyroll

Allows downloading or viewing of old Crunchyroll ID's such as: SRZ.282651 VOL.26453 EPI.842919 FLM.268837

Fixes #351 #249
This commit is contained in:
AnimeDL 2023-07-10 08:25:50 -07:00
parent bfe4ae6164
commit 4a135092e9
4 changed files with 63 additions and 3 deletions

View file

@ -144,6 +144,16 @@ export default class Crunchy implements ServiceClass {
}
}
return true;
} else if (argv.extid) {
await this.refreshToken();
const selected = await this.getObjectById(argv.extid, false, true);
for (const select of selected as Partial<CrunchyEpMeta>[]) {
if (!(await this.downloadEpisode(select as CrunchyEpMeta, {...argv, skipsubs: false }))) {
console.error(`Unable to download selected episode ${select.episodeNumber}`);
return false;
}
}
return true;
}
else{
console.info('No option selected or invalid value entered. Try --help.');
@ -852,13 +862,48 @@ export default class Crunchy implements ServiceClass {
return true;
}
public async getObjectById(e?: string, earlyReturn?: boolean): Promise<ObjectInfo|Partial<CrunchyEpMeta>[]|undefined> {
public async getObjectById(e?: string, earlyReturn?: boolean, external_id?: boolean): Promise<ObjectInfo|Partial<CrunchyEpMeta>[]|undefined> {
if(!this.cmsToken.cms){
console.error('Authentication required!');
return;
}
const doEpsFilter = parseSelect(e as string);
let convertedObjects;
if (external_id) {
const epFilter = parseSelect(e as string);
const objectIds = [];
for (const ob of epFilter.values) {
const extIdReqOpts = [
api.beta_cms,
this.cmsToken.cms.bucket,
'/channels/crunchyroll/objects',
'?',
new URLSearchParams({
'external_id': ob,
'Policy': this.cmsToken.cms.policy,
'Signature': this.cmsToken.cms.signature,
'Key-Pair-Id': this.cmsToken.cms.key_pair_id,
}),
].join('');
const extIdReq = await this.req.getData(extIdReqOpts);
if (!extIdReq.ok || !extIdReq.res) {
console.error('Objects Request FAILED!');
if (extIdReq.error && extIdReq.error.res && extIdReq.error.res.body) {
console.info('[INFO] Body:', extIdReq.error.res.body);
}
continue;
}
const oldObjectInfo = JSON.parse(extIdReq.res.body) as Record<any, any>;
for (const object of oldObjectInfo.items) {
objectIds.push(object.id);
}
}
convertedObjects = objectIds.join(',');
}
const doEpsFilter = parseSelect(convertedObjects ?? e as string);
if(doEpsFilter.values.length < 1){
console.info('\nObjects not selected!\n');

View file

@ -33,6 +33,7 @@ let argvC: {
series: string | undefined;
s: string | undefined;
e: string | undefined;
extid: string | undefined;
q: number;
x: number;
kstream: number;

View file

@ -165,6 +165,17 @@ const args: TAppArg<boolean|number|string|unknown[]>[] = [
usage: '${selection}',
alias: 'episode'
},
{
name: 'extid',
group: 'dl',
describe: 'Set the external id to lookup/download',
docDescribe: 'Set the external id to lookup/download.'
+ '\nAllows you to download or view legacy Crunchyroll Ids ',
service: ['crunchy'],
type: 'string',
usage: '${selection}',
alias: 'externalid'
},
{
name: 'q',
group: 'dl',

View file

@ -54,6 +54,9 @@ const parseSelect = (selectString: string, but = false) : {
if (part.match(/[0-9A-Z]{9}/)) {
select.push(part);
return;
} else if (part.match(/[A-Z]{3}\.[0-9]*/)) {
select.push(part);
return;
}
const match = part.match(/[A-Za-z]+/);
if (match && match.length > 0) {