refactor(turkanime): bölüm tarama akışını ajax tabanlı yap
Ana sayfa scraping mantığı kaldırılarak doğrudan AJAX endpointinden bölüm listesi alınıyor. formatTurkanimeTitleFromSlug fonksiyonu eklenerek başlık formatlaması iyileştirildi.
This commit is contained in:
125
server/server.js
125
server/server.js
@@ -154,6 +154,63 @@ function parseTurkanimeSlug(rawUrl) {
|
||||
}
|
||||
}
|
||||
|
||||
function formatTurkanimeTitleFromSlug(slug) {
|
||||
if (!slug) return null;
|
||||
const parts = slug.split("-").filter(Boolean);
|
||||
const acronymMap = new Map([
|
||||
["sao", "SAO"],
|
||||
["fma", "FMA"],
|
||||
["aot", "AOT"],
|
||||
["bofuri", "BOFURI"],
|
||||
["gto", "GTO"],
|
||||
["gintama", "Gintama"],
|
||||
["hxh", "HxH"],
|
||||
["one", "One"],
|
||||
["opm", "OPM"],
|
||||
["jjk", "JJK"]
|
||||
]);
|
||||
const romanSet = new Set([
|
||||
"i",
|
||||
"ii",
|
||||
"iii",
|
||||
"iv",
|
||||
"v",
|
||||
"vi",
|
||||
"vii",
|
||||
"viii",
|
||||
"ix",
|
||||
"x",
|
||||
"xi",
|
||||
"xii",
|
||||
"xiii",
|
||||
"xiv",
|
||||
"xv"
|
||||
]);
|
||||
const words = [];
|
||||
for (let i = 0; i < parts.length; i += 1) {
|
||||
const part = parts[i];
|
||||
const next = parts[i + 1];
|
||||
const isNumeric = /^\d+$/.test(part);
|
||||
const isNextNumeric = next && /^\d+$/.test(next);
|
||||
if (isNumeric && isNextNumeric) {
|
||||
words.push(`${part}-${next}`);
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
const lower = part.toLowerCase();
|
||||
if (acronymMap.has(lower)) {
|
||||
words.push(acronymMap.get(lower));
|
||||
continue;
|
||||
}
|
||||
if (romanSet.has(lower)) {
|
||||
words.push(lower.toUpperCase());
|
||||
continue;
|
||||
}
|
||||
words.push(part.charAt(0).toUpperCase() + part.slice(1));
|
||||
}
|
||||
return words.join(" ");
|
||||
}
|
||||
|
||||
function logTurkanime(message) {
|
||||
if (!TURKANIME_DEBUG) return;
|
||||
console.log(`Turkanime: ${message}`);
|
||||
@@ -6436,7 +6493,8 @@ app.post("/api/turkanime/episodes", requireAuth, async (req, res) => {
|
||||
let lastUrl = null;
|
||||
let lastStatus = null;
|
||||
|
||||
logTurkanime(`${slug} animesine ait linkler bulunuyor.`);
|
||||
const animeTitle = formatTurkanimeTitleFromSlug(slug) || slug;
|
||||
logTurkanime(`${animeTitle} animesine ait linkler bulunuyor.`);
|
||||
|
||||
let animePage;
|
||||
try {
|
||||
@@ -6444,17 +6502,15 @@ app.post("/api/turkanime/episodes", requireAuth, async (req, res) => {
|
||||
`https://www.turkanime.tv/anime/${slug}`
|
||||
);
|
||||
} catch (err) {
|
||||
logTurkanime(
|
||||
`Anime sayfası okunamadı, fallback taramaya geçiliyor.`
|
||||
);
|
||||
logTurkanime(`Anime sayfası okunamadı.`);
|
||||
}
|
||||
|
||||
const animeId = extractTurkanimeAnimeId(animePage?.html || "");
|
||||
if (!animeId) {
|
||||
logTurkanime(`animeId bulunamadı, işlem durduruldu.`);
|
||||
return res.json({ ok: true, slug, count: 0, episodes: [] });
|
||||
}
|
||||
|
||||
if (animePage?.ok) {
|
||||
let extracted = extractTurkanimeEpisodeLinks(animePage.html, slug);
|
||||
logTurkanime(`Anime sayfasından ${extracted.length} link ayıklandı.`);
|
||||
if (!extracted.length) {
|
||||
const animeId = extractTurkanimeAnimeId(animePage.html);
|
||||
if (animeId) {
|
||||
logTurkanime(`animeId bulundu: ${animeId}`);
|
||||
try {
|
||||
const ajaxPage = await fetchTurkanimeAjaxEpisodes(
|
||||
@@ -6462,7 +6518,7 @@ app.post("/api/turkanime/episodes", requireAuth, async (req, res) => {
|
||||
`https://www.turkanime.tv/anime/${slug}`
|
||||
);
|
||||
if (ajaxPage?.html) {
|
||||
extracted = extractTurkanimeEpisodeLinks(ajaxPage.html, slug);
|
||||
const extracted = extractTurkanimeEpisodeLinks(ajaxPage.html, slug);
|
||||
logTurkanime(
|
||||
`Ajax bolum listesi içinden ${extracted.length} link ayıklandı.`
|
||||
);
|
||||
@@ -6485,37 +6541,7 @@ app.post("/api/turkanime/episodes", requireAuth, async (req, res) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logTurkanime(
|
||||
`Ajax bolum listesi başarısız. Status: ${ajaxPage?.status}`
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
logTurkanime(
|
||||
`Ajax bolum listesi okunamadı: ${err?.message || err}`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
logTurkanime(`animeId bulunamadı, ajax listesi denemesi atlandı.`);
|
||||
}
|
||||
}
|
||||
if (!extracted.length && TURKANIME_DEBUG) {
|
||||
const hasVideo = animePage.html.includes("/video/");
|
||||
const sampleMatches = [];
|
||||
const sampleRegex = /\/video\/[a-z0-9-]+/gi;
|
||||
let m;
|
||||
while ((m = sampleRegex.exec(animePage.html)) && sampleMatches.length < 5) {
|
||||
sampleMatches.push(m[0]);
|
||||
}
|
||||
logTurkanime(
|
||||
`Ham HTML'de /video/ var mı: ${hasVideo ? "evet" : "hayır"}`
|
||||
);
|
||||
if (sampleMatches.length) {
|
||||
logTurkanime(
|
||||
`Ham örnek linkler: ${sampleMatches.join(", ")}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (extracted.length) {
|
||||
extracted.sort((a, b) => {
|
||||
const aNum =
|
||||
@@ -6543,10 +6569,19 @@ app.post("/api/turkanime/episodes", requireAuth, async (req, res) => {
|
||||
}
|
||||
lastUrl = extracted[extracted.length - 1];
|
||||
lastStatus = "listed";
|
||||
logTurkanime(`Son kontrol edilen link: ${lastUrl} (status ${lastStatus})`);
|
||||
logTurkanime(`Toplam ${episodes.length} bolum bulundu`);
|
||||
return res.json({ ok: true, slug, count: episodes.length, episodes });
|
||||
logTurkanime(
|
||||
`Son kontrol edilen link: ${lastUrl} (status ${lastStatus})`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
logTurkanime(
|
||||
`Ajax bolum listesi başarısız. Status: ${ajaxPage?.status}`
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
logTurkanime(
|
||||
`Ajax bolum listesi okunamadı: ${err?.message || err}`
|
||||
);
|
||||
}
|
||||
|
||||
if (lastUrl) {
|
||||
|
||||
Reference in New Issue
Block a user