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(manga | movies): Add missing mangaId in fetchChapterPages, new sflix provider and changes in /servers endpoint error logging in movies routes, add server params in dramacool's episode fetching #640

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/routes/manga/mangakakalot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {

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

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

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

try {
const res = await mangakakalot
.fetchChapterPages(chapterId)
.fetchChapterPages(chapterId,mangaId)
.catch((err: Error) => reply.status(404).send({ message: err.message }));

reply.status(200).send(res);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/movies/dramacool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
fastify.get('/watch', async (request: FastifyRequest, reply: FastifyReply) => {
const episodeId = (request.query as { episodeId: string }).episodeId;
// const mediaId = (request.query as { mediaId: string }).mediaId;
// const server = (request.query as { server: StreamingServers }).server;
const server = (request.query as { server: StreamingServers }).server;

if (typeof episodeId === 'undefined')
return reply.status(400).send({ message: 'episodeId is required' });
try {
const res = await dramacool
.fetchEpisodeSources(episodeId)
.fetchEpisodeSources(episodeId,server)
.catch((err) => reply.status(404).send({ message: 'Media Not found.' }));

reply.status(200).send(res);
Expand Down
6 changes: 6 additions & 0 deletions src/routes/movies/flixhq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
fastify.get('/servers', async (request: FastifyRequest, reply: FastifyReply) => {
const episodeId = (request.query as { episodeId: string }).episodeId;
const mediaId = (request.query as { mediaId: string }).mediaId;

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

try {
let res = redis
? await cache.fetch(
Expand Down
6 changes: 6 additions & 0 deletions src/routes/movies/goku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
async (request: FastifyRequest, reply: FastifyReply) => {
const episodeId = (request.query as { episodeId: string }).episodeId;
const mediaId = (request.query as { mediaId: string }).mediaId;

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

try {
let res = redis
? await cache.fetch(
Expand Down
2 changes: 2 additions & 0 deletions src/routes/movies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import dramacool from './dramacool';
import fmovies from './fmovies';
import goku from './goku';
import movieshd from './movieshd';
import sflix from './sflix';
const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
await fastify.register(flixhq, { prefix: '/flixhq' });
await fastify.register(viewasian, { prefix: '/viewasian' });
await fastify.register(dramacool, { prefix: '/dramacool' });
await fastify.register(fmovies, { prefix: '/fmovies' });
await fastify.register(goku, { prefix: '/goku' });
await fastify.register(movieshd, { prefix: '/movieshd' });
await fastify.register(sflix, { prefix: '/sflix' });
fastify.get('/', async (request: any, reply: any) => {
reply.status(200).send('Welcome to Consumet Movies and TV Shows');
});
Expand Down
6 changes: 6 additions & 0 deletions src/routes/movies/movieshd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
async (request: FastifyRequest, reply: FastifyReply) => {
const episodeId = (request.query as { episodeId: string }).episodeId;
const mediaId = (request.query as { mediaId: string }).mediaId;

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

try {
let res = redis
? await cache.fetch(
Expand Down
231 changes: 231 additions & 0 deletions src/routes/movies/sflix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
import { FastifyRequest, FastifyReply, FastifyInstance, RegisterOptions } from 'fastify';
import { MOVIES } from '@consumet/extensions';
import { StreamingServers } from '@consumet/extensions/dist/models';

import cache from '../../utils/cache';
import { redis } from '../../main';
import { Redis } from 'ioredis';

const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
const sflix = new MOVIES.SFlix();

fastify.get('/', (_, rp) => {
rp.status(200).send({
intro:
"Welcome to the sflix provider: check out the provider's website @ https://sflix.to/",
routes: ['/:query', '/info', '/watch','/recent-shows','/recent-movies','/trending','/servers','/country','/genre'],
documentation: 'https://docs.consumet.org/#tag/sflix',
});
});

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

const page = (request.query as { page: number }).page;

let res = redis
? await cache.fetch(
redis as Redis,
`sflix:${query}:${page}`,
async () => await sflix.search(query, page ? page : 1),
60 * 60 * 6,
)
: await sflix.search(query, page ? page : 1);

reply.status(200).send(res);
});

fastify.get('/recent-shows', async (request: FastifyRequest, reply: FastifyReply) => {
let res = redis
? await cache.fetch(
redis as Redis,
`sflix:recent-shows`,
async () => await sflix.fetchRecentTvShows(),
60 * 60 * 3,
)
: await sflix.fetchRecentTvShows();

reply.status(200).send(res);
});

fastify.get('/recent-movies', async (request: FastifyRequest, reply: FastifyReply) => {
let res = redis
? await cache.fetch(
redis as Redis,
`sflix:recent-movies`,
async () => await sflix.fetchRecentMovies(),
60 * 60 * 3,
)
: await sflix.fetchRecentMovies();

reply.status(200).send(res);
});

fastify.get('/trending', async (request: FastifyRequest, reply: FastifyReply) => {
const type = (request.query as { type: string }).type;
try {
if (!type) {
const res = {
results: [
...(await sflix.fetchTrendingMovies()),
...(await sflix.fetchTrendingTvShows()),
],
};
return reply.status(200).send(res);
}

let res = redis
? await cache.fetch(
redis as Redis,
`sflix:trending:${type}`,
async () =>
type === 'tv'
? await sflix.fetchTrendingTvShows()
: await sflix.fetchTrendingMovies(),
60 * 60 * 3,
)
: type === 'tv'
? await sflix.fetchTrendingTvShows()
: await sflix.fetchTrendingMovies();

reply.status(200).send(res);
} catch (error) {
reply.status(500).send({
message:
'Something went wrong. Please try again later. or contact the developers.',
});
}
});

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

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

try {
let res = redis
? await cache.fetch(
redis as Redis,
`sflix:info:${id}`,
async () => await sflix.fetchMediaInfo(id),
60 * 60 * 3,
)
: await sflix.fetchMediaInfo(id);

reply.status(200).send(res);
} catch (err) {
reply.status(500).send({
message:
'Something went wrong. Please try again later. or contact the developers.',
});
}
});

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

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

if (server && !Object.values(StreamingServers).includes(server))
return reply.status(400).send({ message: 'Invalid server query' });

try {
let res = redis
? await cache.fetch(
redis as Redis,
`sflix:watch:${episodeId}:${mediaId}:${server}`,
async () => await sflix.fetchEpisodeSources(episodeId, mediaId, server),
60 * 30,
)
: await sflix.fetchEpisodeSources(episodeId, mediaId, server);

reply.status(200).send(res);
} catch (err) {
reply
.status(500)
.send({ message: 'Something went wrong. Please try again later.' });
}
});

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

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

try {
let res = redis
? await cache.fetch(
redis as Redis,
`sflix:servers:${episodeId}:${mediaId}`,
async () => await sflix.fetchEpisodeServers(episodeId, mediaId),
60 * 30,
)
: await sflix.fetchEpisodeServers(episodeId, mediaId);

reply.status(200).send(res);
} catch (error) {
reply.status(500).send({
message:
'Something went wrong. Please try again later. or contact the developers.',
});
}
});

fastify.get('/country/:country', async (request: FastifyRequest, reply: FastifyReply) => {
const country = (request.params as { country: string }).country;
const page = (request.query as { page: number }).page ?? 1;
try {
let res = redis
? await cache.fetch(
redis as Redis,
`sflix:country:${country}:${page}`,
async () => await sflix.fetchByCountry(country, page),
60 * 60 * 3,
)
: await sflix.fetchByCountry(country, page);

reply.status(200).send(res);
} catch (error) {
reply.status(500).send({
message:
'Something went wrong. Please try again later. or contact the developers.',
});
}
});


fastify.get('/genre/:genre', async (request: FastifyRequest, reply: FastifyReply) => {
const genre = (request.params as { genre: string }).genre;
const page = (request.query as { page: number }).page ?? 1;
try {
let res = redis
? await cache.fetch(
redis as Redis,
`sflix:genre:${genre}:${page}`,
async () => await sflix.fetchByGenre(genre, page),
60 * 60 * 3,
)
: await sflix.fetchByGenre(genre, page);

reply.status(200).send(res);
} catch (error) {
reply.status(500).send({
message:
'Something went wrong. Please try again later. or contact the developers.',
});
}
});
};
export default routes;
Loading