mirror of
https://github.com/anidl/multi-downloader-nx.git
synced 2026-04-21 00:12:05 +00:00
Episode select with media id
This commit is contained in:
parent
d1972e3725
commit
77a9676eab
5 changed files with 46 additions and 158 deletions
35
crunchy.ts
35
crunchy.ts
|
|
@ -14,7 +14,6 @@ import * as fontsData from './modules/module.fontsData';
|
|||
import * as langsData from './modules/module.langsData';
|
||||
import * as yamlCfg from './modules/module.cfg-loader';
|
||||
import * as yargs from './modules/module.app-args';
|
||||
import * as epsFilter from './modules/module.eps-filter';
|
||||
import Merger, { Font, MergerInput, SubtitleInput } from './modules/module.merger';
|
||||
|
||||
// new-cfg paths
|
||||
|
|
@ -45,6 +44,7 @@ import { ObjectInfo } from './@types/objectInfo';
|
|||
import parseFileName, { Variable } from './modules/module.filename';
|
||||
import { PlaybackData } from './@types/playbackData';
|
||||
import { downloaded } from './modules/module.downloadArchive';
|
||||
import parseSelect from './modules/module.parseSelect';
|
||||
const req = new reqModule.Req(domain, argv);
|
||||
|
||||
// select
|
||||
|
|
@ -462,10 +462,12 @@ async function parseObject(item: ParseItem, pad?: number, getSeries?: boolean, g
|
|||
if(item.type == 'series' && getSeries){
|
||||
argv.series = item.id;
|
||||
await getSeriesById(pad, true);
|
||||
console.log()
|
||||
}
|
||||
if(item.type == 'movie_listing' && getMovieListing){
|
||||
argv['movie-listing'] = item.id;
|
||||
await getMovieListingById(pad+2);
|
||||
console.log()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -641,15 +643,14 @@ async function getSeasonById(){
|
|||
ep: number[],
|
||||
sp: number
|
||||
} = { ep: [], sp: 0 };
|
||||
const epNumLen = epsFilter.epNumLen;
|
||||
const epNumLen = argv.numbers;
|
||||
|
||||
if(episodeList.total < 1){
|
||||
console.log(' [INFO] Season is empty!');
|
||||
return;
|
||||
}
|
||||
|
||||
const doEpsFilter = new epsFilter.doFilter();
|
||||
const selEps = doEpsFilter.checkFilter(argv.e);
|
||||
const doEpsFilter = parseSelect(argv.e as string);
|
||||
const selectedMedia: CrunchyEpMeta[] = [];
|
||||
|
||||
episodeList.items.forEach((item) => {
|
||||
|
|
@ -691,10 +692,10 @@ async function getSeasonById(){
|
|||
}
|
||||
const selEpId = (
|
||||
isSpecial
|
||||
? 'S' + epNumList.sp.toString().padStart(epNumLen['S'], '0')
|
||||
: '' + parseInt(epNum, 10).toString().padStart(epNumLen['E'], '0')
|
||||
? 'S' + epNumList.sp.toString().padStart(epNumLen, '0')
|
||||
: '' + parseInt(epNum, 10).toString().padStart(epNumLen, '0')
|
||||
);
|
||||
if((argv.but && item.playback && selEps.indexOf(selEpId) == -1) || (argv.all && item.playback) || (!argv.but && selEps.indexOf(selEpId) > -1 && !item.isSelected && item.playback)){
|
||||
if((argv.but && item.playback && !doEpsFilter.isSelected([selEpId, item.id])) || (argv.all && item.playback) || (!argv.but && doEpsFilter.isSelected([selEpId, item.id]) && !item.isSelected && item.playback)){
|
||||
selectedMedia.push(epMeta);
|
||||
item.isSelected = true;
|
||||
}
|
||||
|
|
@ -732,22 +733,21 @@ async function getObjectById(returnData?: boolean){
|
|||
return;
|
||||
}
|
||||
|
||||
const doEpsFilter = new epsFilter.doFilter();
|
||||
const inpMedia = doEpsFilter.checkBetaFilter(argv.e as string);
|
||||
const doEpsFilter = parseSelect(argv.e as string);
|
||||
|
||||
if(inpMedia.length < 1){
|
||||
if(doEpsFilter.values.length < 1){
|
||||
console.log('\n[INFO] Objects not selected!\n');
|
||||
return;
|
||||
}
|
||||
|
||||
// node crunchy-beta -e G6497Z43Y,GRZXCMN1W,G62PEZ2E6,G25FVGDEK,GZ7UVPVX5
|
||||
console.log('[INFO] Requested object ID: %s', inpMedia.join(', '));
|
||||
console.log('[INFO] Requested object ID: %s', doEpsFilter.values.join(', '));
|
||||
|
||||
const objectReqOpts = [
|
||||
api.beta_cms,
|
||||
cmsToken.cms.bucket,
|
||||
'/objects/',
|
||||
inpMedia.join(','),
|
||||
doEpsFilter.values.join(','),
|
||||
'?',
|
||||
new URLSearchParams({
|
||||
'Policy': cmsToken.cms.policy,
|
||||
|
|
@ -940,15 +940,14 @@ const itemSelectMultiDub = (eps: Record<string, {
|
|||
items: Item[],
|
||||
langs: langsData.LanguageItem[]
|
||||
}>) => {
|
||||
const doEpsFilter = new epsFilter.doFilter();
|
||||
const selEps = doEpsFilter.checkFilter(argv.e);
|
||||
const doEpsFilter = parseSelect(argv.e as string);
|
||||
|
||||
const ret: Record<string, CrunchyEpMeta> = {};
|
||||
|
||||
const epNumList: {
|
||||
sp: number
|
||||
} = { sp: 0 };
|
||||
const epNumLen = epsFilter.epNumLen;
|
||||
const epNumLen = doEpsFilter.values.length;
|
||||
for (const key of Object.keys(eps)) {
|
||||
const itemE = eps[key];
|
||||
itemE.items.forEach((item, index) => {
|
||||
|
|
@ -988,10 +987,10 @@ const itemSelectMultiDub = (eps: Record<string, {
|
|||
}
|
||||
const selEpId = (
|
||||
isSpecial
|
||||
? 'S' + epNumList.sp.toString().padStart(epNumLen['S'], '0')
|
||||
: '' + parseInt(epNum, 10).toString().padStart(epNumLen['E'], '0')
|
||||
? 'S' + epNumList.sp.toString().padStart(argv.numbers, '0')
|
||||
: '' + parseInt(epNum, 10).toString().padStart(argv.numbers, '0')
|
||||
);
|
||||
if((argv.but && selEps.indexOf(selEpId) == -1) || (argv.all || (selEps.indexOf(selEpId) > -1) && item.playback && !argv.but)){
|
||||
if((argv.but && !doEpsFilter.isSelected([selEpId, item.id])) || (argv.all || (doEpsFilter.isSelected([selEpId, item.id])) && item.playback && !argv.but)){
|
||||
if (Object.prototype.hasOwnProperty.call(ret, key)) {
|
||||
const epMe = ret[key];
|
||||
epMe.data.push({
|
||||
|
|
|
|||
|
|
@ -1,121 +0,0 @@
|
|||
const epNumLen = { E: 4, S: 3, M: 7 };
|
||||
const maxRange = 1000;
|
||||
|
||||
// selectors
|
||||
const epRegex = new RegExp (/^(?:E?|S|M)(\d+)$/);
|
||||
const betaEpRegex = new RegExp (/^[0-9A-Z]{9}$/);
|
||||
const epLtReg = new RegExp (/(?:E|S|M)/);
|
||||
|
||||
class doFilter {
|
||||
ifMaxEp(type: keyof typeof epNumLen, num: number){
|
||||
const maxEp = Math.pow(10, epNumLen[type]) - 1;
|
||||
return num > maxEp ? true : false;
|
||||
}
|
||||
powNum(type: keyof typeof epNumLen){
|
||||
return Math.pow(10, epNumLen[type]);
|
||||
}
|
||||
checkFilter(inputEps?: string){
|
||||
// check
|
||||
const inputEpsArr = inputEps !== undefined
|
||||
? inputEps.toString().split(',') : [];
|
||||
// input range
|
||||
const inputEpsRange: string | string[] = [];
|
||||
|
||||
// filter wrong numbers
|
||||
const filteredArr = inputEpsArr.map((e) => {
|
||||
// convert to uppercase
|
||||
e = e.toUpperCase();
|
||||
// if range
|
||||
if(e.match('-') && e.split('-').length == 2){
|
||||
const eRange: (string|number)[] = e.split('-');
|
||||
// check range
|
||||
if (!eRange[0].toString().match(epRegex)) return '';
|
||||
// set ep latter and pad
|
||||
const epLetter = (eRange[0].toString().match(epLtReg) ? (eRange[0].toString().match(epLtReg) || [])[0] : 'E') as keyof typeof epNumLen;
|
||||
const padLen = epNumLen[epLetter as keyof typeof epNumLen];
|
||||
// parse range
|
||||
eRange[0] = eRange[0].toString().replace(epLtReg, '');
|
||||
eRange[0] = parseInt(eRange[0]);
|
||||
eRange[0] = this.ifMaxEp(epLetter, eRange[0]) ? this.powNum(epLetter) - 1 : eRange[0];
|
||||
eRange[1] = eRange[1].toString().match(/^\d+$/) ? parseInt(eRange[1] as string) : 0;
|
||||
eRange[1] = this.ifMaxEp(epLetter, eRange[1]) ? this.powNum(epLetter) - 1 : eRange[1];
|
||||
console.log(eRange);
|
||||
// check if correct range
|
||||
if (eRange[0] > eRange[1]){
|
||||
const parsedEl = [
|
||||
epLetter != 'E' ? epLetter : '',
|
||||
eRange[0].toString().padStart(padLen, '0'),
|
||||
].join('');
|
||||
return parsedEl;
|
||||
}
|
||||
if(eRange[1] - eRange[0] + 1 > maxRange){
|
||||
eRange[1] = eRange[0] + maxRange - 1;
|
||||
}
|
||||
const rangeLength = eRange[1] - eRange[0] + 1;
|
||||
const epsRangeArr = Array(rangeLength).fill(0);
|
||||
for(const i in epsRangeArr){
|
||||
const parsedRangeEl = [
|
||||
epLetter != 'E' ? epLetter : '',
|
||||
(parseInt(i) + eRange[0]).toString().padStart(padLen, '0'),
|
||||
].join('');
|
||||
inputEpsRange.push(parsedRangeEl);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
else if(e.match(epRegex)){
|
||||
const epLetter = (e.match(epLtReg) ? (e.match(epLtReg) || [])[0] : 'E') as keyof typeof epNumLen;
|
||||
const padLen = epNumLen[epLetter];
|
||||
const e1 = parseInt(e.replace(epLtReg, ''));
|
||||
const e2 = this.ifMaxEp(epLetter, e1) ? this.powNum(epLetter) - 1 : e1;
|
||||
return (epLetter != 'E' ? epLetter : '') + e2.toString().padStart(padLen, '0');
|
||||
}
|
||||
else if(e.match(betaEpRegex)){
|
||||
return e;
|
||||
}
|
||||
return '';
|
||||
});
|
||||
// end
|
||||
const filteredArr1 = [...new Set(filteredArr.concat(inputEpsRange))];
|
||||
const filteredArr2 = filteredArr1.indexOf('') > -1 ? filteredArr1.slice(1) : filteredArr1;
|
||||
return filteredArr2;
|
||||
}
|
||||
checkMediaFilter(e: string){
|
||||
const split = e.split(',');
|
||||
const epLetter = 'M';
|
||||
const inpMedia = [''];
|
||||
// map select
|
||||
split.map((e) => {
|
||||
if(e.match('-')){
|
||||
const eRange = e.split('-');
|
||||
if(eRange[0].match(/^m?\d+$/i)){
|
||||
eRange[0] = eRange[0].replace(/^m/i,'');
|
||||
eRange[0] = (this.ifMaxEp(epLetter, parseInt(eRange[0])) ? this.powNum(epLetter) - 1 : parseInt(eRange[0])).toString();
|
||||
inpMedia.push(eRange[0].toString());
|
||||
}
|
||||
}
|
||||
else if(e.match(/^m?\d+$/i)){
|
||||
const eMedia = parseInt(e.replace(/^m/i,''));
|
||||
const eMediaStr = this.ifMaxEp(epLetter, eMedia) ? this.powNum(epLetter) - 1 : eMedia;
|
||||
inpMedia.push(eMediaStr.toString());
|
||||
}
|
||||
});
|
||||
return [...new Set(inpMedia)].splice(1);
|
||||
}
|
||||
checkBetaFilter(e: string){
|
||||
const e1 = ['', ...e.split(',')];
|
||||
const e2 = e1.map((e) => {
|
||||
if(e.match(betaEpRegex)){
|
||||
return e;
|
||||
}
|
||||
return '';
|
||||
});
|
||||
const e3 = [...new Set(e2)].splice(1);
|
||||
const e4 = e3.length > 100 ? e3.slice(0, 100) : e3;
|
||||
return e4;
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
epNumLen,
|
||||
doFilter,
|
||||
};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
const parseSelect = (selectString: string, but = false) : {
|
||||
isSelected: (val: string) => boolean,
|
||||
isSelected: (val: string|string[]) => boolean,
|
||||
values: string[]
|
||||
} => {
|
||||
if (!selectString)
|
||||
|
|
@ -10,7 +10,6 @@ const parseSelect = (selectString: string, but = false) : {
|
|||
const parts = selectString.split(',');
|
||||
const select: string[] = [];
|
||||
|
||||
|
||||
parts.forEach(part => {
|
||||
if (part.includes('-')) {
|
||||
const splits = part.split('-');
|
||||
|
|
@ -50,6 +49,10 @@ const parseSelect = (selectString: string, but = false) : {
|
|||
}
|
||||
|
||||
} else {
|
||||
if (part.match(/[0-9A-Z]{9}/)) {
|
||||
select.push(part);
|
||||
return;
|
||||
}
|
||||
const match = part.match(/[A-Za-z]+/);
|
||||
if (match && match.length > 0) {
|
||||
if (match.index && match.index !== 0) {
|
||||
|
|
@ -72,22 +75,29 @@ const parseSelect = (selectString: string, but = false) : {
|
|||
return {
|
||||
values: select,
|
||||
isSelected: (st) => {
|
||||
const match = st.match(/[A-Za-z]+/);
|
||||
if (match && match.length > 0) {
|
||||
if (match.index && match.index !== 0) {
|
||||
return false;
|
||||
if (typeof st === "string")
|
||||
st = [st];
|
||||
return st.some(st => {
|
||||
const match = st.match(/[A-Za-z]+/);
|
||||
if (st.match(/[0-9A-Z]{9}/)) {
|
||||
const included = select.includes(st);
|
||||
return but ? !included : included;
|
||||
} else if (match && match.length > 0) {
|
||||
if (match.index && match.index !== 0) {
|
||||
return false;
|
||||
}
|
||||
const letter = st.substring(0, match[0].length);
|
||||
const number = parseInt(st.substring(match[0].length));
|
||||
if (isNaN(number)) {
|
||||
return false;
|
||||
}
|
||||
const included = select.includes(`${letter}${number}`);
|
||||
return but ? !included : included;
|
||||
} else {
|
||||
const included = select.includes(`${parseInt(st)}`);
|
||||
return but ? !included : included;
|
||||
}
|
||||
const letter = st.substring(0, match[0].length);
|
||||
const number = parseInt(st.substring(match[0].length));
|
||||
if (isNaN(number)) {
|
||||
return false;
|
||||
}
|
||||
const included = select.includes(`${letter}${number}`);
|
||||
return but ? !included : included;
|
||||
} else {
|
||||
const included = select.includes(`${parseInt(st)}`);
|
||||
return but ? !included : included;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
|||
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "multi-downloader-nx",
|
||||
"version": "2.0.4",
|
||||
"version": "2.0.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "multi-downloader-nx",
|
||||
"short_name": "aniDL",
|
||||
"version": "2.0.4",
|
||||
"version": "2.0.5",
|
||||
"description": "Download videos from Funimation or Crunchyroll via cli",
|
||||
"keywords": [
|
||||
"download",
|
||||
|
|
|
|||
Loading…
Reference in a new issue