-
Notifications
You must be signed in to change notification settings - Fork 78
Images
Steve edited this page Jan 19, 2018
·
16 revisions
A page's image can come from the pageimage or thumbnail via get_query()
, from an Infobox (via get_parse()
), from Wikidata Property:P18 (via get_wikidata()
), or from the RESTBase image or thumb (via get_rest()
).
Image info is fetched by get_imageinfo()
automatically, and stored in page.data['image']
:
>>> page = wptools.page()
>>> page.get()
en.wikipedia.org (imageinfo) IMAGE_FILES
>>> page.data['image']
[
{'kind': 'parse-image', <imageinfo>}, # get_parse()
{'kind': 'parse-cover', <imageinfo>}, # get_parse()
{'kind': 'query-pageimage', <imageinfo>}, # get_query()
{'kind': 'query-thumbnail', <imageinfo>}, # get_query()
{'kind': 'restbase-image', <imageinfo>}, # get_restbase('/page/summary/{title}')
{'kind': 'restbase-thumb', <imageinfo>}, # get_restbase('/page/summary/{title}')
{'kind': 'wikidata-image', <imageinfo>}, # get_wikidata()
]
You can access image data more easily with page.images()
:
>>> page = wptools.page('Great Wave')
>>> page.get()
>>> page.images('kind')
[{'kind': 'query-pageimage'},
{'kind': 'query-thumbnail'},
{'kind': 'wikidata-image'},
{'kind': 'wikidata-image'},
{'kind': 'restbase-original'},
{'kind': 'restbase-thumb'}]
>>> page.images(['kind','file'])
[{'file': u'File:Tsunami by hokusai 19th century.jpg',
'kind': 'query-pageimage'},
{'file': u'File:Tsunami by hokusai 19th century.jpg',
'kind': 'query-thumbnail'},
{'file': u'File:Great Wave off Kanagawa2.jpg', 'kind': 'wikidata-image'},
{'file': u'File:Katsushika Hokusai - Thirty-Six Views of Mount Fuji- The Great Wave Off the Coast of Kanagawa - Google Art Project.jpg',
'kind': 'wikidata-image'},
{'file': u'File:Tsunami by hokusai 19th century.jpg',
'kind': 'restbase-original'},
{'file': u'File:320px-Tsunami by hokusai 19th century.jpg',
'kind': 'restbase-thumb'}]
>>> page.images(['kind','file'], token='wikidata')
[{'file': u'File:Great Wave off Kanagawa2.jpg',
'kind': 'wikidata-image'},
{'file': u'File:Katsushika Hokusai - Thirty-Six Views of Mount Fuji- The Great Wave Off the Coast of Kanagawa - Google Art Project.jpg',
'kind': 'wikidata-image'}]
We get image license, usage, assessment and other metadata from Extension:CommonsMetadata via the get_imageinfo()
request. You can access image metadata with page.images()
:
>>> page = wptools.page('Great Wave')
>>> page.get_query()
>>> page.images()[0]['metadata']
{u'Artist': {u'source': u'commons-desc-page',
u'value': u'<bdi><a href="https://en.wikipedia.org/wiki/en:Hokusai" class="extiw" title="w:en:Hokusai">Katsushika Hokusai</a></bdi>'},
u'Assessments': {u'hidden': u'',
u'source': u'commons-categories',
u'value': u'potd'},
u'AttributionRequired': {u'hidden': u'',
u'source': u'commons-desc-page',
u'value': u'false'},
u'Categories': {u'hidden': u'',
u'source': u'commons-categories',
u'value': u'Artworks with Wikidata item|Artworks with Wikidata item without material used|Artworks with known accession number|Bequest of Mrs. H. O. Havemeyer|CC-PD-Mark|Formerly featured pictures on Wikimedia Commons|Louisine Havemeyer Collection|PD-Art (PD-old-100-1923)|PD-old-100-1923|Prints of 36 Views of Mount Fuji|The Great Wave off Kanagawa'},
u'CommonsMetadataExtension': {u'hidden': u'',
u'source': u'extension',
u'value': 1.2},
u'Copyrighted': {u'hidden': u'',
u'source': u'commons-desc-page',
u'value': u'False'},
u'Credit': {u'hidden': u'',
u'source': u'commons-desc-page',
u'value': u'<a href="https://en.wikipedia.org/wiki/Metropolitan_Museum_of_Art" class="extiw" title="en:Metropolitan Museum of Art">Metropolitan Museum of Art</a>, online database: entry <a rel="nofollow" class="external text" href="https://www.metmuseum.org/art/collection/search/45434">45434</a>'},
u'DateTime': {u'hidden': u'',
u'source': u'mediawiki-metadata',
u'value': u'2015-03-17 15:18:02'},
u'DateTimeOriginal': {u'source': u'commons-desc-page',
u'value': u'First publication: between circa 1830 and circa 1832.<br>'},
u'ImageDescription': {u'source': u'commons-desc-page',
u'value': u'Although it is often used in tsunami literature, there is no reason to suspect that Hokusai intended it to be interpreted in that way. The waves in this work are sometimes mistakenly referred to as tsunami (\u6d25\u6ce2), but they are more accurately called okinami (\u6c96\u6ce2), great off-shore waves.'},
u'License': {u'hidden': u'',
u'source': u'commons-templates',
u'value': u'pd'},
u'LicenseShortName': {u'hidden': u'',
u'source': u'commons-desc-page',
u'value': u'Public domain'},
u'ObjectName': {u'hidden': u'',
u'source': u'commons-desc-page',
u'value': u'<span class="fn"><span style="font-size:0.9em">Japanese: \u300e\u795e\u5948\u5ddd\u6c96\u6d6a\u88cf\u300f - Kanagawa oki nami ura</span>; <a href="https://en.wikipedia.org/wiki/en:The_Great_Wave_off_Kanagawa" class="extiw" title="w:en:The Great Wave off Kanagawa">The Great Wave off Kanagawa</a>\xa0<span class="wpImageAnnotatorControl wpImageAnnotatorOff"><a href="https://www.wikidata.org/wiki/Q28912605" title="wikidata:Q28912605"><img alt="wikidata:Q28912605" src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Wikidata-logo.svg/20px-Wikidata-logo.svg.png" width="20" height="11" srcset="https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Wikidata-logo.svg/30px-Wikidata-logo.svg.png 1.5x, https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Wikidata-logo.svg/40px-Wikidata-logo.svg.png 2x" data-file-width="1050" data-file-height="590"></a></span></span>'},
u'Restrictions': {u'hidden': u'',
u'source': u'commons-desc-page',
u'value': u''},
u'UsageTerms': {u'hidden': u'',
u'source': u'commons-desc-page',
u'value': u'Public domain'}}
Is the image copyrighted?
>>> page.images()[0]['metadata']['Copyrighted']['value']
u'False'
>>> page.images()[0]['metadata']['UsageTerms']['value']
u'Public domain'
What is the quality Assessment of the image?
>>> page.images()[0]['metadata']['Assessments']['value']
u'potd'
- https://www.mediawiki.org/wiki/API:Images
- https://www.mediawiki.org/wiki/API:Imageinfo
- https://www.mediawiki.org/wiki/API:Licensing
- https://www.mediawiki.org/wiki/Extension:CommonsMetadata
- https://www.mediawiki.org/wiki/Extension:PageImages
- https://commons.wikimedia.org/wiki/Commons:Assessments
- https://github.com/siznax/wptools/issues/14 Figure out "best" image