Change package layout
This commit is contained in:
parent
33f40520da
commit
1d390c72a3
|
@ -67,15 +67,14 @@ aceess_token = session.tokens().get("playlist-read")
|
|||
```python
|
||||
from librespot.core import Session
|
||||
from librespot.metadata import TrackId
|
||||
from librespot.player.codecs import VorbisOnlyAudioQuality
|
||||
from librespot.audio.decoders import AudioQuality
|
||||
from librespot.audio.decoders import AudioQuality, VorbisOnlyAudioQuality
|
||||
|
||||
session = Session.Builder() \
|
||||
.user_pass("Username", "Password") \
|
||||
.create()
|
||||
|
||||
track_id = TrackId.from_uri("spotify:track:xxxxxxxxxxxxxxxxxxxxxx")
|
||||
stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.AudioQuality.VERY_HIGH), False, None)
|
||||
stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False, None)
|
||||
# stream.input_stream.stream().read() to get one byte of the music stream.
|
||||
```
|
||||
|
||||
|
|
|
@ -65,15 +65,14 @@ aceess_token = session.tokens().get("playlist-read")
|
|||
```python
|
||||
from librespot.core import Session
|
||||
from librespot.metadata import TrackId
|
||||
from librespot.player.codecs import VorbisOnlyAudioQuality
|
||||
from librespot.audio.decoders import AudioQuality
|
||||
from librespot.audio.decoders import AudioQuality, VorbisOnlyAudioQuality
|
||||
|
||||
session = Session.Builder() \
|
||||
.user_pass("Username", "Password") \
|
||||
.create()
|
||||
|
||||
track_id = TrackId.from_uri("spotify:track:xxxxxxxxxxxxxxxxxxxxxx")
|
||||
stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.AudioQuality.VERY_HIGH), False,
|
||||
stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False,
|
||||
None)
|
||||
# stream.input_stream.stream().read() to get one byte of the music stream.
|
||||
# ex: 1 (If there is no more voice data, -1 is received as the result.)
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
from __future__ import annotations
|
||||
from librespot.audio import SuperAudioFormat
|
||||
from librespot.proto import Metadata_pb2 as Metadata
|
||||
from librespot.proto.Metadata_pb2 import AudioFile
|
||||
from librespot.structure import AudioQualityPicker
|
||||
import enum
|
||||
import logging
|
||||
import typing
|
||||
|
||||
|
||||
|
@ -35,3 +39,36 @@ class AudioQuality(enum.Enum):
|
|||
file.format) == self:
|
||||
file_list.append(file)
|
||||
return file_list
|
||||
|
||||
|
||||
class VorbisOnlyAudioQuality(AudioQualityPicker):
|
||||
logger = logging.getLogger("Librespot:Player:VorbisOnlyAudioQuality")
|
||||
preferred: AudioQuality
|
||||
|
||||
def __init__(self, preferred: AudioQuality):
|
||||
self.preferred = preferred
|
||||
|
||||
@staticmethod
|
||||
def get_vorbis_file(files: typing.List[Metadata.AudioFile]):
|
||||
for file in files:
|
||||
if hasattr(file, "format") and SuperAudioFormat.get(
|
||||
file.format) == SuperAudioFormat.VORBIS:
|
||||
return file
|
||||
return None
|
||||
|
||||
def get_file(self, files: typing.List[Metadata.AudioFile]):
|
||||
matches: typing.List[Metadata.AudioFile] = self.preferred.get_matches(
|
||||
files)
|
||||
vorbis: Metadata.AudioFile = VorbisOnlyAudioQuality.get_vorbis_file(
|
||||
matches)
|
||||
if vorbis is None:
|
||||
vorbis: Metadata.AudioFile = VorbisOnlyAudioQuality.get_vorbis_file(
|
||||
files)
|
||||
if vorbis is not None:
|
||||
self.logger.warning(
|
||||
"Using {} because preferred {} couldn't be found.".format(
|
||||
vorbis.format, self.preferred))
|
||||
else:
|
||||
self.logger.fatal(
|
||||
"Couldn't find any Vorbis file, available: {}")
|
||||
return vorbis
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
from __future__ import annotations
|
||||
from librespot.audio import SuperAudioFormat
|
||||
from librespot.audio.decoders import AudioQuality
|
||||
from librespot.proto import Metadata_pb2 as Metadata
|
||||
from librespot.structure import AudioQualityPicker
|
||||
import logging
|
||||
import typing
|
||||
|
||||
|
||||
class VorbisOnlyAudioQuality(AudioQualityPicker):
|
||||
logger = logging.getLogger("Librespot:Player:VorbisOnlyAudioQuality")
|
||||
preferred: AudioQuality
|
||||
|
||||
def __init__(self, preferred: AudioQuality):
|
||||
self.preferred = preferred
|
||||
|
||||
@staticmethod
|
||||
def get_vorbis_file(files: typing.List[Metadata.AudioFile]):
|
||||
for file in files:
|
||||
if hasattr(file, "format") and SuperAudioFormat.get(
|
||||
file.format) == SuperAudioFormat.VORBIS:
|
||||
return file
|
||||
return None
|
||||
|
||||
def get_file(self, files: typing.List[Metadata.AudioFile]):
|
||||
matches: typing.List[Metadata.AudioFile] = self.preferred.get_matches(
|
||||
files)
|
||||
vorbis: Metadata.AudioFile = VorbisOnlyAudioQuality.get_vorbis_file(
|
||||
matches)
|
||||
if vorbis is None:
|
||||
vorbis: Metadata.AudioFile = VorbisOnlyAudioQuality.get_vorbis_file(
|
||||
files)
|
||||
if vorbis is not None:
|
||||
self.logger.warning(
|
||||
"Using {} because preferred {} couldn't be found.".format(
|
||||
vorbis.format, self.preferred))
|
||||
else:
|
||||
self.logger.fatal(
|
||||
"Couldn't find any Vorbis file, available: {}")
|
||||
return vorbis
|
Loading…
Reference in New Issue