| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# Copyright 2025 Mike Fährmann |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License version 2 as |
| 7 |
# published by the Free Software Foundation. |
| 8 |
|
| 9 |
"""Extractor for https://are.na/""" |
| 10 |
|
| 11 |
from .common import GalleryExtractor |
| 12 |
|
| 13 |
|
| 14 |
class ArenaChannelExtractor(GalleryExtractor): |
| 15 |
"""Extractor for are.na channels""" |
| 16 |
category = "arena" |
| 17 |
subcategory = "channel" |
| 18 |
root = "https://are.na" |
| 19 |
directory_fmt = ("{category}", "{user[full_name]} ({user[id]})", |
| 20 |
"{channel[title]} ({channel[id]})") |
| 21 |
filename_fmt = "{num:>03}{block[id]:? //}.{extension}" |
| 22 |
archive_fmt = "{channel[id]}/{block[id]}" |
| 23 |
referer = False |
| 24 |
pattern = r"(?:https?://)?(?:www\.)?are\.na/[^/?#]+/([^/?#]+)" |
| 25 |
example = "https://are.na/evan-collins-1522646491/cassette-futurism" |
| 26 |
|
| 27 |
def metadata(self, page): |
| 28 |
url = "https://api.are.na/v2/channels/" + self.groups[0] |
| 29 |
channel = self.request_json(url, headers=False) |
| 30 |
|
| 31 |
channel["date"] = self.parse_datetime_iso( |
| 32 |
channel["created_at"]) |
| 33 |
channel["date_updated"] = self.parse_datetime_iso( |
| 34 |
channel["updated_at"]) |
| 35 |
channel.pop("contents", None) |
| 36 |
|
| 37 |
return { |
| 38 |
"count" : channel.get("length"), |
| 39 |
"user" : channel.pop("user", None), |
| 40 |
"owner" : channel.pop("owner", None), |
| 41 |
"channel": channel, |
| 42 |
} |
| 43 |
|
| 44 |
def images(self, page): |
| 45 |
api = f"https://api.are.na/v2/channels/{self.groups[0]}/contents" |
| 46 |
limit = 100 |
| 47 |
params = {"page": 1, "per": limit} |
| 48 |
|
| 49 |
while True: |
| 50 |
data = self.request_json(api, params=params, headers=False) |
| 51 |
|
| 52 |
contents = data.get("contents") |
| 53 |
if not contents: |
| 54 |
return |
| 55 |
|
| 56 |
for block in contents: |
| 57 |
url = None |
| 58 |
|
| 59 |
# Attachments (e.g., PDFs, files) |
| 60 |
if attachment := block.get("attachment"): |
| 61 |
url = attachment.get("url") |
| 62 |
|
| 63 |
# Images |
| 64 |
elif image := block.get("image"): |
| 65 |
# Prefer original image |
| 66 |
if original := image.get("original"): |
| 67 |
url = original.get("url") |
| 68 |
# Fallback to display/large image if present |
| 69 |
elif display := image.get("display"): |
| 70 |
url = display.get("url") |
| 71 |
elif large := image.get("large"): |
| 72 |
url = large.get("url") |
| 73 |
|
| 74 |
# Some Links/Channels may not have downloadable media |
| 75 |
if not url: |
| 76 |
continue |
| 77 |
|
| 78 |
block["date"] = self.parse_datetime_iso( |
| 79 |
block["created_at"]) |
| 80 |
block["date_updated"] = self.parse_datetime_iso( |
| 81 |
block["updated_at"]) |
| 82 |
|
| 83 |
yield url, { |
| 84 |
"block" : block, |
| 85 |
"source": block.pop("source", None), |
| 86 |
} |
| 87 |
|
| 88 |
if len(contents) < limit: |
| 89 |
return |
| 90 |
params["page"] += 1 |