Skip to content

Commit

Permalink
fix(hhclub): update source fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
techmovie committed Mar 11, 2024
1 parent 7cd5303 commit 578e2c5
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 110 deletions.
1 change: 1 addition & 0 deletions src/config/HH.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ icon: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAMAAAC6V+0/AAAABGdB
asSource: true
asTarget: false
uploadPath: /upload.php
needDoubanInfo: true
seedDomSelector: '.bg-content_bg div.leading-6:nth-child(5)'
search:
path: /torrents.php
Expand Down
117 changes: 117 additions & 0 deletions src/source/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

/**
* 格式化视频类型
* @param {videoType} videoType
* @return
*/
const getVideoType = (videoType:string) => {
if (!videoType) {
return '';
}

videoType = videoType.replace(/[.-]/g, '').toLowerCase();
if (videoType.match(/encode|x264|x265|bdrip|hdrip|压制/ig)) {
return 'encode';
} else if (videoType.match(/remux/ig)) {
return 'remux';
} else if (videoType.match(/uhd|ultra/ig)) {
return 'uhdbluray';
} else if (videoType.match(/blu|discs/ig)) {
return 'bluray';
} else if (videoType.match(/webdl/ig)) {
return 'web';
} else if (videoType.match(/hdtv/ig)) {
return 'hdtv';
} else if (videoType.match(/dvdr/ig)) {
return 'dvdrip';
} else if (videoType.match(/dvd/ig)) {
return 'dvd';
}
return '';
};
/**
* 格式化视频分类
* @param {category} category
*/
const getCategory = (category:string) => {
if (!category) {
return '';
}
category = category.replace(/[.-]/g, '').toLowerCase();
if (category.match(/movie|bd|ultra|电影/ig)) {
return 'movie';
} else if (category.match(/综艺/ig)) {
return 'variety';
} else if (category.match(/tv|drama|剧集|电视/ig)) {
return 'tv';
} else if (category.match(/TVSeries/ig)) {
return 'tvPack';
} else if (category.match(/document|纪录|紀錄|Doc/ig)) {
return 'documentary';
} else if (category.match(/sport|体育/ig)) {
return 'sport';
} else if (category.match(/mv|演唱|concert/ig)) {
return 'concert';
} else if (category.match(/anim|动(画|漫)/ig)) {
return 'cartoon';
} else if (category.match(/App|软件|Software|軟體/ig)) {
return 'app';
} else if (category.match(/电子书|小说|Ebook/ig)) {
return 'ebook';
} else if (category.match(/有声书|AudioBook/ig)) {
return 'audiobook';
} else if (category.match(/杂志|magazine/ig)) {
return 'magazine';
} else if (category.match(/漫画|comics/ig)) {
return 'comics';
} else if (category.match(/公开课/ig)) {
return 'onlineCourse';
} else if (category.match(/资料/ig)) {
return 'ebook';
}
return '';
};

const getResolution = (resolution:string) => {
resolution = resolution.toLowerCase();
if (resolution.match(/4k|2160|UHD/ig)) {
return '2160p';
} else if (resolution.match(/1080(p)?/ig)) { // 兼容烧包
return '1080p';
} else if (resolution.match(/1080i/ig)) {
return '1080i';
} else if (resolution.match(/720(p)?/ig)) { // 兼容烧包
return '720p';
} else if (resolution.match(/sd/ig)) {
return '480p';
}
return resolution;
};

const getFormat = (data:string) => {
if (data.match(/pdf/i)) {
return 'pdf';
} else if (data.match(/EPUB/i)) {
return 'epub';
} else if (data.match(/MOBI/i)) {
return 'mobi';
} else if (data.match(/mp3/i)) {
return 'mp3';
} else if (data.match(/mp4/i)) {
return 'mp4';
} else if (data.match(/txt/i)) {
return 'txt';
} else if (data.match(/azw3/i)) {
return 'azw3';
} else if (data.match(/镜像/i)) {
return 'iso';
}
return 'other';
};

export {
getVideoType,
getCategory,
getResolution,
getFormat,
};
133 changes: 133 additions & 0 deletions src/source/hh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { CURRENT_SITE_NAME, TORRENT_INFO } from '../const';
import { formatTorrentTitle, getSize, getInfoFromBDInfo, getInfoFromMediaInfo, getSourceFromTitle } from '../common';
import { getVideoType, getCategory } from './helper';

export default async () => {
const title = formatTorrentTitle(document.title.match(/"(.+)"/)?.[1] || '');
const subTitle = $("div.font-bold.leading-6:contains('副标题')").next().text().replace(//g, ':');
const imbdDom = $('#kimdb a[href*="imdb.com/title"]');
const siteImdbUrl = imbdDom?.attr('href') ?? '';
const movieName = imbdDom?.text()?.replace(/\n|\s/g, '') ?? '';
const metaInfo = getMetaInfo();
const isBluray = !!metaInfo.videoType?.match(/bluray/i);
const mediaInfo = $('#mediainfo-raw code').text() || '';
const specs = getSpecsFromMediainfo(isBluray, mediaInfo);
if (Object.keys(specs).length > 0) {
Object.assign(metaInfo, specs);
}
const { category, videoType, videoCodec, audioCodec, resolution, size } = metaInfo;

const formatSize = getSize(size);
const year = title?.match(/(19|20)\d{2}/g) ?? [];

const screenshots = $('#screenshot-content img')
.toArray().map((el) => $(el).attr('src')).filter(url => url && url !== '') as string[];

const doubanUrl = $('#douban_info-content').prev().find('a[href*="douban.com"]').attr('href') ?? '';
let description = `
[quote]${mediaInfo}[/quote]
`;
screenshots.forEach((url) => {
description += `[img]${url}[/img]`;
});
const tags = getTagsFromPage();

Object.assign(TORRENT_INFO, {
title,
subtitle: subTitle,
imdbUrl: siteImdbUrl,
description,
year: year.length > 0 ? year.pop() as string : '',
source: getSourceFromTitle(title),
mediaInfo,
screenshots,
movieName,
sourceSite: CURRENT_SITE_NAME,
sourceSiteType: TORRENT_INFO.sourceSiteType,
category: getCategory(category),
size: formatSize,
tags: { ...specs.mediaTags, ...tags },
videoType: getVideoType(videoType),
videoCodec,
audioCodec,
resolution,
doubanUrl,
poster: $('#cover-content')?.attr('src') ?? '',
});
};

const getMetaInfo = () => {
const meta = getMetaValue();
const category = meta['类型'];
const videoType = meta['来源'];
const videoCodec = meta['编码'];
const audioCodec = meta['音频编码'];
const resolution = meta['分辨率'];
const processing = meta['处理'];
const size = meta['大小'];
console.log({
category,
videoType,
videoCodec,
audioCodec,
resolution,
size,
});
return {
category,
videoType,
videoCodec,
audioCodec,
resolution,
processing,
size,
};
};
const getMetaValue = () => {
const result = {} as {[key:string]:string};
$("div.font-bold.leading-6:contains('基本信息')").next().find('div span').each((index, el) => {
if (index % 2 === 0) {
const key = $(el).text().replace(/:|:/g, '').trim();
result[key] = $(el).next().text();
}
});
return result;
};

function getSpecsFromMediainfo (isBluray:boolean, mediaInfo:string) {
const getInfoFunc = isBluray ? getInfoFromBDInfo : getInfoFromMediaInfo;
const { videoCodec, audioCodec, resolution, mediaTags } = getInfoFunc(mediaInfo);
if (videoCodec !== '' && audioCodec !== '' && resolution !== '') {
return {
videoCodec,
audioCodec,
resolution,
mediaTags,
};
}
return {};
}

const getTagsFromPage = () => {
const tags:TorrentInfo.MediaTags = {};
const tagText = $("div.font-bold.leading-6:contains('标签')").next().text();
if (tagText.includes('中字')) {
tags.chinese_subtitle = true;
}
if (tagText.includes('国语')) {
tags.chinese_audio = true;
}
if (tagText.includes('粤语')) {
tags.cantonese_audio = true;
}
if (tagText.includes('DIY')) {
tags.diy = true;
}
if (tagText.includes('杜比视界')) {
tags.dolbyVision = true;
}
if (tagText.includes('HDR')) {
tags.dolbyVision = true;
}
return tags;
};
2 changes: 2 additions & 0 deletions src/source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import getBdcInfo from './bdc';
import getRedInfo from './red';
import getMTVInfo from './mtv';
import getSpeedAppInfo from './speedapp';
import getHHInfo from './hh';

const siteNameMap = {
BeyondHD: getBHDInfo,
Expand All @@ -40,6 +41,7 @@ const siteNameMap = {
DicMusic: getRedInfo,
MTV: getMTVInfo,
SpeedApp: getSpeedAppInfo,
HH: getHHInfo,
};

const siteTypeInfoMap = {
Expand Down

0 comments on commit 578e2c5

Please sign in to comment.