Explorar el Código

feat(JellyfinApi): 添加歌曲去重逻辑

- 引入 seenIds Set 来跟踪已处理的歌曲ID
- 引入 seenComposite Set 来跟踪基于标题、艺术家、专辑和时长的复合键
- 在处理歌曲前检查ID和复合键的重复情况
- 为避免重复添加歌曲,只在未见过ID和复合键时才添加
- 提升歌曲列表的准确性和性能
chendeben hace 7 meses
padre
commit
0bc071b636
Se han modificado 1 ficheros con 12 adiciones y 0 borrados
  1. 12 0
      entry/src/main/ets/common/network/JellyfinApi.ets

+ 12 - 0
entry/src/main/ets/common/network/JellyfinApi.ets

@@ -218,10 +218,22 @@ export class JellyfinApi {
     const response = await this.get<JellyfinItemsResponse>(account, `/Users/${auth.userId}/Items`, params);
     const items = response.Items ?? [];
     const songs: JellyfinSong[] = [];
+    const seenIds = new Set<string>();
+    const seenComposite = new Set<string>();
     for (let i = 0; i < items.length; i++) {
+      const itemId = items[i].Id as string | undefined;
+      if (!itemId || seenIds.has(itemId)) {
+        continue;
+      }
       const song = this.toSong(items[i]);
       if (song) {
+        const compositeKey = `${song.title ?? ''}__${song.artist ?? ''}__${song.album ?? ''}__${song.durationSeconds ?? ''}`;
+        if (seenComposite.has(compositeKey)) {
+          continue;
+        }
         songs.push(song);
+        seenIds.add(song.id);
+        seenComposite.add(compositeKey);
       }
     }
     return songs;