本文整理汇总了Python中calibre.ebooks.metadata.opf2.OPF.get方法的典型用法代码示例。如果您正苦于以下问题:Python OPF.get方法的具体用法?Python OPF.get怎么用?Python OPF.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calibre.ebooks.metadata.opf2.OPF
的用法示例。
在下文中一共展示了OPF.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_dir
# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPF [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPF import get [as 别名]
def process_dir(self, dirpath, filenames, book_id):
book_id = int(book_id)
formats = filter(self.is_ebook_file, filenames)
fmts = [os.path.splitext(x)[1][1:].upper() for x in formats]
sizes = [os.path.getsize(os.path.join(dirpath, x)) for x in formats]
names = [os.path.splitext(x)[0] for x in formats]
opf = os.path.join(dirpath, 'metadata.opf')
mi = OPF(opf, basedir=dirpath).to_book_metadata()
timestamp = os.path.getmtime(opf)
path = os.path.relpath(dirpath, self.src_library_path).replace(os.sep,
'/')
if int(mi.application_id) == book_id:
self.books.append({
'mi': mi,
'timestamp': timestamp,
'formats': list(zip(fmts, sizes, names)),
'id': book_id,
'dirpath': dirpath,
'path': path,
})
else:
self.mismatched_dirs.append(dirpath)
alm = mi.get('author_link_map', {})
for author, link in alm.iteritems():
existing_link, timestamp = self.authors_links.get(author, (None, None))
if existing_link is None or existing_link != link and timestamp < mi.timestamp:
self.authors_links[author] = (link, mi.timestamp)
示例2: test_against_opf2
# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPF [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPF import get [as 别名]
#.........这里部分代码省略.........
"field", "column": "value",
"is_csp": false, "name": "My Enum",
"rec_index": 28, "#extra#": null,
"colnum": 6, "is_multiple2": {},
"category_sort": "value", "display":
{"enum_colors": [], "enum_values":
["One", "Two", "Three"],
"use_decorations": 0}, "search_terms":
["#myenum"], "is_editable": true,
"datatype": "enumeration", "link_column":
"value", "#value#": "Two",
"is_custom": true, "label": "myenum",
"table": "custom_column_6",
"is_multiple": null, "is_category": true}"/>
<meta name="calibre:user_metadata:#isbn" content="{"kind":
"field", "column": "value",
"is_csp": false, "name": "ISBN",
"rec_index": 27, "#extra#": null,
"colnum": 3, "is_multiple2": {},
"category_sort": "value", "display":
{"composite_template":
"{identifiers:select(isbn)}", "contains_html":
false, "use_decorations": 0, "composite_sort":
"text", "make_category": false},
"search_terms": ["#isbn"], "is_editable":
true, "datatype": "composite",
"link_column": "value", "#value#":
"", "is_custom": true, "label":
"isbn", "table": "custom_column_3",
"is_multiple": null, "is_category": false}"/>
<meta name="calibre:user_metadata:#authors" content="{"kind":
"field", "column": "value",
"is_csp": false, "name": "My Authors",
"rec_index": 22, "#extra#": null,
"colnum": 10, "is_multiple2":
{"ui_to_list": "&", "cache_to_list":
"|", "list_to_ui": " & "},
"category_sort": "value", "display":
{"is_names": true}, "search_terms":
["#authors"], "is_editable": true,
"datatype": "text", "link_column":
"value", "#value#": ["calibre, Kovid
Goyal"], "is_custom": true, "label":
"authors", "table": "custom_column_10",
"is_multiple": "|", "is_category":
true}"/>
<meta name="calibre:user_metadata:#date" content="{"kind":
"field", "column": "value",
"is_csp": false, "name": "My Date",
"rec_index": 24, "#extra#": null,
"colnum": 2, "is_multiple2": {},
"category_sort": "value", "display":
{"date_format": "dd-MM-yyyy",
"description": ""}, "search_terms":
["#date"], "is_editable": true,
"datatype": "datetime", "link_column":
"value", "#value#": {"__value__":
"2016-02-17T10:54:15+00:00", "__class__":
"datetime.datetime"}, "is_custom": true,
"label": "date", "table":
"custom_column_2", "is_multiple": null,
"is_category": false}"/>
</metadata><manifest><item href="start.html" media-type="text/html" id="m1"/></manifest><spine><itemref idref="m1"/></spine>
</package>''' # }}}
def compare_metadata(mi2, mi3):
self.ae(mi2.get_all_user_metadata(False), mi3.get_all_user_metadata(False))
for field in ALL_METADATA_FIELDS:
if field not in 'manifest spine':
v2, v3 = getattr(mi2, field, None), getattr(mi3, field, None)
self.ae(v2, v3, '%s: %r != %r' % (field, v2, v3))
mi2 = OPF(BytesIO(raw.encode('utf-8'))).to_book_metadata()
root = etree.fromstring(raw)
root.set('version', '3.0')
mi3, _, raster_cover, first_spine_item = read_metadata(root, return_extra_data=True)
self.assertIsNone(raster_cover)
self.ae('start.html', first_spine_item)
compare_metadata(mi2, mi3)
apply_metadata(root, mi3, force_identifiers=True)
nmi = read_metadata(root)
compare_metadata(mi3, nmi)
mi3.tags = []
mi3.set('#tags', [])
mi3.set('#number', 0)
mi3.set('#commetns', '')
apply_metadata(root, mi3, update_timestamp=True)
self.assertFalse(root.xpath('//*/@name'))
nmi = read_metadata(root)
self.assertEqual(mi2.tags, nmi.tags)
self.assertEqual(mi2.get('#tags'), nmi.get('#tags'))
self.assertEqual(mi2.get('#commetns'), nmi.get('#commetns'))
self.assertEqual(0, nmi.get('#number'))
apply_metadata(root, mi3, apply_null=True)
nmi = read_metadata(root)
self.assertFalse(nmi.tags)
self.assertFalse(nmi.get('#tags'))
self.assertFalse(nmi.get('#commetns'))
self.assertIsNone(apply_metadata(root, mi3, cover_data=b'x', cover_prefix='xxx', add_missing_cover=False))
self.ae('xxx/cover.jpg', apply_metadata(root, mi3, cover_data=b'x', cover_prefix='xxx'))