Я хочу загрузить видео в пользовательскую папку и имя. Я переопределил некоторые методы FilePiplines, но не достиг своей цели. Это мой код piplines.py.
from scrapy.http import Request
from scrapy.pipelines.files import FilesPipeline
import re
class Test2Pipeline(FilesPipeline):
CONVERTED_ORIGINAL = re.compile('^full/[0-9,a-f]+.mp4$')
# name information coming from the spider, in each item
# add this information to Requests() for individual VIDEOS downloads
# through "meta" dict
def get_media_requests(self, item, info):
print ("get_media_requests")
return [Request(x, meta={'file_name': item["file_name"],'file_save':item['file_save']})
for x in item.get(self.files_urls_field, [])]
def file_path(self, request, response, info):
print("file_path")
for key, file, buf, in super(Test2Pipeline, self).file_path(response, request, info):
if self.CONVERTED_ORIGINAL.match(key):
key = self.change_filename(key, response)
yield key, file, buf
def change_filename(self, key, response):
return "{}/{}.mp4".format(response.meta['file_name'][0], response.meta['file_save'][0])