Skip to content

Commit 6a117fa

Browse files
committed
Add Project Runeberg as a trusted book provider
This is mostly copy/pasting of existing support for Project Gutenberg, with a `s/[gG]utenberg/[rR]uneberg/` replacement, but some things have had additional adjustment (like the `download_options` HTML page). Fixes #9983
1 parent f1f4efd commit 6a117fa

File tree

8 files changed

+120
-1
lines changed

8 files changed

+120
-1
lines changed

openlibrary/book_providers.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,29 @@ def get_acquisitions(
366366
]
367367

368368

369+
class ProjectRunebergProvider(AbstractBookProvider):
370+
short_name = 'runeberg'
371+
identifier_key = 'project_runeberg'
372+
373+
def is_own_ocaid(self, ocaid: str) -> bool:
374+
"""Whether the ocaid (IA item ID) is an archive of content from Project Runeberg."""
375+
return 'runeberg' in ocaid
376+
377+
def get_acquisitions(
378+
self,
379+
edition: Edition,
380+
) -> list[Acquisition]:
381+
return [
382+
Acquisition(
383+
access='open-access',
384+
format='web',
385+
price=None,
386+
url=f'https://runeberg.org/{self.get_best_identifier(edition)}/',
387+
provider_name=self.short_name,
388+
)
389+
]
390+
391+
369392
class StandardEbooksProvider(AbstractBookProvider):
370393
short_name = 'standard_ebooks'
371394
identifier_key = 'standard_ebooks'
@@ -528,6 +551,7 @@ class WikisourceProvider(AbstractBookProvider):
528551
DirectProvider(),
529552
LibriVoxProvider(),
530553
ProjectGutenbergProvider(),
554+
ProjectRunebergProvider(),
531555
StandardEbooksProvider(),
532556
OpenStaxProvider(),
533557
CitaPressProvider(),

openlibrary/i18n/messages.pot

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ msgstr ""
554554
#: book_providers/gutenberg_read_button.html
555555
#: book_providers/librivox_read_button.html
556556
#: book_providers/openstax_read_button.html
557+
#: book_providers/runeberg_read_button.html
557558
#: book_providers/standard_ebooks_read_button.html
558559
#: book_providers/wikisource_read_button.html covers/author_photo.html
559560
#: covers/book_cover.html covers/book_cover_single_edition.html
@@ -844,6 +845,7 @@ msgstr ""
844845
#: book_providers/direct_read_button.html
845846
#: book_providers/gutenberg_read_button.html
846847
#: book_providers/openstax_read_button.html
848+
#: book_providers/runeberg_read_button.html
847849
#: book_providers/standard_ebooks_read_button.html
848850
#: book_providers/wikisource_read_button.html books/custom_carousel.html
849851
#: books/edit/edition.html books/show.html books/works-show.html trending.html
@@ -2848,6 +2850,7 @@ msgstr ""
28482850
#: book_providers/ia_download_options.html
28492851
#: book_providers/librivox_download_options.html
28502852
#: book_providers/openstax_download_options.html
2853+
#: book_providers/runeberg_download_options.html
28512854
#: book_providers/standard_ebooks_download_options.html
28522855
#: book_providers/wikisource_download_options.html
28532856
msgid "Download Options"
@@ -2878,6 +2881,7 @@ msgstr ""
28782881
#: book_providers/gutenberg_read_button.html
28792882
#: book_providers/librivox_read_button.html
28802883
#: book_providers/openstax_read_button.html
2884+
#: book_providers/runeberg_read_button.html
28812885
#: book_providers/standard_ebooks_read_button.html
28822886
#: book_providers/wikisource_read_button.html
28832887
#: check_ins/reading_goal_progress.html
@@ -2900,6 +2904,7 @@ msgid "Download an HTML from Project Gutenberg"
29002904
msgstr ""
29012905

29022906
#: book_providers/gutenberg_download_options.html
2907+
#: book_providers/runeberg_download_options.html
29032908
#: book_providers/standard_ebooks_download_options.html type/list/exports.html
29042909
msgid "HTML"
29052910
msgstr ""
@@ -3027,6 +3032,57 @@ msgid ""
30273032
"online."
30283033
msgstr ""
30293034

3035+
#: book_providers/runeberg_download_options.html
3036+
msgid "Download all scanned images from Project Runeberg"
3037+
msgstr ""
3038+
3039+
#: book_providers/runeberg_download_options.html
3040+
msgid "Scanned images"
3041+
msgstr ""
3042+
3043+
#: book_providers/runeberg_download_options.html
3044+
msgid "Download all color images from Project Runeberg"
3045+
msgstr ""
3046+
3047+
#: book_providers/runeberg_download_options.html
3048+
msgid "Color images"
3049+
msgstr ""
3050+
3051+
#: book_providers/runeberg_download_options.html
3052+
msgid "Download all HTML files from Project Runeberg"
3053+
msgstr ""
3054+
3055+
#: book_providers/runeberg_download_options.html
3056+
msgid "Download all text and index files from Project Runeberg"
3057+
msgstr ""
3058+
3059+
#: book_providers/runeberg_download_options.html
3060+
msgid "Text and index files"
3061+
msgstr ""
3062+
3063+
#: book_providers/runeberg_download_options.html
3064+
msgid "Download all OCR text from Project Runeberg"
3065+
msgstr ""
3066+
3067+
#: book_providers/runeberg_download_options.html
3068+
msgid "OCR text"
3069+
msgstr ""
3070+
3071+
#: book_providers/runeberg_download_options.html
3072+
msgid "More at Project Runeberg"
3073+
msgstr ""
3074+
3075+
#: book_providers/runeberg_read_button.html
3076+
msgid "Read eBook from Project Runeberg"
3077+
msgstr ""
3078+
3079+
#: book_providers/runeberg_read_button.html
3080+
msgid ""
3081+
"This book is available from <a href=\"https://runeberg.org/\">Project "
3082+
"Runeberg</a>. Project Runeberg is a trusted book provider of classic "
3083+
"Nordic (Scandinavian) literature in electronic form."
3084+
msgstr ""
3085+
30303086
#: book_providers/standard_ebooks_download_options.html
30313087
msgid "Download an HTML from Standard Ebooks"
30323088
msgstr ""

