|
|
@@ -96,7 +96,9 @@ import { convertPlaylistSongsToVideoItems, emptyView } from '../pages/PlaylistDe
|
|
|
import { Playlist, PlaylistSong } from '../viewmodel/Playlist';
|
|
|
import { Song } from '../viewmodel/Song';
|
|
|
import { SongType } from '../common/enums/SongType';
|
|
|
-import { WebdavManager, WebDavAuthInfo as WebDavManagerAuthInfo } from '../common/util/WebdavManager';
|
|
|
+import { WebdavManager, WebDavAuthInfo as WebDavManagerAuthInfo,
|
|
|
+ buildHttpHeadersWithWebDav,
|
|
|
+ WebDavAuthItem} from '../common/util/WebdavManager';
|
|
|
const TAG = 'LocalMusic';
|
|
|
|
|
|
/**
|
|
|
@@ -108,20 +110,9 @@ interface PlaylistEventData {
|
|
|
songCount: number;
|
|
|
startIndex: number;
|
|
|
songFilePaths: string[];
|
|
|
- webDavAuthInfo?: WebDavAuthInfo; // 新增WebDAV认证信息
|
|
|
+ webDavAuthInfo?: WebDavAuthItem; // 新增WebDAV认证信息
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * WebDAV认证信息(LocalMusic专用)
|
|
|
- */
|
|
|
-interface WebDavAuthInfo {
|
|
|
- accountId: number;
|
|
|
- host: string;
|
|
|
- port: number;
|
|
|
- account: string;
|
|
|
- password: string;
|
|
|
- enableHttps: boolean;
|
|
|
-}
|
|
|
|
|
|
const DEFAULT_INDEX =
|
|
|
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
|
|
@@ -285,7 +276,7 @@ export struct LocalMusic {
|
|
|
ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET;
|
|
|
|
|
|
// WebDAV认证信息缓存(作为实例变量,比全局上下文更可靠)
|
|
|
- private currentWebDavAuthInfo: WebDavAuthInfo | null = null;
|
|
|
+ private currentWebDavAuthInfo: WebDavAuthItem | null = null;
|
|
|
|
|
|
//瀑布流的列数横竖屏动态切换
|
|
|
onIsLandscapeChange() {
|
|
|
@@ -684,7 +675,7 @@ export struct LocalMusic {
|
|
|
Logger.info('heanup eventPlaylistPlay: 接收到歌单播放数据')
|
|
|
|
|
|
// 提取WebDAV认证信息(如果存在)
|
|
|
- let webDavAuthInfo: WebDavAuthInfo | undefined = undefined;
|
|
|
+ let webDavAuthInfo: WebDavAuthItem | undefined = undefined;
|
|
|
if (data.webDavAuthInfo) {
|
|
|
// 将webDavAuthInfo转换为正确的类型
|
|
|
const authData = data.webDavAuthInfo as Record<string, Object>;
|
|
|
@@ -11798,100 +11789,12 @@ export struct LocalMusic {
|
|
|
]);
|
|
|
|
|
|
// 如果是WebDAV网络音频,添加安全的HTTP头认证
|
|
|
- Logger.info(`heanup 开始检查WebDAV认证需求 - currentSong存在: ${!!this.currentSong}`);
|
|
|
- let isWebDavSong = false;
|
|
|
- let webDavAuthInfo: WebDavAuthInfo | null = null;
|
|
|
- if (this.currentSong) {
|
|
|
- const currentSong = this.currentSong;
|
|
|
- Logger.info(`heanup 当前歌曲信息 - name: ${currentSong.name}, type: ${currentSong.type}, filePath: ${currentSong.filePath}`);
|
|
|
- // 检查是否为WebDAV歌曲(优先通过URL特征判断,因为全局上下文可能失效)
|
|
|
- if (currentSong.type === CommonConstants.TYPE_WEBDAV) {
|
|
|
- isWebDavSong=true;
|
|
|
-
|
|
|
- // 优先从实例变量获取认证信息(更可靠)
|
|
|
- if (this.currentWebDavAuthInfo) {
|
|
|
- webDavAuthInfo = this.currentWebDavAuthInfo;
|
|
|
- Logger.info(`heanup 从实例变量获取到WebDAV认证信息,账户ID: ${webDavAuthInfo.accountId}`);
|
|
|
- } else {
|
|
|
- // 回退到全局上下文
|
|
|
- try {
|
|
|
- const globalContext = GlobalContext.getContext();
|
|
|
- webDavAuthInfo = globalContext.getObject('webDavAuthInfo') as WebDavAuthInfo;
|
|
|
- if (webDavAuthInfo) {
|
|
|
- Logger.info(`heanup 从全局上下文获取到WebDAV认证信息,账户ID: ${webDavAuthInfo.accountId}`);
|
|
|
- // 保存到实例变量中作为备份
|
|
|
- this.currentWebDavAuthInfo = webDavAuthInfo;
|
|
|
- } else {
|
|
|
- Logger.warn(`heanup 全局上下文中没有WebDAV认证信息`);
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- Logger.error(`heanup 获取全局上下文失败:`, error.toString());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 如果识别为WebDAV但没有认证信息,尝试使用默认配置或提示用户
|
|
|
- if (!webDavAuthInfo) {
|
|
|
- Logger.warn(`heanup 识别为WebDAV播放但缺少认证信息,可能需要手动配置WebDAV账户`);
|
|
|
- // TODO: 可以在这里添加默认认证逻辑或用户提示
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (isWebDavSong&&webDavAuthInfo) {
|
|
|
- // URL已在doPlay中编码过,这里无需再编码
|
|
|
- // 但确保当前使用的this.videoUrl是已编码的版本
|
|
|
- Logger.info(`heanup 检测到WebDAV播放,添加安全认证头`);
|
|
|
- Logger.info(`heanup 歌曲URL: ${this.videoUrl}`);
|
|
|
- try {
|
|
|
- if (webDavAuthInfo && webDavAuthInfo.accountId) {
|
|
|
- Logger.info(`heanup 找到WebDAV认证信息,账户ID: ${webDavAuthInfo.accountId}`);
|
|
|
- // 使用WebdavManager获取认证头
|
|
|
- const webdavManager = WebdavManager.getInstance();
|
|
|
- const authHeaders = webdavManager.getWebDavAuthHeaders(webDavAuthInfo.accountId);
|
|
|
-
|
|
|
- if (authHeaders) {
|
|
|
- // 添加Basic认证头
|
|
|
- headers.set("authorization", authHeaders.headers.Authorization);
|
|
|
- } else {
|
|
|
- Logger.error(`heanup 无法获取WebDAV认证头`);
|
|
|
- }
|
|
|
- } else {
|
|
|
- Logger.error(`heanup WebDAV认证信息无效或缺少accountId`);
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- Logger.error(`heanup 获取WebDAV认证信息失败:`, error.toString());
|
|
|
- }
|
|
|
-
|
|
|
- // 添加标准的WebDAV请求头
|
|
|
- headers.set("user_agent", "TTMusic-WebDAV/1.0");
|
|
|
- headers.set("accept", "*/*");
|
|
|
- headers.set("accept-range", "bytes");
|
|
|
-
|
|
|
- Logger.info(`heanup WebDAV安全认证头设置完成`);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 输出所有设置的头部信息用于调试
|
|
|
- console.log(`heanup 设置的HTTP头部信息:`);
|
|
|
- const headerIterator = headers.entries();
|
|
|
- let headerEntry = headerIterator.next();
|
|
|
- while (!headerEntry.done) {
|
|
|
- const key = headerEntry.value[0];
|
|
|
- const value = headerEntry.value[1];
|
|
|
- console.log(`heanup ${key}: ${value}`);
|
|
|
- // if (key.toLowerCase().includes('auth')) {
|
|
|
- // Logger.info(`heanup ${key}: [认证信息已隐藏]`);
|
|
|
- // } else {
|
|
|
- // Logger.info(`heanup ${key}: ${value}`);
|
|
|
- // }
|
|
|
- headerEntry = headerIterator.next();
|
|
|
+ if (this.currentSong&&this.currentSong.type === CommonConstants.TYPE_WEBDAV&&this.currentWebDavAuthInfo) {
|
|
|
+ headers = buildHttpHeadersWithWebDav(this.currentSong,this.videoUrl,this.currentWebDavAuthInfo)
|
|
|
}
|
|
|
-
|
|
|
this.mIjkMediaPlayer.setDataSourceHeader(headers);
|
|
|
-
|
|
|
-
|
|
|
- if (isWebDavSong) {
|
|
|
+ if (this.currentSong&&this.currentSong.type === CommonConstants.TYPE_WEBDAV) {
|
|
|
console.log(`heanup 为WebDAV播放设置IjkPlayer选项`);
|
|
|
-
|
|
|
// 网络超时设置(单位:微秒,文档显示应该是字符串格式)
|
|
|
this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", "30000000"); // 30秒
|
|
|
this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "connect_timeout", "30000000"); // 连接超时30秒
|
|
|
@@ -12220,7 +12123,7 @@ export struct LocalMusic {
|
|
|
if (this.currentSong && this.currentSong.type === CommonConstants.TYPE_WEBDAV && this.currentSong.filePath) {
|
|
|
try {
|
|
|
const globalContext = GlobalContext.getContext();
|
|
|
- const webDavAuthInfo = globalContext.getObject('webDavAuthInfo') as WebDavAuthInfo;
|
|
|
+ const webDavAuthInfo = globalContext.getObject('webDavAuthInfo') as WebDavAuthItem;
|
|
|
if (webDavAuthInfo) {
|
|
|
isWebDavError = true;
|
|
|
}
|
|
|
@@ -13482,7 +13385,8 @@ export struct LocalMusic {
|
|
|
/**
|
|
|
* 处理歌单播放请求
|
|
|
*/
|
|
|
- private handlePlaylistPlayRequest(playlistId: string, playlistName: string, songFilePaths: string[], startIndex: number, webDavAuthInfo?: WebDavAuthInfo) {
|
|
|
+ private handlePlaylistPlayRequest(playlistId: string, playlistName:
|
|
|
+ string, songFilePaths: string[], startIndex: number, webDavAuthInfo?: WebDavAuthItem) {
|
|
|
try {
|
|
|
Logger.info(`heanup 处理歌单播放请求: ${playlistName}, 歌曲数量: ${songFilePaths.length}, 开始索引: ${startIndex}`)
|
|
|
|