Change package layout
This commit is contained in:
@@ -67,15 +67,14 @@ aceess_token = session.tokens().get("playlist-read")
|
|||||||
```python
|
```python
|
||||||
from librespot.core import Session
|
from librespot.core import Session
|
||||||
from librespot.metadata import TrackId
|
from librespot.metadata import TrackId
|
||||||
from librespot.player.codecs import VorbisOnlyAudioQuality
|
from librespot.audio.decoders import AudioQuality, VorbisOnlyAudioQuality
|
||||||
from librespot.audio.decoders import AudioQuality
|
|
||||||
|
|
||||||
session = Session.Builder() \
|
session = Session.Builder() \
|
||||||
.user_pass("Username", "Password") \
|
.user_pass("Username", "Password") \
|
||||||
.create()
|
.create()
|
||||||
|
|
||||||
track_id = TrackId.from_uri("spotify:track:xxxxxxxxxxxxxxxxxxxxxx")
|
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.
|
# 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
|
```python
|
||||||
from librespot.core import Session
|
from librespot.core import Session
|
||||||
from librespot.metadata import TrackId
|
from librespot.metadata import TrackId
|
||||||
from librespot.player.codecs import VorbisOnlyAudioQuality
|
from librespot.audio.decoders import AudioQuality, VorbisOnlyAudioQuality
|
||||||
from librespot.audio.decoders import AudioQuality
|
|
||||||
|
|
||||||
session = Session.Builder() \
|
session = Session.Builder() \
|
||||||
.user_pass("Username", "Password") \
|
.user_pass("Username", "Password") \
|
||||||
.create()
|
.create()
|
||||||
|
|
||||||
track_id = TrackId.from_uri("spotify:track:xxxxxxxxxxxxxxxxxxxxxx")
|
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)
|
None)
|
||||||
# stream.input_stream.stream().read() to get one byte of the music stream.
|
# 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.)
|
# ex: 1 (If there is no more voice data, -1 is received as the result.)
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
from __future__ import annotations
|
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.proto.Metadata_pb2 import AudioFile
|
||||||
|
from librespot.structure import AudioQualityPicker
|
||||||
import enum
|
import enum
|
||||||
|
import logging
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
|
||||||
@@ -35,3 +39,36 @@ class AudioQuality(enum.Enum):
|
|||||||
file.format) == self:
|
file.format) == self:
|
||||||
file_list.append(file)
|
file_list.append(file)
|
||||||
return file_list
|
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
|
|
||||||
Reference in New Issue
Block a user