Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show audio/video file lengths #741

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion tagstudio/src/qt/widgets/item_thumb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (C) 2025 Travis Abendshien (CyanVoxel).
# Licensed under the GPL-3.0 License.
# Created for TagStudio: https://github.com/CyanVoxel/TagStudio
import subprocess
import time
import typing
from enum import Enum
Expand All @@ -11,7 +12,7 @@

import structlog
from PIL import Image, ImageQt
from PySide6.QtCore import QEvent, QMimeData, QSize, Qt, QUrl
from PySide6.QtCore import QEvent, QMimeData, QSize, Qt, QThreadPool, QUrl
from PySide6.QtGui import QAction, QDrag, QEnterEvent, QPixmap
from PySide6.QtWidgets import (
QBoxLayout,
Expand All @@ -28,7 +29,9 @@
from src.core.library import ItemType, Library
from src.core.media_types import MediaCategories, MediaType
from src.qt.flowlayout import FlowWidget
from src.qt.helpers.custom_runnable import CustomRunnable
from src.qt.helpers.file_opener import FileOpenerHelper
from src.qt.helpers.vendored.ffmpeg import FFPROBE_CMD
from src.qt.platform_strings import PlatformStrings
from src.qt.translations import Translations
from src.qt.widgets.thumb_button import ThumbButton
Expand Down Expand Up @@ -206,6 +209,7 @@ def __init__(
self.renderer.updated.connect(
lambda timestamp, image, size, filename, ext: (
self.update_thumb(timestamp, image=image),
self.update_count_badge(filename),
self.update_size(timestamp, size=size),
self.set_filename_text(filename),
self.set_extension(ext),
Expand Down Expand Up @@ -421,6 +425,32 @@ def update_thumb(self, timestamp: float, image: QPixmap | None = None):
if timestamp > ItemThumb.update_cutoff:
self.thumb_button.setIcon(image if image else QPixmap())

def update_count_badge(self, filename) -> None:
"""Updates the count badge."""

def set_video_audio():
"""Gets length of audio or video and sets count badge."""
args = [
FFPROBE_CMD,
"-v",
"error",
"-show_entries",
"format=duration",
"-of",
"default=noprint_wrappers=1:nokey=1",
filename,
]
probe = subprocess.run(args, capture_output=True)
probe_result: str = probe.stdout.strip().decode("utf-8")
if probe_result != "N/A" and probe_result != "":
duration: float = float(probe_result)
minutes: int = int(duration // 60)
seconds: int = int(duration - (minutes * 60))
self.count_badge.setText(f"{minutes:02}:{seconds:02}")

runnable = CustomRunnable(set_video_audio)
QThreadPool.globalInstance().start(runnable)

def update_size(self, timestamp: float, size: QSize):
"""Updates attributes of a thumbnail element.

Expand Down