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

Added support for zoro dubs #93

Merged
merged 3 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions dist/providers/anime/enime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/providers/anime/enime.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/providers/anime/zoro.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ declare class Zoro extends AnimeParser {
* @param episodeId Episode id
*/
fetchEpisodeSources: (episodeId: string, server?: StreamingServers) => Promise<ISource>;
private retrieveServerId;
/**
* @param page Page number
*/
Expand Down
50 changes: 29 additions & 21 deletions dist/providers/anime/zoro.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/providers/anime/zoro.js.map

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/providers/meta/anilist.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/providers/meta/anilist.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/providers/anime/enime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ class Enime extends AnimeParser {
)
?.target.split('/')
.pop()
.replace('?ep=', '$episode$')!,
.replace('?ep=', '$episode$')
?.concat(useType === 'zoro' ? "$sub" : "")!,
description: episode.description,
number: episode.number,
title: episode.title,
Expand Down
49 changes: 30 additions & 19 deletions src/providers/anime/zoro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IEpisodeServer,
StreamingServers,
MediaFormat,
SubOrSub,
} from '../../models';

import { StreamSB, USER_AGENT, RapidCloud, StreamTape } from '../../utils';
Expand Down Expand Up @@ -93,6 +94,15 @@ class Zoro extends AnimeParser {
info.type = $('span.item').last().prev().prev().text().toUpperCase() as MediaFormat;
info.url = `${this.baseUrl}/${id}`;

const subDub = $('div.film-stats span.item div.tick-dub').toArray().map((value) => $(value).text().toLowerCase())
if (subDub.length > 1) {
info.subOrDub = SubOrSub.BOTH
} else if (subDub.length > 0) {
info.subOrDub = subDub[0] as SubOrSub
} else {
info.subOrDub = SubOrSub.SUB
}

const episodesAjax = await axios.get(`${this.baseUrl}/ajax/v2/episode/list/${id.split('-').pop()}`, {
headers: {
'X-Requested-With': 'XMLHttpRequest',
Expand All @@ -105,7 +115,7 @@ class Zoro extends AnimeParser {
info.totalEpisodes = $$('div.detail-infor-content > div > a').length;
info.episodes = [];
$$('div.detail-infor-content > div > a').each((i, el) => {
const episodeId = $$(el).attr('href')?.split('/')[2]?.replace('?ep=', '$episode$')!;
const episodeId = $$(el).attr('href')?.split('/')[2]?.replace('?ep=', '$episode$')?.concat(`$${info.subOrDub}`)!;
const number = parseInt($$(el).attr('data-number')!);
const title = $$(el).attr('title');
const url = this.baseUrl + $$(el).attr('href');
Expand Down Expand Up @@ -161,7 +171,13 @@ class Zoro extends AnimeParser {
}
}
if (!episodeId.includes('$episode$')) throw new Error('Invalid episode id');
episodeId = `${this.baseUrl}/watch/${episodeId.replace('$episode$', '?ep=')}`;

// Fallback to using sub if no info found in case of compatibility

// TODO: add both options later
let subOrDub:'sub' | 'dub' = episodeId.split('$')?.pop() === 'dub' ? 'dub' : 'sub';

episodeId = `${this.baseUrl}/watch/${episodeId.replace('$episode$', '?ep=').replace(/\$auto|\$sub|\$dub/gi, '')}`;

try {
const { data } = await axios.get(
Expand All @@ -180,36 +196,24 @@ class Zoro extends AnimeParser {
try {
switch (server) {
case StreamingServers.VidCloud:
serverId = $('div.ps_-block.ps_-block-sub.servers-sub > div.ps__-list > div')
.map((i, el) => ($(el).attr('data-server-id') == '1' ? $(el) : null))
.get()[0]
.attr('data-id')!;
serverId = this.retrieveServerId($, 1, subOrDub);

// zoro's vidcloud server is rapidcloud
if (!serverId) throw new Error('RapidCloud not found');
break;
case StreamingServers.VidStreaming:
serverId = $('div.ps_-block.ps_-block-sub.servers-sub > div.ps__-list > div')
.map((i, el) => ($(el).attr('data-server-id') == '4' ? $(el) : null))
.get()[0]
.attr('data-id')!;
serverId = this.retrieveServerId($, 4, subOrDub);

// zoro's vidcloud server is rapidcloud
if (!serverId) throw new Error('RapidCloud not found');
if (!serverId) throw new Error('vidtreaming not found');
break;
case StreamingServers.StreamSB:
serverId = $('div.ps_-block.ps_-block-sub.servers-sub > div.ps__-list > div')
.map((i, el) => ($(el).attr('data-server-id') == '5' ? $(el) : null))
.get()[0]
.attr('data-id')!;
serverId = this.retrieveServerId($, 5, subOrDub);

if (!serverId) throw new Error('StreamSB not found');
break;
case StreamingServers.StreamTape:
serverId = $('div.ps_-block.ps_-block-sub.servers-sub > div.ps__-list > div')
.map((i, el) => ($(el).attr('data-server-id') == '3' ? $(el) : null))
.get()[0]
.attr('data-id')!;
serverId = this.retrieveServerId($, 3, subOrDub);

if (!serverId) throw new Error('StreamTape not found');
break;
Expand All @@ -227,6 +231,13 @@ class Zoro extends AnimeParser {
}
};

private retrieveServerId = ($: any, index: number, subOrDub: 'sub' | 'dub') => {
return $(`div.ps_-block.ps_-block-sub.servers-${subOrDub} > div.ps__-list > div`)
.map((i: any, el: any) => ($(el).attr('data-server-id') == `${index}` ? $(el) : null))
.get()[0]
.attr('data-id')!;
}

/**
* @param page Page number
*/
Expand Down
9 changes: 9 additions & 0 deletions src/providers/meta/anilist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,15 @@ class Anilist extends AnimeParser {
return [];
}

if (this.provider instanceof Zoro) {
// Set the correct episode sub/dub request type
possibleAnime.episodes.forEach((_: any, index: number) => {
if (possibleAnime.subOrDub === SubOrSub.BOTH) {
possibleAnime.episodes[index].id = possibleAnime.episodes[index].id.replace(`$both`, dub ? '$dub' : '$sub');
}
});
}

const possibleProviderEpisodes = possibleAnime.episodes;

const options = {
Expand Down