Skip to content

Commit 2578f7b

Browse files
committed
[flickr] extract public API key from website (#7564 #7649 #7700 #8553)
this breaks 'oauth:flickr' with the default key, but it allows downloading without custom key / Flickr Pro
1 parent 5da4fb3 commit 2578f7b

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

gallery_dl/extractor/flickr.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,28 @@
1010

1111
from .common import Extractor, Message
1212
from .. import text, oauth, util, exception
13+
from ..cache import memcache
1314

1415
BASE_PATTERN = r"(?:https?://)?(?:www\.|secure\.|m\.)?flickr\.com"
1516

1617

1718
class FlickrExtractor(Extractor):
1819
"""Base class for flickr extractors"""
1920
category = "flickr"
21+
root = "https://www.flickr.com"
2022
filename_fmt = "{category}_{id}.{extension}"
2123
directory_fmt = ("{category}", "{user[username]}")
2224
archive_fmt = "{id}"
2325
request_interval = (1.0, 2.0)
2426
request_interval_min = 0.5
2527

2628
def _init(self):
27-
self.api = FlickrAPI(self)
2829
self.user = None
2930
self.item_id = self.groups[0]
3031

3132
def items(self):
33+
self.api = FlickrAPI(self)
34+
3235
data = self.metadata()
3336
extract = self.api._extract_format
3437
for photo in self.photos():
@@ -75,6 +78,8 @@ class FlickrImageExtractor(FlickrExtractor):
7578
example = "https://www.flickr.com/photos/USER/12345"
7679

7780
def items(self):
81+
self.api = FlickrAPI(self)
82+
7883
item_id, enc_id = self.groups
7984
if enc_id is not None:
8085
alphabet = ("123456789abcdefghijkmnopqrstu"
@@ -129,6 +134,8 @@ def items(self):
129134
return self._album_items()
130135

131136
def _album_items(self):
137+
self.api = FlickrAPI(self)
138+
132139
data = FlickrExtractor.metadata(self)
133140
data["_extractor"] = FlickrAlbumExtractor
134141

@@ -236,8 +243,8 @@ class FlickrAPI(oauth.OAuth1API):
236243
"""
237244

238245
API_URL = "https://api.flickr.com/services/rest/"
239-
API_KEY = "90c368449018a0cb880ea4889cbb8681"
240-
API_SECRET = "e4b83e319c11e9e1"
246+
# API_KEY = ""
247+
API_SECRET = ""
241248
FORMATS = [
242249
("o" , "Original" , None),
243250
("6k", "X-Large 6K" , 6144),
@@ -282,6 +289,14 @@ class FlickrAPI(oauth.OAuth1API):
282289
"10": "Public Domain Mark",
283290
}
284291

292+
@property
293+
@memcache(maxage=3600)
294+
def API_KEY(self):
295+
extr = self.extractor
296+
extr.log.info("Retrieving public API key")
297+
page = extr.request(extr.root + "/prints").text
298+
return text.extr(page, '.flickr.api.site_key = "', '"')
299+
285300
def __init__(self, extractor):
286301
oauth.OAuth1API.__init__(self, extractor)
287302

@@ -489,7 +504,7 @@ def _pagination_sets(self, method, params):
489504
def _extract_format(self, photo):
490505
photo["description"] = photo["description"]["_content"].strip()
491506
photo["views"] = text.parse_int(photo["views"])
492-
photo["date"] = self.parse_timestamp(photo["dateupload"])
507+
photo["date"] = self.extractor.parse_timestamp(photo["dateupload"])
493508
photo["tags"] = photo["tags"].split()
494509

495510
self._extract_metadata(photo)

gallery_dl/extractor/oauth.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,13 @@ class OAuthFlickr(OAuthBase):
258258

259259
def items(self):
260260
yield Message.Version, 1
261-
from . import flickr
261+
# from . import flickr
262262

263263
self._oauth1_authorization_flow(
264-
flickr.FlickrAPI.API_KEY,
265-
flickr.FlickrAPI.API_SECRET,
264+
# flickr.FlickrAPI.API_KEY,
265+
# flickr.FlickrAPI.API_SECRET,
266+
"",
267+
"",
266268
"https://www.flickr.com/services/oauth/request_token",
267269
"https://www.flickr.com/services/oauth/authorize",
268270
"https://www.flickr.com/services/oauth/access_token",

0 commit comments

Comments
 (0)