| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# Copyright 2026 Mike Fährmann & varenc |
| 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://nuremberg.law.harvard.edu/""" |
| 10 |
|
| 11 |
from .common import GalleryExtractor |
| 12 |
from .. import text |
| 13 |
|
| 14 |
|
| 15 |
class HarvardlawnurembergDocumentExtractor(GalleryExtractor): |
| 16 |
"""Extractor for documents on nuremberg.law.harvard.edu""" |
| 17 |
category = "harvardlawnuremberg" |
| 18 |
subcategory = "document" |
| 19 |
root = "https://nuremberg.law.harvard.edu" |
| 20 |
directory_fmt = ("{category}", "{document_id} {slug}") |
| 21 |
filename_fmt = "{document_id}_{num:>03}.{extension}" |
| 22 |
archive_fmt = "{document_id}_{num}" |
| 23 |
pattern = (r"(?:https?://)?nuremberg\.law\.harvard\.edu" |
| 24 |
r"/documents/(\d+)-([^/?#]+)") |
| 25 |
example = "https://nuremberg.law.harvard.edu/documents/12345-SLUG" |
| 26 |
|
| 27 |
def __init__(self, match): |
| 28 |
self.document_id = match[1] |
| 29 |
self.slug = match[2] |
| 30 |
|
| 31 |
# use '?mode=image' to force image mode, |
| 32 |
# even though its the default, to override |
| 33 |
# a possible '?mode=text' in the input URL |
| 34 |
url = (f"{self.root}/documents" |
| 35 |
f"/{self.document_id}-{self.slug}?mode=image") |
| 36 |
GalleryExtractor.__init__(self, match, url) |
| 37 |
|
| 38 |
def metadata(self, page): |
| 39 |
return { |
| 40 |
"document_id": self.document_id, |
| 41 |
"slug" : self.slug, |
| 42 |
"title" : text.unescape( |
| 43 |
text.extr(page, 'aria-level="1">', "</h1>") |
| 44 |
), |
| 45 |
} |
| 46 |
|
| 47 |
def images(self, page): |
| 48 |
results = [] |
| 49 |
for div in text.extract_iter(page, '<div data-screen-url="', "</div>"): |
| 50 |
extr = text.extract_from(div) |
| 51 |
results.append(( |
| 52 |
extr('data-full-url="', '"'), |
| 53 |
{ |
| 54 |
"width" : text.parse_int(extr('data-width="', '"')), |
| 55 |
"height": text.parse_int(extr('data-height="', '"')), |
| 56 |
}, |
| 57 |
)) |
| 58 |
return results |