Path: blob/master/gallery_dl/extractor/desktopography.py
5399 views
# -*- coding: utf-8 -*-12# This program is free software; you can redistribute it and/or modify3# it under the terms of the GNU General Public License version 2 as4# published by the Free Software Foundation.56"""Extractors for https://desktopography.net/"""78from .common import Extractor, Message9from .. import text1011BASE_PATTERN = r"(?:https?://)?desktopography\.net"121314class DesktopographyExtractor(Extractor):15"""Base class for desktopography extractors"""16category = "desktopography"17archive_fmt = "{filename}"18root = "https://desktopography.net"192021class DesktopographySiteExtractor(DesktopographyExtractor):22"""Extractor for all desktopography exhibitions """23subcategory = "site"24pattern = BASE_PATTERN + r"/$"25example = "https://desktopography.net/"2627def items(self):28page = self.request(self.root).text29data = {"_extractor": DesktopographyExhibitionExtractor}3031for exhibition_year in text.extract_iter(32page,33'<a href="https://desktopography.net/exhibition-',34'/">'):3536url = self.root + "/exhibition-" + exhibition_year + "/"37yield Message.Queue, url, data383940class DesktopographyExhibitionExtractor(DesktopographyExtractor):41"""Extractor for a yearly desktopography exhibition"""42subcategory = "exhibition"43pattern = BASE_PATTERN + r"/exhibition-([^/?#]+)/"44example = "https://desktopography.net/exhibition-2020/"4546def __init__(self, match):47DesktopographyExtractor.__init__(self, match)48self.year = match[1]4950def items(self):51url = f"{self.root}/exhibition-{self.year}/"52base_entry_url = "https://desktopography.net/portfolios/"53page = self.request(url).text5455data = {56"_extractor": DesktopographyEntryExtractor,57"year": self.year,58}5960for entry_url in text.extract_iter(61page,62'<a class="overlay-background" href="' + base_entry_url,63'">'):6465url = base_entry_url + entry_url66yield Message.Queue, url, data676869class DesktopographyEntryExtractor(DesktopographyExtractor):70"""Extractor for all resolutions of a desktopography wallpaper"""71subcategory = "entry"72pattern = BASE_PATTERN + r"/portfolios/([\w-]+)"73example = "https://desktopography.net/portfolios/NAME/"7475def __init__(self, match):76DesktopographyExtractor.__init__(self, match)77self.entry = match[1]7879def items(self):80url = f"{self.root}/portfolios/{self.entry}"81page = self.request(url).text8283entry_data = {"entry": self.entry}84yield Message.Directory, entry_data8586for image_data in text.extract_iter(87page,88'<a target="_blank" href="https://desktopography.net',89'">'):9091path, _, filename = image_data.partition(92'" class="wallpaper-button" download="')93text.nameext_from_url(filename, entry_data)94yield Message.Url, self.root + path, entry_data959697