Skip to content

Commit

Permalink
feat(scraper): hack ani fansubs
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Feb 5, 2025
1 parent c04122b commit 7ff360d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
12 changes: 10 additions & 2 deletions packages/scraper/src/ani/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { toMagnetURI } from 'parse-torrent';
import { type ScrapedResource, type ScrapedResourceDetail, retryFn } from '@animegarden/client';

import { NetworkError } from '../error';
import { parseSize, splitOnce, stripSuffix } from '../utils';
import { parseSize, removeExtraSpaces, splitOnce, stripSuffix } from '../utils';

const parser = new Parser();

Expand Down Expand Up @@ -93,7 +93,15 @@ export async function fetchLastestANi(
res.push({
provider: 'ani',
providerId,
title: stripSuffix(item.title, ['.torrent', '.mp3', '.MP3', '.mp4', '.MP4', '.mkv', '.MKV']),
title: stripSuffix(removeExtraSpaces(item.title), [
'.torrent',
'.mp3',
'.MP3',
'.mp4',
'.MP4',
'.mkv',
'.MKV'
]),
href: link,
type: '动画',
magnet,
Expand Down
23 changes: 18 additions & 5 deletions packages/scraper/src/dmhy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ScrapedResource, ScrapedResourceDetail } from '@animegarden/client
import { retryFn } from '@animegarden/client';

import { NetworkError } from '../error';
import { splitOnce, toShanghai } from '../utils';
import { removeExtraSpaces, splitOnce, stripSuffix, toShanghai } from '../utils';

export interface FetchDmhyPageOptions {
page?: number;
Expand Down Expand Up @@ -52,10 +52,10 @@ export async function fetchDmhyPage(
const type = SimpleType[rawType in DisplayType ? DisplayType[rawType] : rawType] ?? '动画';

const titleNode = [...tds[2].children].find((n) => n.tagName === 'A');
if (!titleNode) {
continue;
}
const title = titleNode.textContent?.trim() ?? '';
if (!titleNode) continue;
let title = titleNode.textContent?.trim() ?? '';
if (!title) continue;

const href = 'https://share.dmhy.org' + (titleNode.getAttribute('href') ?? '/').trim();

const fansub: HTMLAnchorElement | null = tds[2].querySelector('span.tag a');
Expand All @@ -79,6 +79,19 @@ export async function fetchDmhyPage(
const matchId = /^(\d+)/.exec(lastHref);
if (!matchId) continue;

// @hack
if (fansubName === 'ANi') {
title = stripSuffix(removeExtraSpaces(title), [
'.torrent',
'.mp3',
'.MP3',
'.mp4',
'.MP4',
'.mkv',
'.MKV'
]);
}

res.push({
provider: 'dmhy',
providerId: matchId[1],
Expand Down
19 changes: 18 additions & 1 deletion packages/scraper/src/moe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ScrapedResource, ScrapedResourceDetail } from '@animegarden/client
import { retryFn } from '@animegarden/client';

import { NetworkError } from '../error';
import { removeExtraSpaces, stripSuffix } from '../utils';

import { getType } from './tag';
import { fetchTeam, fetchUser } from './user';
Expand Down Expand Up @@ -47,10 +48,26 @@ export async function fetchMoePage(
const user = await fetchUser(ofetch, torrent.uploader_id);
const team = torrent.team_id ? await fetchTeam(ofetch, torrent.team_id) : undefined;

let title = torrent.title;

// @hack
if (team?.name === 'ANi') {
// @hack
title = stripSuffix(removeExtraSpaces(title), [
'.torrent',
'.mp3',
'.MP3',
'.mp4',
'.MP4',
'.mkv',
'.MKV'
]);
}

result.push({
provider: 'moe',
providerId: torrent._id,
title: torrent.title,
title,
href: torrent._id,
magnet: torrent.magnet,
tracker: TRACKER,
Expand Down
4 changes: 4 additions & 0 deletions packages/scraper/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export function stripSuffix(text: string, suffixes: string[]) {
return text;
}

export function removeExtraSpaces(str: string): string {
return str.replace(/\s+/g, ' ').trim();
}

export function toShanghai(date: Date) {
const offset = -480 - new Date().getTimezoneOffset();
return new Date(date.getTime() + offset * 60 * 1000);
Expand Down

0 comments on commit 7ff360d

Please sign in to comment.