2018-07-19 18:56:45 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2022-09-23 13:03:33 +02:00
|
|
|
# Copyright 2018-2022 Mike Fährmann
|
2018-07-19 18:56:45 +02: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.
|
|
|
|
|
|
|
|
"""Extract images from https://www.myportfolio.com/"""
|
|
|
|
|
|
|
|
from .common import Extractor, Message
|
2020-07-27 16:15:24 +02:00
|
|
|
from .. import text, exception
|
2018-07-19 18:56:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
class MyportfolioGalleryExtractor(Extractor):
|
|
|
|
"""Extractor for an image gallery on www.myportfolio.com"""
|
|
|
|
category = "myportfolio"
|
|
|
|
subcategory = "gallery"
|
2019-02-08 13:45:40 +01:00
|
|
|
directory_fmt = ("{category}", "{user}", "{title}")
|
2018-07-19 18:56:45 +02:00
|
|
|
filename_fmt = "{num:>02}.{extension}"
|
2019-02-14 16:07:17 +01:00
|
|
|
archive_fmt = "{user}_{filename}"
|
2019-03-06 17:20:24 +01:00
|
|
|
pattern = (r"(?:myportfolio:(?:https?://)?([^/]+)|"
|
2021-12-29 22:39:29 +01:00
|
|
|
r"(?:https?://)?([\w-]+\.myportfolio\.com))"
|
|
|
|
r"(/[^/?&#]+)?")
|
2019-02-08 13:45:40 +01:00
|
|
|
test = (
|
2020-04-08 21:08:05 +02:00
|
|
|
("https://andrewling.myportfolio.com/volvo-xc-90-hybrid", {
|
|
|
|
"url": "acea0690c76db0e5cf267648cefd86e921bc3499",
|
|
|
|
"keyword": "6ac6befe2ee0af921d24cf1dd4a4ed71be06db6d",
|
2018-07-19 18:56:45 +02:00
|
|
|
}),
|
2020-04-08 21:08:05 +02:00
|
|
|
("https://andrewling.myportfolio.com/", {
|
2020-10-22 23:12:59 +02:00
|
|
|
"pattern": r"https://andrewling\.myportfolio\.com/[^/?#+]+$",
|
2020-04-08 21:08:05 +02:00
|
|
|
"count": ">= 6",
|
2019-03-06 17:20:24 +01:00
|
|
|
}),
|
2020-04-08 21:08:05 +02:00
|
|
|
("https://stevenilousphotography.myportfolio.com/society", {
|
2020-07-27 16:15:24 +02:00
|
|
|
"exception": exception.NotFoundError,
|
2020-04-08 21:08:05 +02:00
|
|
|
}),
|
|
|
|
# custom domain
|
2018-07-19 18:56:45 +02:00
|
|
|
("myportfolio:https://tooco.com.ar/6-of-diamonds-paradise-bird", {
|
|
|
|
"count": 3,
|
|
|
|
}),
|
2019-03-06 17:20:24 +01:00
|
|
|
("myportfolio:https://tooco.com.ar/", {
|
2020-04-08 21:08:05 +02:00
|
|
|
"pattern": pattern,
|
2019-03-06 17:20:24 +01:00
|
|
|
"count": ">= 40",
|
|
|
|
}),
|
2019-02-08 13:45:40 +01:00
|
|
|
)
|
2018-07-19 18:56:45 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
Extractor.__init__(self, match)
|
2019-03-06 17:20:24 +01:00
|
|
|
domain1, domain2, self.path = match.groups()
|
|
|
|
self.domain = domain1 or domain2
|
|
|
|
self.prefix = "myportfolio:" if domain1 else ""
|
2018-07-19 18:56:45 +02:00
|
|
|
|
|
|
|
def items(self):
|
2019-03-06 17:20:24 +01:00
|
|
|
url = "https://" + self.domain + (self.path or "")
|
2021-04-24 01:22:57 +02:00
|
|
|
response = self.request(url)
|
|
|
|
if response.history and response.url.endswith(".adobe.com/missing"):
|
|
|
|
raise exception.NotFoundError()
|
|
|
|
page = response.text
|
2018-07-19 18:56:45 +02:00
|
|
|
|
2022-11-04 23:39:38 +01:00
|
|
|
projects = text.extr(
|
|
|
|
page, '<section class="project-covers', '</section>')
|
2019-03-06 17:20:24 +01:00
|
|
|
|
|
|
|
if projects:
|
|
|
|
data = {"_extractor": MyportfolioGalleryExtractor}
|
|
|
|
base = self.prefix + "https://" + self.domain
|
|
|
|
for path in text.extract_iter(projects, ' href="', '"'):
|
|
|
|
yield Message.Queue, base + path, data
|
|
|
|
else:
|
|
|
|
data = self.metadata(page)
|
|
|
|
imgs = self.images(page)
|
|
|
|
data["count"] = len(imgs)
|
|
|
|
yield Message.Directory, data
|
|
|
|
for data["num"], url in enumerate(imgs, 1):
|
|
|
|
yield Message.Url, url, text.nameext_from_url(url, data)
|
2018-07-19 18:56:45 +02:00
|
|
|
|
|
|
|
@staticmethod
|
2019-03-06 17:20:24 +01:00
|
|
|
def metadata(page):
|
|
|
|
"""Collect general image metadata"""
|
2018-07-19 18:56:45 +02:00
|
|
|
# og:title contains data as "<user> - <title>", but both
|
|
|
|
# <user> and <title> can contain a "-" as well, so we get the title
|
|
|
|
# from somewhere else and cut that amount from the og:title content
|
|
|
|
|
2021-04-24 01:22:57 +02:00
|
|
|
extr = text.extract_from(page)
|
|
|
|
user = extr('property="og:title" content="', '"') or \
|
|
|
|
extr('property=og:title content="', '"')
|
|
|
|
descr = extr('property="og:description" content="', '"') or \
|
|
|
|
extr('property=og:description content="', '"')
|
|
|
|
title = extr('<h1 ', '</h1>')
|
2018-07-19 18:56:45 +02:00
|
|
|
|
2020-04-08 21:08:05 +02:00
|
|
|
if title:
|
|
|
|
title = title.partition(">")[2]
|
|
|
|
user = user[:-len(title)-3]
|
2020-07-27 16:15:24 +02:00
|
|
|
elif user:
|
2020-04-08 21:08:05 +02:00
|
|
|
user, _, title = user.partition(" - ")
|
2020-07-27 16:15:24 +02:00
|
|
|
else:
|
|
|
|
raise exception.NotFoundError()
|
2018-07-19 18:56:45 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
"user": text.unescape(user),
|
|
|
|
"title": text.unescape(title),
|
2021-04-24 01:22:57 +02:00
|
|
|
"description": text.unescape(descr),
|
2018-07-19 18:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@staticmethod
|
2019-03-06 17:20:24 +01:00
|
|
|
def images(page):
|
2018-07-19 18:56:45 +02:00
|
|
|
"""Extract and return a list of all image-urls"""
|
2022-09-23 13:03:33 +02:00
|
|
|
return (
|
|
|
|
list(text.extract_iter(page, 'js-lightbox" data-src="', '"')) or
|
|
|
|
list(text.extract_iter(page, 'data-src="', '"'))
|
|
|
|
)
|