librespot-python/librespot/audio/format.py

33 lines
1.1 KiB
Python
Raw Normal View History

2021-09-12 05:58:24 +02:00
from librespot.proto import Metadata_pb2 as Metadata
import enum
class SuperAudioFormat(enum.Enum):
MP3 = 0x00
VORBIS = 0x01
AAC = 0x02
@staticmethod
def get(audio_format: Metadata.AudioFile.Format):
2021-12-04 04:47:54 +01:00
if audio_format in [
Metadata.AudioFile.Format.OGG_VORBIS_96,
Metadata.AudioFile.Format.OGG_VORBIS_160,
Metadata.AudioFile.Format.OGG_VORBIS_320,
2021-12-04 04:47:54 +01:00
]:
2021-09-12 05:58:24 +02:00
return SuperAudioFormat.VORBIS
2021-12-04 04:47:54 +01:00
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,
2021-12-04 04:47:54 +01:00
]:
2021-09-12 05:58:24 +02:00
return SuperAudioFormat.MP3
2021-12-04 04:47:54 +01:00
if audio_format in [
Metadata.AudioFile.Format.AAC_24,
Metadata.AudioFile.Format.AAC_48,
Metadata.AudioFile.Format.AAC_24_NORM,
2021-12-04 04:47:54 +01:00
]:
2021-09-12 05:58:24 +02:00
return SuperAudioFormat.AAC
raise RuntimeError("Unknown audio format: {}".format(audio_format))