mirror of
https://github.com/LukeSpad/BeoGateway.git
synced 2024-12-23 21:51:51 +00:00
Add files via upload
This commit is contained in:
parent
6af36fffdb
commit
8ac5f574b4
7 changed files with 66 additions and 33 deletions
|
@ -7,7 +7,9 @@ import threading
|
||||||
from Foundation import NSAppleScript
|
from Foundation import NSAppleScript
|
||||||
from ScriptingBridge import SBApplication
|
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,
|
basic transport control of the player,
|
||||||
query of player status,
|
query of player status,
|
||||||
playing existing playlists,
|
playing existing playlists,
|
||||||
|
@ -28,6 +30,7 @@ class MusicController(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.app = SBApplication.applicationWithBundleIdentifier_("com.apple.Music")
|
self.app = SBApplication.applicationWithBundleIdentifier_("com.apple.Music")
|
||||||
|
|
||||||
|
|
||||||
# ########################################################################################
|
# ########################################################################################
|
||||||
# Player information
|
# Player information
|
||||||
def get_current_track_info(self):
|
def get_current_track_info(self):
|
||||||
|
@ -53,14 +56,15 @@ class MusicController(object):
|
||||||
def playpause(self):
|
def playpause(self):
|
||||||
self.app.playpause()
|
self.app.playpause()
|
||||||
|
|
||||||
def play(self):
|
def play(self, playlist_name):
|
||||||
if PLAYSTATE.get(self.app.playerState()) in ['Wind', 'Rewind']:
|
if PLAYSTATE.get(self.app.playerState()) in ['Wind', 'Rewind']:
|
||||||
self.app.resume()
|
self.app.resume()
|
||||||
elif PLAYSTATE.get(self.app.playerState()) == 'Pause':
|
elif PLAYSTATE.get(self.app.playerState()) == 'Pause':
|
||||||
self.app.playpause()
|
self.app.playpause()
|
||||||
elif PLAYSTATE.get(self.app.playerState()) == 'Stop':
|
elif PLAYSTATE.get(self.app.playerState()) == 'Stop':
|
||||||
self. app.setValue_forKey_('true', 'shuffleEnabled')
|
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)
|
playlist.playOnce_(None)
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
|
@ -109,9 +113,36 @@ class MusicController(object):
|
||||||
|
|
||||||
def play_playlist(self, playlist):
|
def play_playlist(self, playlist):
|
||||||
self.app.stop()
|
self.app.stop()
|
||||||
|
self.app.setValue_forKey_('true', 'shuffleEnabled')
|
||||||
playlist = self.app.sources().objectWithName_("Library").playlists().objectWithName_(playlist)
|
playlist = self.app.sources().objectWithName_("Library").playlists().objectWithName_(playlist)
|
||||||
playlist.playOnce_(None)
|
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
|
# Accessory functions - threaded due to execution time
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -160,19 +160,19 @@ class BLHIPClient(asynchat.async_chat):
|
||||||
# Create the socket
|
# Create the socket
|
||||||
try:
|
try:
|
||||||
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
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)
|
indigo.server.log("Error creating socket: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
# Now connect
|
# Now connect
|
||||||
try:
|
try:
|
||||||
self.connect((self._host, self._port))
|
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)
|
indigo.server.log("\tError with address: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
except socket.timeout, e:
|
except socket.timeout as e:
|
||||||
indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR)
|
indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
indigo.server.log("\tError opening connection: " + str(e), level=logging.ERROR)
|
indigo.server.log("\tError opening connection: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
else:
|
else:
|
||||||
|
@ -193,10 +193,10 @@ class BLHIPClient(asynchat.async_chat):
|
||||||
def send_cmd(self, telegram):
|
def send_cmd(self, telegram):
|
||||||
try:
|
try:
|
||||||
self.push(telegram.encode("ascii") + "\r\n")
|
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)
|
indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -143,7 +143,7 @@ beo4_commanddict = OrderedDict(
|
||||||
(0xDA, "Cinema_On"),
|
(0xDA, "Cinema_On"),
|
||||||
(0xDB, "Cinema_Off"),
|
(0xDB, "Cinema_Off"),
|
||||||
# Other controls:
|
# Other controls:
|
||||||
(0x7C, "Status"), #??? 0x5D ???
|
(0x7C, "Status"), # ??? 0x5D ???
|
||||||
(0xF7, "Stand"),
|
(0xF7, "Stand"),
|
||||||
(0x0A, "Clear"),
|
(0x0A, "Clear"),
|
||||||
(0x0B, "Store"),
|
(0x0B, "Store"),
|
||||||
|
@ -181,6 +181,7 @@ beo4_commanddict = OrderedDict(
|
||||||
# Functions:
|
# Functions:
|
||||||
(0x40, "Guide"),
|
(0x40, "Guide"),
|
||||||
(0x43, "Info"),
|
(0x43, "Info"),
|
||||||
|
(0xE3, "Home Control"),
|
||||||
(0x0F, "Function_1"),
|
(0x0F, "Function_1"),
|
||||||
(0x10, "Function_2"),
|
(0x10, "Function_2"),
|
||||||
(0x11, "Function_3"),
|
(0x11, "Function_3"),
|
||||||
|
@ -345,7 +346,7 @@ beoremoteone_keydict = OrderedDict(
|
||||||
(0xDA, "Cinema_On"),
|
(0xDA, "Cinema_On"),
|
||||||
(0xDB, "Cinema_Off"),
|
(0xDB, "Cinema_Off"),
|
||||||
# Other controls:
|
# Other controls:
|
||||||
(0x7C, "Status"), #??? 0x5D ???
|
(0x7C, "Status"), # ??? 0x5D ???
|
||||||
(0xF7, "Stand"),
|
(0xF7, "Stand"),
|
||||||
(0x0A, "Clear"),
|
(0x0A, "Clear"),
|
||||||
(0x0B, "Store"),
|
(0x0B, "Store"),
|
||||||
|
@ -381,6 +382,7 @@ beoremoteone_keydict = OrderedDict(
|
||||||
(0x79, "Red Repeat"),
|
(0x79, "Red Repeat"),
|
||||||
(0x7E, "Key Release"),
|
(0x7E, "Key Release"),
|
||||||
# Functions:
|
# Functions:
|
||||||
|
(0xE3, "Home Control"),
|
||||||
(0x40, "Guide"),
|
(0x40, "Guide"),
|
||||||
(0x43, "Info"),
|
(0x43, "Info"),
|
||||||
# Cursor functions:
|
# Cursor functions:
|
||||||
|
|
|
@ -104,19 +104,19 @@ class MLCLIClient(asynchat.async_chat):
|
||||||
# Create the socket
|
# Create the socket
|
||||||
try:
|
try:
|
||||||
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
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)
|
indigo.server.log("Error creating socket: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
# Now connect
|
# Now connect
|
||||||
try:
|
try:
|
||||||
self.connect((self._host, self._port))
|
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)
|
indigo.server.log("\tError with address: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
except socket.timeout, e:
|
except socket.timeout as e:
|
||||||
indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR)
|
indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
indigo.server.log("\tError opening connection: " + str(e), level=logging.ERROR)
|
indigo.server.log("\tError opening connection: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
else:
|
else:
|
||||||
|
@ -136,10 +136,10 @@ class MLCLIClient(asynchat.async_chat):
|
||||||
def send_cmd(self, telegram):
|
def send_cmd(self, telegram):
|
||||||
try:
|
try:
|
||||||
self.push(telegram + "\r\n")
|
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)
|
indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -12,7 +12,7 @@ import Resources.CONSTANTS as CONST
|
||||||
class MLConfig:
|
class MLConfig:
|
||||||
|
|
||||||
def __init__(self, host_address='blgw.local', user='admin', pwd='admin', debug=False):
|
def __init__(self, host_address='blgw.local', user='admin', pwd='admin', debug=False):
|
||||||
self.debug =debug
|
self.debug = debug
|
||||||
|
|
||||||
self._host = host_address
|
self._host = host_address
|
||||||
self._user = user
|
self._user = user
|
||||||
|
|
|
@ -189,19 +189,19 @@ class MLGWClient(asynchat.async_chat):
|
||||||
# Create the socket
|
# Create the socket
|
||||||
try:
|
try:
|
||||||
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
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)
|
indigo.server.log("Error creating socket: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
# Now connect
|
# Now connect
|
||||||
try:
|
try:
|
||||||
self.connect((self._host, self._port))
|
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)
|
indigo.server.log("\tError with address: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
except socket.timeout, e:
|
except socket.timeout as e:
|
||||||
indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR)
|
indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
indigo.server.log("\tError opening connection: " + str(e), level=logging.ERROR)
|
indigo.server.log("\tError opening connection: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
else:
|
else:
|
||||||
|
@ -242,10 +242,10 @@ class MLGWClient(asynchat.async_chat):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.push(str(bytearray(telegram)))
|
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)
|
indigo.server.log("\tSocket connection to timed out: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -279,19 +279,19 @@ class MLtnClient(asynchat.async_chat):
|
||||||
# Create the socket
|
# Create the socket
|
||||||
try:
|
try:
|
||||||
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
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)
|
indigo.server.log("Error creating socket: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
# Now connect
|
# Now connect
|
||||||
try:
|
try:
|
||||||
self.connect((self._host, self._port))
|
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)
|
indigo.server.log("\tError with address: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
except socket.timeout, e:
|
except socket.timeout as e:
|
||||||
indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR)
|
indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
indigo.server.log("\tError opening connection: " + str(e), level=logging.ERROR)
|
indigo.server.log("\tError opening connection: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
else:
|
else:
|
||||||
|
@ -311,10 +311,10 @@ class MLtnClient(asynchat.async_chat):
|
||||||
def _send_cmd(self, telegram):
|
def _send_cmd(self, telegram):
|
||||||
try:
|
try:
|
||||||
self.push(telegram + "\r\n")
|
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)
|
indigo.server.log("\tSocket connection timed out: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
else:
|
else:
|
||||||
|
@ -326,21 +326,21 @@ class MLtnClient(asynchat.async_chat):
|
||||||
def toggle_events(self):
|
def toggle_events(self):
|
||||||
try:
|
try:
|
||||||
self.push('e')
|
self.push('e')
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
|
|
||||||
def toggle_macros(self):
|
def toggle_macros(self):
|
||||||
try:
|
try:
|
||||||
self.push('m')
|
self.push('m')
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
|
|
||||||
def toggle_commands(self):
|
def toggle_commands(self):
|
||||||
try:
|
try:
|
||||||
self.push('c')
|
self.push('c')
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
indigo.server.log("Error sending data: " + str(e), level=logging.ERROR)
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue