1 # -*- coding: utf-8 -*-
2 from librarian import RDFNS, DCNS
4 FORMATS = ('PDF', 'HTML', 'TXT', 'EPUB', 'MOBI')
6 FORMATS_WITH_CHILDREN = ('PDF', 'EPUB', 'MOBI')
17 PRODUCT_FORM_DETAILS = {
26 'E105': ('html', 'text/html'),
27 'E107': ('pdf', 'application/pdf'),
28 'E112': ('txt', 'text/plain'),
29 'E101': ('epub', 'application/epub+zip'),
30 'E127': ('mobi', 'application/x-mobipocket-ebook'),
33 VOLUME_SEPARATORS = (u'. część ', u', część ', u', tom ', u'. der tragödie ')
36 def is_institution(name):
37 return name.startswith(u'Zgromadzenie Ogólne')
40 def get_volume(title):
41 for volume_separator in VOLUME_SEPARATORS:
42 if volume_separator in title.lower():
43 vol_idx = title.lower().index(volume_separator)
44 stripped = title[:vol_idx]
45 vol_name = title[vol_idx + 2:]
46 return stripped, vol_name
50 def dc_values(desc, tag):
51 return [e.text.strip() for e in desc.findall('.//' + DCNS(tag))]
54 def isbn_data(wldoc, file_format=None):
55 desc = wldoc.edoc.find('.//' + RDFNS('Description'))
56 title, volume = get_volume(dc_values(desc, 'title')[0])
57 author = '; '.join(author.strip() for author in dc_values(desc, 'creator'))
59 'imprint': '; '.join(dc_values(desc, 'publisher')),
63 'part_number': volume,
64 'name': author if not is_institution(author) else '',
65 'corporate_name': author if is_institution(author) else '',
66 'edition_type': 'DGO',
67 'edition_number': '1',
68 'language': dc_values(desc, 'language')[0],
69 'dc_slug': wldoc.book_info.url.slug,
72 data['product_form'] = PRODUCT_FORMS[file_format]
73 data['product_form_detail'] = PRODUCT_FORM_DETAILS[file_format]
76 has_children = len(dc_values(desc, 'relation.hasPart')) > 0
77 data['formats'] = FORMATS_WITH_CHILDREN if has_children else FORMATS