Example #1
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))
Example #2
0
    def player_update(self, old_state, new_state):
        if new_state.state != old_state.state:
            if new_state.state == PlayerState.Playing:
                if MediaManager().media_data.type != "Radio":
                    self.state = UIState.Playing
                else:
                    self.state = UIState.Home

            if new_state.state == PlayerState.Paused:
                if MediaManager().media_data.type != "Radio":
                    self.state = UIState.Paused
Example #3
0
    def play_url():
        instance = int(request.args.get("instance"))
        title = urllib.parse.unquote(request.args.get("title"))
        url = urllib.parse.unquote(request.args.get("url"))
        Logger().write(
            LogVerbosity.Info,
            "Play url " + title + "(" + url + ") on " + str(instance))

        if instance == 1:
            if url.startswith("magnet:"):
                MediaManager().start_torrent(title, url, None)
            else:
                MediaManager().start_url(title, url)
        else:
            APIController().slave_command(instance, "media", "start_url",
                                          title, url)
        return "OK"
Example #4
0
    def stop_player():
        instance = int(request.args.get("instance"))
        Logger().write(LogVerbosity.Info, "Stop playing on " + str(instance))

        if instance == 1:
            MediaManager().stop_play()
        else:
            APIController().slave_command(instance, "media", "stop_play")
        return "OK"
Example #5
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))
Example #6
0
    def pause_resume_player():
        instance = int(request.args.get("instance"))
        Logger().write(LogVerbosity.Info, "Pause/resume on " + str(instance))

        if instance == 1:
            MediaManager().pause_resume()
        else:
            APIController().slave_command(instance, "media", "pause_resume")
        return "OK"
Example #7
0
    def media_update(self, old_data, new_data):
        if new_data.title is not None and self.state == UIState.Home:
            self.state = UIState.Loading
        if new_data.title is None and self.state != UIState.Home:
            self.state = UIState.Home

        if MediaManager().media_data.type == "Radio":
            self.set_now_playing(new_data.title)
        else:
            self.set_now_playing(None)
Example #8
0
 def init_singletons():
     Stats()
     VLCPlayer()
     NextEpisodeManager()
     WiFiController()
     MediaManager()
     Updater()
     ThreadManager()
     PresenceManager()
     RuleManager()
Example #9
0
    def seek():
        instance = int(request.args.get("instance"))
        position = int(request.args.get("position"))
        Logger().write(LogVerbosity.Info,
                       "Seek " + str(instance) + " to " + str(position))

        if instance == 1:
            MediaManager().seek(position)
        else:
            APIController().slave_command(instance, "media", "seek", position)
        return "OK"
Example #10
0
    def change_audio():
        instance = int(request.args.get("instance"))
        track = int(request.args.get("track"))
        Logger().write(LogVerbosity.Info,
                       "Set audio on " + str(instance) + " to " + str(track))

        if instance == 1:
            MediaManager().change_audio(track)
        else:
            APIController().slave_command(instance, "media", "change_audio",
                                          track)
        return "OK"
Example #11
0
    def change_volume():
        instance = int(request.args.get("instance"))
        volume = int(request.args.get("volume"))
        Logger().write(LogVerbosity.Info,
                       "Set volume on " + str(instance) + " to " + str(volume))

        if instance == 1:
            MediaManager().change_volume(volume)
        else:
            APIController().slave_command(instance, "media", "change_volume",
                                          volume)
        return "OK"
Example #12
0
    def play_radio():
        radio_id = int(request.args.get("id"))
        radio = [x for x in Database().get_radios() if x.id == radio_id][0]
        instance = int(request.args.get("instance"))

        Logger().write(LogVerbosity.Info,
                       "Play radio " + radio.title + " on " + str(instance))
        if instance == 1:
            MediaManager().start_radio(radio.title, radio.url)
        else:
            APIController().slave_command(instance, "media", "start_radio",
                                          radio.title, radio.url)
        return "OK"
