From 3b88c9e6d9a4cdeca9fb64683fd720f4a063c931 Mon Sep 17 00:00:00 2001 From: Rafael Moraes <50295204+glomatico@users.noreply.github.com> Date: Wed, 25 Feb 2026 21:52:28 -0300 Subject: [PATCH] Add AudioQuality.mp4 and refactor audio checks --- votify/interface/audio.py | 3 +-- votify/interface/enums.py | 10 +++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/votify/interface/audio.py b/votify/interface/audio.py index 66eb2de..f4e3cbf 100644 --- a/votify/interface/audio.py +++ b/votify/interface/audio.py @@ -1,7 +1,6 @@ import logging from .base import SpotifyBaseInterface -from .constants import AAC_AUDIO_QUALITIES from .enums import AudioQuality from .exceptions import VotifyMediaAudioQualityNotAvailableException from .types import DecryptionKeyAv, StreamInfo, StreamInfoAv @@ -25,7 +24,7 @@ class SpotifyAudioInterface(SpotifyBaseInterface): skip_pssh: bool, ) -> StreamInfoAv | None: if ( - self.audio_quality.value not in AAC_AUDIO_QUALITIES + not self.audio_quality.mp4 or self.audio_quality.premium and not self.api.premium_session ): diff --git a/votify/interface/enums.py b/votify/interface/enums.py index 2e7d7e7..ef46472 100644 --- a/votify/interface/enums.py +++ b/votify/interface/enums.py @@ -3,11 +3,11 @@ from __future__ import annotations from enum import Enum from .constants import ( + AAC_AUDIO_QUALITIES, FORMAT_ID_MAP, MEDIA_RATING_STR_MAP, MEDIA_TYPE_STR_MAP, PREMIUM_AUDIO_QUALITIES, - AAC_AUDIO_QUALITIES, VORBIS_AUDIO_QUALITIES, ) @@ -54,18 +54,22 @@ class AudioQuality(Enum): def premium(self) -> bool: return self.value in PREMIUM_AUDIO_QUALITIES + @property + def mp4(self) -> bool: + return self.value in AAC_AUDIO_QUALITIES + @property def format_id(self) -> str | None: return FORMAT_ID_MAP.get(self.value) @property def previous_quality(self) -> "AudioQuality" | None: - if self.value in VORBIS_AUDIO_QUALITIES: + if not self.mp4: if self.value == "vorbis-high": return AudioQuality.VORBIS_MEDIUM elif self.value == "vorbis-medium": return AudioQuality.VORBIS_LOW - elif self.value in AAC_AUDIO_QUALITIES: + else: if self.value == "aac-high": return AudioQuality.AAC_MEDIUM return None