diff --git a/docs/configuration.rst b/docs/configuration.rst index 60c17422..a995c139 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -2687,6 +2687,19 @@ Description for possible field names. +extractor.flickr.profile +------------------------ +Type + ``bool`` +Default + ``false`` +Description + Extract additional ``user`` profile metadata. + + Note: This requires 1 additional API call per user profile. + See `flickr.people.getInfo `__ for details. + + extractor.flickr.videos ----------------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 8023c5d0..0fbf834b 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -280,6 +280,7 @@ "exif" : false, "info" : false, "metadata": false, + "profile" : false, "size-max": null, "videos" : true }, diff --git a/gallery_dl/extractor/flickr.py b/gallery_dl/extractor/flickr.py index 42564049..eb68c3e4 100644 --- a/gallery_dl/extractor/flickr.py +++ b/gallery_dl/extractor/flickr.py @@ -48,6 +48,8 @@ class FlickrExtractor(Extractor): def metadata(self): """Return general metadata""" self.user = self.api.urls_lookupUser(self.item_id) + if self.config("profile", False): + self.user.update(self.api.people_getInfo(self.user["nsid"])) return {"user": self.user} def photos(self): @@ -87,7 +89,11 @@ class FlickrImageExtractor(FlickrExtractor): else: self.api._extract_photo(photo) - photo["user"] = photo["owner"] + if self.config("profile", False): + photo["user"] = self.api.people_getInfo(photo["owner"]["nsid"]) + else: + photo["user"] = photo["owner"] + photo["title"] = photo["title"]["_content"] photo["comments"] = text.parse_int(photo["comments"]["_content"]) photo["description"] = photo["description"]["_content"] @@ -322,6 +328,26 @@ class FlickrAPI(oauth.OAuth1API): params = {"group_id": group_id} return self._pagination("groups.pools.getPhotos", params) + def people_getInfo(self, user_id): + """Get information about a user.""" + params = {"user_id": user_id} + user = self._call("people.getInfo", params) + + try: + user = user["person"] + for key in ("description", "username", "realname", "location", + "profileurl", "photosurl", "mobileurl"): + if isinstance(user.get(key), dict): + user[key] = user[key]["_content"] + photos = user["photos"] + for key in ("count", "firstdate", "firstdatetaken"): + if isinstance(photos.get(key), dict): + photos[key] = photos[key]["_content"] + except Exception: + pass + + return user + def people_getPhotos(self, user_id): """Return photos from the given user's photostream.""" params = {"user_id": user_id} diff --git a/test/results/flickr.py b/test/results/flickr.py index c877a905..3518f6eb 100644 --- a/test/results/flickr.py +++ b/test/results/flickr.py @@ -16,6 +16,7 @@ __tests__ = ( "#options" : { "contexts": True, "exif": True, + "profile": True, }, "#urls" : "https://live.staticflickr.com/7463/16089302239_de18cd8017_b_d.jpg", "#pattern" : flickr.FlickrImageExtractor.pattern, @@ -43,6 +44,37 @@ __tests__ = ( "url" : str, "views" : int, "width" : 1024, + + "user": { + "description": str, + "has_adfree": 0, + "has_free_educational_resources": 0, + "has_free_standard_shipping": 0, + "has_stats": 0, + "iconfarm": 8, + "iconserver": "7265", + "id": "59437997@N05", + "ispro": 0, + "location": "Canada", + "mobileurl": "https://www.flickr.com/photos/departingyyz/", + "nsid": "59437997@N05", + "path_alias": "departingyyz", + "photosurl": "https://www.flickr.com/photos/departingyyz/", + "profileurl": "https://www.flickr.com/people/departingyyz/", + "realname": "Joshua Paul Shefman", + "username": "departing(YYZ)", + "photos": { + "count": int, + "firstdate": "1297577284", + "firstdatetaken": "2008-07-07 18:31:47", + }, + "timezone": { + "label": "Eastern Time (US & Canada)", + "offset": "-05:00", + "timezone": 14, + "timezone_id": "EST5EDT", + }, + }, }, { @@ -166,7 +198,10 @@ __tests__ = ( "#url" : "https://www.flickr.com/photos/shona_s/favorites", "#category": ("", "flickr", "favorite"), "#class" : flickr.FlickrFavoriteExtractor, - "#options" : {"info": True}, + "#options" : { + "info": True, + "profile": True, + }, "#urls" : ( "https://live.staticflickr.com/7322/8719105033_4a21140220_o_d.jpg", "https://live.staticflickr.com/7376/8720226282_eae0faefd1_o_d.jpg", @@ -179,6 +214,38 @@ __tests__ = ( "license_name": "All Rights Reserved", "notes" : dict, "safety_level": "0", + "owner": { + "iconfarm" : int, + "iconserver": str, + "location" : None, + "nsid" : str, + "path_alias": None, + "realname" : str, + "username" : str, + }, + "user": { + "nsid": "95410434@N08", + "path_alias": "shona_s", + "username": "Shona_S", + + "description": "", + "has_adfree": 0, + "has_free_educational_resources": 0, + "has_free_standard_shipping": 0, + "has_stats": 0, + "iconfarm": 0, + "iconserver": "0", + "id": "95410434@N08", + "ispro": 0, + "mobileurl": "https://www.flickr.com/photos/shona_s/", + "photosurl": "https://www.flickr.com/photos/shona_s/", + "profileurl": "https://www.flickr.com/people/shona_s/", + "photos": { + "count": 28, + "firstdate": "1367947187", + "firstdatetaken": "2012-09-21 19:35:39", + }, + }, }, {