Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the _pb2 suffix need for protobuf compiled files and also fixed issue with proxy configuration in requests Session #43

Merged
merged 5 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion librespot/Version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from librespot.proto.Keyexchange import *
from librespot.proto.Keyexchange_pb2 import *
import platform


Expand Down
2 changes: 1 addition & 1 deletion librespot/ZeroconfServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from librespot.common import Utils
from librespot.core import Session
from librespot.crypto import DiffieHellman
from librespot.proto import Connect
from librespot.proto import Connect_pb2 as Connect
from librespot.standard import Closeable
from librespot.standard import Runnable

Expand Down
4 changes: 2 additions & 2 deletions librespot/audio/AudioKeyManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def get_audio_key(self,
return self.get_audio_key(gid, file_id, False)
raise RuntimeError(
"Failed fetching audio key! gid: {}, fileId: {}".format(
Utils.Utils.bytes_to_hex(gid),
Utils.Utils.bytes_to_hex(file_id)))
Utils.bytes_to_hex(gid),
Utils.bytes_to_hex(file_id)))

return key

Expand Down
2 changes: 1 addition & 1 deletion librespot/audio/GeneralAudioStream.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import typing

if typing.TYPE_CHECKING:
from librespot.audio import AbsChunkedInputStream
from librespot.audio.AbsChunkedInputStream import AbsChunkedInputStream
from librespot.audio.format import SuperAudioFormat


Expand Down
18 changes: 9 additions & 9 deletions librespot/audio/PlayableContentFeeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from librespot.core import Session
from librespot.metadata import PlayableId
from librespot.metadata import TrackId
from librespot.proto import Metadata
from librespot.proto import StorageResolve
from librespot.proto import Metadata_pb2 as Metadata
from librespot.proto import StorageResolve_pb2 as StorageResolve


