[flickr] add 'info' option (#4720 #6817)

This commit is contained in:
Mike Fährmann
2025-05-12 16:44:44 +02:00
parent bd7fcdab4c
commit 6b84de6cf7
4 changed files with 52 additions and 8 deletions

View File

@@ -2653,6 +2653,19 @@ Description
See `flickr.photos.getExif <https://www.flickr.com/services/api/flickr.photos.getExif.html>`__ for details.
extractor.flickr.info
---------------------
Type
``bool``
Default
``false``
Description
For each photo, retrieve its "full" metadata as provided by
`flickr.photos.getInfo <https://www.flickr.com/services/api/flickr.photos.getInfo.html>`__
Note: This requires 1 additional API call per photo.
extractor.flickr.metadata
-------------------------
Type

View File

@@ -278,6 +278,7 @@
"contexts": false,
"exif" : false,
"info" : false,
"metadata": false,
"size-max": null,
"videos" : true

View File

@@ -81,7 +81,7 @@ class FlickrImageExtractor(FlickrExtractor):
photo = self.api.photos_getInfo(item_id)
self.api._extract_metadata(photo)
self.api._extract_metadata(photo, False)
if photo["media"] == "video" and self.api.videos:
self.api._extract_video(photo)
else:
@@ -279,9 +279,10 @@ class FlickrAPI(oauth.OAuth1API):
def __init__(self, extractor):
oauth.OAuth1API.__init__(self, extractor)
self.exif = extractor.config("exif", False)
self.videos = extractor.config("videos", True)
self.contexts = extractor.config("contexts", False)
self.meta_exif = extractor.config("exif", False)
self.meta_info = extractor.config("info", False)
self.meta_contexts = extractor.config("contexts", False)
self.maxsize = extractor.config("size-max")
if isinstance(self.maxsize, str):
@@ -522,8 +523,24 @@ class FlickrAPI(oauth.OAuth1API):
photo["width"] = photo["height"] = 0
return photo
def _extract_metadata(self, photo):
if self.exif:
def _extract_metadata(self, photo, info=True):
if info and self.meta_info:
try:
photo.update(self.photos_getInfo(photo["id"]))
photo["user"] = photo["owner"]
photo["title"] = photo["title"]["_content"]
photo["comments"] = text.parse_int(
photo["comments"]["_content"])
photo["description"] = photo["description"]["_content"]
photo["tags"] = [t["raw"] for t in photo["tags"]["tag"]]
photo["views"] = text.parse_int(photo["views"])
photo["id"] = text.parse_int(photo["id"])
except Exception as exc:
self.log.warning(
"Unable to retrieve 'info' data for %s (%s: %s)",
photo["id"], exc.__class__.__name__, exc)
if self.meta_exif:
try:
photo.update(self.photos_getExif(photo["id"]))
except Exception as exc:
@@ -531,7 +548,7 @@ class FlickrAPI(oauth.OAuth1API):
"Unable to retrieve 'exif' data for %s (%s: %s)",
photo["id"], exc.__class__.__name__, exc)
if self.contexts:
if self.meta_contexts:
try:
photo.update(self.photos_getAllContexts(photo["id"]))
except Exception as exc:

View File

@@ -38,6 +38,8 @@ __tests__ = (
"media" : "photo",
"pool" : list,
"set" : list,
"safety_level": "0",
"tags" : list,
"url" : str,
"views" : int,
"width" : 1024,
@@ -164,8 +166,19 @@ __tests__ = (
"#url" : "https://www.flickr.com/photos/shona_s/favorites",
"#category": ("", "flickr", "favorite"),
"#class" : flickr.FlickrFavoriteExtractor,
"#pattern" : flickr.FlickrImageExtractor.pattern,
"#count" : 4,
"#options" : {"info": True},
"#urls" : (
"https://live.staticflickr.com/7322/8719105033_4a21140220_o_d.jpg",
"https://live.staticflickr.com/7376/8720226282_eae0faefd1_o_d.jpg",
"https://live.staticflickr.com/7460/8720245516_ab06f80353_o_d.jpg",
"https://live.staticflickr.com/8268/8705102120_64349ebac2_o_d.jpg",
),
"dates" : dict,
"license" : "0",
"license_name": "All Rights Reserved",
"notes" : dict,
"safety_level": "0",
},
{