Merge pull request #43 from pawanpaudel93/main

Fixed the _pb2 suffix need for protobuf compiled files and also fixed issue with proxy configuration in requests Session
This commit is contained in:
こうから 2021-05-26 20:45:48 +09:00 committed by GitHub
commit b96b369c3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 87 additions and 91 deletions

View File

@ -1,4 +1,4 @@
from librespot.proto.Keyexchange import *
from librespot.proto.Keyexchange_pb2 import *
import platform

View File

@ -11,7 +11,7 @@ from zeroconf import Zeroconf
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

View File

@ -52,8 +52,8 @@ class AudioKeyManager(PacketsReceiver):
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

View File

@ -2,7 +2,7 @@ from __future__ import annotations
import typing
if typing.TYPE_CHECKING:
from librespot.audio import AbsChunkedInputStream
from librespot.audio.AbsChunkedInputStream import AbsChunkedInputStream
from librespot.audio.format import SuperAudioFormat

View File

@ -12,8 +12,8 @@ from librespot.common.Utils import Utils
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:
@ -41,7 +41,7 @@ class PlayableContentFeeder:
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,
@ -74,7 +74,7 @@ class PlayableContentFeeder:
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(
@ -98,7 +98,7 @@ class PlayableContentFeeder:
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()
@ -124,15 +124,15 @@ class PlayableContentFeeder:
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:

View File

@ -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:

View File

@ -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

View File

@ -10,8 +10,8 @@ from librespot.audio import NormalizationData
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:
@ -28,7 +28,7 @@ class CdnFeedHelper:
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
@ -55,7 +55,7 @@ class CdnFeedHelper:
@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)
@ -64,7 +64,7 @@ class CdnFeedHelper:
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)
@ -82,7 +82,7 @@ class CdnFeedHelper:
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
@ -94,7 +94,7 @@ class CdnFeedHelper:
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(

View File

@ -17,14 +17,14 @@ from librespot.audio.decrypt import NoopAudioDecrypt
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:
@ -55,7 +55,7 @@ class CdnManager:
halt_listener: HaltListener):
return CdnManager.Streamer(
self._session,
StreamId(episode),
StreamId.StreamId(episode),
SuperAudioFormat.MP3,
CdnManager.CdnUrl(self, None, external_url),
self._session.cache(),
@ -188,7 +188,7 @@ class CdnManager:
GeneralWritableStream.GeneralWritableStream,
):
_session: Session = None
_streamId: StreamId = None
_streamId: StreamId.StreamId = None
_executorService = concurrent.futures.ThreadPoolExecutor()
_audioFormat: SuperAudioFormat = None
_audioDecrypt: AudioDecrypt = None
@ -204,7 +204,7 @@ class CdnManager:
def __init__(
self,
session: Session,
stream_id: StreamId,
stream_id: StreamId.StreamId,
audio_format: SuperAudioFormat,
cdn_url,
cache: CacheManager,

View File

@ -3,7 +3,7 @@ from __future__ import annotations
import enum
import typing
from librespot.proto.Metadata import AudioFile
from librespot.proto.Metadata_pb2 import AudioFile
class AudioQuality(enum.Enum):

View File

@ -3,7 +3,7 @@ from __future__ import annotations
import typing
if typing.TYPE_CHECKING:
from librespot.proto import Metadata
from librespot.proto import Metadata_pb2 as Metadata
class AudioQualityPicker:

View File

@ -1,4 +1,4 @@
from librespot.proto import Metadata
from librespot.proto import Metadata_pb2 as Metadata
import enum

View File

@ -74,7 +74,7 @@ class ChannelManager(Closeable, PacketsReceiver.PacketsReceiver):
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()

View File

@ -35,10 +35,10 @@ from librespot.dealer import ApiClient
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
@ -321,7 +321,7 @@ 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
@ -329,7 +329,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener):
_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
@ -348,16 +348,13 @@ class Session(Closeable, SubListener, DealerClient.MessageListener):
@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),
@ -686,7 +683,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener):
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!")
@ -728,7 +725,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener):
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

View File

@ -9,8 +9,8 @@ from librespot.metadata import ArtistId
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

View File

@ -13,8 +13,8 @@ from librespot.crypto import Packet
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

View File

@ -1,6 +1,6 @@
import typing
from librespot.proto import Mercury
from librespot.proto import Mercury_pb2 as Mercury
class RawMercuryRequest:

