Unable To Rename Downloaded Images Through Pipelines Without The Usage Of Item.py
I've created a script using python's scrapy module to download and rename movie images from multiple pages out of a torrent site and store them in a desktop folder. When it is abou
Solution 1:
You need to subclass the original ImagesPipeline
:
from scrapy.pipelines.images import ImagesPipeline
classYifyPipeline(ImagesPipeline):
deffile_path(self, request, response=None, info=None):
image_name = request.url.split('/')[-1]
return image_name
And then refer to it in your settings:
custom_settings = {
'ITEM_PIPELINES': {'my_project.pipelines.YifyPipeline': 1},
}
But be aware that a simple "use the exact filename" idea will cause issues when different files have the same name, unless you add a unique folder structure or an additional component to the filename. That's one reason checksums-based filenames are used by default. Refer to the original file_path
, in case you want to include some of the original logic to prevent that.
Post a Comment for "Unable To Rename Downloaded Images Through Pipelines Without The Usage Of Item.py"