示例#1
0
    def __init__(self, torrent):
        super().__init__(torrent, "download")

        self.torrent = torrent

        self.init = False
        self.prio = False
        self.last_get_result = 0, 0
        self.last_get_time = 0

        self.queue = []
        self.slow_peer_piece_offset = 0
        self._ticks = 0

        self.start_piece = 0
        self.end_piece = 0
        self.stream_end_buffer_pieces = 0
        self.stream_play_buffer_high_priority = 0
        self.max_chunk_size = Settings.get_int("max_chunk_size")

        self.download_mode = DownloadMode.Full
        self.peers_per_piece = [(100, 2, 5), (95, 1, 2), (0, 1, 1)]

        self._event_id_stopped = EventManager.register_event(
            EventType.TorrentStopped, self.unregister)
        self._event_id_torrent_state = EventManager.register_event(
            EventType.TorrentStateChange, self.init_queue)

        self.queue_log = ""
示例#2
0
    def __init__(self):
        self.subtitle_sources = [
            SubtitlesOpenSubtitles(),
        ]

        self.sub_file_directory = Settings.get_string("base_folder") + "/subs/"
        self.sub_files = []

        self.file_size = 0
        self.file_length = 0
        self.file_name = None
        self.first_64k = None
        self.last_64k = None

        # create subtitles directory
        if not os.path.exists(self.sub_file_directory):
            os.makedirs(self.sub_file_directory)

        # remove old subtitles files
        file_list = glob.glob(self.sub_file_directory + "*.srt")
        for f in file_list:
            os.remove(f)

        EventManager.register_event(EventType.SearchSubtitles,
                                    self.search_subtitles)
示例#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 wait_for_event(max_time, event):
     UtilController.health_cache[event] = False
     evnt = EventManager.register_event(
         event, lambda *x: UtilController.assign(event))
     result = UtilController.wait_for(
         max_time, lambda: UtilController.health_cache[event])
     EventManager.deregister_event(evnt)
     return result
示例#5
0
    def __init__(self):
        self.own_node = None

        self.routing_table = Table(self)
        self.table_lock = Lock()

        self.socket = Socket(Settings.get_int("dht_port"), self.on_node_seen,
                             self.on_node_timeout, self.on_query)
        self.engine = Engine("DHT Engine", 5000)
        self.engine.add_work_item("DHT Refresh buckets", 1000 * 60,
                                  self.refresh_buckets, False)
        self.engine.add_work_item("DHT Save nodes", 1000 * 60 * 5,
                                  self.save_nodes, False)

        self.running_tasks = []
        self.torrent_nodes = dict()

        EventManager.register_event(EventType.RequestPeers, self.search_peers)
        EventManager.register_event(EventType.NewDHTNode, self.add_node)
示例#6
0
    def __init__(self, torrent):
        super().__init__(torrent, "network")

        self.running = True
        self.torrent = torrent

        self.speed_log = 0

        self.average_download_counter = AverageCounter(self, 3)

        self.thread = None
        self._event_id_stopped = EventManager.register_event(EventType.TorrentStopped, self.unregister)
示例#7
0
    def __init__(self):
        self.__vlc_instance = None
        self.player_state = PlayerData()

        self.instantiate_vlc()

        self.media = None
        self.__player = self.__vlc_instance.media_player_new()
        self.__list_player = self.__vlc_instance.media_list_player_new()
        self.__list_player.set_media_player(self.__player)

        self.__event_manager = self.__player.event_manager()

        self.set_volume(75)

        EventManager.register_event(EventType.SetSubtitleFiles,
                                    self.set_subtitle_files)
        EventManager.register_event(EventType.StopPlayer, self.stop)

        self.player_observer = CustomThread(self.observe_player,
                                            "Player observer")
        self.player_observer.start()
        self.stop_player_thread = None
示例#8
0
    def __init__(self, torrent):
        super().__init__(torrent, "peers")

        self.torrent = torrent
        self.potential_peers = []
        self.connecting_peers = []
        self.connected_peers = []
        self.disconnected_peers = []
        self.cant_connect_peers = []
        self.complete_peer_list = []
        self.max_peers_connected = Settings.get_int("max_peers_connected")
        self.max_peers_connecting = Settings.get_int("max_peers_connecting")
        self._peer_request_interval = Settings.get_int("peer_request_interval")
        self._peer_request_interval_no_potential = Settings.get_int(
            "peer_request_interval_no_potential")
        self.random = Random()
        self.download_start = 0
        self.start_time = current_time()
        self.last_peer_request = 0
        self.checked_no_peers = False

        self._event_id_stopped = EventManager.register_event(
            EventType.TorrentStopped, self.unregister)
        self._event_id_torrent_change = EventManager.register_event(
            EventType.TorrentStateChange, self.torrent_state_change)
        self._event_id_peers_found = EventManager.register_event(
            EventType.PeersFound, self.add_potential_peers)

        self.high_speed_peers = 0
        self.medium_speed_peers = 0

        # Log properties
        self.potential_peers_log = 0
        self.connecting_peers_log = 0
        self.connected_peers_log = 0
        self.disconnected_peers_log = 0
        self.cant_connect_peers_log = 0
示例#9
0
    def __init__(self, torrent):
        super().__init__(torrent, "data")
        self.torrent = torrent
        self._pieces = dict()
        self.init_done = False
        self.total_pieces = 0
        self.piece_length = 0
        self.bitfield = None
        self.hashes = []

        self.block_size = Settings.get_int("block_size")
        self.broadcasted_hash_data = False
        self._event_id_stopped = EventManager.register_event(
            EventType.TorrentStopped, self.unregister)
        self.blocks_done_length = 0
        self.last_piece_index = 0
示例#10
0
    def __init__(self, id, uri):
        super().__init__(None, "Torrent")

        self.left = 0
        self.overhead = 0

        self.name = None
        self.id = id
        self.uri = uri
        self.total_size = 0
        self.uploaded = 0
        self.piece_length = 0
        self.piece_hashes = None
        self.announce_uris = []
        self.info_hash = None
        self.files = []
        self.__state = TorrentState.Initial

        self.media_file = None
        self.selected_media_file = None

        self.stream_file_hash = None

        self._user_file_selected_id = EventManager.register_event(
            EventType.TorrentMediaFileSelection, self.user_file_selected)

        self.engine = Engine.Engine('Main processor', 500, self)

        self.tracker_manager = TrackerManager()
        self.peer_manager = TorrentPeerManager(self)
        self.data_manager = TorrentDataManager(self)
        self.download_manager = TorrentDownloadManager(self)
        self.stream_manager = StreamManager(self)
        self.metadata_manager = TorrentMetadataManager(self)
        self.network_manager = TorrentNetworkManager(self)
        self.message_processor = TorrentMessageProcessor(self)
        self.peer_processor = TorrentPeerProcessor(self)
        self.cache_manager = TorrentCacheManager(self)
示例#11
0
    def __init__(self):
        self.trackers = []
        self.initialized = False

        self.request_peers_id = EventManager.register_event(EventType.RequestPeers, self.request_peers)