Skip to content

Commit

Permalink
feat(mteam): support to get torrent link
Browse files Browse the repository at this point in the history
  • Loading branch information
techmovie committed May 25, 2024
1 parent 76dd458 commit 5523bc9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@svgr/core": "^6.0.0",
"@svgr/plugin-svgo": "^6.0.0",
"@types/jquery": "^3.5.5",
"@types/parse-torrent": "^5.8.7",
"@types/tampermonkey": "^4.0.5",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
Expand Down
26 changes: 23 additions & 3 deletions src/source/mt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
formatTorrentTitle, getSpecsFromMediainfo
, getAudioCodecFromTitle, getVideoCodecFromTitle, getScreenshotsFromBBCode,
getSourceFromTitle, getAreaCode,
getBDInfoOrMediaInfo,
getBDInfoOrMediaInfo, fetch,
} from '../common';

import type { TorrentDetailInfo, IMDbInfo } from '../types/sites/mt';
Expand Down Expand Up @@ -79,7 +79,7 @@ const getTorrentInfo = async (info: TorrentDetailInfo): Promise<TorrentInfo.Info
const screenshots = await getScreenshotsFromBBCode(descr);
let mediaTags = {};
let mediaInfoOrBDInfo = mediainfo;
const isBluray = !!videoType.match(/bluray/i);
const isBluray = !!videoType?.match(/bluray/i);
if (!mediaInfoOrBDInfo) {
const { bdinfo, mediaInfo } = getBDInfoOrMediaInfo(descr);
mediaInfoOrBDInfo = isBluray ? bdinfo : mediaInfo;
Expand All @@ -92,10 +92,12 @@ const getTorrentInfo = async (info: TorrentDetailInfo): Promise<TorrentInfo.Info
mediaTags = specs.mediaTags || {};
}
let area = '';
const areaMatch = descr.match(/(\s+|\s+)?\s*(.+)/)?.[2];
const areaMatch = descr.match(/(\s*|\s*|\s*)?\s*(.+)/)?.[2];
if (areaMatch) {
area = getAreaCode(areaMatch);
}
await getTorrentURL();

return {
sourceSite: CURRENT_SITE_NAME,
sourceSiteType: CURRENT_SITE_INFO.siteType,
Expand Down Expand Up @@ -159,3 +161,21 @@ const getMovieInfo = (data: IMDbInfo) => {
poster: photo.full || photo.thumb,
};
};

const getTorrentURL = async () => {
const torrentId = location.pathname.match(/detail\/(\d+)/)?.[1] ?? '';
if (!torrentId) {
return '';
}
const formData = new FormData();
formData.append('id', torrentId);
const response = await fetch('https://api.m-team.cc/api/torrent/genDlToken', {
method: 'POST',
data: formData,
headers: {
Authorization: localStorage.getItem('auth') || '',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
},
});
CURRENT_SITE_INFO.torrentLink = response?.data ?? '';
};
2 changes: 1 addition & 1 deletion src/source/nexusphp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export default async () => {
TORRENT_INFO.isForbidden = !!isForbidden;
// 兼容家园
if (!processing || processing.match(/raw|encode/)) {
const areaMatch = descriptionBBCode.match(/(\s+|\s+)?\s*(.+)/)?.[2];
const areaMatch = descriptionBBCode.match(/(\s*|\s*|\s*)?\s*(.+)/)?.[2];
if (areaMatch) {
TORRENT_INFO.area = getAreaCode(areaMatch);
}
Expand Down
23 changes: 23 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,13 @@
dependencies:
"@types/node" "*"

"@types/magnet-uri@*":
version "5.1.5"
resolved "https://registry.yarnpkg.com/@types/magnet-uri/-/magnet-uri-5.1.5.tgz#8034da138edb41f007729ff18c76e0454df42438"
integrity sha512-SbBjlb1KGe38VfjRR+mwqztJd/4skhdKkRbIzPDhTy7IAeEAPZWIVSEkZw00Qr4ZZOGR3/ATJ20WWPBfrKHGdA==
dependencies:
"@types/node" "*"

"@types/minimist@^1.2.0":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c"
Expand All @@ -1074,6 +1081,22 @@
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==

"@types/parse-torrent-file@*":
version "4.0.6"
resolved "https://registry.yarnpkg.com/@types/parse-torrent-file/-/parse-torrent-file-4.0.6.tgz#11801dfd5b0a017302a164b72c8869f2bcba15b1"
integrity sha512-SxqVth0Iv0WuEkqWS5MaY4S4Tlyi+QHkElQREvsUPw2xHcPgKyQ2dkJRRv5vAxmLzH+tnMdOj1Nws/wsenbzUw==
dependencies:
"@types/node" "*"

"@types/parse-torrent@^5.8.7":
version "5.8.7"
resolved "https://registry.yarnpkg.com/@types/parse-torrent/-/parse-torrent-5.8.7.tgz#68bca7701201a67568fdc7f194bdf3f2a49c2c11"
integrity sha512-vZtYe450hO+KL7B5fejM8CHWg1LPZKeVXlolphPsWf6n4H0ZUlI6ICbqHoaFmH7JQmU2yRbGgyvqqizdFuGPFQ==
dependencies:
"@types/magnet-uri" "*"
"@types/node" "*"
"@types/parse-torrent-file" "*"

"@types/responselike@*", "@types/responselike@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/responselike/-/responselike-1.0.0.tgz#251f4fe7d154d2bad125abe1b429b23afd262e29"
Expand Down

0 comments on commit 5523bc9

Please sign in to comment.