Show media title (Artist – Title) instead of filename when available

- Extract title and artist tags via mutagen easy=True in get_media_info
- Display "Artist – Title" in both grid and list views, fall back to filename
- Show original filename in tooltip on hover

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-09 03:42:32 +03:00
parent 4c13322936
commit 13df69adb4
2 changed files with 26 additions and 11 deletions

View File

@@ -122,24 +122,37 @@ class BrowserService:
@staticmethod
def get_media_info(file_path: Path) -> dict:
"""Get duration and bitrate of a media file (header-only read).
"""Get duration, bitrate, and title of a media file (header-only read).
Args:
file_path: Path to the media file.
Returns:
Dict with 'duration' (float or None) and 'bitrate' (int or None).
Dict with 'duration' (float or None), 'bitrate' (int or None),
and 'title' (str or None).
"""
result = {"duration": None, "bitrate": None}
result = {"duration": None, "bitrate": None, "title": None}
if not HAS_MUTAGEN:
return result
try:
audio = MutagenFile(str(file_path))
audio = MutagenFile(str(file_path), easy=True)
if audio is not None and hasattr(audio, "info"):
if hasattr(audio.info, "length"):
result["duration"] = round(audio.info.length, 2)
if hasattr(audio.info, "bitrate") and audio.info.bitrate:
result["bitrate"] = audio.info.bitrate
if audio is not None and hasattr(audio, "tags") and audio.tags:
tags = audio.tags
title = None
artist = None
if "title" in tags:
title = tags["title"][0] if isinstance(tags["title"], list) else tags["title"]
if "artist" in tags:
artist = tags["artist"][0] if isinstance(tags["artist"], list) else tags["artist"]
if artist and title:
result["title"] = f"{artist} \u2013 {title}"
elif title:
result["title"] = title
except Exception:
pass
return result
@@ -262,9 +275,11 @@ class BrowserService:
info = BrowserService.get_media_info(item_path)
item["duration"] = info["duration"]
item["bitrate"] = info["bitrate"]
item["title"] = info["title"]
else:
item["duration"] = None
item["bitrate"] = None
item["title"] = None
return {
"folder_id": folder_id,