예제 #1
0
 def updated_my_channel(self, tdef):
     """
     Notify the core that we updated our channel.
     """
     with db_session:
         my_channel = self.mds.ChannelMetadata.get(
             infohash=tdef.get_infohash())
     if (my_channel and my_channel.status == COMMITTED
             and not self.download_manager.download_exists(
                 bytes(my_channel.infohash))):
         dcfg = DownloadConfig(state_dir=self.state_dir)
         dcfg.set_dest_dir(self.mds.channels_dir)
         dcfg.set_channel_download(True)
         return self.download_manager.start_download(tdef=tdef, config=dcfg)
예제 #2
0
    async def download_channel(self, channel):
        """
        Download a channel with a given infohash and title.
        :param channel: The channel metadata ORM object.
        """

        metainfo = await self.download_manager.get_metainfo(bytes(
            channel.infohash),
                                                            timeout=60,
                                                            hops=0)
        if metainfo is None:
            # Timeout looking for the channel metainfo. Probably, there are no seeds.
            # TODO: count the number of tries we had with the channel, so we can stop trying eventually
            return
        try:
            if metainfo[b'info'][b'name'].decode('utf-8') != channel.dirname:
                # Malformed channel
                # TODO: stop trying to download this channel until it is updated with a new infohash
                return
        except (KeyError, TypeError):
            return

        dcfg = DownloadConfig(state_dir=self.state_dir)
        dcfg.set_dest_dir(self.mds.channels_dir)
        dcfg.set_channel_download(True)
        tdef = TorrentDef(metainfo=metainfo)

        download = self.download_manager.start_download(tdef=tdef,
                                                        config=dcfg,
                                                        hidden=True)
        try:
            await download.future_finished
        except CancelledError:
            pass
        else:
            self.channels_processing_queue[channel.infohash] = (
                PROCESS_CHANNEL_DIR, channel)
        return download