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 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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue