Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX NicoNicoSeiga: only use the fallback #6372

Merged
merged 3 commits into from
Dec 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 19 additions & 30 deletions src/web/mjs/connectors/NicoNicoSeiga.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ export default class NicoNicoSeiga extends Connector {
};

this.mangaListPage = "/manga/list";
this.mangaListEndPoint = "/ajax/manga/list";

this.queryManga = 'div#comic_list ul li.mg_item div.mg_title div.title a';
this.querySeriesCount = 'div#main div#mg_main_column';

this.queryMangaTitle = 'div.main_title h1';

this.queryChapters = 'div.mg_episode_list div.inner ul li.episode_item div.episode div.description div.title a';

this.queryPages = 'div.pages ul#page_contents li.page div.note source.lazyload';
this.pageTemplateURL = 'https://seiga.nicovideo.jp/image/source/';
}

async _getMangaFromURI(uri) {
Expand All @@ -36,11 +34,11 @@ export default class NicoNicoSeiga extends Connector {

async _getMangasFromRequest(uri) {
let request = new Request(uri, this.requestOptions);
let data = await this.fetchJSON(request);
return data.map(series => {
let data = await this.fetchDOM(request, this.queryManga);
return data.map(anchor => {
return {
id: this.getRootRelativeOrAbsoluteLink('/comic/' + series.id, request.url),
title: series.title
id: anchor.pathname,
title: anchor.text
};
});
}
Expand All @@ -50,7 +48,7 @@ export default class NicoNicoSeiga extends Connector {
let data = await this.fetchDOM(request, this.querySeriesCount);
let totalPages = Math.ceil(data[0].dataset.count/10);
let mangaList = [];
let uri = new URL(this.mangaListEndPoint, this.url);
let uri = new URL(this.mangaListPage, this.url);
for(let page = 1; page <= totalPages; page++) {
uri.searchParams.set('page', page);
let mangas = await this._getMangasFromRequest(uri);
Expand Down Expand Up @@ -84,27 +82,18 @@ export default class NicoNicoSeiga extends Connector {
}

async _handleConnectorURI(payload) {
try {
// first try to get high quality image (await promise, otherwise try/catch won't work)
let data = await super._handleConnectorURI(this.pageTemplateURL + payload.id);
if(data.mimeType.startsWith('image/')) {
return data;
}
throw new Error('Failed to get high quality image => downloading low quality image!');
} catch(error) {
// get low quality DRM image as fallback
let uri = new URL(payload.original);
let request = new Request(uri, this.requestOptions);
let response = await fetch(request);
let encrypted = new Uint8Array(await response.arrayBuffer());
let key = this._getKeyFromUrl(payload.original);
let buffer = {
mimeType: 'application/octet-stream',
data: this._decrypt(encrypted, key)
};
this._applyRealMime(buffer);
return buffer;
}
let uri = new URL(payload.original);
let request = new Request(uri, this.requestOptions);
let response = await fetch(request);
let encrypted = new Uint8Array(await response.arrayBuffer());
let key = this._getKeyFromUrl(payload.original);
let buffer = {
mimeType: 'application/octet-stream',
data: this._decrypt(encrypted, key)
};
this._applyRealMime(buffer);
return buffer;
//}
}

/*********************************
Expand All @@ -128,4 +117,4 @@ export default class NicoNicoSeiga extends Connector {
e[n] = e[n] ^ r[n % i];
return e;
}
}
}
Loading