예제 #1
0
 def check_download_speed(self):
     current_max = Stats().total('max_download_speed')
     current_speed = self.network_manager.average_download_counter.get_speed(
     )
     if current_speed > current_max:
         Stats().set('max_download_speed', current_speed)
     return True
예제 #2
0
 def add_connected_peer_stat(source):
     if source == PeerSource.DHT:
         Stats().add('peers_source_dht_connected', 1)
     elif source == PeerSource.HttpTracker:
         Stats().add('peers_source_http_tracker_connected', 1)
     elif source == PeerSource.UdpTracker:
         Stats().add('peers_source_udp_tracker_connected', 1)
     elif source == PeerSource.PeerExchange:
         Stats().add('peers_source_exchange_connected', 1)
예제 #3
0
 def add_potential_peer_stat(source):
     if source == PeerSource.DHT:
         Stats().add('peers_source_dht', 1)
     elif source == PeerSource.HttpTracker:
         Stats().add('peers_source_http_tracker', 1)
     elif source == PeerSource.UdpTracker:
         Stats().add('peers_source_udp_tracker', 1)
     elif source == PeerSource.PeerExchange:
         Stats().add('peers_source_exchange', 1)
예제 #4
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))
예제 #5
0
파일: start.py 프로젝트: JKorf/MediaPi
 def init_singletons():
     Stats()
     VLCPlayer()
     NextEpisodeManager()
     WiFiController()
     MediaManager()
     Updater()
     ThreadManager()
     PresenceManager()
     RuleManager()
예제 #6
0
    def start(self):
        self.connected_on = 0
        Logger().write(LogVerbosity.All, str(self.peer.id) + ' connecting to ' + str(self.uri.netloc))
        Stats().add('peers_connect_try', 1)

        if not self.connection.connect():
            Stats().add('peers_connect_failed', 1)
            if self.peer is not None:
                Logger().write(LogVerbosity.All, str(self.peer.id) + ' could not connect to ' + str(self.uri.netloc))
                self.peer.stop_async("Can't connect")
            return

        if self.peer.state is not PeerState.Starting:
            return

        self.connected_on = current_time()
        self.peer.add_connected_peer_stat(self.peer.source)
        Stats().add('peers_connect_success', 1)
        Logger().write(LogVerbosity.Debug, str(self.peer.id) + ' connected to ' + str(self.uri.netloc))
        self.peer.state = PeerState.Started

        self.in_thread = CustomThread(self.socket_reader, "Peer " + str(self.peer.id) + " input")
        self.in_thread.start()
예제 #7
0
    def block_done(self, peer, piece_index, offset, data):
        Timing().start_timing("done_blocks")
        piece = self._pieces[piece_index]
        Logger().write(
            LogVerbosity.All,
            str(peer.id) + ' Received piece message: ' + str(piece.index) +
            ', block offset: ' + str(offset))

        if self.torrent.state == TorrentState.Done:
            Logger().write(LogVerbosity.All,
                           'Received a block but torrent already done')
            self.torrent.overhead += len(data)
            return

        if piece.index < self.torrent.stream_position:
            Logger().write(LogVerbosity.All,
                           'Received a block which is no longer needed')
            self.torrent.overhead += len(data)
            return

        if piece.done or piece.cleared:
            Logger().write(
                LogVerbosity.All,
                'Received block but piece was already done or cleared')
            self.torrent.overhead += len(data)
            return

        block = piece.get_block_by_offset(offset)
        if block.done:
            Logger().write(LogVerbosity.All,
                           'Received block but block was already done')
            self.torrent.overhead += len(data)
            return

        self.write_block(piece, block, data)

        self.torrent.left -= block.length
        Stats().add('total_downloaded', block.length)

        if self.init_done:
            if self.torrent.state != TorrentState.Done:
                if self.torrent.left == 0:
                    self.torrent.torrent_done()

        Timing().stop_timing("done_blocks")
예제 #8
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))
예제 #9
0
파일: start.py 프로젝트: JKorf/MediaPi
    def __init__(self):
        Logger().start(Settings.get_int("log_level"))
        sys.excepthook = self.handle_exception

        Logger().write(LogVerbosity.Info, "Starting")
        self.running = True

        self.version = datetime.fromtimestamp(
            self.get_latest_change()).strftime("%Y-%m-%d %H:%M:%S")
        self.is_slave = Settings.get_bool("slave")
        self.pi = sys.platform == "linux" or sys.platform == "linux2"

        Logger().write(
            LogVerbosity.Info, "Python version " + str(sys.version_info[0]) +
            "." + str(sys.version_info[1]) + "." + str(sys.version_info[2]))
        Logger().write(LogVerbosity.Info,
                       "MediaPlayer build [" + self.version + "]")
        Logger().write(LogVerbosity.Info, "Slave: " + str(self.is_slave))
        if self.is_slave:
            Logger().write(
                LogVerbosity.Info,
                "Master ip: " + str(Settings.get_string("master_ip")))
        Logger().write(LogVerbosity.Info, "Pi: " + str(self.pi))
        Logger().write(LogVerbosity.Info,
                       "UI: " + str(Settings.get_bool("UI")))

        Logger().write(LogVerbosity.Debug, "Initializing database")
        Database().init_database()

        Logger().write(LogVerbosity.Debug, "Initializing singletons")
        self.init_singletons()

        Logger().write(LogVerbosity.Debug, "Initializing sounds and folders")
        self.init_sound()
        self.init_folders()

        Logger().write(LogVerbosity.Debug, "Initializing API")
        APIController().start()

        Logger().write(LogVerbosity.Debug, "Initializing WiFi controller")
        WiFiController().check_wifi()

        Logger().write(LogVerbosity.Debug, "Initializing stats")
        Stats().start()
        Stats().set('start_time', current_time())

        Logger().write(LogVerbosity.Debug, "Initializing presence manager")
        PresenceManager().start()

        Logger().write(LogVerbosity.Debug, "Initializing rule manager")
        RuleManager().start()

        Logger().write(LogVerbosity.Debug, "Initializing TV manager")
        TVManager().start()

        if not self.is_slave:
            Logger().write(LogVerbosity.Debug, "Initializing TradeFriManager")
            TradfriManager().init()

            Logger().write(LogVerbosity.Debug,
                           "Initializing master file server")
            self.file_listener = StreamListener("MasterFileServer", 50015)
            self.file_listener.start_listening()

        Logger().write(LogVerbosity.Important, "Started")
        if Settings.get_bool("UI"):
            from UI.TV.GUI import App
            self.gui = App.initialize()
        else:
            while self.running:
                time.sleep(5)