Definiendo estructura del proyecto
commit
607dc863c5
@ -0,0 +1 @@
|
|||||||
|
node_modules
|
@ -0,0 +1,18 @@
|
|||||||
|
# Monoschinos API REST
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
## Monoschinos API REST
|
||||||
|
## Rewrite in typescript
|
||||||
|
```
|
||||||
|
|
||||||
|
* ### Dependencies
|
||||||
|
* Axios
|
||||||
|
* Morgan
|
||||||
|
* Cheerio
|
||||||
|
* Cors
|
||||||
|
* Dotenv
|
||||||
|
|
||||||
|
Documentation (soon)
|
||||||
|
|
||||||
|
#### Based on original work by [atleugim](https://github.com/atleugim/monoschinos-api)
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"watch": ["src"],
|
||||||
|
"ext": "ts",
|
||||||
|
"ignore": ["src/**/.spect.ts"],
|
||||||
|
"exec": "npx ts-node"
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"name": "monoschinos-api-ts",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"build": "tsc ",
|
||||||
|
"dev": "nodemon src/index.ts"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/axios": "^0.14.0",
|
||||||
|
"@types/cheerio": "^0.22.28",
|
||||||
|
"@types/cors": "^2.8.10",
|
||||||
|
"@types/dotenv": "^8.2.0",
|
||||||
|
"@types/express": "^4.17.11",
|
||||||
|
"@types/morgan": "^1.9.2",
|
||||||
|
"nodemon": "^2.0.7",
|
||||||
|
"ts-node": "^9.1.1",
|
||||||
|
"typescript": "^4.2.3"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^0.21.1",
|
||||||
|
"cheerio": "^1.0.0-rc.5",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"dotenv": "^8.2.0",
|
||||||
|
"express": "^4.17.1",
|
||||||
|
"morgan": "^1.10.0"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Hello from my server</h1>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
@ -0,0 +1,14 @@
|
|||||||
|
import express from "express";
|
||||||
|
import cors from "cors";
|
||||||
|
import morgan from "morgan";
|
||||||
|
import routes from './routes/api.routes';
|
||||||
|
|
||||||
|
const app = express()
|
||||||
|
|
||||||
|
app.use(cors(),morgan('dev'));
|
||||||
|
|
||||||
|
|
||||||
|
app.use('/', express.static('public'));
|
||||||
|
app.use('/', routes);
|
||||||
|
|
||||||
|
export default app;
|
@ -0,0 +1,21 @@
|
|||||||
|
const appConfig = {
|
||||||
|
host: process.env.HOST || 'localhost',
|
||||||
|
port: process.env.PORT || 8000
|
||||||
|
}
|
||||||
|
const page = "https://monoschinos2.com";
|
||||||
|
|
||||||
|
const urls = {
|
||||||
|
main: '',
|
||||||
|
emision: page +'/emision?page=',
|
||||||
|
search: page +'/search?q=',
|
||||||
|
anime: page +'/anime',
|
||||||
|
episode: page +'/ver',
|
||||||
|
gender: page +'/genero',
|
||||||
|
letter: page +'/letra',
|
||||||
|
ova: page +'/categoria/ova'
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
urls,
|
||||||
|
appConfig
|
||||||
|
}
|
@ -0,0 +1,209 @@
|
|||||||
|
import cheerio from 'cheerio';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { urls } from '../config';
|
||||||
|
import { LastestAnimeI, AnimeI, SuggestionI, GenderI } from "../models/interfaces";
|
||||||
|
|
||||||
|
|
||||||
|
async function getLastest(req: any, res: any) {
|
||||||
|
try {
|
||||||
|
const bodyResponse = await axios.get(`${urls.main}`);
|
||||||
|
const $ = cheerio.load(bodyResponse.data);
|
||||||
|
|
||||||
|
const animes: any = [];
|
||||||
|
|
||||||
|
let getLastest = $('.container .caps .container')[0];
|
||||||
|
|
||||||
|
$(getLastest).find('.row article').each((i, e) => {
|
||||||
|
let el = $(e);
|
||||||
|
let title = el.find('.Title').html().split('\t')[0]
|
||||||
|
let cover = el.find('.Image img').attr('src');
|
||||||
|
let type = el.find('.Image figure span').text();
|
||||||
|
type = type.substring(1, type.length)
|
||||||
|
let episode: any = el.find('.dataEpi .episode').text();
|
||||||
|
episode = parseInt(episode.split('\n')[1])
|
||||||
|
let id: any = el.find('a').attr('href');
|
||||||
|
id = id.split('/')[4]
|
||||||
|
id = id.split('-')
|
||||||
|
id.splice(id.length - 2, 2);
|
||||||
|
id = `${id.join('-')}-episodio-${episode}`;
|
||||||
|
|
||||||
|
let anime:LastestAnimeI = {
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
cover,
|
||||||
|
episode,
|
||||||
|
type
|
||||||
|
}
|
||||||
|
|
||||||
|
animes.push(anime);
|
||||||
|
})
|
||||||
|
|
||||||
|
res.status(200)
|
||||||
|
.json(
|
||||||
|
animes
|
||||||
|
)
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500)
|
||||||
|
.json({
|
||||||
|
message: err.message,
|
||||||
|
success: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getEmision(req: any, res: any) {
|
||||||
|
try {
|
||||||
|
let { page } = req.query;
|
||||||
|
if (!page) { page = 1 }
|
||||||
|
|
||||||
|
const response = await axios.get(`${urls.emision}${page}`);
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
|
||||||
|
let animes: any = [];
|
||||||
|
|
||||||
|
$('.animes .container .row article').each((i, e) => {
|
||||||
|
let el = $(e);
|
||||||
|
|
||||||
|
let id = el.find('a').attr('href');
|
||||||
|
id = id.split('/')[4]
|
||||||
|
let title = el.find('.Title').text();
|
||||||
|
let img = el.find('.Image img').attr('src');
|
||||||
|
let category = el.find('.category').text();
|
||||||
|
category = category.substring(1, category.length)
|
||||||
|
let year = parseInt(el.find('.fecha').text());
|
||||||
|
|
||||||
|
const anime = {
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
img,
|
||||||
|
category,
|
||||||
|
year
|
||||||
|
}
|
||||||
|
|
||||||
|
animes.push(anime);
|
||||||
|
})
|
||||||
|
|
||||||
|
let totalPages: any = $('.pagination').children().length;
|
||||||
|
totalPages = $('.pagination').find('.page-item')[totalPages - 2];
|
||||||
|
let pages = parseInt($(totalPages).text());
|
||||||
|
|
||||||
|
res.status(200),
|
||||||
|
res.json(
|
||||||
|
animes
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
res.json({
|
||||||
|
message: err.message,
|
||||||
|
success: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getAnime(req:any, res:any) {
|
||||||
|
try {
|
||||||
|
let {id} = req.params;
|
||||||
|
const response = await axios.get(`${urls.anime}/${id}`);
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
let anime:AnimeI = {};
|
||||||
|
let genders = []
|
||||||
|
let episodes = []
|
||||||
|
let sugestions = []
|
||||||
|
// Episodes
|
||||||
|
$('.SerieCaps').each((i, e) => {
|
||||||
|
let el = $(e);
|
||||||
|
let totalEpisodes = el.children().length;
|
||||||
|
|
||||||
|
$('.container .SerieCaps .item').each((i, e) => {
|
||||||
|
let el = $(e);
|
||||||
|
let episodeId = el.attr('href');
|
||||||
|
episodeId = episodeId.split('/')[4]
|
||||||
|
let episode = {
|
||||||
|
number: totalEpisodes,
|
||||||
|
id: episodeId
|
||||||
|
}
|
||||||
|
episodes.push(episode)
|
||||||
|
episodes[i] = episode;
|
||||||
|
anime.episodes = episodes
|
||||||
|
totalEpisodes--
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// Genders
|
||||||
|
$('.generos a').each((i, e) => {
|
||||||
|
let el = $(e);
|
||||||
|
let title = el.text();
|
||||||
|
let id = el.attr('href').split('/')[4]
|
||||||
|
let gender: GenderI = {
|
||||||
|
title,
|
||||||
|
id
|
||||||
|
}
|
||||||
|
genders.push(gender)
|
||||||
|
})
|
||||||
|
// Suggestions
|
||||||
|
$('.container .row .col-12 .recom article').each((i, e) => {
|
||||||
|
let el = $(e);
|
||||||
|
let id = el.find('a').attr('href');
|
||||||
|
id = id.split('/')[4]
|
||||||
|
let title = el.find('a .Title').text().replace(/ Sub Español/gi, '')
|
||||||
|
let cover = el.find('a .Image img').attr('src');
|
||||||
|
let year = parseInt(el.find('.fecha').text());
|
||||||
|
|
||||||
|
let sugestionAnime:SuggestionI = {
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
cover,
|
||||||
|
year
|
||||||
|
}
|
||||||
|
|
||||||
|
sugestions.push(sugestionAnime);
|
||||||
|
});
|
||||||
|
// Information
|
||||||
|
$('.TPost.Serie.Single').each((i, e) => {
|
||||||
|
let el = $(e);
|
||||||
|
let banner = el.find('.Banner img').attr('src');
|
||||||
|
if (banner == 'https://monoschinos2.com/assets/img/no_image.png') {
|
||||||
|
banner = 'https://image.freepik.com/free-vector/404-error-page-found_41910-364.jpg'
|
||||||
|
}
|
||||||
|
let title = el.find('h1.Title').text().replace(/ Sub Español/gi, '')
|
||||||
|
let sinopsis = el.find(' .row .col-sm-9 .Description p').text();
|
||||||
|
let status = el.find(' .row .col-sm-9 .Type').text().trim();
|
||||||
|
let date1 = el.find(' .row .col-sm-9 .after-title:nth-child(n)').text();
|
||||||
|
let date = date1.replace(/ /gi, "").replace(/\n/gi, "").replace(/Finalizado/gi, '').replace(/Estreno/gi, '').slice(0, 10)
|
||||||
|
let type1 = date1.replace(/ /gi, "").replace(/\n/gi, "").replace(/Finalizado/gi, '').replace(/Estreno/gi, '').replace(`${date}`, '')
|
||||||
|
let type = type1.slice(1, type1.length)
|
||||||
|
let cover = el.find('.Image img').attr('src');
|
||||||
|
anime = {
|
||||||
|
id,
|
||||||
|
type,
|
||||||
|
title,
|
||||||
|
banner,
|
||||||
|
sinopsis,
|
||||||
|
status,
|
||||||
|
date,
|
||||||
|
cover,
|
||||||
|
genders,
|
||||||
|
sugestions,
|
||||||
|
episodes
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!anime.episodes) {
|
||||||
|
anime.episodes = []
|
||||||
|
};
|
||||||
|
res.json(
|
||||||
|
anime
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
res.json({
|
||||||
|
message: err.message,
|
||||||
|
success: false
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export {
|
||||||
|
getLastest,
|
||||||
|
getEmision,
|
||||||
|
getAnime,
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
import app from './app';
|
||||||
|
import { appConfig } from './config'
|
||||||
|
|
||||||
|
function init(host:any, port:any) {
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.info(`API Running on: ${host}:${port}`);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
init(appConfig.host, appConfig.port)
|
@ -0,0 +1,49 @@
|
|||||||
|
export interface EmisionResponse{
|
||||||
|
animes: Array<EmisionI>;
|
||||||
|
pages: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EmisionI{
|
||||||
|
id:string;
|
||||||
|
title:string;
|
||||||
|
cover:string;
|
||||||
|
category:string;
|
||||||
|
year:string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LastestAnimeI {
|
||||||
|
title: string
|
||||||
|
cover: string
|
||||||
|
id: string
|
||||||
|
episode: string
|
||||||
|
type: string
|
||||||
|
}
|
||||||
|
export interface AnimeI{
|
||||||
|
id?: string;
|
||||||
|
title?: string;
|
||||||
|
banner?: string;
|
||||||
|
type?: string;
|
||||||
|
cover?: string;
|
||||||
|
sinopsis?: string;
|
||||||
|
status?: string;
|
||||||
|
date?: string;
|
||||||
|
genders?: Array<GenderI>;
|
||||||
|
sugestions?: Array<SuggestionI>;
|
||||||
|
episodes?: Array<EpisodeI>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GenderI{
|
||||||
|
id:string;
|
||||||
|
title:string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SuggestionI{
|
||||||
|
id?:string;
|
||||||
|
title?:string;
|
||||||
|
cover?:string;
|
||||||
|
year?:number;
|
||||||
|
}
|
||||||
|
export interface EpisodeI{
|
||||||
|
id?:string;
|
||||||
|
number?:string;
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
|
||||||
|
|
||||||
|
const routes = Router();
|
||||||
|
|
||||||
|
import { getEmision, getLastest, getAnime } from '../controllers/controller'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
routes.get('/lastest', (req, res) => {
|
||||||
|
getLastest(req, res);
|
||||||
|
})
|
||||||
|
routes.get('/emision', (req, res) => {
|
||||||
|
getEmision(req, res);
|
||||||
|
})
|
||||||
|
|
||||||
|
routes.get('/anime/:id', (req, res) => {
|
||||||
|
getAnime(req, res);
|
||||||
|
})
|
||||||
|
export default routes
|
@ -0,0 +1,71 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||||
|
|
||||||
|
/* Basic Options */
|
||||||
|
// "incremental": true, /* Enable incremental compilation */
|
||||||
|
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||||
|
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||||
|
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||||
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
|
// "checkJs": true, /* Report errors in .js files. */
|
||||||
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
||||||
|
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||||
|
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||||
|
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||||
|
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||||
|
"outDir": "./dist/", /* Redirect output structure to the directory. */
|
||||||
|
"rootDir": "./src/", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||||
|
// "composite": true, /* Enable project compilation */
|
||||||
|
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||||
|
"removeComments": true, /* Do not emit comments to output. */
|
||||||
|
// "noEmit": true, /* Do not emit outputs. */
|
||||||
|
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||||
|
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||||
|
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||||
|
|
||||||
|
/* Strict Type-Checking Options */
|
||||||
|
"strict": false, /* Enable all strict type-checking options. */
|
||||||
|
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||||
|
"strictNullChecks": false, /* Enable strict null checks. */
|
||||||
|
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||||
|
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||||
|
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||||
|
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||||
|
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||||
|
|
||||||
|
/* Additional Checks */
|
||||||
|
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||||
|
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||||
|
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||||
|
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||||
|
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
||||||
|
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
||||||
|
|
||||||
|
/* Module Resolution Options */
|
||||||
|
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||||
|
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||||
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||||
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||||
|
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||||
|
// "types": [], /* Type declaration files to be included in compilation. */
|
||||||
|
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||||
|
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||||
|
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||||
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||||
|
|
||||||
|
/* Source Map Options */
|
||||||
|
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||||
|
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||||
|
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||||
|
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||||
|
|
||||||
|
/* Experimental Options */
|
||||||
|
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||||
|
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||||
|
|
||||||
|
/* Advanced Options */
|
||||||
|
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||||
|
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue