fix(route): JavBus best magnet link (#11342)

This commit is contained in:
Ethan Shen
2022-11-29 00:26:13 +08:00
committed by GitHub
parent c3e78ee7df
commit 445594870d
2 changed files with 20 additions and 3 deletions
+8 -2
View File
@@ -4,6 +4,11 @@ const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
const toSize = (raw) => {
const matches = raw.match(/(\d+(\.\d+)?)(\w+)/);
return matches[3] === 'GB' ? matches[1] * 1024 : matches[1];
};
module.exports = async (ctx) => {
const isWestern = /^\/western/.test(ctx.path);
@@ -19,7 +24,7 @@ module.exports = async (ctx) => {
const $ = cheerio.load(response.data);
let items = $('.movie-box')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 30)
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 50)
.toArray()
.map((item) => {
item = $(item);
@@ -98,11 +103,12 @@ module.exports = async (ctx) => {
link: td.first().attr('href'),
size: td.eq(1).text().trim(),
date: td.last().text().trim(),
score: content(tr).find('a').length ** 8 * toSize(td.eq(1).text().trim()),
};
});
if (magnets) {
item.enclosure_url = magnets[0].link;
item.enclosure_url = magnets.sort((a, b) => b.score - a.score)[0].link;
item.enclosure_type = 'application/x-bittorrent';
}
} catch (e) {
+12 -1
View File
@@ -9,9 +9,20 @@
{{/if}}
<br>
<h4>磁力連結投稿</h4>
<table>
<tr>
<th>磁力名稱</th>
<th>檔案大小</th>
<th>分享日期</th>
</tr>
{{each magnets magnet}}
<li><a href="{{ magnet.link }}">{{ magnet.title }} [{{ magnet.size }}] ({{ magnet.date }})</a></li>
<tr>
<td><a href="{{ magnet.link }}">{{ magnet.title }}</a></td>
<td>{{ magnet.size }}</td>
<td>{{ magnet.date }}</td>
</tr>
{{/each}}
</table>
<h4>樣品圖像</h4>
{{each thumbs}}
<img src="{{ $value }}">