def spotify_playlists_currated( request ): result = { "message": "failed" } try: redis_connection = redis_connect() mode = redis_connection.get( "STATE.MODE" ) if mode is None: raise Exception( "No STATE.MODE Key" ) mode = json.loads( mode ) if mode["type"] == "IDLE": result["message"] = "success" result["mode"] = mode json_result( result ) status_response = requests.get( mode["control_endpoints"]["status"] , headers=json_headers , params=play_params ) status_response.raise_for_status() mode["status_object"] = status_response.json() if mode["status_object"]["status"].lower() == "playing": mode["state"] = "playing" result["message"] = "success" result["mode"] = mode redis_connection.set( "STATE.MODE" , json.dumps( mode ) ) else: raise Exception( "Could Not Get Spotify To Start Playing" ) except Exception as e: print( e ) result["error"] = str( e ) return json_result( result )
def get_ip(request): result = {"message": "failed", "ip": None} def exec_block(): redis_connection = redis_connect() config = redis_connection.get("CONFIG.VIZIO_TV_CONTROLLER_SERVER") config = json.loads(config) tv_config = config["tv"] tv = viziocontroller.VizioController(tv_config) if tv.ip: result["message"] = "success" result["ip"] = tv.ip config["tv"]["ip"] = tv.ip redis_connection.set("CONFIG.VIZIO_TV_CONTROLLER_SERVER", json.dumps(config)) try: exec_block() except Exception as e: print(e) rescan_for_tv() try: exec_block() except Exception as e: result["error"] = str(e) return json_result(result)
def play(request): result = {"message": "failed"} try: # 1.) Get State ensure_usb_drive_is_mounted() vlc_config = get_vlc_config_from_redis() vlc = VLCController(vlc_config) # 2.) Calculate Next Episode file_path = request.args.get("file_path") next_episode = get_next_episode(file_path) pprint(next_episode) # 3.) Play Episode vlc.add(next_episode["file_path"]) time.sleep(1) if int(next_episode["current_time"]) > 5: vlc.seek(int(next_episode["current_time"]) - 5) vlc.volume_set(100) time.sleep(3) vlc.fullscreen_on() # 4.) Get Status result["status"] = vlc.get_common_info() # 5.) Update Duration Meta Data update_duration_metadata(result["status"]["status"]["duration"], result["status"]["status"]["file_path"]) result["message"] = "success" except Exception as e: print(e) result["error"] = str(e) return json_result(result)
def volume_mute_on(request): result = {"message": "failed", "volume": None} def exec_block(): tv_config = get_tv_config_from_redis() tv = viziocontroller.VizioController(tv_config) tv.api.set_audio_setting("mute", "On") muted = tv.api.get_setting("audio", "mute") result["volume"] = tv.api.get_volume() muted = muted["ITEMS"][0]["VALUE"] if muted == "On": muted = True elif muted == "Off": muted = False else: muted = "unknown" result["muted"] = muted result["message"] = "success" try: exec_block() except Exception as e: print(e) rescan_for_tv() try: exec_block() except Exception as e: result["error"] = str(e) return json_result(result)
def resume(request): result = {"message": "failed"} try: playback_pause() result["message"] = "success" except Exception as e: print(e) result["error"] = str(e) return json_result(result)
def check_time(request): result = {"message": "failed"} try: manual_time_check() result["message"] = "success" except Exception as e: PrintException() result["error"] = str(e) return json_result(result)
async def play(request): result = {"message": "failed"} try: playback_play() result["message"] = "success" except Exception as e: PrintException() result["error"] = str(e) return json_result(result)
def status( request ): result = { "message": "failed" } try: result["status"] = "" result["message"] = "success" except Exception as e: print( e ) result["error"] = str( e ) return json_result( result )
def next(request): result = {"message": "failed"} try: print("1.) /next") playback_next() result["message"] = "success" except Exception as e: PrintException() result["error"] = str(e) return json_result(result)
def previous(request): result = {"message": "failed"} try: playback_previous() time.sleep(1) result["message"] = "success" except Exception as e: print(e) result["error"] = str(e) return json_result(result)
def stop(request): result = {"message": "failed"} try: playback_stop() time.sleep(1) result["message"] = "success" except Exception as e: PrintException() result["error"] = str(e) return json_result(result)
def status(request): result = {"message": "failed"} try: vlc_config = get_vlc_config_from_redis() vlc = VLCController(vlc_config) result["status"] = vlc.get_common_info() result["message"] = "success" except Exception as e: print(e) result["error"] = str(e) return json_result(result)
def status(request): result = {"message": "failed"} try: usb_config = get_usb_config_from_redis() usb_storage = USBStorage(usb_config) time.sleep(3) result["message"] = "success" except Exception as e: print(e) result["error"] = str(e) return json_result(result)
def status(request): result = {"message": "failed"} try: redis = redis_connect() result["status"] = redis_circular_list.current( redis, "STATE.WEBSITES.DISNEY_PLUS.LIBRARY.VIDEOS") result["status"] = json.loads(result["status"]) result["message"] = "success" except Exception as e: PrintException() result["error"] = str(e) return json_result(result)
def add(request): result = {"message": "failed"} try: vlc_config = get_vlc_config_from_redis() vlc = VLCController(vlc_config) file_path = request.args.get("file_path") vlc.add(file_path) time.sleep(1) vlc.fullscreen_on() result["status"] = vlc.get_common_info() result["message"] = "success" except Exception as e: print(e) result["error"] = str(e) return json_result(result)
def seek(request): result = {"message": "failed"} try: vlc_config = get_vlc_config_from_redis() vlc = VLCController(vlc_config) seconds = request.args.get("seconds") if seconds == False or seconds == None: seconds = 1 vlc.seek(seconds) result["status"] = vlc.get_common_info() result["message"] = "success" except Exception as e: print(e) result["error"] = str(e) return json_result(result)
def volume_down(request): result = {"message": "failed"} try: vlc_config = get_vlc_config_from_redis() vlc = VLCController(vlc_config) step = request.args.get("step") if step == False or step == None: step = 1 vlc.volume_down(step) result["status"] = vlc.get_common_info() result["message"] = "success" except Exception as e: print(e) result["error"] = str(e) return json_result(result)
def next(request): result = {"message": "failed"} try: # 1.) Get State ensure_usb_drive_is_mounted() redis = redis_connect() config = redis.get("CONFIG.LOCAL_STORAGE_CONTROLLER_SERVER") config = json.loads(config) vlc_config = config["vlc"] # 2.) Advance to Next TV Show in Circular List next_tv_show_name_b64 = redis_circular_list.next( redis, "STATE.USB_STORAGE.LIBRARY.TV_SHOWS") next_tv_show_name = utils.base64_decode(next_tv_show_name_b64) # 3.) Advance to Next Episode in TV Show even though current one might be un-finished file_path_b64 = redis_circular_list.next( redis, f"STATE.USB_STORAGE.LIBRARY.TV_SHOWS.{next_tv_show_name_b64}") episode = get_current_episode(file_path_b64) # 4.) Start Episode vlc = VLCController(vlc_config) vlc.add(episode["file_path"]) time.sleep(1) if int(episode["current_time"]) > 5: vlc.seek(int(episode["current_time"]) - 5) vlc.volume_set(100) time.sleep(3) vlc.fullscreen_on() # 5.) Get Status result["status"] = vlc.get_common_info() pprint(result["status"]) # 6.) Update Duration update_duration_metadata(result["status"]["status"]["duration"], result["status"]["status"]["file_path"]) result["message"] = "success" except Exception as e: print(e) result["error"] = str(e) return json_result(result)
def volume_get(request): result = {"message": "failed", "volume": None} def exec_block(): tv_config = get_tv_config_from_redis() tv = viziocontroller.VizioController(tv_config) result["volume"] = tv.api.get_volume() result["message"] = "success" try: exec_block() except Exception as e: print(e) rescan_for_tv() try: exec_block() except Exception as e: result["error"] = str(e) return json_result(result)
def input_get_current(request): result = {"message": "failed"} def exec_block(): tv_config = get_tv_config_from_redis() tv = viziocontroller.VizioController(tv_config) current_input = tv.api.get_current_input() result["current_input"] = current_input["name"] result["message"] = "success" try: exec_block() except Exception as e: print(e) rescan_for_tv() try: exec_block() except Exception as e: result["error"] = str(e) return json_result(result)
async def ws_consumer(request): result = {"message": "failed"} try: print("Disney Plus Websocket Consumer") data = request.form if "channel" not in data: raise Exception("no channel in message") pprint(data) if data["channel"][0] != "disney_plus": result["status"] = "channel is not disney" raise Exception("channel is not disney") if "current_time" in data and "time_remaining" in data: video = update_current_video_time_info(None, data["current_time"][0], data["time_remaining"][0], data["playback_state"][0]) else: video = update_current_video_time_info() result["message"] = "success" if video["over"] == True: restart_response = requests.get( "http://127.0.0.1:11001/api/button/next") result["status"] = "video is over , pressing Button --> next()" if data["message"][0] == "agent_ready": print("Disney Plus Userscript is Ready") on_agent_ready() if data["message"][0] == "first_play": print("Disney Plus Userscript says its Playing") on_first_play() elif data["message"][0] == "agent_never_connected": print("Disney Plus Userscript Never Connected") on_agent_never_connected() except Exception as e: PrintException() result["error"] = str(e) return json_result(result)