|
|
@@ -14,6 +14,49 @@ interface MetadataRequestPayload {
|
|
|
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.
|
|
|
* The event handler is executed in the worker thread.
|
|
|
@@ -291,6 +334,12 @@ async function analyzeCachedMediaMetadata(
|
|
|
songType ?? CommonConstants.TYPE_LOCAL,
|
|
|
extra?.autoParseMusicName ?? false
|
|
|
);
|
|
|
+ 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({
|
|
|
code: 105,
|
|
|
data: {
|
|
|
@@ -306,7 +355,7 @@ async function analyzeCachedMediaMetadata(
|
|
|
pixelMapPath: videoItem.pixelMapPath,
|
|
|
artist: videoItem.artist,
|
|
|
album: videoItem.album,
|
|
|
- name: videoItem.name
|
|
|
+ name: resolvedName
|
|
|
}
|
|
|
});
|
|
|
} catch (error) {
|