def __init__(self, video_url, log_uuid, show_loading_screen): self.__logger = Logger().set_namespace(self.__class__.__name__) if log_uuid: Logger.set_uuid(log_uuid) else: Logger.set_uuid(Logger.make_uuid()) self.__config_loader = ConfigLoader() self.__video_url = video_url self.__show_loading_screen = show_loading_screen # Store the PGIDs separately, because attempting to get the PGID later via `os.getpgid` can # raise `ProcessLookupError: [Errno 3] No such process` if the process is no longer running self.__video_broadcast_proc_pgid = None self.__download_and_convert_video_proc_pgid = None # Metadata about the video we are using, such as title, resolution, file extension, etc # Access should go through self.get_video_info() to populate it lazily self.__video_info = None # Bind multicast traffic to eth0. Otherwise it might send over wlan0 -- multicast doesn't work well over wifi. # `|| true` to avoid 'RTNETLINK answers: File exists' if the route has already been added. (subprocess.check_output( f"sudo ip route add {MulticastHelper.ADDRESS}/32 dev eth0 || true", shell=True, executable='/usr/bin/bash', stderr=subprocess.STDOUT)) self.__control_message_helper = ControlMessageHelper( ).setup_for_broadcaster() self.__do_housekeeping(for_end_of_video=False) self.__register_signal_handlers()
def __play_screensaver(self): log_uuid = 'SCREENSAVER__' + Logger.make_uuid() Logger.set_uuid(log_uuid) # choose random screensaver video to play screensavers_config = self.__config_loader.get_raw_config( )['screensavers'] if self.__config_loader.is_any_receiver_dual_video_output(): options = screensavers_config['720p'] else: options = screensavers_config['1080p'] screensaver_data = random.choice(list(options.values())) path = DirectoryUtils().root_dir + '/' + screensaver_data['video_path'] self.__logger.info("Starting broadcast of screensaver...") self.__do_broadcast(path, log_uuid)
def __play_playlist_item(self, playlist_item): if not self.__playlist.set_current_video( playlist_item["playlist_video_id"]): # Someone deleted the item from the queue in between getting the item and starting it. return log_uuid = Logger.make_uuid() Logger.set_uuid(log_uuid) self.__logger.info( f"Starting broadcast for playlist_video_id: {playlist_item['playlist_video_id']}" ) msg = { 'log_uuid': log_uuid, 'loading_screen_data': self.__choose_random_loading_screen() } self.__control_message_helper.send_msg( ControlMessageHelper.TYPE_SHOW_LOADING_SCREEN, msg) self.__do_broadcast(playlist_item['url'], log_uuid) self.__playlist_item = playlist_item