fix manga relation finding
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
"idb": "^7.1.1",
|
"idb": "^7.1.1",
|
||||||
"pinia": "^2.1.6",
|
"pinia": "^2.1.6",
|
||||||
"pinia-class-component": "^0.9.4",
|
"pinia-class-component": "^0.9.4",
|
||||||
|
"string-similarity-js": "^2.1.4",
|
||||||
"vue": "^3.3.4",
|
"vue": "^3.3.4",
|
||||||
"vue-class-component": "^8.0.0-rc.1",
|
"vue-class-component": "^8.0.0-rc.1",
|
||||||
"vue-good-table-next": "^0.2.1",
|
"vue-good-table-next": "^0.2.1",
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
export function handleJsonResponse(res: Primise<T>): Promise<T> {
|
export class ApiError extends Error {
|
||||||
|
readonly statusCode: number;
|
||||||
|
|
||||||
|
constructor(statusCode: number, message?: string) {
|
||||||
|
super(message);
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function handleJsonResponse<T>(res: Promise<Response>): Promise<T> {
|
||||||
return res.then(async e => {
|
return res.then(async e => {
|
||||||
if (e.status === 200) {
|
if (e.status === 200) {
|
||||||
return await e.json();
|
return await e.json();
|
||||||
}
|
}
|
||||||
throw new Error('Api error ' + e.status + ': ' + await e.text());
|
throw new ApiError(e.status, 'Api error ' + e.status + ': ' + await e.text());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,9 @@ import MangaUpdatesApi from '@/data/api/MangaUpdatesApi';
|
|||||||
import {DbStore} from '@/stores/DbStore';
|
import {DbStore} from '@/stores/DbStore';
|
||||||
import {MangaStore} from '@/stores/MangaStore';
|
import {MangaStore} from '@/stores/MangaStore';
|
||||||
import type {MangaUpdatesChapter} from '@/data/models/mangaupdates/MangaUpdatesChapter';
|
import type {MangaUpdatesChapter} from '@/data/models/mangaupdates/MangaUpdatesChapter';
|
||||||
|
import type {MangaUpdatesSearchResultRecord} from '@/data/models/mangaupdates/MangaUpdatesSearchResultRecord';
|
||||||
|
import stringSimilarity from 'string-similarity-js';
|
||||||
|
import {ApiError} from '@/data/api/ApiUtils';
|
||||||
|
|
||||||
export default class MangaUpdatesDataService {
|
export default class MangaUpdatesDataService {
|
||||||
private readonly mangaUpdatesApi = new MangaUpdatesApi();
|
private readonly mangaUpdatesApi = new MangaUpdatesApi();
|
||||||
@@ -10,11 +13,17 @@ export default class MangaUpdatesDataService {
|
|||||||
const mangaStore = new MangaStore();
|
const mangaStore = new MangaStore();
|
||||||
const dbStore = new DbStore();
|
const dbStore = new DbStore();
|
||||||
this.findMissingRelations(mangaStore, dbStore, progress)
|
this.findMissingRelations(mangaStore, dbStore, progress)
|
||||||
.catch(_ => {})
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
})
|
||||||
.then(_ => this.fetchSeriesUpdates(mangaStore, dbStore, progress))
|
.then(_ => this.fetchSeriesUpdates(mangaStore, dbStore, progress))
|
||||||
.catch(_ => {})
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
})
|
||||||
.then(_ => this.fetchSeriesChapterUpdates(mangaStore, dbStore, progress))
|
.then(_ => this.fetchSeriesChapterUpdates(mangaStore, dbStore, progress))
|
||||||
.catch(_ => {})
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
})
|
||||||
.then(_ => progress.onFinished());
|
.then(_ => progress.onFinished());
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
@@ -33,16 +42,38 @@ export default class MangaUpdatesDataService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const results = await this.mangaUpdatesApi.search(m.title.romaji);
|
let matching: { record: MangaUpdatesSearchResultRecord }[] = [];
|
||||||
const matching = results.results
|
for (let title of [m.title.native, m.title.romaji, m.title.english]) {
|
||||||
|
if (!title?.trim().length) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let results;
|
||||||
|
try {
|
||||||
|
results = await this.mangaUpdatesApi.search(title);
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof ApiError && [400, 500].includes(err.statusCode)) {
|
||||||
|
console.debug(err);
|
||||||
|
} else {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
} finally {
|
||||||
|
await new Promise((r) => setTimeout(r, 1000));
|
||||||
|
}
|
||||||
|
matching = results.results
|
||||||
|
.filter(e => stringSimilarity(title, e.record.title, 2, false) >= 0.95)
|
||||||
.filter(e => allowTypes.has(e.record.type.toLowerCase())) //check if a manga or similar but not novel
|
.filter(e => allowTypes.has(e.record.type.toLowerCase())) //check if a manga or similar but not novel
|
||||||
.filter(e => m.startDate.year - 1 <= e.record.year && e.record.year <= m.startDate.year + 1); //check year +-1
|
.filter(e => m.startDate.year - 1 <= e.record.year && e.record.year <= m.startDate.year + 1); //check year +-1
|
||||||
if (matching.length === 0) {
|
if (matching.length === 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (matching.length === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
await mangaStore.addMangaUpdatesRelations([{aniListMediaId: m.id, mangaUpdatesSeriesId: matching[0].record.series_id}]);
|
await mangaStore.addMangaUpdatesRelations([{aniListMediaId: m.id, mangaUpdatesSeriesId: matching[0].record.series_id}]);
|
||||||
await new Promise((r) => setTimeout(r, 1000));
|
|
||||||
} finally {
|
} finally {
|
||||||
await progress.onProgress('relations', ++i, media.length);
|
await progress.onProgress('relations', ++i, media.length);
|
||||||
}
|
}
|
||||||
@@ -60,7 +91,19 @@ export default class MangaUpdatesDataService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const series = await this.mangaUpdatesApi.get(relation.mangaUpdatesSeriesId);
|
let series;
|
||||||
|
try {
|
||||||
|
series = await this.mangaUpdatesApi.get(relation.mangaUpdatesSeriesId);
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof ApiError && [400, 500].includes(err.statusCode)) {
|
||||||
|
console.debug(err);
|
||||||
|
} else {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
} finally {
|
||||||
|
await new Promise((r) => setTimeout(r, 1000));
|
||||||
|
}
|
||||||
await mangaStore.updateMangaUpdatesSeries([series]);
|
await mangaStore.updateMangaUpdatesSeries([series]);
|
||||||
} finally {
|
} finally {
|
||||||
await progress.onProgress('series', ++i, relations.length);
|
await progress.onProgress('series', ++i, relations.length);
|
||||||
@@ -79,7 +122,19 @@ export default class MangaUpdatesDataService {
|
|||||||
// continue;
|
// continue;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const groups = await this.mangaUpdatesApi.groups(s.series_id);
|
let groups;
|
||||||
|
try {
|
||||||
|
groups = await this.mangaUpdatesApi.groups(s.series_id);
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof ApiError && [400, 500].includes(err.statusCode)) {
|
||||||
|
console.debug(err);
|
||||||
|
} else {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
} finally {
|
||||||
|
await new Promise((r) => setTimeout(r, 1000));
|
||||||
|
}
|
||||||
|
|
||||||
const updates = groups.release_list
|
const updates = groups.release_list
|
||||||
.map(r => {
|
.map(r => {
|
||||||
|
|||||||
Reference in New Issue
Block a user