예제 #1
0
    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()
예제 #2
0
    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))
예제 #3
0
    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
예제 #4
0
 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')
     ])
예제 #5
0
 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()
예제 #6
0
파일: start.py 프로젝트: JKorf/MediaPi
 def init_singletons():
     Stats()
     VLCPlayer()
     NextEpisodeManager()
     WiFiController()
     MediaManager()
     Updater()
     ThreadManager()
     PresenceManager()
     RuleManager()
예제 #7
0
 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
         ])
예제 #8
0
 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()
예제 #9
0
    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()
예제 #10
0
 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)
예제 #11
0
    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))
예제 #12
0
    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()
예제 #13
0
 def change_audio(self, track):
     VLCPlayer().set_audio_track(track)
예제 #14
0
    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
예제 #15
0
    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())
예제 #16
0
 def change_subtitle_delay(self, delay):
     VLCPlayer().set_subtitle_delay(delay)
예제 #17
0
 def change_volume(self, change_volume):
     VLCPlayer().set_volume(change_volume)
예제 #18
0
 def change_subtitle(self, track):
     VLCPlayer().set_subtitle_track(track)
예제 #19
0
 def seek(self, position):
     VLCPlayer().set_time(position)
예제 #20
0
 def pause_resume(self):
     VLCPlayer().pause_resume()