Example #13
0
    def change_sub_delay():
        instance = int(request.args.get("instance"))
        delay = int(request.args.get("delay"))
        Logger().write(
            LogVerbosity.Info,
            "Set sub delay on " + str(instance) + " to " + str(delay))

        if instance == 1:
            MediaManager().change_subtitle_delay(delay)
        else:
            APIController().slave_command(instance, "media",
                                          "change_subtitle_delay", delay)
        return "OK"
Example #14
0
    def play_youtube():
        instance = int(request.args.get("instance"))
        title = urllib.parse.unquote(request.args.get("title"))
        url = urllib.parse.unquote(request.args.get("url"))
        position = int(request.args.get("position"))

        Logger().write(LogVerbosity.Info,
                       "Play youtube " + title + " on " + str(instance))
        if instance == 1:
            MediaManager().start_youtube(title, url, position)
        else:
            APIController().slave_command(instance, "media", "start_youtube",
                                          title, url, position)
        return "OK"
Example #15
0
    def play_file():
        instance = int(request.args.get("instance"))
        position = int(request.args.get("position"))
        file = urllib.parse.unquote(request.args.get("path"))
        if sys.platform == "win32":
            file = "C:" + file

        Logger().write(LogVerbosity.Info,
                       "Play file " + file + " on " + str(instance))

        if instance == 1:
            MediaManager().start_file(file, position)
        else:
            APIController().slave_command(instance, "media", "start_file",
                                          file, position)
        return "OK"
Example #16
0
    def play_torrent():
        instance = int(request.args.get("instance"))
        title = urllib.parse.unquote(request.args.get("title"))
        url = urllib.parse.unquote(request.args.get("url"))
        magnet_uri = TorrentController.get_magnet_url(url)
        if magnet_uri is None:
            Logger().write(LogVerbosity.Error,
                           "Failed to find torrent magnet uri")
            return "OK"

        Logger().write(LogVerbosity.Info,
                       "Play torrent " + title + " on " + str(instance))
        if instance == 1:
            MediaManager().start_torrent(title, magnet_uri)
        else:
            APIController().slave_command(instance, "media", "start_torrent",
                                          title, magnet_uri)
        return "OK"
Example #17
0
    def play_episode():
        instance = int(request.args.get("instance"))
        title = urllib.parse.unquote(request.args.get("title"))
        movie_id = request.args.get("id")
        url = urllib.parse.unquote(request.args.get("url"))
        img = urllib.parse.unquote(request.args.get("img"))
        position = int(request.args.get("position"))
        season = int(request.args.get("season"))
        episode = int(request.args.get("episode"))

        Logger().write(LogVerbosity.Info,
                       "Play episode " + title + " on " + str(instance))
        if instance == 1:
            MediaManager().start_episode(movie_id, season, episode, title, url,
                                         img, position)
        else:
            APIController().slave_command(instance, "media", "start_episode",
                                          movie_id, season, episode, title,
                                          url, img, position)
        return "OK"
Example #18
0
    def on_command(topic, command, args):
        Logger().write(LogVerbosity.Debug, "Master command " + topic + ": " + command)

        method = None
        if topic == "media":
            from MediaPlayer.MediaManager import MediaManager
            method = getattr(MediaManager(), command)

        if topic == "updater":
            from Updater import Updater
            method = getattr(Updater(), command)

        if topic == "system":
            if command == "restart_device":
                os.system('sudo reboot')
            if command == "restart_application":
                python = sys.executable
                os.execl(python, python, *sys.argv)
            if command == "close_application":
                sys.exit()

        if method is not None:
            cb_thread = CustomThread(method, "Master command", args)
            cb_thread.start()
Example #19
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
Example #20
0
 def execute(self):
     # TODO slave?
     radio = [x for x in Database().get_radios() if x.id == self.channel][0]
     from MediaPlayer.MediaManager import MediaManager
     MediaManager().start_radio(radio.title, radio.url)
Example #21
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())