def stop_play(self): stop_torrent = False if VLCPlayer().player_state.state == PlayerState.Nothing: stop_torrent = True VLCPlayer().stop() if stop_torrent: self.stop_torrent() while self.torrent is not None: time.sleep(0.2) self.media_data.reset()
def init(): from Controllers.TradfriManager import TradfriManager from MediaPlayer.MediaManager import MediaManager from MediaPlayer.Player.VLCPlayer import VLCPlayer from Updater import Updater from Shared.State import StateManager from Shared.Stats import Stats APIController.slaves.register_callback( lambda old, new: UIWebsocketController.broadcast( "slaves", new.data)) TradfriManager().tradfri_state.register_callback( lambda old, new: UIWebsocketController.broadcast("tradfri", new)) StateManager().state_data.register_callback( lambda old, new: UIWebsocketController.broadcast("1.state", new)) VLCPlayer().player_state.register_callback( lambda old, new: UIWebsocketController.broadcast("1.player", new)) MediaManager().media_data.register_callback( lambda old, new: UIWebsocketController.broadcast("1.media", new)) MediaManager().torrent_data.register_callback( lambda old, new: UIWebsocketController.broadcast("1.torrent", new)) Stats().cache.register_callback( lambda old, new: UIWebsocketController.broadcast("1.stats", new)) Updater().update_state.register_callback( lambda old, new: UIWebsocketController.broadcast("1.update", new))
def __init__(self): self.media_data = MediaData() self.torrent_data = TorrentData() self.torrent = None self.subtitle_provider = SubtitleProvider() self.next_episode_manager = NextEpisodeManager() self.play_position = 0 self.play_length = 0 self.history_id = 0 self.last_tracking_update = 0 self.dht_enabled = Settings.get_bool("dht") if self.dht_enabled: self.dht = DHTEngine() self.dht.start() EventManager.register_event(EventType.AbortingTorrent, self.aborting_torrent) EventManager.register_event(EventType.TorrentMediaSelectionRequired, self.media_selection_required) EventManager.register_event(EventType.TorrentMediaFileSet, lambda x: self._start_playing_torrent()) EventManager.register_event(EventType.TorrentStopped, lambda: self.on_torrent_stopped()) VLCPlayer().player_state.register_callback(self.player_state_change) self.torrent_observer = CustomThread(self.observe_torrent, "Torrent observer") self.torrent_observer.start() self.next_epi_thread = None
def process_file_info_for_subtitles(self, size, first_64k, last_64k): Logger().write(LogVerbosity.Debug, "Received file info from master, requesting subs") EventManager.throw_event(EventType.SearchSubtitles, [ self.media_data.title, size, VLCPlayer().get_length(), first_64k.encode('utf8'), last_64k.encode('utf8') ])
def start_radio(self, name, url): self.stop_play() VLCPlayer().play(url, 0) self.media_data.start_update() self.media_data.type = "Radio" self.media_data.title = name self.media_data.image = None self.media_data.stop_update() TVManager().switch_input_to_pi()
def init_singletons(): Stats() VLCPlayer() NextEpisodeManager() WiFiController() MediaManager() Updater() ThreadManager() PresenceManager() RuleManager()
def update_subtitles(self, new_state): media_type = self.media_data.type if media_type == "File": if Settings.get_bool("slave"): SlaveClientController.request_master_cb( "get_file_info", self.process_file_info_for_subtitles, 5, self.media_data.url) else: size, first_64k, last_64k = get_file_info(self.media_data.url) EventManager.throw_event(EventType.SearchSubtitles, [ self.media_data.title, size, VLCPlayer().get_length(), first_64k, last_64k ]) elif media_type == "Show" or media_type == "Movie" or media_type == "Torrent": EventManager.throw_event(EventType.SearchSubtitles, [ os.path.basename(self.torrent.media_file.name), self.torrent.media_file.length, VLCPlayer().get_length(), self.torrent.media_file.first_64k, self.torrent.media_file.last_64k ])
def start_url(self, title, url): self.stop_play() VLCPlayer().play(url, 0) if Settings.get_bool("slave"): self.history_id, = SlaveClientController.request_master( "add_watched_url", 5, url, current_time()) else: self.history_id = Database().add_watched_url(url, current_time()) self.media_data.start_update() self.media_data.type = "Url" self.media_data.title = title self.media_data.stop_update() TVManager().switch_input_to_pi()
def __init__(self, torrent): super().__init__(torrent, "stream manager") self.torrent = torrent self.stream_position_piece_index = 0 self.listener = StreamListener("TorrentServer", 50009, torrent) self.init = False self.start_buffer = 0 self.end_buffer_start_byte = 0 self.start_buffer_end_byte = 0 self.has_played = False self.last_request_end = 0 VLCPlayer().player_state.register_callback(self.player_change) self.listener.start_listening()
def _start_playing_torrent(self): if Settings.get_bool("slave"): self.history_id, = SlaveClientController.request_master( "add_watched_torrent", 5, self.media_data.type, self.media_data.title, self.media_data.id, self.torrent.uri, self.torrent.media_file.path, self.media_data.image, self.media_data.season, self.media_data.episode, current_time()) else: self.history_id = Database().add_watched_torrent( self.media_data.type, self.media_data.title, self.media_data.id, self.torrent.uri, self.torrent.media_file.path, self.media_data.image, self.media_data.season, self.media_data.episode, current_time()) VLCPlayer().play("http://localhost:50009/torrent", self.media_data.start_from)
def init(): if Settings.get_int("log_level") == 0: import logging logging.getLogger('requests').setLevel(logging.WARNING) logging.basicConfig(level=logging.DEBUG) from MediaPlayer.MediaManager import MediaManager from MediaPlayer.Player.VLCPlayer import VLCPlayer from Updater import Updater from Shared.State import StateManager from Shared.Stats import Stats StateManager().state_data.register_callback(lambda old, new: SlaveClientController.broadcast("state", new)) VLCPlayer().player_state.register_callback(lambda old, new: SlaveClientController.broadcast("player", new)) MediaManager().media_data.register_callback(lambda old, new: SlaveClientController.broadcast("media", new)) MediaManager().torrent_data.register_callback(lambda old, new: SlaveClientController.broadcast("torrent", new)) Stats().cache.register_callback(lambda old, new: SlaveClientController.broadcast("stats", new)) Updater().update_state.register_callback(lambda old, new: SlaveClientController.broadcast("update", new))
def start_file(self, url, time): actual_url = url if Settings.get_bool("slave"): actual_url = "http://" + Settings.get_string( "master_ip") + ":50015/file/" + urllib.parse.quote(url) self.stop_play() VLCPlayer().play(actual_url, time) if Settings.get_bool("slave"): self.history_id, = SlaveClientController.request_master( "add_watched_file", 5, url, current_time()) else: self.history_id = Database().add_watched_file(url, current_time()) self.media_data.start_update() self.media_data.type = "File" self.media_data.title = os.path.basename(url) self.media_data.url = url self.media_data.image = None self.media_data.stop_update() TVManager().switch_input_to_pi()
def change_audio(self, track): VLCPlayer().set_audio_track(track)
def run_torrent_check(result): best_movie_torrents = MovieController.request_movies( MovieController.movies_api_path + "movies/1?sort=Trending")[0:20] all_torrents = [] for arr in [x.torrents for x in best_movie_torrents]: all_torrents += arr if len(all_torrents) == 0: return torrent = max(all_torrents, key=lambda t: t.seeds / (t.peers or 1)) Logger().write( LogVerbosity.Info, "System health selected torrent at " + torrent.quality + ", " + str(torrent.peers) + "/" + str(torrent.seeds) + " l/s") MediaManager().start_movie(0, "Health check", torrent.url, None, 0) created = UtilController.wait_for( 2000, lambda: MediaManager().torrent is not None) result.torrent_starting_result.set_result(created, "Didn't create torrent") if not created: return result executing = UtilController.wait_for( 10000, lambda: MediaManager().torrent.is_preparing or MediaManager( ).torrent.is_executing) result.torrent_starting_result.set_result(executing, "Torrent isn't executing") if not executing: return result downloading = UtilController.wait_for( 10000, lambda: MediaManager().torrent.network_manager. average_download_counter.total > 0) result.torrent_downloading_result.set_result( downloading, "No bytes downloaded at all") playing = False if downloading: playing = UtilController.wait_for( 30000, lambda: VLCPlayer().player_state.playing_for > 0) result.torrent_playing_result.set_result( playing, "Didn't start playing torrent") if playing: MediaManager().seek(1000 * 60 * 5) # seek to 5 minutes in playing = UtilController.wait_for( 10000, lambda: VLCPlayer().player_state.playing_for > 1000 * 60 * 5) result.torrent_playing_after_seek_result.set_result( playing, "Didn't start playing torrent after seeking") MediaManager().stop_play() stopped_event = UtilController.wait_for_event(20000, EventType.TorrentStopped) result.torrent_disposing_result.set_result( stopped_event, "Torrent stopped event not received") if stopped_event: disposed = UtilController.wait_for( 5000, lambda: len( objgraph.by_type( 'MediaPlayer.Torrents.Torrent.Torrent.Torrent')) == 0) result.torrent_disposing_result.set_result( disposed, "Torrent not disposed after stopping") return result
def __init__(self, parent, *args, **kwargs): tk.Frame.__init__(self, parent) self.parent = parent self._state = UIState.Home self.loading_details_visible = False self.background_time = 60 * 15 self.background_max_requests = 5 self.background_images = [] self.base_image_path = os.getcwd() + "/UI/TV/Images/" self.background_canvas = None self.background_image = None self.name_label = None self.time_label = None self.date_label = None self.playing_label = None self.playing_value = None self.info_background = None self.loading_speed_label = None self.loading_buffered_label = None self.loading_speed_value = None self.loading_buffered_value = None self.loading_peers_connected_label = None self.loading_peers_connected_value = None self.loading_peers_available_value = None self.loading_peers_available_label = None self.loading_gif = None self.rects = [] self.images = [] self.player_frame = None self.status_image_frame = None self.pause_image = None self.weather_max = None self.weather_min = None self.weather_temp = None self.weather_icon_image = None self.init_UI() VLCPlayer().player_state.register_callback(self.player_update) MediaManager().media_data.register_callback(self.media_update) MediaManager().torrent_data.register_callback(self.torrent_update) self.image_fetcher_thread = CustomThread(self.get_backgrounds, "UI background downloader") self.image_fetcher_thread.start() self.background_swapper_thread = CustomThread(self.swap_backgrounds, "UI background swapper") self.background_swapper_thread.start() self.time_change_thread = CustomThread(self.change_time, "UI time changer") self.time_change_thread.start() self.current_weather_thread = CustomThread(self.get_weather_data, "UI current weather") self.current_weather_thread.start() VLCPlayer().set_window(self.player_frame.winfo_id())
def change_subtitle_delay(self, delay): VLCPlayer().set_subtitle_delay(delay)
def change_volume(self, change_volume): VLCPlayer().set_volume(change_volume)
def change_subtitle(self, track): VLCPlayer().set_subtitle_track(track)
def seek(self, position): VLCPlayer().set_time(position)
def pause_resume(self): VLCPlayer().pause_resume()