Skip to content

Commit

Permalink
feat (types): added intro
Browse files Browse the repository at this point in the history
  • Loading branch information
riimuru committed Jul 25, 2022
1 parent c4ae4f4 commit 3180634
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
ISource,
ISubtitle,
IMovieResult,
Intro,
} from './types';
import { LibgenBookObject, GetComicsComicsObject, ZLibraryObject } from './type-objects';

Expand Down Expand Up @@ -80,4 +81,5 @@ export {
ISource,
ISubtitle,
IMovieResult,
Intro,
};
9 changes: 9 additions & 0 deletions src/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,17 @@ export interface ISubtitle {
lang: string;
}

/**
* The start, and the end of the intro or opening in seconds.
*/
export interface Intro {
start: number;
end: number;
}

export interface ISource {
headers?: { [k: string]: string };
intro?: Intro;
subtitles?: ISubtitle[];
sources: IVideo[];
}
Expand Down
6 changes: 0 additions & 6 deletions src/providers/meta/anilist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,6 @@ class Anilist extends AnimeParser {

if (nodes) {
nodes.forEach((node: any) => {
console.log({
season: node.season,
anilistSeason: season,
startDate: node.startDate.trim().split('-')[0],
anilistStartDate: startDate,
});
if (node.season === season && node.startDate.trim().split('-')[0] === startDate.toString()) {
const episodes = node.episodes.nodes;

Expand Down
15 changes: 12 additions & 3 deletions src/utils/extractors/vidcloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios';
import { load } from 'cheerio';
import FormData from 'form-data';

import { VideoExtractor, IVideo, ISubtitle } from '../../models';
import { VideoExtractor, IVideo, ISubtitle, Intro } from '../../models';
import { USER_AGENT } from '..';

class VidCloud extends VideoExtractor {
Expand All @@ -17,7 +17,10 @@ class VidCloud extends VideoExtractor {
videoUrl: URL,
isAlternative: boolean = false
): Promise<{ sources: IVideo[] } & { subtitles: ISubtitle[] }> => {
const result: { sources: IVideo[]; subtitles: ISubtitle[] } = { sources: [], subtitles: [] };
const result: { sources: IVideo[]; subtitles: ISubtitle[]; intro?: Intro } = {
sources: [],
subtitles: [],
};
try {
const id = videoUrl.href.split('/').pop()?.split('?')[0];
const options = {
Expand All @@ -40,7 +43,7 @@ class VidCloud extends VideoExtractor {
);
}
const {
data: { sources, tracks },
data: { sources, tracks, intro },
} = res;

this.sources = sources.map((s: any) => ({
Expand Down Expand Up @@ -77,6 +80,12 @@ class VidCloud extends VideoExtractor {
}
result.sources.push(...this.sources);
}
if (intro.end > 1) {
result.intro = {
start: intro.start,
end: intro.end,
};
}
} else if (
videoUrl.href.includes(new URL(this.host2).host) ||
videoUrl.href.includes(new URL(this.host).host)
Expand Down
19 changes: 10 additions & 9 deletions test/anime/zoro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ import { ANIME } from '../../src/providers';
jest.setTimeout(120000);

test('returns a filled array of anime list', async () => {
const animepahe = new ANIME.Zoro();
const data = await animepahe.search('Overlord IV');
const zoro = new ANIME.Zoro();
const data = await zoro.search('Overlord IV');
expect(data.results).not.toEqual([]);
});

test('returns a filled object of anime data', async () => {
const animepahe = new ANIME.AnimePahe();
const res = await animepahe.search('Overlord IV');
const data = await animepahe.fetchAnimeInfo(res.results[3].id); // Overlord IV id
const zoro = new ANIME.Zoro();
const res = await zoro.search('Overlord IV');
const data = await zoro.fetchAnimeInfo(res.results[3].id); // Overlord IV id
expect(data).not.toBeNull();
expect(data.description).not.toBeNull();
expect(data.episodes).not.toEqual([]);
});

test('returns a filled object of episode sources', async () => {
const animepahe = new ANIME.AnimePahe();
const res = await animepahe.search('Overlord IV');
const info = await animepahe.fetchAnimeInfo(res.results[3].id);
const data = await animepahe.fetchEpisodeSources(info.episodes![0].id); // Overlord IV episode 1 id
const zoro = new ANIME.Zoro();
const res = await zoro.search('Overlord IV');
const info = await zoro.fetchAnimeInfo(res.results[3].id);
const data = await zoro.fetchEpisodeSources(info.episodes![0].id); // Overlord IV episode 1 id
console.log(data);
expect(data.sources).not.toEqual([]);
});

0 comments on commit 3180634

Please sign in to comment.