Merge remote-tracking branch 'origin/rewrite' into rewrite

# Conflicts:
#	librespot/zeroconf.py
This commit is contained in:
kokarare1212
2021-09-14 07:07:49 +09:00
2 changed files with 10 additions and 12 deletions

View File

@@ -1097,10 +1097,13 @@ class Session(Closeable, MessageListener, SubListener):
def blob(self, username: str, blob: bytes) -> Session.Builder: def blob(self, username: str, blob: bytes) -> Session.Builder:
if self.device_id is None: if self.device_id is None:
raise TypeError("You must specify the device ID first.") raise TypeError("You must specify the device ID first.")
self.login_credentials = self.decrypt_blob(self.device_id, username, blob) self.login_credentials = self.decrypt_blob(self.device_id,
username, blob)
return self return self
def decrypt_blob(self, device_id: str, username: str, encrypted_blob: bytes) -> Authentication.LoginCredentials: def decrypt_blob(
self, device_id: str, username: str,
encrypted_blob: bytes) -> Authentication.LoginCredentials:
encrypted_blob = base64.b64decode(encrypted_blob) encrypted_blob = base64.b64decode(encrypted_blob)
sha1 = SHA1.new() sha1 = SHA1.new()
sha1.update(device_id.encode()) sha1.update(device_id.encode())
@@ -1119,7 +1122,9 @@ class Session(Closeable, MessageListener, SubListener):
type_int = self.read_blob_int(blob) type_int = self.read_blob_int(blob)
type_ = Authentication.AuthenticationType.Name(type_int) type_ = Authentication.AuthenticationType.Name(type_int)
if type_ is None: if type_ is None:
raise IOError(TypeError("Unknown AuthenticationType: {}".format(type_int))) raise IOError(
TypeError(
"Unknown AuthenticationType: {}".format(type_int)))
le = self.read_blob_int(blob) le = self.read_blob_int(blob)
auth_data = blob.read(le) auth_data = blob.read(le)
return Authentication.LoginCredentials( return Authentication.LoginCredentials(

View File

@@ -71,8 +71,8 @@ class ZeroconfServer(Closeable):
"CPath": "/", "CPath": "/",
"VERSION": "1.0", "VERSION": "1.0",
"STACK": "SP", "STACK": "SP",
}, self.get_useful_hostname() + ".", },
addresses=[socket.inet_aton(socket.gethostbyname(self.get_useful_hostname()))] inner.device_name,
) )
self.__zeroconf.register_service(self.__service_info) self.__zeroconf.register_service(self.__service_info)
threading.Thread(target=self.__zeroconf.start, name="zeroconf-multicast-dns-server").start() threading.Thread(target=self.__zeroconf.start, name="zeroconf-multicast-dns-server").start()
@@ -81,13 +81,6 @@ class ZeroconfServer(Closeable):
self.__zeroconf.close() self.__zeroconf.close()
self.__runner.close() self.__runner.close()
def get_useful_hostname(self) -> str:
host = socket.gethostname()
if host == "localhost":
pass
else:
return host
def handle_add_user(self, __socket: socket.socket, params: dict[str, str], http_version: str) -> None: def handle_add_user(self, __socket: socket.socket, params: dict[str, str], http_version: str) -> None:
username = params.get("userName") username = params.get("userName")
if not username: if not username: