小雅对id进行base58

This commit is contained in:
mtvpls
2026-01-11 22:05:32 +08:00
parent b6026199e3
commit 30278b3ac1
5 changed files with 99 additions and 11 deletions
+41
View File
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any,no-console */
import he from 'he';
import Hls from 'hls.js';
import bs58 from 'bs58';
function getDoubanImageProxyConfig(): {
proxyType:
@@ -330,3 +331,43 @@ export function cleanHtmlTags(text: string): string {
// 使用 he 库解码 HTML 实体
return he.decode(cleanedText);
}
/**
* 将字符串编码为 Base58
* @param str 要编码的字符串
* @returns Base58 编码后的字符串
*/
export function base58Encode(str: string): string {
if (!str) return '';
// 在浏览器环境中使用 TextEncoder
if (typeof window !== 'undefined') {
const encoder = new TextEncoder();
const bytes = encoder.encode(str);
return bs58.encode(bytes);
}
// 在 Node.js 环境中使用 Buffer
const buffer = Buffer.from(str, 'utf-8');
return bs58.encode(buffer);
}
/**
* 将 Base58 字符串解码为原始字符串
* @param encoded Base58 编码的字符串
* @returns 解码后的原始字符串
*/
export function base58Decode(encoded: string): string {
if (!encoded) return '';
const bytes = bs58.decode(encoded);
// 在浏览器环境中使用 TextDecoder
if (typeof window !== 'undefined') {
const decoder = new TextDecoder();
return decoder.decode(bytes);
}
// 在 Node.js 环境中使用 Buffer
return Buffer.from(bytes).toString('utf-8');
}
+21 -2
View File
@@ -21,11 +21,14 @@ export interface XiaoyaMetadata {
* 从文件夹名提取 TMDb ID 和年份
* 格式: "标题 (年份) {tmdb-id}"
*/
function parseFolderName(folderName: string): {
function parseFolderName(folderName: string | undefined): {
title?: string;
year?: string;
tmdbId?: number;
} {
if (!folderName || typeof folderName !== 'string') {
return {};
}
const match = folderName.match(/^(.+?)\s*\((\d{4})\)\s*\{tmdb-(\d+)\}$/);
if (match) {
return {
@@ -85,7 +88,18 @@ export async function getXiaoyaMetadata(
tmdbProxy?: string
): Promise<XiaoyaMetadata> {
const pathParts = videoPath.split('/').filter(Boolean);
const isInSeasonDir = /season\s*\d+/i.test(pathParts[pathParts.length - 2]);
// 验证路径格式
if (pathParts.length < 2) {
throw new Error(`无效的视频路径格式: ${videoPath}`);
}
const isInSeasonDir = pathParts.length >= 2 && /season\s*\d+/i.test(pathParts[pathParts.length - 2]);
// 验证路径长度是否足够
if (isInSeasonDir && pathParts.length < 3) {
throw new Error(`Season目录路径格式不正确: ${videoPath}`);
}
// 确定元数据目录
const metadataDir = isInSeasonDir
@@ -94,6 +108,11 @@ export async function getXiaoyaMetadata(
const folderName = pathParts[isInSeasonDir ? pathParts.length - 3 : pathParts.length - 2];
// 验证 folderName 是否有效
if (!folderName) {
throw new Error(`无法从路径中提取文件夹名: ${videoPath}`);
}
// 优先级 1: 从文件夹名提取 TMDb ID
const folderInfo = parseFolderName(folderName);
if (folderInfo.tmdbId) {