Skip to content

Commit

Permalink
fix parse magnet title
Browse files Browse the repository at this point in the history
  • Loading branch information
ovnrain committed Nov 10, 2023
1 parent 1b61e23 commit 7b0e845
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions api/router/v1/javbusParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,29 +158,30 @@ export function convertMagnetsHTML(html: string) {
const magnets = doc
.querySelectorAll('tr')
.map<Magnet>((tr) => {
const link = tr.querySelector('td a')?.getAttribute('href') ?? '';
const id = link.match(/magnet:\?xt=urn:btih:(\w+)/)?.[1] ?? '';
const isHD = Boolean(
tr
.querySelector('td')
?.querySelectorAll('a')
.find((a) => a.textContent.includes('高清')),
);
const hasSubtitle = Boolean(
tr
.querySelector('td')
?.querySelectorAll('a')
.find((a) => a.textContent.includes('字幕')),
);
const title = tr.querySelector('td a')?.textContent.trim() ?? '';
const firstAnchor = tr.querySelector('td a');
const tagAnchors = firstAnchor?.querySelectorAll('a');

const link = firstAnchor?.getAttribute('href') ?? '';
const id = link?.match(/magnet:\?xt=urn:btih:(\w+)/)?.[1] ?? '';

const isHD = Boolean(tagAnchors?.find((a) => a.textContent.includes('高清')));
const hasSubtitle = Boolean(tagAnchors?.find((a) => a.textContent.includes('字幕')));

if (tagAnchors?.length) {
tagAnchors.forEach((a) => {
a.remove();
});
}

const title = firstAnchor?.textContent.trim() ?? '';
const size = tr.querySelector('td:nth-child(2) a')?.textContent.trim() ?? null;
const numberSize = size ? bytes(size) : null;
const shareDate = tr.querySelector('td:nth-child(3) a')?.textContent.trim() ?? null;

return { id, link, isHD, title, size, numberSize, shareDate, hasSubtitle };
})
.filter(({ id, link, title }) => id && link && title)
.sort((a, b) => bytes.parse(b.size ?? '') - bytes.parse(a.size ?? ''));
.sort((a, b) => (a.numberSize && b.numberSize ? b.numberSize - a.numberSize : 0));

return magnets;
}
Expand Down

0 comments on commit 7b0e845

Please sign in to comment.