Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion nix/package/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ python3Packages.buildPythonApplication {
pillow-heif
py7zr
pydantic
pydub
pygments
pyside6
rarfile
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ dependencies = [
"Pillow>=10.2,<12",
"py7zr~=1.1.3",
"pydantic~=2.10",
"pydub~=0.25",
"Pygments~=2.20",
"PySide6==6.11.2",
"rarfile==4.2",
Expand Down Expand Up @@ -101,7 +100,6 @@ filterwarnings = [
ignore = [
".venv/**",
"src/tagstudio/core/library/json/",
"src/tagstudio/previews/vendored/pydub/",
]
include = ["src/tagstudio", "tests"]
# Reference for the settings here: https://github.com/microsoft/pyright/blob/main/docs/configuration.md
Expand All @@ -122,7 +120,6 @@ reportUnannotatedClassAttribute = false
reportUninitializedInstanceVariable = false

[tool.ruff]
exclude = ["home_ui.py", "resources.py", "resources_rc.py"]
line-length = 100

[tool.ruff.lint]
Expand Down
27 changes: 15 additions & 12 deletions src/tagstudio/core/library/alchemy/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import random
from dataclasses import dataclass, field, replace
from pathlib import Path
from typing import Any

import structlog

Expand Down Expand Up @@ -82,17 +83,15 @@ class SortingModeEnum(enum.Enum):

@dataclass
class BrowsingState:
"""Represent a state of the Library grid view."""
"""Represent a browsing history state for a library."""

page_index: int = 0
page_positions: dict[int, int] = field(default_factory=dict)
sorting_mode: SortingModeEnum = SortingModeEnum.DATE_ADDED
ascending: bool = False
first_visible_entry_id: int | None = field(default=None, compare=False)
page_index: int = 0
query: str | None = None
random_seed: float = 0

show_hidden_entries: bool = False

query: str | None = None
sorting_mode: SortingModeEnum = SortingModeEnum.DATE_ADDED

# Abstract Syntax Tree Of the current Search Query
@property
Expand Down Expand Up @@ -141,19 +140,23 @@ def from_tag_name(cls, tag_name: str) -> BrowsingState:
return cls(query=f'tag:"{tag_name}"')

def with_page_index(self, index: int) -> BrowsingState:
return replace(self, page_index=index)
return replace(self, page_index=index, first_visible_entry_id=None)

def with_sorting_mode(self, mode: SortingModeEnum) -> BrowsingState:
seed = self.random_seed
if mode == SortingModeEnum.RANDOM:
seed = random.random()
return replace(self, sorting_mode=mode, random_seed=seed)
return self._with_new_results(sorting_mode=mode, random_seed=seed)

def with_sorting_direction(self, ascending: bool) -> BrowsingState:
return replace(self, ascending=ascending)
return self._with_new_results(ascending=ascending)

def with_search_query(self, search_query: str) -> BrowsingState:
return replace(self, query=search_query)
return self._with_new_results(query=search_query)

def with_show_hidden_entries(self, show_hidden_entries: bool) -> BrowsingState:
return replace(self, show_hidden_entries=show_hidden_entries)
return self._with_new_results(show_hidden_entries=show_hidden_entries)

def _with_new_results(self, **changes: Any) -> BrowsingState:
"""Copy this state with changes to its results, starting back on the first page."""
return replace(self, page_index=0, first_visible_entry_id=None, **changes)
2 changes: 1 addition & 1 deletion src/tagstudio/core/library/alchemy/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def get_entries(self, entry_ids: Iterable[int]) -> list[Entry]:
with Session(self.engine) as session:
statement = select(Entry).where(Entry.id.in_(entry_ids))
entries = dict((e.id, e) for e in session.scalars(statement))
return [entries[id] for id in entry_ids]
return [entries[id] for id in entry_ids if id in entries]

def get_entries_full(self, entry_ids: list[int] | set[int]) -> Iterator[Entry]:
"""Load entry and join with all joins and all tags."""
Expand Down
20 changes: 14 additions & 6 deletions src/tagstudio/previews/renderers/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: MIT


import subprocess
from io import BytesIO
from pathlib import Path
from typing import override
Expand All @@ -17,15 +18,17 @@

from tagstudio.core.enums import Theme
from tagstudio.core.media_types import MediaTypes
from tagstudio.core.utils.ffmpeg_status import FfmpegStatus
from tagstudio.core.utils.silent_subprocess import silent_run
from tagstudio.core.utils.types import unwrap
from tagstudio.previews.base_preview import RENDER, BasePreview
from tagstudio.previews.effects import apply_overlay_color
from tagstudio.previews.vendored.pydub.audio_segment import (
_AudioSegment as AudioSegment, # pyright: ignore[reportPrivateUsage]
)
from tagstudio.qt.views.styles.palette import UiColor

logger = structlog.get_logger(__name__)

_WAVEFORM_SAMPLE_RATE = 8000 # Good enough for the waveforms while still being small bits of data


class AudioPreview(BasePreview):
media_type_name = "audio"
Expand Down Expand Up @@ -120,8 +123,13 @@ def audio_waveform_thumb(filepath: Path, theme: Theme, size: tuple[int, int]) ->

try:
bar_count: int = 32
audio = AudioSegment.from_file(filepath, filepath.suffix.lower()[1:]) # pyright: ignore[reportUnknownVariableType]
data = np.frombuffer(buffer=audio._data, dtype=f"<i{audio.sample_width}")
command = [unwrap(FfmpegStatus.which()), "-nostdin", "-v", "error", "-i", str(filepath)]
command += ["-vn", "-ac", "1", "-ar", str(_WAVEFORM_SAMPLE_RATE), "-f", "s16le", "-"]
ffmpeg = silent_run(
command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, close_fds=False
)
ffmpeg.check_returncode()
data = np.frombuffer(buffer=ffmpeg.stdout, dtype="<i2")
# Bars are twice as wide as the gaps between them, with double gaps at the edges
bar_margin: float = size_scaled / (bar_count * 3 + 3)
line_width: float = bar_margin * 2
Expand Down Expand Up @@ -162,7 +170,7 @@ def audio_waveform_thumb(filepath: Path, theme: Theme, size: tuple[int, int]) ->

current_x = current_x + line_width + bar_margin

im.resize(size, Resampling.BILINEAR)
im = im.resize(size, Resampling.BILINEAR)
im = apply_overlay_color(im, UiColor.GREEN, theme)

except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion src/tagstudio/previews/vendored/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def probe(filename: Path | str, timeout: int | None = None, **kwargs: ...):
args += [filename] # pyright: ignore

# PATCHED
p = silent_popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = silent_popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=False)
communicate_kwargs = {}
if timeout is not None:
communicate_kwargs["timeout"] = timeout
Expand Down
Loading
Loading