class PlayableContentFeeder:
Expand Down Expand Up @@ -41,7 +41,7 @@ def load(
playable_id: PlayableId,
audio_quality_picker: AudioQualityPicker,
preload: bool,
halt_listener: HaltListener,
halt_listener: HaltListener.HaltListener,
):
if type(playable_id) is TrackId:
return self.load_track(playable_id, audio_quality_picker, preload,
Expand Down Expand Up @@ -74,7 +74,7 @@ def load_track(
track_id_or_track: typing.Union[TrackId, Metadata.Track],
audio_quality_picker: AudioQualityPicker,
preload: bool,
halt_listener: HaltListener,
halt_listener: HaltListener.HaltListener,
):
if type(track_id_or_track) is TrackId:
original = self.session.api().get_metadata_4_track(
Expand All @@ -98,7 +98,7 @@ def load_stream(
track: Metadata.Track,
episode: Metadata.Episode,
preload: bool,
halt_lister: HaltListener,
halt_lister: HaltListener.HaltListener,
):
if track is None and episode is None:
raise RuntimeError()
Expand All @@ -124,15 +124,15 @@ def load_stream(
class LoadedStream:
episode: Metadata.Episode
track: Metadata.Track
input_stream: GeneralAudioStream
normalization_data: NormalizationData
input_stream: GeneralAudioStream.GeneralAudioStream
normalization_data: NormalizationData.NormalizationData
metrics: PlayableContentFeeder.Metrics

def __init__(
self,
track_or_episode: typing.Union[Metadata.Track, Metadata.Episode],
input_stream: GeneralAudioStream,
normalization_data: NormalizationData,
input_stream: GeneralAudioStream.GeneralAudioStream,
normalization_data: NormalizationData.NormalizationData,
metrics: PlayableContentFeeder.Metrics,
):
if type(track_or_episode) is Metadata.Track:
Expand Down
2 changes: 1 addition & 1 deletion librespot/audio/StreamId.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from librespot.common.Utils import Utils
from librespot.proto import Metadata
from librespot.proto import Metadata_pb2 as Metadata


class StreamId:
Expand Down
16 changes: 8 additions & 8 deletions librespot/audio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from librespot.audio.AbsChunkedInputStream import AbsChunkedInputStream
from librespot.audio.AudioKeyManager import AudioKeyManager
from librespot.audio.GeneralAudioStream import GeneralAudioStream
from librespot.audio.GeneralWritableStream import GeneralWritableStream
from librespot.audio.HaltListener import HaltListener
from librespot.audio.NormalizationData import NormalizationData
from librespot.audio.PlayableContentFeeder import PlayableContentFeeder
from librespot.audio.StreamId import StreamId
from librespot.audio import AbsChunkedInputStream
from librespot.audio import AudioKeyManager
from librespot.audio import GeneralAudioStream
from librespot.audio import GeneralWritableStream
from librespot.audio import HaltListener
from librespot.audio import NormalizationData
from librespot.audio import PlayableContentFeeder
from librespot.audio import StreamId
14 changes: 7 additions & 7 deletions librespot/audio/cdn/CdnFeedHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from librespot.audio import PlayableContentFeeder
from librespot.common import Utils
from librespot.core import Session
from librespot.proto import Metadata
from librespot.proto import StorageResolve
from librespot.proto import Metadata_pb2 as Metadata
from librespot.proto import StorageResolve_pb2 as StorageResolve


class CdnFeedHelper:
Expand All @@ -28,7 +28,7 @@ def load_track(
file: Metadata.AudioFile,
resp_or_url: typing.Union[StorageResolve.StorageResolveResponse, str],
preload: bool,
halt_listener: HaltListener,
halt_listener: HaltListener.HaltListener,
) -> PlayableContentFeeder.PlayableContentFeeder.LoadedStream:
if type(resp_or_url) is str:
url = resp_or_url
Expand All @@ -55,7 +55,7 @@ def load_track(
@staticmethod
def load_episode_external(
session: Session, episode: Metadata.Episode,
halt_listener: HaltListener
halt_listener: HaltListener.HaltListener
) -> PlayableContentFeeder.PlayableContentFeeder.LoadedStream:
resp = session.client().head(episode.external_url)

Expand All @@ -64,7 +64,7 @@ def load_episode_external(

url = resp.url
CdnFeedHelper._LOGGER.debug("Fetched external url for {}: {}".format(
Utils.Utils.bytes_to_hex(episode.gid), url))
Utils.bytes_to_hex(episode.gid), url))

streamer = session.cdn().stream_external_episode(
episode, url, halt_listener)
Expand All @@ -82,7 +82,7 @@ def load_episode(
episode: Metadata.Episode,
file: Metadata.AudioFile,
resp_or_url: typing.Union[StorageResolve.StorageResolveResponse, str],
halt_listener: HaltListener,
halt_listener: HaltListener.HaltListener,
) -> PlayableContentFeeder.PlayableContentFeeder.LoadedStream:
if type(resp_or_url) is str:
url = resp_or_url
Expand All @@ -94,7 +94,7 @@ def load_episode(

streamer = session.cdn().stream_file(file, key, url, halt_listener)
input_stream = streamer.stream()
normalization_data = NormalizationData.read(input_stream)
normalization_data = NormalizationData.NormalizationData.read(input_stream)
if input_stream.skip(0xA7) != 0xA7:
raise IOError("Couldn't skip 0xa7 bytes!")
return PlayableContentFeeder.PlayableContentFeeder.LoadedStream(
Expand Down
10 changes: 5 additions & 5 deletions librespot/audio/cdn/CdnManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
from librespot.audio.format import SuperAudioFormat
from librespot.audio.storage import ChannelManager
from librespot.common import Utils
from librespot.proto import StorageResolve
from librespot.proto import StorageResolve_pb2 as StorageResolve

if typing.TYPE_CHECKING:
from librespot.audio.decrypt.AudioDecrypt import AudioDecrypt
from librespot.audio.HaltListener import HaltListener
from librespot.cache.CacheManager import CacheManager
from librespot.core.Session import Session
from librespot.proto import Metadata
from librespot.proto import Metadata_pb2 as Metadata


class CdnManager:
Expand Down Expand Up @@ -55,7 +55,7 @@ def stream_external_episode(self, episode: Metadata.Episode,
halt_listener: HaltListener):
return CdnManager.Streamer(
self._session,
StreamId(episode),
StreamId.StreamId(episode),
SuperAudioFormat.MP3,
CdnManager.CdnUrl(self, None, external_url),
self._session.cache(),
Expand Down Expand Up @@ -188,7 +188,7 @@ class Streamer(
GeneralWritableStream.GeneralWritableStream,
):
_session: Session = None
_streamId: StreamId = None
_streamId: StreamId.StreamId = None
_executorService = concurrent.futures.ThreadPoolExecutor()
_audioFormat: SuperAudioFormat = None
_audioDecrypt: AudioDecrypt = None
Expand All @@ -204,7 +204,7 @@ class Streamer(
def __init__(
self,
session: Session,
stream_id: StreamId,
stream_id: StreamId.StreamId,
audio_format: SuperAudioFormat,
cdn_url,
cache: CacheManager,
Expand Down
2 changes: 1 addition & 1 deletion librespot/audio/decoders/AudioQuality.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import enum
import typing

from librespot.proto.Metadata import AudioFile
from librespot.proto.Metadata_pb2 import AudioFile


class AudioQuality(enum.Enum):
Expand Down
2 changes: 1 addition & 1 deletion librespot/audio/format/AudioQualityPicker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import typing

if typing.TYPE_CHECKING:
from librespot.proto import Metadata
from librespot.proto import Metadata_pb2 as Metadata


class AudioQualityPicker:
Expand Down
2 changes: 1 addition & 1 deletion librespot/audio/format/SuperAudioFormat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from librespot.proto import Metadata
from librespot.proto import Metadata_pb2 as Metadata
import enum


Expand Down
2 changes: 1 addition & 1 deletion librespot/audio/storage/ChannelManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def dispatch(self, packet: Packet) -> None:
else:
self._LOGGER.warning(
"Couldn't handle packet, cmd: {}, payload: {}".format(
packet.cmd, Utils.Utils.bytes_to_hex(packet.payload)))
packet.cmd, Utils.bytes_to_hex(packet.payload)))

def close(self) -> None:
self._executorService.shutdown()
Expand Down
33 changes: 15 additions & 18 deletions librespot/core/Session.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
from librespot.dealer import DealerClient
from librespot.mercury import MercuryClient
from librespot.mercury import SubListener
from librespot.proto import Authentication
from librespot.proto import Connect
from librespot.proto import Keyexchange
from librespot.proto.ExplicitContentPubsub import UserAttributesUpdate
from librespot.proto import Authentication_pb2 as Authentication
from librespot.proto import Connect_pb2 as Connect
from librespot.proto import Keyexchange_pb2 as Keyexchange
from librespot.proto.ExplicitContentPubsub_pb2 import UserAttributesUpdate
from librespot.standard import BytesInputStream
from librespot.standard import Closeable
from librespot.standard import Proxy
Expand Down Expand Up @@ -321,15 +321,15 @@ class Session(Closeable, SubListener, DealerClient.MessageListener):
_receiver: Session.Receiver = None
_apWelcome: Authentication.APWelcome = None
_mercuryClient: MercuryClient = None
_audioKeyManager: AudioKeyManager = None
_audioKeyManager: AudioKeyManager.AudioKeyManager = None
_channelManager: ChannelManager = None
_tokenProvider: TokenProvider = None
_cdnManager: CdnManager = None
_cacheManager = None
_dealer: DealerClient = None
_api: ApiClient = None
_search: SearchManager = None
_contentFeeder: PlayableContentFeeder = None
_contentFeeder: PlayableContentFeeder.PlayableContentFeeder = None
_eventService: EventService = None
_countryCode: str = None
_closed: bool = False
Expand All @@ -348,16 +348,13 @@ def __init__(self, inner: Session.Inner, addr: str):
@staticmethod
def _create_client(conf: Session.Configuration) -> requests.Session:
client = requests.Session()
if conf.proxyAuth and conf.proxyType is not Proxy.Type.DIRECT:
if conf.proxyAuth:
proxy_setting = [
conf.proxyUsername,
conf.proxyPassword,
conf.proxyAddress,
conf.proxyPort,
]
else:
proxy_setting = [conf.proxyAddress, conf.proxyPort]
if conf.proxyAddress and conf.proxyPort and conf.proxyType is not Proxy.Type.DIRECT:
proxy_setting = [
conf.proxyUsername,
conf.proxyPassword,
conf.proxyAddress,
conf.proxyPort,
]
client.proxies = {
"http": "{}:{}@{}:{}".format(*proxy_setting),
"https": "{}:{}@{}:{}".format(*proxy_setting),
Expand Down Expand Up @@ -686,7 +683,7 @@ def mercury(self) -> MercuryClient:
raise RuntimeError("Session isn't authenticated!")
return self._mercuryClient

def audio_key(self) -> AudioKeyManager:
def audio_key(self) -> AudioKeyManager.AudioKeyManager:
self._wait_auth_lock()
if self._audioKeyManager is None:
raise RuntimeError("Session isn't authenticated!")
Expand Down Expand Up @@ -728,7 +725,7 @@ def api(self) -> ApiClient:
raise RuntimeError("Session isn't authenticated!")
return self._api

def content_feeder(self) -> PlayableContentFeeder:
def content_feeder(self) -> PlayableContentFeeder.PlayableContentFeeder:
if self._contentFeeder is None:
raise RuntimeError("Session isn't authenticated!")
return self._contentFeeder
Expand Down
4 changes: 2 additions & 2 deletions librespot/dealer/ApiClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from librespot.metadata import EpisodeId
from librespot.metadata import ShowId
from librespot.metadata import TrackId
from librespot.proto import Connect
from librespot.proto import Metadata
from librespot.proto import Connect_pb2 as Connect
from librespot.proto import Metadata_pb2 as Metadata
from librespot.standard import Closeable


Expand Down
4 changes: 2 additions & 2 deletions librespot/mercury/MercuryClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from librespot.mercury import JsonMercuryRequest
from librespot.mercury import RawMercuryRequest
from librespot.mercury import SubListener
from librespot.proto import Mercury
from librespot.proto import Pubsub
from librespot.proto import Mercury_pb2 as Mercury
from librespot.proto import Pubsub_pb2 as Pubsub
from librespot.standard import BytesInputStream
from librespot.standard import BytesOutputStream
from librespot.standard import Closeable
Expand Down
2 changes: 1 addition & 1 deletion librespot/mercury/RawMercuryRequest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import typing

from librespot.proto import Mercury
from librespot.proto import Mercury_pb2 as Mercury


class RawMercuryRequest:
Expand Down
10 changes: 5 additions & 5 deletions librespot/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from librespot.common import Base62
from librespot.common import Utils
from librespot.proto.ContextTrack import ContextTrack
from librespot.proto.ContextTrack_pb2 import ContextTrack


class SpotifyId:
Expand Down Expand Up @@ -166,14 +166,14 @@ def from_uri(uri: str) -> EpisodeId:
if matcher is not None:
episode_id = matcher.group(1)
return EpisodeId(
Utils.Utils.bytes_to_hex(
Utils.bytes_to_hex(
PlayableId.BASE62.decode(episode_id, 16)))
TypeError("Not a Spotify episode ID: {}".format(uri))

@staticmethod
def from_base62(base62: str) -> EpisodeId:
return EpisodeId(
Utils.Utils.bytes_to_hex(PlayableId.BASE62.decode(base62, 16)))
Utils.bytes_to_hex(PlayableId.BASE62.decode(base62, 16)))

@staticmethod
def from_hex(hex_str: str) -> EpisodeId:
Expand All @@ -184,13 +184,13 @@ def to_mercury_uri(self) -> str:

def to_spotify_uri(self) -> str:
return "Spotify:episode:{}".format(
PlayableId.BASE62.encode(Utils.Utils.hex_to_bytes(self._hexId)))
PlayableId.BASE62.encode(Utils.hex_to_bytes(self._hexId)))

def hex_id(self) -> str:
return self._hexId

def get_gid(self) -> bytes:
return Utils.Utils.hex_to_bytes(self._hexId)
return Utils.hex_to_bytes(self._hexId)


class ShowId(SpotifyId):
Expand Down
Loading