Skip to content

Commit

Permalink
feat!: migrate to latest animegarden
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Jan 29, 2024
1 parent f5f1042 commit 359579f
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 77 deletions.
30 changes: 12 additions & 18 deletions packages/animegarden/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,21 @@ export function formatAnimeGardenSearchURL(anime: Anime) {
}

export function printKeywords(anime: Anime, logger: ConsolaInstance) {
if (anime.plan.keywords.include.length === 1) {
const first = anime.plan.keywords.include[0];
const sum = first.reduce((acc, t) => acc + width(t), 0);
if (sum > 50) {
logger.log(dim('Include keywords | ') + underline(overflowText(first[0], 50)));
for (const t of first.slice(1)) {
logger.log(` ${dim('|')} ${underline(overflowText(t, 50))}`);
}
} else {
logger.log(
`${dim('Include keywords')} ${first
.map((t) => underline(overflowText(t, 50)))
.join(dim(' | '))}`
);
const include = anime.plan.keywords.include;
const sum = include.reduce((acc, t) => acc + width(t), 0);
if (sum > 50) {
logger.log(dim('Include keywords | ') + underline(overflowText(include[0], 50)));
for (const t of include.slice(1)) {
logger.log(` ${dim('|')} ${underline(overflowText(t, 50))}`);
}
} else {
logger.log(dim(`Include keywords:`));
for (const include of anime.plan.keywords.include) {
logger.log(` ${DOT} ${include.map((t) => underline(overflowText(t, 50))).join(' | ')}`);
}
logger.log(
`${dim('Include keywords')} ${include
.map((t) => underline(overflowText(t, 50)))
.join(dim(' | '))}`
);
}

if (anime.plan.keywords.exclude.length > 0) {
logger.log(
`${dim(`Exclude keywords`)} [ ${anime.plan.keywords.exclude
Expand Down
1 change: 1 addition & 0 deletions packages/animegarden/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function AnimeGarden(options: AnimeGardenOptions): Plugin {

const resource = await fetchResourceDetail(
ufetch,
'dmhy',
video.source.magnet.split('/').at(-1)!
);

Expand Down
5 changes: 1 addition & 4 deletions packages/animegarden/src/resources/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,11 @@ export class ResourcesCache {
return false;
}

const stringifyArray = (include: string[][]) => {
return include.map((inc) => `[${inc.map(normalizeTitle).join(',')}]`).join(',');
};
const stringify = (keys?: string[]) => (keys ?? []).join(',');

if (
!cache.filter.include ||
stringifyArray(cache.filter.include) !== stringifyArray(anime.plan.keywords.include)
stringify(cache.filter.include) !== stringify(anime.plan.keywords.include)
) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bangumi/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export async function getCollections(username: string) {

async function getFansub(titles: string[]) {
const { resources } = await fetchResources(ufetch, {
include: [titles],
include: titles,
count: -1,
retry: 5
});
Expand Down
24 changes: 4 additions & 20 deletions packages/cli/test/__snapshots__/space.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ exports[`system > should load 1`] = `
"keywords": {
"exclude": [],
"include": [
[
"熊熊勇闯异世界 Punch!",
],
"熊熊勇闯异世界 Punch!",
],
},
"preference": {
Expand Down Expand Up @@ -73,10 +71,8 @@ exports[`system > should load 1`] = `
"keywords": {
"exclude": [],
"include": [
[
"天国大魔境",
"Tengoku Daimakyou",
],
"天国大魔境",
"Tengoku Daimakyou",
],
},
"preference": {
Expand Down Expand Up @@ -136,19 +132,7 @@ exports[`system > should load 1`] = `
"闪耀色彩",
],
"include": [
[
"偶像大师 灰姑娘女孩 U149",
],
[
"偶像大师",
"iDOLM@STER",
],
[
"灰姑娘女孩",
],
[
"U149",
],
"偶像大师 灰姑娘女孩 U149",
],
},
"preference": {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/anime/anime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ export class Anime {
return false;
}
}
for (const list of this.plan.keywords.include) {
if (list.every((keyword) => !text.includes(keyword))) {
return false;
for (const key of this.plan.keywords.include) {
if (text.includes(key)) {
return true;
}
}
return true;
Expand Down
12 changes: 5 additions & 7 deletions packages/core/src/plan/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,24 @@ function resolveKeywordsArray(
if (keywords !== undefined && keywords !== null) {
if (typeof keywords === 'string') {
if (!keywords.startsWith('!')) {
return { include: [titles, [keywords]], exclude: [] };
return { include: [...titles, keywords], exclude: [] };
} else {
return { include: [titles], exclude: [keywords.slice(1)] };
return { include: titles, exclude: [keywords.slice(1)] };
}
} else if (Array.isArray(keywords)) {
const include: string[][] = [titles];
const include: string[] = [];
const exclude: string[] = [];
for (const keyword of keywords) {
if (typeof keyword === 'string') {
if (!keyword.startsWith('!')) {
include.push([keyword]);
include.push(keyword);
} else {
exclude.push(keyword.slice(1));
}
} else if (Array.isArray(keyword)) {
include.push(keyword);
}
}
return { include, exclude };
}
}
return { include: [titles], exclude: [] };
return { include: titles, exclude: [] };
}
2 changes: 1 addition & 1 deletion packages/core/src/plan/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface AnimePlan {
}

export interface KeywordsParams {
readonly include: string[][];
readonly include: string[];

readonly exclude: string[];
}
24 changes: 4 additions & 20 deletions packages/core/test/__snapshots__/space.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ exports[`Load Space > should work 2`] = `
"keywords": {
"exclude": [],
"include": [
[
"熊熊勇闯异世界 Punch!",
],
"熊熊勇闯异世界 Punch!",
],
},
"preference": {
Expand Down Expand Up @@ -167,10 +165,8 @@ exports[`Load Space > should work 2`] = `
"keywords": {
"exclude": [],
"include": [
[
"天国大魔境",
"Tengoku Daimakyou",
],
"天国大魔境",
"Tengoku Daimakyou",
],
},
"preference": {
Expand Down Expand Up @@ -230,19 +226,7 @@ exports[`Load Space > should work 2`] = `
"闪耀色彩",
],
"include": [
[
"偶像大师 灰姑娘女孩 U149",
],
[
"偶像大师",
"iDOLM@STER",
],
[
"灰姑娘女孩",
],
[
"U149",
],
"偶像大师 灰姑娘女孩 U149",
],
},
"preference": {
Expand Down
4 changes: 1 addition & 3 deletions packages/core/test/fixtures/space/plans/2023.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@ onair:
bgm: 376703
fansub: 喵萌奶茶屋
keywords:
- [偶像大师, iDOLM@STER]
- 灰姑娘女孩
- U149
- 偶像大师 灰姑娘女孩 U149
- '!闪耀色彩'

0 comments on commit 359579f

Please sign in to comment.