From dfe14d430085b66411b9349bc54b9834a8e0fdff Mon Sep 17 00:00:00 2001 From: savokiss Date: Tue, 6 Sep 2022 18:49:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20domp4=20=E8=AF=A6=E6=83=85=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=20guid=20(#10702)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: domp4 详情返回 guid * fix: domp4 guid with urlType --- lib/v2/domp4/detail.js | 10 +++++++--- lib/v2/domp4/utils.js | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/v2/domp4/detail.js b/lib/v2/domp4/detail.js index 130160cc7..f1924daaf 100644 --- a/lib/v2/domp4/detail.js +++ b/lib/v2/domp4/detail.js @@ -1,6 +1,6 @@ const cheerio = require('cheerio'); const got = require('@/utils/got'); -const { decodeCipherText, composeMagnetUrl } = require('./utils'); +const { decodeCipherText, composeMagnetUrl, getUrlType } = require('./utils'); const baseUrl = 'https://www.domp4.cc'; @@ -16,13 +16,17 @@ function getItemList($, detailUrl) { ); const { downurls } = data.Data[0]; return downurls.map((item) => { - const [title, magnet] = item.split('$'); + const [title, downurl] = item.split('$'); + const urlType = getUrlType(downurl); + // only magnet need compose trackers + const enclosureUrl = urlType === 'magnet' ? composeMagnetUrl(downurl) : downurl; return { - enclosure_url: composeMagnetUrl(magnet), + enclosure_url: enclosureUrl, enclosure_length: '', enclosure_type: 'application/x-bittorrent', title, link: detailUrl, + guid: `${title}-${urlType}`, }; }); } diff --git a/lib/v2/domp4/utils.js b/lib/v2/domp4/utils.js index f4f694e70..087a9a2a3 100644 --- a/lib/v2/domp4/utils.js +++ b/lib/v2/domp4/utils.js @@ -35,6 +35,19 @@ function composeMagnetUrl(magnet, trackers = magnetTrackers) { return `${magnet}&tr=${trackers.join('&tr=')}`; } +/** + * method for download url type + */ +function getUrlType(url) { + if (url.startsWith('magnet:')) { + return 'magnet'; + } + if (url.startsWith('ed2k:')) { + return 'ed2k'; + } + return ''; +} + /** * method for generating magnet url * from the detail page source @@ -67,6 +80,7 @@ function decodeCipherText(p, a, c, k, e, d) { module.exports = { magnetTrackers, + getUrlType, composeMagnetUrl, decodeCipherText, };