fix: domp4 详情返回 guid (#10702)

* fix: domp4 详情返回 guid

* fix: domp4 guid with urlType
This commit is contained in:
savokiss 2022-09-06 18:49:52 +08:00 committed by GitHub
parent 38aa2eb4ab
commit dfe14d4300
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -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}`,
};
});
}

View File

@ -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,
};