Skip to content

Commit 2463e86

Browse files
committed
Merge pull request #97 from SAbotsup/patch-2
Added trailer extraction support from anime info page
2 parents ba1dca2 + cfa5f49 commit 2463e86

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/extractors/animeInfo.extractor.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,27 @@ async function extractAnimeInfo(id) {
7676
animeInfo[key] = value;
7777
});
7878

79+
const trailers = [];
80+
$('.block_area-promotions-list .screen-items .item').each((_, element) => {
81+
const el = $(element);
82+
const title = el.attr('data-title');
83+
const url = el.attr('data-src');
84+
if (url) {
85+
const fullUrl = url.startsWith('//') ? `https:${url}` : url;
86+
let videoId = null;
87+
const match = fullUrl.match(/\/embed\/([^?&]+)/);
88+
if (match && match[1]) {
89+
videoId = match[1];
90+
}
91+
trailers.push({
92+
title: title || null,
93+
url: fullUrl,
94+
thumbnail: videoId ? `https://img.youtube.com/vi/${videoId}/hqdefault.jpg` : null
95+
});
96+
}
97+
});
98+
animeInfo.trailers = trailers;
99+
79100
const season_id = formatTitle(title, data_id);
80101
animeInfo["Overview"] = overviewElement.text().trim();
81102
animeInfo["tvInfo"] = tvInfo;

0 commit comments

Comments
 (0)