From 6b84de6cf761f380bd18a309352abbdb95b2184b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 12 May 2025 16:44:44 +0200 Subject: [PATCH] [flickr] add 'info' option (#4720 #6817) --- docs/configuration.rst | 13 +++++++++++++ docs/gallery-dl.conf | 1 + gallery_dl/extractor/flickr.py | 29 +++++++++++++++++++++++------ test/results/flickr.py | 17 +++++++++++++++-- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 0313cb14..60c17422 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -2653,6 +2653,19 @@ Description See `flickr.photos.getExif `__ for details. +extractor.flickr.info +--------------------- +Type + ``bool`` +Default + ``false`` +Description + For each photo, retrieve its "full" metadata as provided by + `flickr.photos.getInfo `__ + + Note: This requires 1 additional API call per photo. + + extractor.flickr.metadata ------------------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index ea04bb50..8023c5d0 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -278,6 +278,7 @@ "contexts": false, "exif" : false, + "info" : false, "metadata": false, "size-max": null, "videos" : true diff --git a/gallery_dl/extractor/flickr.py b/gallery_dl/extractor/flickr.py index b8d72c64..ede15776 100644 --- a/gallery_dl/extractor/flickr.py +++ b/gallery_dl/extractor/flickr.py @@ -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: diff --git a/test/results/flickr.py b/test/results/flickr.py index 0182b36b..c877a905 100644 --- a/test/results/flickr.py +++ b/test/results/flickr.py @@ -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", }, {