Some code cleanup

This commit is contained in:
AnimeDL 2024-06-20 13:32:27 -07:00
parent 436a4ca4d1
commit a6d740e9e9
4 changed files with 16 additions and 23 deletions

2
adn.ts
View file

@ -615,7 +615,7 @@ export default class AnimationDigitalNetwork implements ServiceClass {
// set plQualityStr // set plQualityStr
const plBandwidth = Math.round(pl.attributes.BANDWIDTH/1024); const plBandwidth = Math.round(pl.attributes.BANDWIDTH/1024);
const qualityStrAdd = `${plResolutionText} (${plBandwidth}KiB/s)`; const qualityStrAdd = `${plResolutionText} (${plBandwidth}KiB/s)`;
const qualityStrRegx = new RegExp(qualityStrAdd.replace(/(:|\(|\)|\/)/g, '\\$1'), 'm'); const qualityStrRegx = new RegExp(qualityStrAdd.replace(/([:()/])/g, '\\$1'), 'm');
const qualityStrMatch = !plQuality.map(a => a.str).join('\r\n').match(qualityStrRegx); const qualityStrMatch = !plQuality.map(a => a.str).join('\r\n').match(qualityStrRegx);
if(qualityStrMatch){ if(qualityStrMatch){
plQuality.push({ plQuality.push({

2
ao.ts
View file

@ -213,7 +213,7 @@ export default class AnimeOnegai implements ServiceClass {
} }
//Item is movie, lets define it manually //Item is movie, lets define it manually
if (series.data.asset_type === 1 && series.seasons.length === 0) { if (series.data.asset_type === 1 && series.seasons.length === 0) {
let lang: string | undefined = undefined; let lang: string | undefined;
if (this.jpnStrings.some(str => series.data.title.includes(str))) lang = 'ja'; if (this.jpnStrings.some(str => series.data.title.includes(str))) lang = 'ja';
else if (this.porStrings.some(str => series.data.title.includes(str))) lang = 'pt'; else if (this.porStrings.some(str => series.data.title.includes(str))) lang = 'pt';
else if (this.spaStrings.some(str => series.data.title.includes(str))) lang = 'es'; else if (this.spaStrings.some(str => series.data.title.includes(str))) lang = 'es';

View file

@ -614,8 +614,8 @@ export default class Crunchy implements ServiceClass {
if(item.hide_metadata){ if(item.hide_metadata){
iMetadata.hide_metadata = item.hide_metadata; iMetadata.hide_metadata = item.hide_metadata;
} }
const showObjectMetadata = oMetadata.length > 0 && !iMetadata.hide_metadata ? true : false; const showObjectMetadata = oMetadata.length > 0 && !iMetadata.hide_metadata;
const showObjectBooleans = oBooleans.length > 0 && !iMetadata.hide_metadata ? true : false; const showObjectBooleans = oBooleans.length > 0 && !iMetadata.hide_metadata;
// make obj ids // make obj ids
const objects_ids: string[] = []; const objects_ids: string[] = [];
objects_ids.push(oTypes[item.type as keyof typeof oTypes] + ':' + item.id); objects_ids.push(oTypes[item.type as keyof typeof oTypes] + ':' + item.id);
@ -670,7 +670,7 @@ export default class Crunchy implements ServiceClass {
console.info( console.info(
'%s- Availability notes: %s', '%s- Availability notes: %s',
''.padStart(pad + 2, ' '), ''.padStart(pad + 2, ' '),
item.availability_notes.replace(/\[[^\]]*\]?/gm, '') item.availability_notes.replace(/\[[^\]]*]?/gm, '')
); );
} }
if(item.type == 'series' && getSeries){ if(item.type == 'series' && getSeries){
@ -753,7 +753,7 @@ export default class Crunchy implements ServiceClass {
return; return;
} }
for(const item of movieListing.data){ for(const item of movieListing.data){
this.logObject(item, pad, false, false); await this.logObject(item, pad, false, false);
} }
//Movies //Movies
@ -764,7 +764,7 @@ export default class Crunchy implements ServiceClass {
} }
const moviesList = await moviesListReq.res.json(); const moviesList = await moviesListReq.res.json();
for(const item of moviesList.data){ for(const item of moviesList.data){
this.logObject(item, pad+2); await this.logObject(item, pad + 2);
} }
} }
@ -822,7 +822,7 @@ export default class Crunchy implements ServiceClass {
return { isOk: false, reason: new Error('Show request failed. No more information provided.') }; return { isOk: false, reason: new Error('Show request failed. No more information provided.') };
} }
const showInfo = await showInfoReq.res.json(); const showInfo = await showInfoReq.res.json();
this.logObject(showInfo.data[0], 0); await this.logObject(showInfo.data[0], 0);
let episodeList = { total: 0, data: [], meta: {} } as CrunchyEpisodeList; let episodeList = { total: 0, data: [], meta: {} } as CrunchyEpisodeList;
//get episode info //get episode info
@ -1211,7 +1211,7 @@ export default class Crunchy implements ServiceClass {
// Make sure we have a media id without a : in it // Make sure we have a media id without a : in it
const currentMediaId = (mMeta.mediaId.includes(':') ? mMeta.mediaId.split(':')[1] : mMeta.mediaId); const currentMediaId = (mMeta.mediaId.includes(':') ? mMeta.mediaId.split(':')[1] : mMeta.mediaId);
//Make sure token is up to date //Make sure token is up-to-date
await this.refreshToken(true, true); await this.refreshToken(true, true);
let currentVersion; let currentVersion;
let isPrimary = mMeta.isSubbed; let isPrimary = mMeta.isSubbed;
@ -1418,7 +1418,7 @@ export default class Crunchy implements ServiceClass {
let playStream: CrunchyPlayStream | null = null; let playStream: CrunchyPlayStream | null = null;
if (options.cstream !== 'none') { if (options.cstream !== 'none') {
const playbackReq = await this.req.getData(`https://cr-play-service.prd.crunchyrollsvc.com/v1/${currentVersion ? currentVersion.guid : currentMediaId}/${CrunchyPlayStreams[options.cstream]}/play`, AuthHeaders); const playbackReq = await this.req.getData(`https://cr-play-service.stg.crunchyrollsvc.com/v1/${currentVersion ? currentVersion.guid : currentMediaId}/${CrunchyPlayStreams[options.cstream]}/play`, AuthHeaders);
if (!playbackReq.ok || !playbackReq.res) { if (!playbackReq.ok || !playbackReq.res) {
console.error('Non-DRM Request Stream URLs FAILED!'); console.error('Non-DRM Request Stream URLs FAILED!');
} else { } else {
@ -1517,7 +1517,7 @@ export default class Crunchy implements ServiceClass {
if(s.hardsub_lang == '-'){ if(s.hardsub_lang == '-'){
return false; return false;
} }
return s.hardsub_lang == options.hslang ? true : false; return s.hardsub_lang == options.hslang;
}); });
} }
else{ else{
@ -1529,10 +1529,7 @@ export default class Crunchy implements ServiceClass {
} }
} else { } else {
streams = streams.filter((s) => { streams = streams.filter((s) => {
if(s.hardsub_lang != '-'){ return s.hardsub_lang == '-';
return false;
}
return true;
}); });
if(streams.length < 1){ if(streams.length < 1){
console.warn('Raw streams not available!'); console.warn('Raw streams not available!');
@ -1893,7 +1890,7 @@ export default class Crunchy implements ServiceClass {
// set plQualityStr // set plQualityStr
const plBandwidth = Math.round(pl.attributes.BANDWIDTH/1024); const plBandwidth = Math.round(pl.attributes.BANDWIDTH/1024);
const qualityStrAdd = `${plResolutionText} (${plBandwidth}KiB/s)`; const qualityStrAdd = `${plResolutionText} (${plBandwidth}KiB/s)`;
const qualityStrRegx = new RegExp(qualityStrAdd.replace(/(:|\(|\)|\/)/g, '\\$1'), 'm'); const qualityStrRegx = new RegExp(qualityStrAdd.replace(/([:()/])/g, '\\$1'), 'm');
const qualityStrMatch = !plQuality.map(a => a.str).join('\r\n').match(qualityStrRegx); const qualityStrMatch = !plQuality.map(a => a.str).join('\r\n').match(qualityStrRegx);
if(qualityStrMatch){ if(qualityStrMatch){
plQuality.push({ plQuality.push({
@ -2530,7 +2527,7 @@ export default class Crunchy implements ServiceClass {
} }
const showInfo = await showInfoReq.res.json(); const showInfo = await showInfoReq.res.json();
if (log) if (log)
this.logObject(showInfo, 0); await this.logObject(showInfo, 0);
let episodeList = { total: 0, data: [], meta: {} } as CrunchyEpisodeList; let episodeList = { total: 0, data: [], meta: {} } as CrunchyEpisodeList;
//get episode info //get episode info

View file

@ -127,7 +127,7 @@ export default class Hidive implements ServiceClass {
useProxy: true useProxy: true
}; };
// get request type // get request type
const isGet = method == 'GET' ? true : false; const isGet = method == 'GET';
if(!isGet){ if(!isGet){
options.body = body == '' ? body : JSON.stringify(body); options.body = body == '' ? body : JSON.stringify(body);
options.headers['Content-Type'] = 'application/json'; options.headers['Content-Type'] = 'application/json';
@ -243,11 +243,7 @@ export default class Hidive implements ServiceClass {
}, 'auth'); }, 'auth');
if(!authReq.ok || !authReq.res){ if(!authReq.ok || !authReq.res){
console.error('Token refresh failed, reinitializing session...'); console.error('Token refresh failed, reinitializing session...');
if (!this.initSession()) { return this.initSession();
return false;
} else {
return true;
}
} }
const tokens: Record<string, string> = JSON.parse(authReq.res.body); const tokens: Record<string, string> = JSON.parse(authReq.res.body);
for (const token in tokens) { for (const token in tokens) {