openlibrary/macros/RawQueryCarousel.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
$code:
2323
# Limit to just fields needed to render carousels
24-
params = { 'q': query, 'fields': 'key,title,subtitle,author_name,cover_i,ia,availability,id_project_gutenberg,id_librivox,id_standard_ebooks,id_openstax' }
24+
params = { 'q': query, 'fields': 'key,title,subtitle,author_name,cover_i,ia,availability,id_project_gutenberg,id_project_runeberg,id_librivox,id_standard_ebooks,id_openstax' }
2525
# Don't need fields in the search UI url, since they don't do anything there
2626
url = url or "/search?" + urlencode({'q': query})
2727
if has_fulltext_only:

openlibrary/plugins/worksearch/code.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ def get_doc(doc: SolrDocument):
388388
cover_edition_key=doc.get('cover_edition_key', None),
389389
languages=doc.get('language', []),
390390
id_project_gutenberg=doc.get('id_project_gutenberg', []),
391+
id_project_runeberg=doc.get('id_project_runeberg', []),
391392
id_librivox=doc.get('id_librivox', []),
392393
id_standard_ebooks=doc.get('id_standard_ebooks', []),
393394
id_openstax=doc.get('id_openstax', []),

openlibrary/plugins/worksearch/schemes/works.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class WorkSearchScheme(SearchScheme):
185185
# FIXME: These should be fetched from book_providers, but can't cause circular
186186
# dep
187187
'id_project_gutenberg',
188+
'id_project_runeberg',
188189
'id_librivox',
189190
'id_standard_ebooks',
190191
'id_openstax',

openlibrary/plugins/worksearch/tests/test_worksearch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def test_get_doc():
6262
'cover_edition_key': 'OL1111795M',
6363
'languages': [],
6464
'id_project_gutenberg': [],
65+
'id_project_runeberg': [],
6566
'id_librivox': [],
6667
'id_standard_ebooks': [],
6768
'id_openstax': [],
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
$def with(runeberg_id)
2+
3+
<hr>
4+
<div class="cta-section">
5+
<p class="cta-section-title">$_("Download Options")</p>
6+
<ul class="ebook-download-options">
7+
<li><a href="https://runeberg.org/$(runeberg_id).zip" title="$_('Download all scanned images from Project Runeberg')">$_("Scanned images")</a></li>
8+
<li><a href="https://runeberg.org/download.pl?mode=jpgzip&work=$runeberg_id" title="$_('Download all color images from Project Runeberg')">$_("Color images")</a></li>
9+
<li><a href="https://runeberg.org/download.pl?mode=html&work=$runeberg_id" title="$_('Download all HTML files from Project Runeberg')">$_("HTML")</a></li>
10+
<li><a href="https://runeberg.org/download.pl?mode=txtzip&work=$runeberg_id" title="$_('Download all text and index files from Project Runeberg')">$_("Text and index files")</a></li>
11+
<li><a href="https://runeberg.org/download.pl?mode=ocrtext&work=$runeberg_id" title="$_('Download all OCR text from Project Runeberg')">$_("OCR text")</a></li>
12+
<li><a href="https://runeberg.org/download.pl?mode=work&work=$runeberg_id">$_("More at Project Runeberg")</a></li>
13+
</ul>
14+
</div>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
$def with(runeberg_id, analytics_attr)
2+
3+
<div class="cta-button-group">
4+
<a
5+
href="https://runeberg.org/$runeberg_id/"
6+
title="$_('Read eBook from Project Runeberg')"
7+
class="cta-btn cta-btn--available cta-btn--read cta-btn--external cta-btn--runeberg"
8+
target="_blank"
9+
$:analytics_attr('Read')
10+
aria-haspopup="true"
11+
aria-controls="runeberg-toast"
12+
>$_('Read')</a>
13+
</div>
14+
15+
$if render_once('runeberg-toast'):
16+
<div class="toast toast--book-provider" data-toast-trigger=".cta-btn--runeberg" id="runeberg-toast" style="display:none">
17+
<div class="toast__body">
18+
$:_('This book is available from <a href="https://runeberg.org/">Project Runeberg</a>. Project Runeberg is a trusted book provider of classic Nordic (Scandinavian) literature in electronic form.')
19+
<a href="https://runeberg.org/admin/">$_("Learn more")</a>
20+
</div>
21+
<a class="toast__close">&times;<span class="shift">$_("Close")</span></a>
22+
</div>

0 commit comments

Comments
 (0)