Skip to content

Commit

Permalink
Merge pull request #490 from Eltik/main
Browse files Browse the repository at this point in the history
feat: Switch from Anime -> Anify + bug fixes.
  • Loading branch information
Eltik authored Oct 18, 2023
2 parents b084aeb + 3eab45a commit cbe5fd1
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 214 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"homepage": "https://github.com/consumet/consumet.ts#readme",
"dependencies": {
"@consumet/extensions": "https://github.com/consumet/consumet.ts.git",
"@consumet/extensions": "github:consumet/consumet.ts",
"@fastify/cors": "^8.2.0",
"@types/fastify-cors": "^2.1.0",
"@types/node": "^18.11.17",
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const redis =
new Redis({
host: process.env.REDIS_HOST,
port: Number(process.env.REDIS_PORT),
password: process.env.REDIS_PASSWORD
password: process.env.REDIS_PASSWORD,
});

export const tmdbApi = process.env.TMDB_KEY && process.env.TMDB_KEY;
Expand Down
20 changes: 13 additions & 7 deletions src/routes/anime/enime.ts → src/routes/anime/anify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import { FastifyRequest, FastifyReply, FastifyInstance, RegisterOptions } from '
import { ANIME } from '@consumet/extensions';

const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
const enime = new ANIME.Enime();
const anify = new ANIME.Anify();

fastify.get('/', (_, rp) => {
rp.status(200).send({
intro:
"Welcome to the enime provider: check out the provider's website @ https://enime.com/",
"Welcome to the Anify provider: check out the provider's website @ https://anify.tv/",
routes: ['/:query', '/info/:id', '/watch/:episodeId'],
documentation: 'https://docs.consumet.org/#tag/enime',
documentation: 'https://docs.consumet.org/#tag/anify',
});
});

fastify.get('/:query', async (request: FastifyRequest, reply: FastifyReply) => {
const query = (request.params as { query: string }).query;

const res = await enime.search(query);
const res = await anify.search(query);

reply.status(200).send(res);
});
Expand All @@ -28,7 +28,7 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
return reply.status(400).send({ message: 'id is required' });

try {
const res = await enime
const res = await anify
.fetchAnimeInfo(id)
.catch((err) => reply.status(404).send({ message: err }));

Expand All @@ -42,13 +42,19 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {

fastify.get('/watch', async (request: FastifyRequest, reply: FastifyReply) => {
const episodeId = (request.query as { episodeId: string }).episodeId;
const episodeNumber = (request.query as { episodeNumber: string }).episodeNumber;
const animeId = (request.query as { animeId: string }).animeId;

if (typeof episodeId === 'undefined')
return reply.status(400).send({ message: 'episodeId is required' });
if (typeof episodeNumber === 'undefined')
return reply.status(400).send({ message: 'episodeNumber is required' });
if (typeof animeId === 'undefined')
return reply.status(400).send({ message: 'animeId is required' });

try {
const res = await enime
.fetchEpisodeSources(episodeId)
const res = await anify
.fetchEpisodeSources(episodeId, Number(episodeNumber), animeId)
.catch((err) => reply.status(404).send({ message: err }));

reply.status(200).send(res);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/anime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import animepahe from './animepahe';
import zoro from './zoro';
import nineanime from './9anime';
import animefox from './animefox';
import enime from './enime';
import anify from './anify';
import crunchyroll from './crunchyroll';
import bilibili from './bilibili';
import marin from './marin';
Expand All @@ -17,7 +17,7 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
await fastify.register(zoro, { prefix: '/zoro' });
await fastify.register(nineanime, { prefix: '/9anime' });
await fastify.register(animefox, { prefix: '/animefox' });
await fastify.register(enime, { prefix: '/enime' });
await fastify.register(anify, { prefix: '/anify' });
await fastify.register(crunchyroll, { prefix: '/crunchyroll' });
await fastify.register(bilibili, { prefix: '/bilibili' });
await fastify.register(marin, { prefix: '/marin' });
Expand Down
3 changes: 1 addition & 2 deletions src/routes/meta/anilist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,10 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
async (request: FastifyRequest, reply: FastifyReply) => {
const provider = (request.query as { provider: 'gogoanime' | 'zoro' }).provider;
const page = (request.query as { page: number }).page;
const perPage = (request.query as { perPage: number }).perPage;

const anilist = generateAnilistMeta(provider);

const res = await anilist.fetchRecentEpisodes(provider, page, perPage);
const res = await anilist.fetchRecentEpisodes(provider, page);

reply.status(200).send(res);
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/meta/tmdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
let tmdb = new META.TMDB(tmdbApi);
if (typeof provider !== 'undefined') {
const possibleProvider = PROVIDERS_LIST.MOVIES.find(
(p) => p.name.toLowerCase() === provider.toLocaleLowerCase()
(p) => p.name.toLowerCase() === provider.toLocaleLowerCase()
);
tmdb = new META.TMDB(tmdbApi, possibleProvider);
}
Expand Down
23 changes: 13 additions & 10 deletions src/utils/image-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import { FastifyRequest, FastifyReply, FastifyInstance, RegisterOptions } from '

class ImageProxy {
public async getImageProxy(fastify: FastifyInstance, options: RegisterOptions) {
const getImage = async (url: string, options: AxiosRequestConfig): Promise<string> => {
const data = await axios
.get(url, {
responseType: "arraybuffer",
...options,
})
.catch((err) => {
return { data: err.response.data };
});
return data.data;
const getImage = async (
url: string,
options: AxiosRequestConfig
): Promise<string> => {
const data = await axios
.get(url, {
responseType: 'arraybuffer',
...options,
})
.catch((err) => {
return { data: err.response.data };
});
return data.data;
};
fastify.get('/image-proxy', async (request: FastifyRequest, reply: FastifyReply) => {
const { url } = request.query as { url: string };
Expand Down
Loading

0 comments on commit cbe5fd1

Please sign in to comment.