Эх сурвалжийг харах

点击网盘的歌曲 修复文件名变成缓存的md5的文件名的问题

onecold 9 сар өмнө
parent
commit
54c271fc43

+ 11 - 8
entry/src/main/ets/common/util/Utility.ets

@@ -667,14 +667,15 @@ export class Utility {
   }
   }
 
 
   //获取音乐资源的属性值,
   //获取音乐资源的属性值,
-  static async uriGetMusicAssetsFromFile(context:Context,uri:string,type:number,autoParseMusicName?:boolean): Promise<VideoItem> {
+  static async uriGetMusicAssetsFromFile(context:Context,uri:string,type:number
+    ,autoParseMusicName?:boolean,originFileName?:string): Promise<VideoItem> {
     await ReqPermissionUtil.persistPermission(uri);
     await ReqPermissionUtil.persistPermission(uri);
     if(StrUtil.isNotEmpty(uri)&&uri.toLowerCase().endsWith('.cue')){
     if(StrUtil.isNotEmpty(uri)&&uri.toLowerCase().endsWith('.cue')){
       const cueItem = new VideoItem(FileUtil.getFileName(uri),uri,uri,type,0,'')
       const cueItem = new VideoItem(FileUtil.getFileName(uri),uri,uri,type,0,'')
       cueItem.fileName = FileUtil.getFileName(uri)
       cueItem.fileName = FileUtil.getFileName(uri)
       return  cueItem
       return  cueItem
     }
     }
-    return Utility.readMetaInfoFFmpeg(context,uri,type,autoParseMusicName)
+    return Utility.readMetaInfoFFmpeg(context,uri,type,autoParseMusicName,originFileName)
 
 
     //华为官方不支持的格式 不支持内嵌歌词Dsf,aif,aiff,wav  不支持内嵌封面dsf,aif,aiff
     //华为官方不支持的格式 不支持内嵌歌词Dsf,aif,aiff,wav  不支持内嵌封面dsf,aif,aiff
     if(StrUtil.isNotEmpty(uri)){
     if(StrUtil.isNotEmpty(uri)){
@@ -852,7 +853,8 @@ export class Utility {
   }
   }
 
 
 
 
-  static async  readMetaInfoFFmpeg(context:Context,inputPath: string,type:number,autoParseMusicName?:boolean): Promise<VideoItem> {
+  static async  readMetaInfoFFmpeg(context:Context,inputPath: string,type:number,
+    autoParseMusicName?:boolean,originFileName?:string): Promise<VideoItem> {
     return new Promise((resolve, reject) => {
     return new Promise((resolve, reject) => {
       inputPath = FileUtil.getFilePath(inputPath)
       inputPath = FileUtil.getFilePath(inputPath)
       let commands = ["ffprobe", "-v", "quiet", "-print_format", "json", "-show_format", "-show_streams", inputPath];
       let commands = ["ffprobe", "-v", "quiet", "-print_format", "json", "-show_format", "-show_streams", inputPath];
@@ -920,16 +922,17 @@ export class Utility {
               if(autoParseMusicName){
               if(autoParseMusicName){
                 const musicData = parseMusicFileName(file.name);
                 const musicData = parseMusicFileName(file.name);
                 if (musicData.isValid)  {
                 if (musicData.isValid)  {
-                  // console.log(`onecold 艺术家:${musicData.artist}`);   // 输出:周杰伦
-                  // console.log(`onecold 歌曲名:${musicData.title}`);   // 输出:七里香
+                  console.log(`onecold 艺术家:${musicData.artist}`);   // 输出:周杰伦
+                  console.log(`onecold 歌曲名:${musicData.title}`);   // 输出:七里香
                   title = musicData.title
                   title = musicData.title
                   if(artist==''||artist==undefined)
                   if(artist==''||artist==undefined)
                     artist = musicData.artist
                     artist = musicData.artist
                 } else {
                 } else {
-                  title = file.name
+
+                  title = originFileName||file.name
                 }
                 }
               }else{
               }else{
-                title = file.name
+                title =  originFileName||file.name
               }
               }
 
 
             }
             }
@@ -1806,7 +1809,7 @@ export function parseMusicFileName(fileName: string): MusicInfo {
       result.title.length > 0;
       result.title.length > 0;
   } else {
   } else {
     result.title = baseName;
     result.title = baseName;
-    result.isValid = result.title.length > 0;
+    result.isValid = false;
   }
   }
 
 
   return result;
   return result;

+ 1 - 1
entry/src/main/ets/view/LocalMusic.ets

@@ -283,6 +283,7 @@ function scheduleMetadataExtractionFromCache(
     data2: cachePath,
     data2: cachePath,
     data3: song.type,
     data3: song.type,
     data4: {
     data4: {
+      name:song.name,
       originFilePath: song.filePath,
       originFilePath: song.filePath,
       originId: song.id,
       originId: song.id,
       autoParseMusicName: options.autoParseMusicName ?? false
       autoParseMusicName: options.autoParseMusicName ?? false
@@ -12830,7 +12831,6 @@ export struct LocalMusic {
     const headers = new Map<string, string>();
     const headers = new Map<string, string>();
     headers.set("User-Agent", "TTMusic-WebDAV/1.0");
     headers.set("User-Agent", "TTMusic-WebDAV/1.0");
     headers.set("Accept", "*/*");
     headers.set("Accept", "*/*");
-    // headers.set("Range", "bytes=0-");
     if (this.currentSong&&StrUtil.isEmpty(this.currentSong.pixelMapPath)
     if (this.currentSong&&StrUtil.isEmpty(this.currentSong.pixelMapPath)
     &&PreferencesUtil.getStringSync('COVER_API',  '') != '') {
     &&PreferencesUtil.getStringSync('COVER_API',  '') != '') {
       //如果封面为空,则搜索封面
       //如果封面为空,则搜索封面

+ 5 - 50
entry/src/main/ets/workers/Worker.ets

@@ -9,53 +9,12 @@ import { VideoItem } from '../viewmodel/VideoItem';
 const workerPort: ThreadWorkerGlobalScope = worker.workerPort;
 const workerPort: ThreadWorkerGlobalScope = worker.workerPort;
 
 
 interface MetadataRequestPayload {
 interface MetadataRequestPayload {
+  name?: string;
   originFilePath?: string;
   originFilePath?: string;
   originId?: string;
   originId?: string;
   autoParseMusicName?: boolean;
   autoParseMusicName?: boolean;
 }
 }
 
 
-function extractFileNameFromPath(path?: string): string {
-  if (!path) {
-    return '';
-  }
-  let working = path;
-  try {
-    working = decodeURIComponent(path);
-  } catch (err) {
-    // ignore decode failure and fall back to original path
-  }
-  working = working.replace(/\\/g, '/');
-  const queryIndex = working.indexOf('?');
-  if (queryIndex >= 0) {
-    working = working.substring(0, queryIndex);
-  }
-  const hashIndex = working.indexOf('#');
-  if (hashIndex >= 0) {
-    working = working.substring(0, hashIndex);
-  }
-  const lastSlash = working.lastIndexOf('/');
-  return lastSlash >= 0 ? working.substring(lastSlash + 1) : working;
-}
-
-function isLikelyUrl(value?: string): boolean {
-  if (!value) {
-    return false;
-  }
-  const trimmed = value.trim();
-  return /^https?:\/\//i.test(trimmed) || /^[a-z]+:\/\/.+/i.test(trimmed);
-}
-
-function isHostLikeName(value?: string): boolean {
-  if (!value) {
-    return false;
-  }
-  const trimmed = value.trim();
-  if (!trimmed || trimmed.includes(' ')) {
-    return false;
-  }
-  const domainPattern = /^[a-z0-9.-]+\.[a-z]{2,}$/i;
-  return domainPattern.test(trimmed);
-}
 
 
 /**
 /**
  * Defines the event handler to be called when the worker thread receives a message sent by the host thread.
  * Defines the event handler to be called when the worker thread receives a message sent by the host thread.
@@ -328,18 +287,14 @@ async function analyzeCachedMediaMetadata(
     return;
     return;
   }
   }
   try {
   try {
+    const originFileName = extra?.name;//传原始文件名,而不是缓存文件名
     const videoItem = await Utility.uriGetMusicAssetsFromFile(
     const videoItem = await Utility.uriGetMusicAssetsFromFile(
       context,
       context,
       cachePath,
       cachePath,
       songType ?? CommonConstants.TYPE_LOCAL,
       songType ?? CommonConstants.TYPE_LOCAL,
-      extra?.autoParseMusicName ?? false
+      extra?.autoParseMusicName ?? false,
+      originFileName
     );
     );
-    const cacheFileName = FileUtil.getFileName(cachePath);
-    const originFileName = extractFileNameFromPath(extra?.originFilePath);
-    let resolvedName = videoItem.name?.trim() ?? '';
-    if (!resolvedName || resolvedName === cacheFileName || isLikelyUrl(resolvedName) || isHostLikeName(resolvedName)) {
-      resolvedName = originFileName || videoItem.fileName || cacheFileName;
-    }
     workerPort.postMessage({
     workerPort.postMessage({
       code: 105,
       code: 105,
       data: {
       data: {
@@ -355,7 +310,7 @@ async function analyzeCachedMediaMetadata(
         pixelMapPath: videoItem.pixelMapPath,
         pixelMapPath: videoItem.pixelMapPath,
         artist: videoItem.artist,
         artist: videoItem.artist,
         album: videoItem.album,
         album: videoItem.album,
-        name: resolvedName
+        name: videoItem.name
       }
       }
     });
     });
   } catch (error) {
   } catch (error) {