1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
4 from librarian import RDFNS, DCNS
7 FORMATS = ('PDF', 'HTML', 'TXT', 'EPUB', 'MOBI')
9 FORMATS_WITH_CHILDREN = ('PDF', 'EPUB', 'MOBI')
20 PRODUCT_FORM_DETAILS = {
29 'E105': ('html', 'text/html'),
30 'E107': ('pdf', 'application/pdf'),
31 'E112': ('txt', 'text/plain'),
32 'E101': ('epub', 'application/epub+zip'),
33 'E127': ('mobi', 'application/x-mobipocket-ebook'),
36 VOLUME_SEPARATORS = ('. część ', ', część ', ', tom ', '. der tragödie ')
39 def is_institution(name):
40 return name.startswith('Zgromadzenie Ogólne')
43 def get_volume(title):
44 for volume_separator in VOLUME_SEPARATORS:
45 if volume_separator in title.lower():
46 vol_idx = title.lower().index(volume_separator)
47 stripped = title[:vol_idx]
48 vol_name = title[vol_idx + 2:]
49 return stripped, vol_name
53 def dc_values(desc, tag):
54 return [e.text.strip() for e in desc.findall('.//' + DCNS(tag))]
57 def isbn_data(wldoc, file_format=None):
58 desc = wldoc.edoc.find('.//' + RDFNS('Description'))
59 title, volume = get_volume(dc_values(desc, 'title')[0])
60 author = '; '.join(author.strip() for author in dc_values(desc, 'creator'))
62 'imprint': '; '.join(dc_values(desc, 'publisher')),
66 'part_number': volume,
67 'name': author if not is_institution(author) else '',
68 'corporate_name': author if is_institution(author) else '',
69 'edition_type': 'DGO',
70 'edition_number': '1',
71 'language': dc_values(desc, 'language')[0],
72 'dc_slug': wldoc.book_info.url.slug,
75 data['product_form'] = PRODUCT_FORMS[file_format]
76 data['product_form_detail'] = PRODUCT_FORM_DETAILS[file_format]
79 has_children = len(dc_values(desc, 'relation.hasPart')) > 0
80 data['formats'] = FORMATS_WITH_CHILDREN if has_children else FORMATS