From 808007117458d3fd812ae6a95ba3e386a8877b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 29 Sep 2018 16:17:26 +0200 Subject: [PATCH] [flickr] improve album metadata (closes #109) --- gallery_dl/extractor/flickr.py | 42 ++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/gallery_dl/extractor/flickr.py b/gallery_dl/extractor/flickr.py index 00c7a925edb..0f00c7186bd 100644 --- a/gallery_dl/extractor/flickr.py +++ b/gallery_dl/extractor/flickr.py @@ -114,7 +114,7 @@ class FlickrAlbumExtractor(FlickrExtractor): test = [(("https://www.flickr.com/photos/" "shona_s/albums/72157633471741607"), { "url": "baf4a3d1b15afcecf9638000a12c0eb3d5df9024", - "keyword": "3a99f962f30691dc1b2da46be56fe1b7768fe707", + "keyword": "b579f19134ab8217f05979e52adf7712898492c7", })] def __init__(self, match): @@ -122,21 +122,13 @@ def __init__(self, match): self.album_id = match.group(2) def data(self): - self._generator = self.api.photosets_getPhotos(self.album_id) - self._first = next(self._generator) - photoset = self._first.copy() - del photoset["photo"] - return {"album": photoset} + data = FlickrExtractor.data(self) + data["album"] = self.api.photosets_getInfo( + self.album_id, self.user["nsid"]) + return data def photos(self): - for photo in self._photos(): - self.api._extract_format(photo) - yield photo - - def _photos(self): - yield from self._first["photo"] - for photoset in self._generator: - yield from photoset["photo"] + return self.api.photosets_getPhotos(self.album_id) class FlickrGalleryExtractor(FlickrExtractor): @@ -293,11 +285,7 @@ def galleries_getInfo(self, gallery_id): """Gets information about a gallery.""" params = {"gallery_id": gallery_id} gallery = self._call("galleries.getInfo", params)["gallery"] - del gallery["count_views"] - del gallery["count_comments"] - gallery["title"] = gallery["title"]["_content"] - gallery["description"] = gallery["description"]["_content"] - return gallery + return self._clean_info(gallery) def galleries_getPhotos(self, gallery_id): """Return the list of photos for a gallery.""" @@ -340,10 +328,16 @@ def photos_search(self, params): """Return a list of photos matching some criteria.""" return self._listing("photos.search", params.copy()) + def photosets_getInfo(self, photoset_id, user_id): + """Gets information about a photoset.""" + params = {"photoset_id": photoset_id, "user_id": user_id} + photoset = self._call("photosets.getInfo", params)["photoset"] + return self._clean_info(photoset) + def photosets_getPhotos(self, photoset_id): """Get the list of photos in a set.""" params = {"photoset_id": photoset_id} - return self._pagination("photosets.getPhotos", params) + return self._listing("photosets.getPhotos", params) def urls_lookupGroup(self, groupname): """Returns a group NSID, given the url to a group's page.""" @@ -433,3 +427,11 @@ def _extract_format(self, photo): else: # extra API call to get photo url and size photo["photo"] = self.photos_getSizes(photo["id"])[-1] + + @staticmethod + def _clean_info(info): + del info["count_views"] + del info["count_comments"] + info["title"] = info["title"]["_content"] + info["description"] = info["description"]["_content"] + return info