Exemple #1
0
    def download(cls, url) -> HttpResponse:
        """
        下载视频
        :param url:
        :return:
        """
        # 检查文件
        index = cls.index(url)
        file = store.find(vtype, index)
        if file is not None:
            return Service.stream(file, index)

        result = cls.fetch(url, model=1)
        if not result.is_success():
            return HttpResponseServerError(result.get_data())

        dheaders = download_headers.copy()
        dheaders['referer'] = result.ref

        res = http_utils.get(url=result.get_data(), header=dheaders)
        if http_utils.is_error(res):
            return HttpResponseServerError(str(res))

        store.save(vtype, res, index)
        res.close()

        file = store.find(vtype, index)
        return Service.stream(file, index)
Exemple #2
0
    def proxy_download(cls, vtype, url, header: dict, extra: str, mode=1) -> HttpResponse:
        # 检查文件
        index = cls.index(url)
        file, filename = store.find(vtype, index, extra)
        if file is not None:
            return Service.stream(file, filename)

        result = cls.fetch(url, mode=mode)
        if not result.is_success():
            return HttpResponseServerError(result.get_data())

        if mode == 1:
            header = header.copy()
            header['referer'] = result.ref

        if result.is_image():
            res = store.save_image(vtype, result.get_data(), index)
            if res is not None:
                return res
        else:
            res = http_utils.get(url=result.get_data(), header=header)
            if http_utils.is_error(res):
                return HttpResponseServerError(str(res))

            store.save(vtype, res, index, result.extra)
            res.close()

        file, filename = store.find(vtype, index, result.extra)
        return Service.stream(file, filename)