|
|
@@ -89,6 +89,8 @@ import { findWebDavCacheIfExists, triggerWebDavCacheDownload } from '../common/n
|
|
|
import { navidromeApi } from '../common/network/NavidromeApi';
|
|
|
import { ServerLogUtil } from '../common/util/ServerLogUtil';
|
|
|
import { ensureSmbFileStreaming, SmbStreamingMeta } from '../common/network/SmbFileCache';
|
|
|
+import { ensureBaiduFileCached } from '../common/network/BaiduFileCache';
|
|
|
+import FileManager from '../common/util/FileManager';
|
|
|
|
|
|
import { HSBColorPicker, HSBColorPickerLayout } from '@keke/color-picker'
|
|
|
import app from '@system.app';
|
|
|
@@ -621,13 +623,62 @@ async function setVideoUrlForSong(song: VideoItem, options?: MetadataExtractionO
|
|
|
if (!account) {
|
|
|
throw new Error('百度网盘账户不可用');
|
|
|
}
|
|
|
- Logger.info(TAG, `Baidu播放准备 - accountId: ${account.id}, fsId: ${song.baiduFsId || song.id}`);
|
|
|
- const downloadUrl = await manager.getBaiduDownloadUrl(account, song);
|
|
|
- Logger.info(TAG, `Baidu播放URL已经构建完成: ${downloadUrl}`);
|
|
|
- return downloadUrl;
|
|
|
+ Logger.info(TAG, `百度网盘播放准备 - accountId: ${account.id}, fsId: ${song.baiduFsId || song.id}`);
|
|
|
+
|
|
|
+ const fsId = song.baiduFsId || song.id;
|
|
|
+ if (!fsId) {
|
|
|
+ throw new Error('缺少百度网盘文件fs_id');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 优先使用remote_rel_path,回退到文件名
|
|
|
+ const relativePath = song.remote_rel_path || song.name || song.fileName || song.filePath;
|
|
|
+ const cachedPath = await resolveCacheFilePath(
|
|
|
+ RemoteCacheType.BAIDU,
|
|
|
+ account.id?.toString(),
|
|
|
+ relativePath
|
|
|
+ );
|
|
|
+
|
|
|
+ const fileExists = await FileManager.isExist(cachedPath.cachePath);
|
|
|
+ if (fileExists) {
|
|
|
+ const fileSize = await FileManager.getFileSize(cachedPath.cachePath);
|
|
|
+ if (fileSize > 0) {
|
|
|
+ Logger.info(TAG, `百度网盘文件已缓存: ${cachedPath.cachePath}`);
|
|
|
+ void scheduleMetadataExtractionFromCache(song, cachedPath.cachePath, metadataOptions, song.videoSize);
|
|
|
+ return cachedPath.cachePath;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 缓存不存在或无效,获取文件信息(包含大小和下载链接)
|
|
|
+ Logger.info(TAG, `百度网盘文件未缓存,准备获取文件信息: ${relativePath}`);
|
|
|
+ const fileInfo = await manager.getBaiduFileInfo(account, fsId);
|
|
|
+ Logger.info(TAG, `百度网盘文件信息获取成功: 大小=${fileInfo.size}字节,链接已获取`);
|
|
|
+
|
|
|
+ // 立即返回下载链接,开始播放
|
|
|
+ Logger.info(TAG, `返回下载链接进行播放,同时后台缓存: ${fileInfo.dlink}`);
|
|
|
+
|
|
|
+ // 异步进行缓存,不阻塞播放
|
|
|
+ void (async () => {
|
|
|
+ try {
|
|
|
+ Logger.info(TAG, `后台开始缓存百度网盘文件: ${relativePath},大小: ${fileInfo.size}字节`);
|
|
|
+ const cachedFilePath = await ensureBaiduFileCached(
|
|
|
+ account,
|
|
|
+ fsId,
|
|
|
+ relativePath,
|
|
|
+ fileInfo.dlink,
|
|
|
+ fileInfo.size
|
|
|
+ );
|
|
|
+ Logger.info(TAG, `后台缓存完成: ${cachedFilePath}`);
|
|
|
+ void scheduleMetadataExtractionFromCache(song, cachedFilePath, metadataOptions, song.videoSize);
|
|
|
+ } catch (cacheError) {
|
|
|
+ const cacheErr = cacheError as Error;
|
|
|
+ Logger.warn(TAG, `后台缓存失败: ${cacheErr.message}`);
|
|
|
+ }
|
|
|
+ })();
|
|
|
+
|
|
|
+ return fileInfo.dlink;
|
|
|
} catch (error) {
|
|
|
const err = error as Error;
|
|
|
- Logger.error(TAG, `百度网盘获取播放链接失败: ${err.message}`);
|
|
|
+ Logger.error(TAG, `百度网盘播放链接获取失败: ${err.message}`);
|
|
|
throw err;
|
|
|
}
|
|
|
}
|