MCPcopy Index your code
hub / github.com/karpathy/reader3 / extract_metadata_robust

Function extract_metadata_robust

reader3.py:149–170  ·  view source on GitHub ↗

Extracts metadata handling both single and list values.

(book_obj)

Source from the content-addressed store, hash-verified

147
148
149def extract_metadata_robust(book_obj) -> BookMetadata:
150 """
151 Extracts metadata handling both single and list values.
152 """
153 def get_list(key):
154 data = book_obj.get_metadata('DC', key)
155 return [x[0] for x in data] if data else []
156
157 def get_one(key):
158 data = book_obj.get_metadata('DC', key)
159 return data[0][0] if data else None
160
161 return BookMetadata(
162 title=get_one('title') or "Untitled",
163 language=get_one('language') or "en",
164 authors=get_list('creator'),
165 description=get_one('description'),
166 publisher=get_one('publisher'),
167 date=get_one('date'),
168 identifiers=get_list('identifier'),
169 subjects=get_list('subject')
170 )
171
172
173# --- Main Conversion Logic ---

Callers 1

process_epubFunction · 0.85

Calls 3

BookMetadataClass · 0.85
get_oneFunction · 0.85
get_listFunction · 0.85

Tested by

no test coverage detected