Skip to content

Commit

Permalink
fix(route): domp4 支持自定义域名 (#13169)
Browse files Browse the repository at this point in the history
* fix: mp4kan 网页改版问题

* feat: domp4 支持多域名

* Update lib/v2/domp4/utils.js

* fix: fixed domain for guid

---------
  • Loading branch information
savokiss authored Sep 1, 2023
1 parent ab6423f commit 24e6b08
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/v2/domp4/detail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
const { baseUrl, decodeCipherText, composeMagnetUrl, getUrlType } = require('./utils');

const { decodeCipherText, composeMagnetUrl, getUrlType, ensureDomain } = require('./utils');

// 兼容没有 script 标签的情况,直接解析 dom
function getDomList($, detailUrl) {
Expand Down Expand Up @@ -68,6 +69,7 @@ function getMetaInfo($) {

module.exports = async (ctx) => {
const { id } = ctx.params;
const { domain } = ctx.query;
let pureId = id;
let detailType = 'html';
// compatible for .html suffix in radar
Expand All @@ -78,7 +80,7 @@ module.exports = async (ctx) => {
if (/^\d+$/.test(pureId)) {
detailType = 'detail';
}
const detailUrl = `${baseUrl}/${detailType}/${pureId}.html`;
const detailUrl = `${ensureDomain(ctx, domain)}/${detailType}/${pureId}.html`;

const res = await got(detailUrl);
const $ = cheerio.load(res.data);
Expand Down
11 changes: 7 additions & 4 deletions lib/v2/domp4/latest.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');

const { baseUrl } = require('./utils');

const latestUrl = `${baseUrl}/custom/update.html`;
const { defaultDomain, ensureDomain } = require('./utils');

function getItemList($, type) {
const list = $(`#${type} .list-group-item`)
Expand All @@ -12,14 +10,19 @@ function getItemList($, type) {
item = $(item);
return {
title: item.find('a').text(),
link: `${baseUrl}${item.find('a').attr('href')}`,
link: `https://${defaultDomain}${item.find('a').attr('href')}`, // fixed domain for guid
};
});
return list;
}

module.exports = async (ctx) => {
const { type = 'vod' } = ctx.params;
const { domain } = ctx.query;

const hostUrl = ensureDomain(ctx, domain);
const latestUrl = `${hostUrl}/custom/update.html`;

const res = await got.get(latestUrl);
const $ = cheerio.load(res.data);
const list = getItemList($, type);
Expand Down
17 changes: 15 additions & 2 deletions lib/v2/domp4/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const baseUrl = 'https://www.mp4kan.com';
const config = require('@/config').value;

const defaultDomain = 'mp4us.com';

const allowedDomains = ['domp4.cc', 'mp4kan.com', 'mp4us.com', 'wemp4.com', 'dbmp4.com'];

/**
* trackers from https://www.domp4.cc/Style/2020/js/base.js?v=2
Expand Down Expand Up @@ -80,10 +84,19 @@ function decodeCipherText(p, a, c, k, e, d) {
return p;
}

function ensureDomain(ctx, domain = defaultDomain) {
const origin = `https://${domain}`;
if (!config.feature.allow_user_supply_unsafe_domain && !allowedDomains.includes(new URL(origin).hostname)) {
ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`);
}
return origin;
}

module.exports = {
baseUrl,
defaultDomain,
magnetTrackers,
getUrlType,
composeMagnetUrl,
decodeCipherText,
ensureDomain,
};
12 changes: 12 additions & 0 deletions website/docs/routes/multimedia.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,18 @@ BT 之家的域名会变更,本路由以 <https://www.btbtt20.com> 为默认

## DoMP4 影视 {#domp4-ying-shi}

:::tip

由于网站有多个备用域名,默认使用 `mp4us.com`,可以通过在路由最后加上 `?domain=<域名>` 切换域名。

目前可用域名有:

```javascript
['domp4.cc', 'mp4kan.com', 'mp4us.com', 'wemp4.com', 'dbmp4.com']
```

:::

### 最近更新 {#domp4-ying-shi-zui-jin-geng-xin}

<Route author="savokiss" example="/domp4/latest/vod" path="/domp4/latest/:type?" paramsDesc={['`vod` 代表电影,`tv` 代表电视剧,默认 vod']} radar="1"/>
Expand Down

0 comments on commit 24e6b08

Please sign in to comment.