Update index.js
Browse files
index.js
CHANGED
|
@@ -8,29 +8,25 @@ const app = express();
|
|
| 8 |
app.use(cors());
|
| 9 |
app.use(express.static(path.join(path.resolve(), 'public')));
|
| 10 |
|
| 11 |
-
// Endpoint untuk mendapatkan daftar anime
|
| 12 |
app.get('/api/anime', async (req, res) => {
|
| 13 |
try {
|
| 14 |
const response = await axios.get('https://samehadaku.email/');
|
| 15 |
const $ = cheerio.load(response.data);
|
| 16 |
const animeList = [];
|
| 17 |
|
| 18 |
-
// Memproses setiap anime dan menghilangkan bagian episode dari URL
|
| 19 |
$('li[itemtype="http://schema.org/CreativeWork"]').each((index, element) => {
|
| 20 |
const title = $(element).find('.entry-title a').text().trim();
|
| 21 |
const link = $(element).find('.thumb a').attr('href');
|
| 22 |
const image = $(element).find('.thumb img').attr('src');
|
| 23 |
const episode = $(element).find('span > author[itemprop="name"]').text().trim();
|
| 24 |
-
|
| 25 |
-
// Ambil ID anime dengan menghapus bagian episode
|
| 26 |
const id = link.replace('https://samehadaku.email/', '').replace('/', '').replace(/-episode-\d+/i, ''); // Menghapus bagian episode
|
| 27 |
|
| 28 |
-
// Membuat URL baru tanpa bagian episode
|
| 29 |
const animeUrl = `${id}`;
|
| 30 |
|
| 31 |
animeList.push({
|
| 32 |
title,
|
| 33 |
-
link: animeUrl,
|
| 34 |
image,
|
| 35 |
episode,
|
| 36 |
id,
|
|
@@ -45,28 +41,24 @@ app.get('/api/anime', async (req, res) => {
|
|
| 45 |
}
|
| 46 |
});
|
| 47 |
|
| 48 |
-
// Endpoint untuk mendapatkan detail anime berdasarkan ID
|
| 49 |
app.get('/api/anime/:id', async (req, res) => {
|
| 50 |
const { id } = req.params;
|
| 51 |
const url = `https://samehadaku.email/${id}`;
|
| 52 |
|
| 53 |
try {
|
| 54 |
-
// Ambil halaman detail anime berdasarkan ID
|
| 55 |
const response = await axios.get(url);
|
| 56 |
const $ = cheerio.load(response.data);
|
| 57 |
|
| 58 |
const animeTitle = $('h1.page-title').text().replace('Category: ', '').trim();
|
| 59 |
const episodes = [];
|
| 60 |
|
| 61 |
-
// Scraping episode-episode yang ada
|
| 62 |
$('article.post').each((index, element) => {
|
| 63 |
const episodeTitle = $(element).find('.title').text().trim();
|
| 64 |
const episodeLink = $(element).find('a').attr('href');
|
| 65 |
const episodeImage = $(element).find('img').attr('src');
|
| 66 |
const episodeScore = $(element).find('.score').text().trim();
|
| 67 |
const episodeTime = $(element).find('.chdt').text().trim();
|
| 68 |
-
|
| 69 |
-
// Menambahkan id berdasarkan link episode (contoh: kimi-wa-meido-sama-episode-7)
|
| 70 |
const episodeId = episodeLink.replace('https://samehadaku.email/', '').replace('/', '').trim();
|
| 71 |
|
| 72 |
episodes.push({
|
|
@@ -75,11 +67,10 @@ app.get('/api/anime/:id', async (req, res) => {
|
|
| 75 |
image: episodeImage,
|
| 76 |
score: episodeScore,
|
| 77 |
time: episodeTime,
|
| 78 |
-
id: episodeId
|
| 79 |
});
|
| 80 |
});
|
| 81 |
|
| 82 |
-
// Menyajikan data anime tanpa iframe
|
| 83 |
res.json({
|
| 84 |
anime: {
|
| 85 |
title: animeTitle,
|
|
@@ -93,13 +84,11 @@ app.get('/api/anime/:id', async (req, res) => {
|
|
| 93 |
}
|
| 94 |
});
|
| 95 |
|
| 96 |
-
// Endpoint untuk mendapatkan detail episode berdasarkan ID anime dan episode
|
| 97 |
app.get('/api/anime/episode/:id', async (req, res) => {
|
| 98 |
const { id } = req.params;
|
| 99 |
const url = `https://samehadaku.email/${id}`;
|
| 100 |
|
| 101 |
try {
|
| 102 |
-
// Ambil halaman detail episode berdasarkan ID
|
| 103 |
const response = await axios.get(url);
|
| 104 |
const $ = cheerio.load(response.data);
|
| 105 |
|
|
@@ -164,26 +153,15 @@ app.get('/api/anime/image/:id', async (req, res) => {
|
|
| 164 |
const url = `https://samehadaku.email/anime/${id}`; // Fetch data from this URL
|
| 165 |
|
| 166 |
try {
|
| 167 |
-
// Fetch the anime page for the given ID
|
| 168 |
const response = await axios.get(url);
|
| 169 |
-
|
| 170 |
-
// Parse the HTML response
|
| 171 |
const $ = cheerio.load(response.data);
|
| 172 |
-
|
| 173 |
-
// Find the image URL within the <div class="thumb">
|
| 174 |
const imageUrl = $('.thumb[itemprop="image"] img').attr('src');
|
| 175 |
|
| 176 |
if (imageUrl) {
|
| 177 |
-
// Fetch the image data as a binary buffer
|
| 178 |
const imageResponse = await axios.get(imageUrl, { responseType: 'arraybuffer' });
|
| 179 |
-
|
| 180 |
-
// Set the content type based on the image format (adjust MIME type as needed)
|
| 181 |
res.set('Content-Type', 'image/jpeg'); // Update this if the image is in a different format (e.g., PNG)
|
| 182 |
-
|
| 183 |
-
// Send the binary image data to the client
|
| 184 |
res.send(imageResponse.data);
|
| 185 |
} else {
|
| 186 |
-
// If no image is found, return a 404 error
|
| 187 |
res.status(404).send('Image not found');
|
| 188 |
}
|
| 189 |
} catch (error) {
|
|
|
|
| 8 |
app.use(cors());
|
| 9 |
app.use(express.static(path.join(path.resolve(), 'public')));
|
| 10 |
|
|
|
|
| 11 |
app.get('/api/anime', async (req, res) => {
|
| 12 |
try {
|
| 13 |
const response = await axios.get('https://samehadaku.email/');
|
| 14 |
const $ = cheerio.load(response.data);
|
| 15 |
const animeList = [];
|
| 16 |
|
|
|
|
| 17 |
$('li[itemtype="http://schema.org/CreativeWork"]').each((index, element) => {
|
| 18 |
const title = $(element).find('.entry-title a').text().trim();
|
| 19 |
const link = $(element).find('.thumb a').attr('href');
|
| 20 |
const image = $(element).find('.thumb img').attr('src');
|
| 21 |
const episode = $(element).find('span > author[itemprop="name"]').text().trim();
|
| 22 |
+
|
|
|
|
| 23 |
const id = link.replace('https://samehadaku.email/', '').replace('/', '').replace(/-episode-\d+/i, ''); // Menghapus bagian episode
|
| 24 |
|
|
|
|
| 25 |
const animeUrl = `${id}`;
|
| 26 |
|
| 27 |
animeList.push({
|
| 28 |
title,
|
| 29 |
+
link: animeUrl,
|
| 30 |
image,
|
| 31 |
episode,
|
| 32 |
id,
|
|
|
|
| 41 |
}
|
| 42 |
});
|
| 43 |
|
|
|
|
| 44 |
app.get('/api/anime/:id', async (req, res) => {
|
| 45 |
const { id } = req.params;
|
| 46 |
const url = `https://samehadaku.email/${id}`;
|
| 47 |
|
| 48 |
try {
|
|
|
|
| 49 |
const response = await axios.get(url);
|
| 50 |
const $ = cheerio.load(response.data);
|
| 51 |
|
| 52 |
const animeTitle = $('h1.page-title').text().replace('Category: ', '').trim();
|
| 53 |
const episodes = [];
|
| 54 |
|
|
|
|
| 55 |
$('article.post').each((index, element) => {
|
| 56 |
const episodeTitle = $(element).find('.title').text().trim();
|
| 57 |
const episodeLink = $(element).find('a').attr('href');
|
| 58 |
const episodeImage = $(element).find('img').attr('src');
|
| 59 |
const episodeScore = $(element).find('.score').text().trim();
|
| 60 |
const episodeTime = $(element).find('.chdt').text().trim();
|
| 61 |
+
|
|
|
|
| 62 |
const episodeId = episodeLink.replace('https://samehadaku.email/', '').replace('/', '').trim();
|
| 63 |
|
| 64 |
episodes.push({
|
|
|
|
| 67 |
image: episodeImage,
|
| 68 |
score: episodeScore,
|
| 69 |
time: episodeTime,
|
| 70 |
+
id: episodeId
|
| 71 |
});
|
| 72 |
});
|
| 73 |
|
|
|
|
| 74 |
res.json({
|
| 75 |
anime: {
|
| 76 |
title: animeTitle,
|
|
|
|
| 84 |
}
|
| 85 |
});
|
| 86 |
|
|
|
|
| 87 |
app.get('/api/anime/episode/:id', async (req, res) => {
|
| 88 |
const { id } = req.params;
|
| 89 |
const url = `https://samehadaku.email/${id}`;
|
| 90 |
|
| 91 |
try {
|
|
|
|
| 92 |
const response = await axios.get(url);
|
| 93 |
const $ = cheerio.load(response.data);
|
| 94 |
|
|
|
|
| 153 |
const url = `https://samehadaku.email/anime/${id}`; // Fetch data from this URL
|
| 154 |
|
| 155 |
try {
|
|
|
|
| 156 |
const response = await axios.get(url);
|
|
|
|
|
|
|
| 157 |
const $ = cheerio.load(response.data);
|
|
|
|
|
|
|
| 158 |
const imageUrl = $('.thumb[itemprop="image"] img').attr('src');
|
| 159 |
|
| 160 |
if (imageUrl) {
|
|
|
|
| 161 |
const imageResponse = await axios.get(imageUrl, { responseType: 'arraybuffer' });
|
|
|
|
|
|
|
| 162 |
res.set('Content-Type', 'image/jpeg'); // Update this if the image is in a different format (e.g., PNG)
|
|
|
|
|
|
|
| 163 |
res.send(imageResponse.data);
|
| 164 |
} else {
|
|
|
|
| 165 |
res.status(404).send('Image not found');
|
| 166 |
}
|
| 167 |
} catch (error) {
|