zimscraperlib.zim.items
libzim Item helpers
Classes:
-
Item–libzim.writer.Item returning props for path/title/mimetype
-
StaticItem–scraperlib Item with auto contentProvider from
contentorfilepath -
URLItem–StaticItem to automatically fetch and feed an URL resource
Functions:
-
no_indexing_indexdata–IndexData asking libzim not to index this item
Item
Item(
path: str | None = None,
title: str | None = None,
mimetype: str | None = None,
hints: dict[Hint, int] | None = None,
**kwargs: Any,
)
Bases: Item
libzim.writer.Item returning props for path/title/mimetype
Methods:
-
get_hints– -
get_mimetype– -
get_path– -
get_title–
Attributes:
Source code in src/zimscraperlib/zim/items.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
should_index
property
should_index
get_hints
Source code in src/zimscraperlib/zim/items.py
60 61 | |
get_mimetype
get_mimetype() -> str
Source code in src/zimscraperlib/zim/items.py
57 58 | |
get_path
get_path() -> str
Source code in src/zimscraperlib/zim/items.py
51 52 | |
get_title
get_title() -> str
Source code in src/zimscraperlib/zim/items.py
54 55 | |
StaticItem
StaticItem(
content: str | bytes | None = None,
fileobj: IOBase | None = None,
filepath: Path | None = None,
path: str | None = None,
title: str | None = None,
mimetype: str | None = None,
hints: dict[Hint, int] | None = None,
index_data: IndexData | None = None,
*,
auto_index: bool = True,
**kwargs: Any,
)
Bases: Item
scraperlib Item with auto contentProvider from content or filepath
Sets a ref to itself on the File/String content providers so it outlives them
We need Item to survive its ContentProvider so that we can track lifecycle
more efficiently: now when the libzim destroys the CP, python will destroy
the Item and we can be notified that we're effectively through with our content
By default, content is automatically indexed (either by the libzim itself for
supported documents - text or html for now or by the python-scraperlib - only PDF
supported for now). If you do not want this, set auto_index to False to disable
both indexing (libzim and python-scraperlib).
It is also possible to pass index_data to configure custom indexing of the item.
If item title is not set by caller, it is automatically populated from index_data.
Methods:
Attributes:
-
get_indexdata(Callable[[], IndexData]) – -
should_index– -
title–
Source code in src/zimscraperlib/zim/items.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
should_index
property
should_index
title
instance-attribute
title = title
get_contentprovider
get_contentprovider() -> ContentProvider
Source code in src/zimscraperlib/zim/items.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
get_hints
Source code in src/zimscraperlib/zim/items.py
60 61 | |
get_mimetype
get_mimetype() -> str
Source code in src/zimscraperlib/zim/items.py
57 58 | |
get_path
get_path() -> str
Source code in src/zimscraperlib/zim/items.py
51 52 | |
get_title
get_title() -> str
Source code in src/zimscraperlib/zim/items.py
54 55 | |
URLItem
URLItem(
url: str,
path: str | None = None,
title: str | None = None,
mimetype: str | None = None,
hints: dict[Hint, int] | None = None,
*,
use_disk: bool | None = None,
**kwargs: Any,
)
Bases: StaticItem
StaticItem to automatically fetch and feed an URL resource
Appropriate for retrieving/bundling static assets that you don't need to post-process.
Uses URL's path as zim path if none provided
Keeps single in-memory copy of content for HTML resources (indexed)
Works transparently on servers returning a Content-Length header (most)
Swaps a copy of the content either in memory or on disk (use_disk=True)
in case the content size could not be retrieved from headers.
Use tmp_dir to point location of that temp file.
Methods:
-
download_for_size–Download URL to a temp file and return its tempfile and size
-
get_contentprovider– -
get_hints– -
get_mimetype– -
get_path– -
get_title–
Attributes:
-
fileobj– -
filepath– -
get_indexdata(Callable[[], IndexData]) – -
should_index– -
size– -
title– -
url–
Source code in src/zimscraperlib/zim/items.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
filepath
instance-attribute
filepath = target
should_index
property
should_index
title
instance-attribute
title = title
download_for_size
staticmethod
download_for_size(
url: ParseResult,
tmp_dir: Path | None = None,
*,
on_disk: bool,
)
Download URL to a temp file and return its tempfile and size
Source code in src/zimscraperlib/zim/items.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
get_contentprovider
get_contentprovider()
Source code in src/zimscraperlib/zim/items.py
299 300 301 302 303 304 305 | |
get_hints
Source code in src/zimscraperlib/zim/items.py
60 61 | |
get_mimetype
get_mimetype() -> str
Source code in src/zimscraperlib/zim/items.py
292 293 294 295 296 297 | |
get_path
get_path() -> str
Source code in src/zimscraperlib/zim/items.py
286 287 | |
get_title
get_title() -> str
Source code in src/zimscraperlib/zim/items.py
289 290 | |
no_indexing_indexdata
no_indexing_indexdata() -> IndexData
IndexData asking libzim not to index this item
Source code in src/zimscraperlib/zim/items.py
64 65 66 | |