From 8ac5f574b4dc91d2c508afae5a1d07f7fca49dfe Mon Sep 17 00:00:00 2001 From: LukeSpad <64772822+LukeSpad@users.noreply.github.com> Date: Thu, 17 Mar 2022 21:22:31 +0000 Subject: [PATCH] Add files via upload --- .../Server Plugin/Resources/ASBridge.py | 37 +++++++++++++++++-- .../Server Plugin/Resources/BLHIP_CLIENT.py | 12 +++--- .../Server Plugin/Resources/CONSTANTS.py | 6 ++- .../Server Plugin/Resources/MLCLI_CLIENT.py | 12 +++--- .../Server Plugin/Resources/MLCONFIG.py | 2 +- .../Server Plugin/Resources/MLGW_CLIENT.py | 12 +++--- .../Server Plugin/Resources/MLtn_CLIENT.py | 18 ++++----- 7 files changed, 66 insertions(+), 33 deletions(-) diff --git a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/ASBridge.py b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/ASBridge.py index 31a6fd4..bf39bae 100644 --- a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/ASBridge.py +++ b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/ASBridge.py @@ -7,7 +7,9 @@ import threading from Foundation import NSAppleScript from ScriptingBridge import SBApplication -''' Module defining a MusicController class for Apple Music, enables: +''' This module requires PyObjC to be installed in order to use the AppleScriptingBridge for Apple Music + + Module defining a MusicController class for Apple Music, enables: basic transport control of the player, query of player status, playing existing playlists, @@ -28,6 +30,7 @@ class MusicController(object): def __init__(self): self.app = SBApplication.applicationWithBundleIdentifier_("com.apple.Music") + # ######################################################################################## # Player information def get_current_track_info(self): @@ -53,14 +56,15 @@ class MusicController(object): def playpause(self): self.app.playpause() - def play(self): + def play(self, playlist_name): if PLAYSTATE.get(self.app.playerState()) in ['Wind', 'Rewind']: self.app.resume() elif PLAYSTATE.get(self.app.playerState()) == 'Pause': self.app.playpause() elif PLAYSTATE.get(self.app.playerState()) == 'Stop': self. app.setValue_forKey_('true', 'shuffleEnabled') - playlist = self.app.sources().objectWithName_("Library") + # playlist = self.app.sources().objectWithName_("Library") + playlist = self.app.sources().objectWithName_("Library").playlists().objectWithName_(playlist_name) playlist.playOnce_(None) def pause(self): @@ -109,9 +113,36 @@ class MusicController(object): def play_playlist(self, playlist): self.app.stop() + self.app.setValue_forKey_('true', 'shuffleEnabled') playlist = self.app.sources().objectWithName_("Library").playlists().objectWithName_(playlist) playlist.playOnce_(None) + def get_playlist_names(self): + playlists = [] + # Generate and return a list of playlists in Apple Music + for playlist in self.app.sources().objectWithName_("Library").playlists(): + playlists.append(playlist.name()) + + return playlists + + def set_rating(self, rate): + # Set the rating of the track in % + self.app.currentTrack().setValue_forKey_(str(rate), 'rating') + + if int(rate) == 100: + # If rated 100% then set to loved and ensure the track is enabled + self.app.currentTrack().setValue_forKey_('true', 'loved') + self.app.currentTrack().setValue_forKey_('true', 'enabled') + elif int(rate) == 0: + # If rated 0% then set to disliked and disable the track so it will not be played in shuffle + self.app.currentTrack().setValue_forKey_('true', 'disliked') + self.app.currentTrack().setValue_forKey_('false', 'enabled') + else: + # else remove disliked/loved flags and check the track is enabled for playback + self.app.currentTrack().setValue_forKey_('false', 'disliked') + self.app.currentTrack().setValue_forKey_('false', 'loved') + self.app.currentTrack().setValue_forKey_('true', 'enabled') + # ######################################################################################## # Accessory functions - threaded due to execution time @staticmethod diff --git a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/BLHIP_CLIENT.py b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/BLHIP_CLIENT.py index 0ec9dbb..5b84e43 100644 --- a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/BLHIP_CLIENT.py +++ b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/BLHIP_CLIENT.py @@ -160,19 +160,19 @@ class BLHIPClient(asynchat.async_chat): # Create the socket try: self.create_socket(socket.AF_INET, socket.SOCK_STREAM) - except socket.error, e: + except socket.error as e: indigo.server.log("Error creating socket: " + str(e), level=logging.ERROR) self.handle_close() # Now connect try: self.connect((self._host, self._port)) - except socket.gaierror, e: + except socket.gaierror as e: indigo.server.log("\tError with address: " + str(e), level=logging.ERROR) self.handle_close() - except socket.timeout, e: + except socket.timeout as e: indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR) self.handle_close() - except socket.error, e: + except socket.error as e: indigo.server.log("\tError opening connection: " + str(e), level=logging.ERROR) self.handle_close() else: @@ -193,10 +193,10 @@ class BLHIPClient(asynchat.async_chat): def send_cmd(self, telegram): try: self.push(telegram.encode("ascii") + "\r\n") - except socket.timeout, e: + except socket.timeout as e: indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR) self.handle_close() - except socket.error, e: + except socket.error as e: indigo.server.log("Error sending data: " + str(e), level=logging.ERROR) self.handle_close() else: diff --git a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/CONSTANTS.py b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/CONSTANTS.py index d8fb620..0eec4ce 100644 --- a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/CONSTANTS.py +++ b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/CONSTANTS.py @@ -143,7 +143,7 @@ beo4_commanddict = OrderedDict( (0xDA, "Cinema_On"), (0xDB, "Cinema_Off"), # Other controls: - (0x7C, "Status"), #??? 0x5D ??? + (0x7C, "Status"), # ??? 0x5D ??? (0xF7, "Stand"), (0x0A, "Clear"), (0x0B, "Store"), @@ -181,6 +181,7 @@ beo4_commanddict = OrderedDict( # Functions: (0x40, "Guide"), (0x43, "Info"), + (0xE3, "Home Control"), (0x0F, "Function_1"), (0x10, "Function_2"), (0x11, "Function_3"), @@ -345,7 +346,7 @@ beoremoteone_keydict = OrderedDict( (0xDA, "Cinema_On"), (0xDB, "Cinema_Off"), # Other controls: - (0x7C, "Status"), #??? 0x5D ??? + (0x7C, "Status"), # ??? 0x5D ??? (0xF7, "Stand"), (0x0A, "Clear"), (0x0B, "Store"), @@ -381,6 +382,7 @@ beoremoteone_keydict = OrderedDict( (0x79, "Red Repeat"), (0x7E, "Key Release"), # Functions: + (0xE3, "Home Control"), (0x40, "Guide"), (0x43, "Info"), # Cursor functions: diff --git a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLCLI_CLIENT.py b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLCLI_CLIENT.py index 3bbb05b..c2e113d 100644 --- a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLCLI_CLIENT.py +++ b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLCLI_CLIENT.py @@ -104,19 +104,19 @@ class MLCLIClient(asynchat.async_chat): # Create the socket try: self.create_socket(socket.AF_INET, socket.SOCK_STREAM) - except socket.error, e: + except socket.error as e: indigo.server.log("Error creating socket: " + str(e), level=logging.ERROR) self.handle_close() # Now connect try: self.connect((self._host, self._port)) - except socket.gaierror, e: + except socket.gaierror as e: indigo.server.log("\tError with address: " + str(e), level=logging.ERROR) self.handle_close() - except socket.timeout, e: + except socket.timeout as e: indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR) self.handle_close() - except socket.error, e: + except socket.error as e: indigo.server.log("\tError opening connection: " + str(e), level=logging.ERROR) self.handle_close() else: @@ -136,10 +136,10 @@ class MLCLIClient(asynchat.async_chat): def send_cmd(self, telegram): try: self.push(telegram + "\r\n") - except socket.timeout, e: + except socket.timeout as e: indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR) self.handle_close() - except socket.error, e: + except socket.error as e: indigo.server.log("Error sending data: " + str(e), level=logging.ERROR) self.handle_close() else: diff --git a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLCONFIG.py b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLCONFIG.py index c1fc0bc..7c5f609 100644 --- a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLCONFIG.py +++ b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLCONFIG.py @@ -12,7 +12,7 @@ import Resources.CONSTANTS as CONST class MLConfig: def __init__(self, host_address='blgw.local', user='admin', pwd='admin', debug=False): - self.debug =debug + self.debug = debug self._host = host_address self._user = user diff --git a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLGW_CLIENT.py b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLGW_CLIENT.py index ea34dd1..69fdea3 100644 --- a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLGW_CLIENT.py +++ b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLGW_CLIENT.py @@ -189,19 +189,19 @@ class MLGWClient(asynchat.async_chat): # Create the socket try: self.create_socket(socket.AF_INET, socket.SOCK_STREAM) - except socket.error, e: + except socket.error as e: indigo.server.log("Error creating socket: " + str(e), level=logging.ERROR) self.handle_close() # Now connect try: self.connect((self._host, self._port)) - except socket.gaierror, e: + except socket.gaierror as e: indigo.server.log("\tError with address: " + str(e), level=logging.ERROR) self.handle_close() - except socket.timeout, e: + except socket.timeout as e: indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR) self.handle_close() - except socket.error, e: + except socket.error as e: indigo.server.log("\tError opening connection: " + str(e), level=logging.ERROR) self.handle_close() else: @@ -242,10 +242,10 @@ class MLGWClient(asynchat.async_chat): try: self.push(str(bytearray(telegram))) - except socket.timeout, e: + except socket.timeout as e: indigo.server.log("\tSocket connection to timed out: " + str(e), level=logging.ERROR) self.handle_close() - except socket.error, e: + except socket.error as e: indigo.server.log("Error sending data: " + str(e), level=logging.ERROR) self.handle_close() else: diff --git a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLtn_CLIENT.py b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLtn_CLIENT.py index de1361d..1cd108f 100644 --- a/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLtn_CLIENT.py +++ b/BeoGateway.indigoPlugin/Contents/Server Plugin/Resources/MLtn_CLIENT.py @@ -279,19 +279,19 @@ class MLtnClient(asynchat.async_chat): # Create the socket try: self.create_socket(socket.AF_INET, socket.SOCK_STREAM) - except socket.error, e: + except socket.error as e: indigo.server.log("Error creating socket: " + str(e), level=logging.ERROR) self.handle_close() # Now connect try: self.connect((self._host, self._port)) - except socket.gaierror, e: + except socket.gaierror as e: indigo.server.log("\tError with address: " + str(e), level=logging.ERROR) self.handle_close() - except socket.timeout, e: + except socket.timeout as e: indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR) self.handle_close() - except socket.error, e: + except socket.error as e: indigo.server.log("\tError opening connection: " + str(e), level=logging.ERROR) self.handle_close() else: @@ -311,10 +311,10 @@ class MLtnClient(asynchat.async_chat): def _send_cmd(self, telegram): try: self.push(telegram + "\r\n") - except socket.timeout, e: + except socket.timeout as e: indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR) self.handle_close() - except socket.error, e: + except socket.error as e: indigo.server.log("Error sending data: " + str(e), level=logging.ERROR) self.handle_close() else: @@ -326,21 +326,21 @@ class MLtnClient(asynchat.async_chat): def toggle_events(self): try: self.push('e') - except socket.error, e: + except socket.error as e: indigo.server.log("Error sending data: " + str(e), level=logging.ERROR) self.handle_close() def toggle_macros(self): try: self.push('m') - except socket.error, e: + except socket.error as e: indigo.server.log("Error sending data: " + str(e), level=logging.ERROR) self.handle_close() def toggle_commands(self): try: self.push('c') - except socket.error, e: + except socket.error as e: indigo.server.log("Error sending data: " + str(e), level=logging.ERROR) self.handle_close()