def __init__(self): self.mode = -1 self.mode_avail_list = [ CONST.MODE_VIDEO, CONST.MODE_HANGOUT, CONST.MODE_1ST_FLOOR ] #, CONST.MODE_3RD_FLOOR, CONST.MODE_KITCHEN] self.vlc_window_name = r".*VLC" try: pywinauto.findwindows.find_window(title_re=self.vlc_window_name) self.vlc = VLCClient("::1") self.vlc.connect() self.vlc_status = self.vlc.status().split("\r\n")[-1] except Exception as e: print "Please start VLC player: vlc Desktop\playlist.xspf --loop --extraintf telnet --telnet-password admin" print "Remember to add vlc to PATH and Configure the hotkeys in the preference" exit() self.hangout_window_name = r"Google Hangout" try: pywinauto.findwindows.find_window( title_re=self.hangout_window_name) except Exception as e: print "Please start Hangout app" exit() self.web_window_name = r"Brightness of 1st-Floor" try: pywinauto.findwindows.find_window(title_re=self.web_window_name) except Exception as e: print "Please start Webpage" exit() self.update_time = time.time()
def __init__(self, startVol=70): self.vlc = VLCClient("::1") # VLC connection for monitoring thread to avoid multiple telnet send commands # at the same time, i.e. when user is changing songs while check is in # progress. This scenario would cause a telnet timeout and crash self.vlc_monitoring = VLCClient("::1") self.current_playing = "" self.current_playing_from_vlc = "" self.current_vlc_playlist_id = 4 - 1 # The Vlc playlist index starts with 4 self.vlc_is_playing = "" self.next_playing = [] self.thread_stopper = False try: self.vlc.connect( ) # Esthablishing a connection via VLCClient class self.vlc_monitoring.connect( ) # Seperate connection for monitoring thread logger.disp_log_entry("info", "connected to vlc media player") except ConnectionRefusedError: # TODO: Further error handling logger.error("Connection to vlc could not be established!") self.volume(startVol) # Setting start value from config self.start_monitoring_thread()
def __init__(self, active_video_file, idle_video_file): self.active_video_file = active_video_file self.idle_video_file = idle_video_file self.vlc = VLCClient("::1") subprocess.Popen("vlc --intf telnet --telnet-pass admin", shell=True, stdout=subprocess.PIPE) time.sleep(2) self.vlc.connect()
import sys import time if len(sys.argv) < 2: print 'Usage: vlcrc <pebble-id>' exit(1) vlc_host = "localhost" pebble_id = sys.argv[1] lightblue = True pair = False lock = Lock() try: vlc = VLCClient(vlc_host) vlc.connect() except: print("Cannot connect to vlc instance, check whether vlc is running or telnet interface is enabled") print("Error: " + str(sys.exc_info())) exit(1) try: pebble = libpebble.Pebble(pebble_id, using_lightblue=lightblue, pair_first=pair) except: vlc.disconnect(); print("Cannot connect to pebble, check whether bluetooth is enabled in here and pebble") print("Error: " + str(sys.exc_info())) exit(1) state = "stopped"
import time from vlcclient import VLCClient stream = "http://nhkwglobal-i.akamaihd.net/hls/live/222714/nhkwglobal/index_1180.m3u8" sleepdelay = 3 vlc = VLCClient("::1") vlc.connect() print "connected to vlc ", vlc.server_version print "adding stream", stream print vlc.add(stream) print "sleeping", sleepdelay time.sleep(sleepdelay) print "snapshot 1" print vlc.snapshot() print "sleeping", sleepdelay time.sleep(sleepdelay) print "snapshot 2" print vlc.snapshot() print "sleeping", sleepdelay time.sleep(sleepdelay) print "snapshot 3"
class GestureSwitch(): def __init__(self): self.mode = -1 self.mode_avail_list = [ CONST.MODE_VIDEO, CONST.MODE_HANGOUT, CONST.MODE_1ST_FLOOR ] #, CONST.MODE_3RD_FLOOR, CONST.MODE_KITCHEN] self.vlc_window_name = r".*VLC" try: pywinauto.findwindows.find_window(title_re=self.vlc_window_name) self.vlc = VLCClient("::1") self.vlc.connect() self.vlc_status = self.vlc.status().split("\r\n")[-1] except Exception as e: print "Please start VLC player: vlc Desktop\playlist.xspf --loop --extraintf telnet --telnet-password admin" print "Remember to add vlc to PATH and Configure the hotkeys in the preference" exit() self.hangout_window_name = r"Google Hangout" try: pywinauto.findwindows.find_window( title_re=self.hangout_window_name) except Exception as e: print "Please start Hangout app" exit() self.web_window_name = r"Brightness of 1st-Floor" try: pywinauto.findwindows.find_window(title_re=self.web_window_name) except Exception as e: print "Please start Webpage" exit() self.update_time = time.time() def update_bool(self, in_change_mode, in_gesture): print "GestureSwitch update_bool mode is ", in_change_mode, "gesture is", in_gesture if self.update_time + 0.2 > time.time(): return None if in_change_mode: self.mode = (self.mode + 1) % len(self.mode_avail_list) return self.update(self.mode, CONST.GESTURE_DIRTY) else: return self.update(self.mode, in_gesture) def update(self, in_change_mode, in_gesture): if in_change_mode == -1: return None print "GestureSwitch mode is ", in_change_mode, "gesture is", in_gesture self.mode = in_change_mode self.update_time = time.time() try: if in_change_mode == CONST.MODE_VIDEO: out_mode1gesture = in_gesture out_mode2gesture = CONST.GESTURE_DIRTY out_mode3gesture = CONST.GESTURE_DIRTY out_mode4gesture = CONST.GESTURE_DIRTY out_mode5gesture = CONST.GESTURE_DIRTY pywinauto.win32functions.SetForegroundWindow( pywinauto.findwindows.find_window( title_re=self.vlc_window_name)) elif in_change_mode == CONST.MODE_HANGOUT: if "pause" not in self.vlc.status().split("\r\n")[-1]: self.vlc.pause() out_mode1gesture = CONST.GESTURE_DIRTY out_mode2gesture = in_gesture out_mode3gesture = CONST.GESTURE_DIRTY out_mode4gesture = CONST.GESTURE_DIRTY out_mode5gesture = CONST.GESTURE_DIRTY try: w = pywinauto.findwindows.find_window( title_re=self.hangout_window_name) except Exception as e: w = pywinauto.findwindows.find_window( title_re="Incoming video call") pywinauto.win32functions.SetForegroundWindow(w) elif in_change_mode == CONST.MODE_1ST_FLOOR: if "pause" not in self.vlc.status().split("\r\n")[-1]: self.vlc.pause() out_mode1gesture = CONST.GESTURE_DIRTY out_mode2gesture = CONST.GESTURE_DIRTY out_mode3gesture = in_gesture out_mode4gesture = CONST.GESTURE_DIRTY out_mode5gesture = CONST.GESTURE_DIRTY pywinauto.win32functions.SetForegroundWindow( pywinauto.findwindows.find_window( title_re=self.web_window_name)) elif in_change_mode == CONST.MODE_3RD_FLOOR: if "pause" not in self.vlc.status().split("\r\n")[-1]: self.vlc.pause() out_mode1gesture = CONST.GESTURE_DIRTY out_mode2gesture = CONST.GESTURE_DIRTY out_mode3gesture = CONST.GESTURE_DIRTY out_mode4gesture = in_gesture out_mode5gesture = CONST.GESTURE_DIRTY pywinauto.win32functions.SetForegroundWindow( pywinauto.findwindows.find_window( title_re=self.web_window_name)) elif in_change_mode == CONST.MODE_KITCHEN: if "pause" not in self.vlc.status().split("\r\n")[-1]: self.vlc.pause() out_mode1gesture = CONST.GESTURE_DIRTY out_mode2gesture = CONST.GESTURE_DIRTY out_mode3gesture = CONST.GESTURE_DIRTY out_mode4gesture = CONST.GESTURE_DIRTY out_mode5gesture = in_gesture pywinauto.win32functions.SetForegroundWindow( pywinauto.findwindows.find_window( title_re=self.web_window_name)) except Exception as e: print repr(e) print traceback.format_exc() return None return (out_mode1gesture, out_mode2gesture, out_mode3gesture, out_mode4gesture, out_mode5gesture)
import time from vlcclient import VLCClient stream = "http://nhkwglobal-i.akamaihd.net/hls/live/222714/nhkwglobal/index_1180.m3u8" sleepdelay = 3 vlc = VLCClient("::1") vlc.connect() print "connected to vlc ", vlc.server_version print "adding stream", stream print vlc.add(stream) print "sleeping", sleepdelay time.sleep(sleepdelay) print "snapshot 1" print vlc.snapshot() print "sleeping", sleepdelay time.sleep(sleepdelay)
import numpy as np import cv2 from Displayer import * from MyMeanShiftTracker import * from vlcclient import VLCClient cap = cv2.VideoCapture(0) tracker = None displayer = Displayer('Debug Window') vlc = VLCClient("::1") vlc.connect() while(True): # Capture frame-by-frame ret, frame = cap.read() if tracker is None: tracker = MeanShiftTracker(frame, (20, 20), None) key = displayer.get_key() if key & 0xFF == ord('a'): print('---------------------------------') tracker.toggle_printstuff() tracker.update_warp(frame) pframe = tracker.get_frame_with_tracker() gest = tracker.recognize_gesture() if gest is not None:
class VLC: def __init__(self, active_video_file, idle_video_file): self.active_video_file = active_video_file self.idle_video_file = idle_video_file self.vlc = VLCClient("::1") subprocess.Popen("vlc --intf telnet --telnet-pass admin", shell=True, stdout=subprocess.PIPE) time.sleep(2) self.vlc.connect() def play_active(self): self._play_videofile(self.active_video_file) def play_idle_video(self): self.vlc.add(self.idle_video_file) # self.vlc.loop() self.vlc.set_fullscreen(True) def enqueue_idle_video(self): self.vlc.enqueue(self.idle_video_file) def rewind_video(self): self.vlc.rewind() def _play_videofile(self, videofile, loop=False): print('Now playing videofile', videofile) self.vlc.add(videofile) self.vlc.set_fullscreen(True)
class PlayerCtl: """ VLC Media Player controller. This class contains the logic to interact with vlcclient and manage current playlist and status. """ # TODO: play/pause syncronisation with VLC # TODO: MP3 tag access def __init__(self, startVol=70): self.vlc = VLCClient("::1") # VLC connection for monitoring thread to avoid multiple telnet send commands # at the same time, i.e. when user is changing songs while check is in # progress. This scenario would cause a telnet timeout and crash self.vlc_monitoring = VLCClient("::1") self.current_playing = "" self.current_playing_from_vlc = "" self.current_vlc_playlist_id = 4 - 1 # The Vlc playlist index starts with 4 self.vlc_is_playing = "" self.next_playing = [] self.thread_stopper = False try: self.vlc.connect( ) # Esthablishing a connection via VLCClient class self.vlc_monitoring.connect( ) # Seperate connection for monitoring thread logger.disp_log_entry("info", "connected to vlc media player") except ConnectionRefusedError: # TODO: Further error handling logger.error("Connection to vlc could not be established!") self.volume(startVol) # Setting start value from config self.start_monitoring_thread() def _monitoring_thread(self): time.sleep(0.5) self.current_playing_from_vlc = self.get_vlc_internal_current_title() while not self.thread_stopper: try: # Fixing inconsistency in Vlc playback status if self.current_playing_from_vlc != self.get_vlc_internal_current_title() \ and int(self.get_vlc_is_currently_playing()) == 1: # Playing title has changed if self.next_playing: # If Playlist is not empty self.current_playing = self.next_playing.pop(0) self.delete_from_vlc_playlist( self.current_vlc_playlist_id) self.current_vlc_playlist_id = self.current_vlc_playlist_id + 1 self.current_playing_from_vlc = self.get_vlc_internal_current_title( ) logger.disp_log_entry( "playlist", "Now playing: " + self.get_clean_title(self.current_playing)) if int(self.get_vlc_is_currently_playing() ) == 0 and not self.next_playing: # Playback is stopped and playlist is empty self.current_playing = "" self.delete_from_vlc_playlist(self.current_vlc_playlist_id) except ValueError: # TODO: This might be fixed with second vlc connection thread logger.warning("Inconsistency in VLC output detected") logger.warning("Playlist might be asynchronous!") self.vlc_is_playing = self.get_vlc_is_currently_playing() time.sleep(0.1) def start_monitoring_thread(self): """ Starts the monitoring thread """ Thread(target=self._monitoring_thread).start() def stop_monitoring_thread(self): """ Stops the monitoring thread """ self.thread_stopper = True def add(self, filepath): """ Adds and plays the given file to the playlist """ self.vlc.add(filepath) self.current_playing = filepath self.next_playing.insert(0, self.current_playing) self.vlc_is_playing = self.get_vlc_is_currently_playing() def enqueue(self, filepath): """ Adds the given file to the end of the playlist """ self.vlc.enqueue(filepath) self.next_playing.append(filepath) logger.disp_log_entry( "playlist", "Added to queue: " + self.get_clean_title(filepath)) def next(self): """ Plays the next title in the playlist """ self.vlc.next() def skip(self, amount): """ Skips a given amount of titles """ for i in range(0, amount): self.next() time.sleep(0.5) # FIXME: Direct access to playlist def volume(self, vol): """ Sets the volume to the given input """ self.vlc.volume(vol) logger.disp_log_entry("info", "setting volume to " + str(vol)) def volup(self): """ Increases the volume by 10 percent """ self.vlc.volup() logger.disp_log_entry("info", "raising volume") def voldown(self): """ Lowers the volume by 10 percent """ self.vlc.voldown() logger.disp_log_entry("info", "lowering volume") def stop(self): """ Stops the playback """ self.vlc.stop() def clear(self): """ Clears the playlist """ self.vlc.clear() self.next_playing = [] self.current_playing = None logger.disp_log_entry("warning", "cleared playlist") def shutdown(self): """ Terminates VLC and the title monitoring Thread """ self.vlc.raw("shutdown") self.stop_monitoring_thread() logger.disp_log_entry("info", "Shutting down vlc client") def raw(self, command): """ Executes a raw telnet command """ self.vlc.raw(command) def get_volume(self): """ Returns the current playback volume """ current_volume = float(self.vlc.volume().decode("utf-8").replace( ",", ".")) while current_volume == 1.0: # Fix for inconsistent vlc output current_volume = float(self.vlc.volume().decode("utf-8").replace( ",", ".")) return current_volume def get_vlc_internal_current_title(self): """ Returns the internal name of the current playing title """ return self.vlc_monitoring.raw("get_title") def get_vlc_is_currently_playing(self): """ Returns 1 when playing, 0 when not """ return self.vlc_monitoring.raw("is_playing") def delete_from_vlc_playlist(self, trackid): """ Deletes the Song with the given id from VLC internal playlist """ self.vlc_monitoring.raw("delete " + str(trackid)) def get_current_playing(self): """ Returns the current title in a formatted form """ return self.get_clean_title(self.current_playing) def get_playlist(self): """ Returns the current playlist """ returnlist = self.next_playing # returnlist.insert(0,self.currentPlaying) return returnlist def get_clean_title(self, filepath): """ Returns the clean title of a given filepath """ # TODO: Add Mp3-Tag reader instead of using file names if filepath != "": return filepath.split("/")[-1].split(".")[-2].strip() else: return ""