Beispiel #1
0
class AllDebridResolver(TorrentResolverBase):
    """
    Resolver for All Debrid
    """
    def __init__(self):
        super(AllDebridResolver, self).__init__()
        self.debrid_module = AllDebrid()
        self._source_normalization = (
            ("size", "size", lambda k: (k / 1024) / 1024),
            ("filename", ["release_title", "path"], None),
            ("id", "id", None),
            ("link", "link", None),
        )
        self.magnet_id = None

    def _fetch_source_files(self, torrent, item_information):
        self.magnet_id = self.debrid_module.upload_magnet(
            torrent['hash'])["magnets"][0]["id"]
        status = self.debrid_module.magnet_status(self.magnet_id)["magnets"]
        if status["status"] != "Ready":
            raise UnexpectedResponse(status)
        return status['links']

    def resolve_stream_url(self, file_info):
        """
        Convert provided source file into a link playable through debrid service
        :param file_info: Normalised information on source file
        :return: streamable link
        """
        return self.debrid_module.resolve_hoster(file_info["link"])

    def _do_post_processing(self, item_information, torrent):
        pass
class _AllDebridDownloader(_DebridDownloadBase):
    def __init__(self, source):
        super(_AllDebridDownloader, self).__init__(source)
        self.debrid_module = AllDebrid()
        self.available_files = []

    def _fetch_available_files(self):
        self.magnet_id = self.debrid_module.upload_magnet(self.source['hash'])["magnets"][0]["id"]
        status = self.debrid_module.magnet_status(self.magnet_id)['magnets']
        if status["status"] != "Ready":
            raise UnexpectedResponse(status)
        return [{'path': i['filename'], 'url': i['link']} for i in status['links']]

    def _get_single_item_info(self, source):
        return source

    def _resolve_file_url(self, file):
        return self.debrid_module.resolve_hoster(file[0]["url"])