2019-03-05 22:33:37 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-09-11 16:30:55 +02:00
|
|
|
# Copyright 2019-2023 Mike Fährmann
|
2019-03-05 22:33:37 +01:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
|
|
|
|
"""Extractors for Shopify instances"""
|
|
|
|
|
2021-01-27 23:43:14 +01:00
|
|
|
from .common import BaseExtractor, Message
|
2019-03-07 22:55:26 +01:00
|
|
|
from .. import text
|
2019-03-05 22:33:37 +01:00
|
|
|
|
|
|
|
|
2021-01-27 23:43:14 +01:00
|
|
|
class ShopifyExtractor(BaseExtractor):
|
2019-03-06 09:16:27 +01:00
|
|
|
"""Base class for Shopify extractors"""
|
2019-03-05 22:33:37 +01:00
|
|
|
basecategory = "shopify"
|
|
|
|
filename_fmt = "{product[title]}_{num:>02}_{id}.{extension}"
|
|
|
|
archive_fmt = "{id}"
|
|
|
|
|
|
|
|
def __init__(self, match):
|
2021-01-27 23:43:14 +01:00
|
|
|
BaseExtractor.__init__(self, match)
|
|
|
|
self.item_url = self.root + match.group(match.lastindex)
|
2019-03-07 15:31:15 +01:00
|
|
|
|
2019-03-05 22:33:37 +01:00
|
|
|
def items(self):
|
|
|
|
data = self.metadata()
|
|
|
|
yield Message.Directory, data
|
|
|
|
|
2021-08-28 18:23:22 +02:00
|
|
|
for product in self.products():
|
2019-03-05 22:33:37 +01:00
|
|
|
for num, image in enumerate(product.pop("images"), 1):
|
|
|
|
text.nameext_from_url(image["src"], image)
|
|
|
|
image.update(data)
|
|
|
|
image["product"] = product
|
|
|
|
image["num"] = num
|
|
|
|
yield Message.Url, image["src"], image
|
|
|
|
|
|
|
|
def metadata(self):
|
|
|
|
"""Return general metadata"""
|
|
|
|
return {}
|
|
|
|
|
|
|
|
def products(self):
|
|
|
|
"""Return an iterable with all relevant product URLs"""
|
|
|
|
|
|
|
|
|
2021-01-27 23:43:14 +01:00
|
|
|
BASE_PATTERN = ShopifyExtractor.update({
|
2022-05-10 15:49:36 +02:00
|
|
|
"chelseacrew": {
|
|
|
|
"root": "https://chelseacrew.com",
|
|
|
|
"pattern": r"(?:www\.)?chelseacrew\.com",
|
|
|
|
},
|
2021-01-27 23:43:14 +01:00
|
|
|
"fashionnova": {
|
|
|
|
"root": "https://www.fashionnova.com",
|
|
|
|
"pattern": r"(?:www\.)?fashionnova\.com",
|
|
|
|
},
|
2022-05-10 15:49:36 +02:00
|
|
|
"loungeunderwear": {
|
|
|
|
"root": "https://loungeunderwear.com",
|
|
|
|
"pattern": r"(?:[a-z]+\.)?loungeunderwear\.com",
|
|
|
|
},
|
|
|
|
"michaelscameras": {
|
|
|
|
"root": "https://michaels.com.au",
|
|
|
|
"pattern": r"michaels\.com\.au",
|
|
|
|
},
|
|
|
|
"modcloth": {
|
|
|
|
"root": "https://modcloth.com",
|
|
|
|
"pattern": r"modcloth\.com",
|
|
|
|
},
|
2023-01-31 19:54:41 +01:00
|
|
|
"ohpolly": {
|
|
|
|
"root": "https://www.ohpolly.com",
|
|
|
|
"pattern": r"(?:www\.)?ohpolly\.com",
|
|
|
|
},
|
2021-04-13 03:05:23 +02:00
|
|
|
"omgmiamiswimwear": {
|
2021-08-28 18:34:12 +02:00
|
|
|
"root": "https://www.omgmiamiswimwear.com",
|
2022-05-09 22:20:09 +02:00
|
|
|
"pattern": r"(?:www\.)?omgmiamiswimwear\.com",
|
2021-08-28 18:34:12 +02:00
|
|
|
},
|
2022-05-10 15:49:36 +02:00
|
|
|
"pinupgirlclothing": {
|
|
|
|
"root": "https://pinupgirlclothing.com",
|
|
|
|
"pattern": r"pinupgirlclothing\.com",
|
|
|
|
},
|
|
|
|
"raidlondon": {
|
|
|
|
"root": "https://www.raidlondon.com",
|
|
|
|
"pattern": r"(?:www\.)?raidlondon\.com",
|
|
|
|
},
|
|
|
|
"unique-vintage": {
|
|
|
|
"root": "https://www.unique-vintage.com",
|
|
|
|
"pattern": r"(?:www\.)?unique\-vintage\.com",
|
|
|
|
},
|
2021-08-28 18:34:12 +02:00
|
|
|
"windsorstore": {
|
|
|
|
"root": "https://www.windsorstore.com",
|
2022-05-09 22:20:09 +02:00
|
|
|
"pattern": r"(?:www\.)?windsorstore\.com",
|
2021-04-13 03:05:23 +02:00
|
|
|
},
|
2021-01-27 23:43:14 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2019-03-05 22:33:37 +01:00
|
|
|
class ShopifyCollectionExtractor(ShopifyExtractor):
|
|
|
|
"""Base class for collection extractors for Shopify based sites"""
|
|
|
|
subcategory = "collection"
|
|
|
|
directory_fmt = ("{category}", "{collection[title]}")
|
2021-01-27 23:43:14 +01:00
|
|
|
pattern = BASE_PATTERN + r"(/collections/[\w-]+)/?(?:$|[?#])"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://www.fashionnova.com/collections/TITLE"
|
2019-03-05 22:33:37 +01:00
|
|
|
|
|
|
|
def metadata(self):
|
|
|
|
return self.request(self.item_url + ".json").json()
|
|
|
|
|
|
|
|
def products(self):
|
2021-08-28 18:23:22 +02:00
|
|
|
url = self.item_url + "/products.json"
|
2023-04-03 08:49:09 +02:00
|
|
|
params = {"page": 1}
|
2021-08-28 18:23:22 +02:00
|
|
|
|
2023-04-03 08:49:09 +02:00
|
|
|
while True:
|
|
|
|
data = self.request(url, params=params).json()["products"]
|
|
|
|
if not data:
|
2021-08-28 18:23:22 +02:00
|
|
|
return
|
2023-04-03 08:49:09 +02:00
|
|
|
yield from data
|
|
|
|
params["page"] += 1
|
2019-03-05 22:33:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ShopifyProductExtractor(ShopifyExtractor):
|
|
|
|
"""Base class for product extractors for Shopify based sites"""
|
|
|
|
subcategory = "product"
|
|
|
|
directory_fmt = ("{category}", "Products")
|
2021-01-27 23:43:14 +01:00
|
|
|
pattern = BASE_PATTERN + r"((?:/collections/[\w-]+)?/products/[\w-]+)"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://www.fashionnova.com/collections/TITLE/products/NAME"
|
2019-03-05 22:33:37 +01:00
|
|
|
|
|
|
|
def products(self):
|
2021-08-28 18:23:22 +02:00
|
|
|
product = self.request(self.item_url + ".json").json()["product"]
|
|
|
|
del product["image"]
|
|
|
|
return (product,)
|