- Add `FLAC_FLAC` (16), `FLAC_FLAC_24BIT` (22) format codes (based on librespot-org/librespot#796, librespot-org/librespot#1424) - Regenerate Metadata_pb2.py with protoc 3.20.1 - Add enums: `SuperAudioFormat.FLAC`, `AudioQuality.LOSSLESS` - Refactor to generic DRY `FormatOnlyAudioQuality` base class while maintaining existing `VorbisOnlyAudioQuality` as wrapper - Remove `AAC_24_NORM` (replaced by `FLAC_FLAC` at code 16)
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from librespot.proto import Metadata_pb2 as Metadata
|
|
import enum
|
|
|
|
|
|
class SuperAudioFormat(enum.Enum):
|
|
MP3 = 0x00
|
|
VORBIS = 0x01
|
|
AAC = 0x02
|
|
FLAC = 0x03
|
|
|
|
@staticmethod
|
|
def get(audio_format: Metadata.AudioFile.Format):
|
|
if audio_format in [
|
|
Metadata.AudioFile.Format.OGG_VORBIS_96,
|
|
Metadata.AudioFile.Format.OGG_VORBIS_160,
|
|
Metadata.AudioFile.Format.OGG_VORBIS_320,
|
|
]:
|
|
return SuperAudioFormat.VORBIS
|
|
if audio_format in [
|
|
Metadata.AudioFile.Format.MP3_256,
|
|
Metadata.AudioFile.Format.MP3_320,
|
|
Metadata.AudioFile.Format.MP3_160,
|
|
Metadata.AudioFile.Format.MP3_96,
|
|
Metadata.AudioFile.Format.MP3_160_ENC,
|
|
]:
|
|
return SuperAudioFormat.MP3
|
|
if audio_format in [
|
|
Metadata.AudioFile.Format.AAC_24,
|
|
Metadata.AudioFile.Format.AAC_48,
|
|
]:
|
|
return SuperAudioFormat.AAC
|
|
if audio_format in [
|
|
Metadata.AudioFile.Format.FLAC_FLAC,
|
|
Metadata.AudioFile.Format.FLAC_FLAC_24BIT,
|
|
]:
|
|
return SuperAudioFormat.FLAC
|
|
raise RuntimeError("Unknown audio format: {}".format(audio_format))
|