View File

@ -4,7 +4,7 @@ import re
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:
@ -166,14 +166,14 @@ class EpisodeId(SpotifyId, PlayableId):
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:
@ -184,13 +184,13 @@ class EpisodeId(SpotifyId, PlayableId):
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):

View File

@ -7,11 +7,11 @@ from librespot.dealer import DealerClient
from librespot.player import Player
from librespot.player import PlayerConfiguration
from librespot.player.state import DeviceStateHandler
from librespot.proto import Connect
from librespot.proto.Player import ContextPlayerOptions
from librespot.proto.Player import PlayerState
from librespot.proto.Player import Restrictions
from librespot.proto.Player import Suppressions
from librespot.proto import Connect_pb2 as Connect
from librespot.proto.Player_pb2 import ContextPlayerOptions
from librespot.proto.Player_pb2 import PlayerState
from librespot.proto.Player_pb2 import Restrictions
from librespot.proto.Player_pb2 import Suppressions
class StateWrapper(DeviceStateHandler.Listener, DealerClient.MessageListener):

View File

@ -6,7 +6,7 @@ import typing
from librespot.audio.decoders.AudioQuality import AudioQuality
from librespot.audio.format.AudioQualityPicker import AudioQualityPicker
from librespot.audio.format.SuperAudioFormat import SuperAudioFormat
from librespot.proto import Metadata
from librespot.proto import Metadata_pb2 as Metadata
class VorbisOnlyAudioQuality(AudioQualityPicker):

View File

@ -1,2 +1 @@
from librespot.player.codecs.VorbisOnlyAudioQuality import \
VorbisOnlyAudioQuality
from librespot.player.codecs.VorbisOnlyAudioQuality import VorbisOnlyAudioQuality

View File

@ -11,8 +11,8 @@ import urllib.parse
from librespot.common import Utils
from librespot.core import Session
from librespot.player import PlayerConfiguration
from librespot.proto import Connect
from librespot.proto import Player
from librespot.proto import Connect_pb2 as Connect
from librespot.proto import Player_pb2 as Player
class DeviceStateHandler:

View File

@ -2,7 +2,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: canvaz.proto
"""Generated protocol buffer code."""
import CanvazMeta as canvaz__meta__pb2
import CanvazMeta_pb2 as canvaz__meta__pb2
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection

View File

@ -11,7 +11,7 @@ from google.protobuf import symbol_database as _symbol_database
_sym_db = _symbol_database.Default()
import librespot.proto.Player as player__pb2
import librespot.proto.Player_pb2 as player__pb2
DESCRIPTOR = _descriptor.FileDescriptor(
name='connect.proto',

View File

@ -2,7 +2,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: context_page.proto
"""Generated protocol buffer code."""
import ContextTrack as context__track__pb2
import ContextTrack_pb2 as context__track__pb2
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection

View File

@ -2,8 +2,8 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: context.proto
"""Generated protocol buffer code."""
import ContextPage as context__page__pb2
import Restrictions as restrictions__pb2
import ContextPage_pb2 as context__page__pb2
import Restrictions_pb2 as restrictions__pb2
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection

View File

@ -2,7 +2,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: playback.proto
"""Generated protocol buffer code."""
import ContextTrack as context__track__pb2
import ContextTrack_pb2 as context__track__pb2
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection

View File

@ -2,7 +2,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: queue.proto
"""Generated protocol buffer code."""
import ContextTrack as context__track__pb2
import ContextTrack_pb2 as context__track__pb2
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection

View File

@ -2,9 +2,9 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: session.proto
"""Generated protocol buffer code."""
import Context as context__pb2
import ContextPlayerOptions as context__player__options__pb2
import PlayOrigin as play__origin__pb2
import Context_pb2 as context__pb2
import ContextPlayerOptions_pb2 as context__player__options__pb2
import PlayOrigin_pb2 as play__origin__pb2
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection

View File

@ -2,10 +2,10 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: transfer_state.proto
"""Generated protocol buffer code."""
import ContextPlayerOptions as context__player__options__pb2
import Playback as playback__pb2
import Queue as queue__pb2
import Session as session__pb2
import ContextPlayerOptions_pb2 as context__player__options__pb2
import Playback_pb2 as playback__pb2
import Queue_pb2 as queue__pb2
import Session_pb2 as session__pb2
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection