示例#1
0
    def download_channel(self, channel):
        """
        Download a channel with a given infohash and title.
        :param channel: The channel metadata ORM object.
        """
        dcfg = DownloadStartupConfig()
        dcfg.set_dest_dir(self.session.lm.mds.channels_dir)
        dcfg.set_channel_download(True)
        tdef = TorrentDefNoMetainfo(infohash=str(channel.infohash),
                                    name=channel.dir_name)
        download = self.session.start_download_from_tdef(tdef, dcfg)

        def on_channel_download_finished(dl):
            channel_dirname = os.path.join(self.session.lm.mds.channels_dir,
                                           dl.get_def().get_name())
            self.session.lm.mds.process_channel_dir(channel_dirname,
                                                    channel.public_key,
                                                    external_thread=True)
            self.session.lm.mds._db.disconnect()

        def _on_failure(failure):
            self._logger.error(
                "Error when processing channel dir download: %s", failure)

        finished_deferred = download.finished_deferred.addCallback(
            lambda dl: deferToThread(on_channel_download_finished, dl))
        finished_deferred.addErrback(_on_failure)

        return download, finished_deferred
示例#2
0
 def updated_my_channel(self, new_torrent_path):
     """
     Notify the core that we updated our channel.
     :param new_torrent_path: path to the new torrent file
     """
     # Start the new download
     tdef = TorrentDef.load(new_torrent_path)
     dcfg = DownloadStartupConfig()
     dcfg.set_dest_dir(self.mds.channels_dir)
     dcfg.set_channel_download(True)
     self.add(tdef, dcfg)
示例#3
0
 def updated_my_channel(self, tdef):
     """
     Notify the core that we updated our channel.
     """
     with db_session:
         my_channel = self.session.lm.mds.ChannelMetadata.get_my_channel()
     if my_channel and my_channel.status == COMMITTED and not self.session.has_download(str(my_channel.infohash)):
         dcfg = DownloadStartupConfig()
         dcfg.set_dest_dir(self.session.lm.mds.channels_dir)
         dcfg.set_channel_download(True)
         self.session.lm.add(tdef, dcfg)
示例#4
0
 def updated_my_channel(self, tdef):
     """
     Notify the core that we updated our channel.
     """
     with db_session:
         my_channel = self.session.lm.mds.ChannelMetadata.get_my_channel()
     if my_channel and my_channel.status == COMMITTED and not self.session.has_download(
             str(my_channel.infohash)):
         dcfg = DownloadStartupConfig()
         dcfg.set_dest_dir(self.session.lm.mds.channels_dir)
         dcfg.set_channel_download(True)
         self.session.lm.add(tdef, dcfg)
示例#5
0
    def download_channel(self, channel):
        """
        Download a channel with a given infohash and title.
        :param channel: The channel metadata ORM object.
        """
        finished_deferred = Deferred()

        dcfg = DownloadStartupConfig()
        dcfg.set_dest_dir(self.mds.channels_dir)
        dcfg.set_channel_download(True)
        tdef = TorrentDefNoMetainfo(infohash=str(channel.infohash), name=channel.title)
        download = self.session.start_download_from_tdef(tdef, dcfg)
        channel_id = channel.public_key
        download.finished_callback = lambda dl: self.on_channel_download_finished(dl, channel_id, finished_deferred)
        return download, finished_deferred
示例#6
0
    def download_channel(self, channel):
        """
        Download a channel with a given infohash and title.
        :param channel: The channel metadata ORM object.
        """
        dcfg = DownloadStartupConfig()
        dcfg.set_dest_dir(self.session.lm.mds.channels_dir)
        dcfg.set_channel_download(True)
        tdef = TorrentDefNoMetainfo(infohash=str(channel.infohash), name=channel.dir_name)
        download = self.session.start_download_from_tdef(tdef, dcfg)

        def on_channel_download_finished(dl):
            channel_dirname = os.path.join(self.session.lm.mds.channels_dir, dl.get_def().get_name())
            self.session.lm.mds.process_channel_dir(channel_dirname, channel.public_key, external_thread=True)
            self.session.lm.mds._db.disconnect()

        def _on_failure(failure):
            self._logger.error("Error when processing channel dir download: %s", failure)

        finished_deferred = download.finished_deferred.addCallback(
            lambda dl: deferToThread(on_channel_download_finished, dl))
        finished_deferred.addErrback(_on_failure)

        return download, finished_deferred