Skip to content

Commit 8dfb03a

Browse files
committed
smartplaylist: Fix duplicate entries and count bug
Deduplicate playlist output by URI instead of comparing bytes to PlaylistItem objects. Increment matched/pretend counts only when a new entry is actually added. This prevents duplicate lines when the same track is reached via multiple query paths.
1 parent bc3cca2 commit 8dfb03a

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

beetsplug/smartplaylist.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,10 @@ def update_playlists(self, lib: Library, pretend: bool = False) -> None:
283283
if relative_to:
284284
relative_to = normpath(relative_to)
285285

286-
# Maps playlist filenames to lists of track filenames.
286+
# Maps playlist filenames to lists of track entries and URI sets used
287+
# to deduplicate output lines.
287288
m3us: dict[str, list[PlaylistItem]] = {}
289+
m3u_uris_by_name: dict[str, set[Any]] = {}
288290

289291
for playlist in self._matched_playlists:
290292
name, (query, q_sort), (album_query, a_q_sort) = playlist
@@ -326,6 +328,7 @@ def update_playlists(self, lib: Library, pretend: bool = False) -> None:
326328
m3u_name = sanitize_path(m3u_name, lib.replacements)
327329
if m3u_name not in m3us:
328330
m3us[m3u_name] = []
331+
m3u_uris_by_name[m3u_name] = set()
329332
item_uri = item.path
330333
if tpl:
331334
item_uri = tpl.replace("$id", str(item.id)).encode("utf-8")
@@ -342,7 +345,8 @@ def update_playlists(self, lib: Library, pretend: bool = False) -> None:
342345
)
343346
item_uri = prefix + item_uri
344347

345-
if item_uri not in m3us[m3u_name]:
348+
if item_uri not in m3u_uris_by_name[m3u_name]:
349+
m3u_uris_by_name[m3u_name].add(item_uri)
346350
m3us[m3u_name].append(PlaylistItem(item, item_uri))
347351
if pretend and self.config["pretend_paths"]:
348352
print(displayable_path(item_uri))

0 commit comments

Comments
 (0)