Skip to content

Commit c79b7cd

Browse files
committed
[AniLINK] implement source selection in animekai
1 parent c1861dd commit c79b7cd

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

AniLINK/AniLINK_Episode-Link-Extractor.user.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name AniLINK - Episode Link Extractor
33
// @namespace https://greasyfork.org/en/users/781076-jery-js
4-
// @version 6.22.0
4+
// @version 6.22.1
55
// @description Stream or download your favorite anime series effortlessly with AniLINK! Unlock the power to play any anime series directly in your preferred video player or download entire seasons in a single click using popular download managers like IDM. AniLINK generates direct download links for all episodes, conveniently sorted by quality. Elevate your anime-watching experience now!
66
// @icon https://www.google.com/s2/favicons?domain=animepahe.ru
77
// @author Jery
@@ -804,21 +804,18 @@ const Websites = [
804804
},
805805
extractEpisodes: async function* (status) {
806806
status.text = 'Fetching episode list...';
807-
// const epItems = await applyEpisodeRangeFilter($('a[num]').get().map(e=> ({id: e.getAttribute('token'), num: e.getAttribute('num'), type: e.getAttribute('langs'), name: e.querySelector('span').textContent})));
808-
const epElms = await applyEpisodeRangeFilter($('a[num]').get());
807+
const epElms = await applyEpisodeRangeFilter($('a[num]').get()); if (!epElms?.length) return;
808+
const srcCfg = await (async () => {
809+
const servers = await fetch(`/ajax/links/list?token=${epElms[0].getAttribute('token')}&_=${await this._encdec(epElms[0].getAttribute('token'))}`).then(r => r.json().then(d => d.result)).then(t => (new DOMParser()).parseFromString(t, 'text/html')).then(doc => $(doc).find('.server').map((i, e) => `${this._typeSuffix(e.closest('div').dataset.id)} - ${e.textContent}`).get());
810+
return await showSourceSelector(servers, 'animekai', { mode: 'single' });
811+
})();
809812
for (let i = 0; i < epElms.length; i += this._chunkSize)
810813
yield* yieldEpisodesFromPromises(epElms.slice(i, i + this._chunkSize).map(async ep => {
811-
const epNum = ep.getAttribute('num');
812-
status.text = `Extracting Episodes ${(epNum - Math.min(this._chunkSize, epNum) + 1)} - ${epNum}...`;
813-
const servers = await fetch(`/ajax/links/list?token=${ep.getAttribute('token')}&_=${await this._encdec(ep.getAttribute('token'))}`).then(r => r.json().then(d => d.result)).then(t => (new DOMParser()).parseFromString(t, 'text/html'))
814-
.then(doc => $(doc).find('.server').map((i, e) => ({ lid: e.dataset.lid, name: `${this._typeSuffix(e.closest('div').dataset.id)} - ${e.textContent}` })).get())
815-
.catch(e => showToast(`Failed to fetch servers for Ep ${epNum}`));
816-
const links = {};
817-
await Promise.all(servers.map(async s => {
818-
links[s.name] = await fetch(`/ajax/links/view?id=${s.lid}&_=${await this._encdec(s.lid)}`).then(r => r.json().then(d => d.result))
819-
.then(val => this._encdec(val, 'd').then(async d => await Extractors.use(d.url)))
820-
.catch(e => showToast(`Failed to fetch Ep ${epNum} from ${s.name}: ${e.message || e}`))
821-
}));
814+
const epNum = ep.getAttribute('num'); status.text = `Extracting Episodes ${(epNum - Math.min(this._chunkSize, epNum) + 1)} - ${epNum}...`;
815+
const servers = await fetch(`/ajax/links/list?token=${ep.getAttribute('token')}&_=${await this._encdec(ep.getAttribute('token'))}`).then(r => r.json().then(d => d.result)).then(t => (new DOMParser()).parseFromString(t, 'text/html')).then(doc => $(doc).find('.server').map((i, e) => ({ lid: e.dataset.lid, name: `${this._typeSuffix(e.closest('div').dataset.id)} - ${e.textContent}` })).get()).catch(e => showToast(`Failed to fetch servers for Ep ${epNum}`));
816+
const links = {}, fetchSource = async s => { try { links[s.name] = await fetch(`/ajax/links/view?id=${s.lid}&_=${await this._encdec(s.lid)}`).then(r => r.json().then(d => d.result)).then(val => this._encdec(val, 'd').then(async d => await Extractors.use(d.url))); } catch (e) { showToast(`Failed to fetch Ep ${epNum} from ${s.name}: ${e.message || e}`); } };
817+
if (srcCfg?.mode === 'single') { for (const key of srcCfg.sources) { const s = servers.find(srv => srv.name === key); if (s) { await fetchSource(s); if (Object.keys(links).length) break; } } }
818+
else for (const key of srcCfg.sources) { const s = servers.find(srv => srv.name === key); if (s) await fetchSource(s); }
822819
return new Episode(epNum, $('h1').text(), links, $('.poster-wrap-bg').attr('style').match(/https.*\.[a-z]+/g)[0], ep.querySelector('span').textContent);
823820
}))
824821
},

0 commit comments

Comments
 (0)