|
10 | 10 |
|
11 | 11 | from .common import Extractor, Message |
12 | 12 | from .. import text, oauth, util, exception |
| 13 | +from ..cache import memcache |
13 | 14 |
|
14 | 15 | BASE_PATTERN = r"(?:https?://)?(?:www\.|secure\.|m\.)?flickr\.com" |
15 | 16 |
|
16 | 17 |
|
17 | 18 | class FlickrExtractor(Extractor): |
18 | 19 | """Base class for flickr extractors""" |
19 | 20 | category = "flickr" |
| 21 | + root = "https://www.flickr.com" |
20 | 22 | filename_fmt = "{category}_{id}.{extension}" |
21 | 23 | directory_fmt = ("{category}", "{user[username]}") |
22 | 24 | archive_fmt = "{id}" |
23 | 25 | request_interval = (1.0, 2.0) |
24 | 26 | request_interval_min = 0.5 |
25 | 27 |
|
26 | 28 | def _init(self): |
27 | | - self.api = FlickrAPI(self) |
28 | 29 | self.user = None |
29 | 30 | self.item_id = self.groups[0] |
30 | 31 |
|
31 | 32 | def items(self): |
| 33 | + self.api = FlickrAPI(self) |
| 34 | + |
32 | 35 | data = self.metadata() |
33 | 36 | extract = self.api._extract_format |
34 | 37 | for photo in self.photos(): |
@@ -75,6 +78,8 @@ class FlickrImageExtractor(FlickrExtractor): |
75 | 78 | example = "https://www.flickr.com/photos/USER/12345" |
76 | 79 |
|
77 | 80 | def items(self): |
| 81 | + self.api = FlickrAPI(self) |
| 82 | + |
78 | 83 | item_id, enc_id = self.groups |
79 | 84 | if enc_id is not None: |
80 | 85 | alphabet = ("123456789abcdefghijkmnopqrstu" |
@@ -129,6 +134,8 @@ def items(self): |
129 | 134 | return self._album_items() |
130 | 135 |
|
131 | 136 | def _album_items(self): |
| 137 | + self.api = FlickrAPI(self) |
| 138 | + |
132 | 139 | data = FlickrExtractor.metadata(self) |
133 | 140 | data["_extractor"] = FlickrAlbumExtractor |
134 | 141 |
|
@@ -236,8 +243,8 @@ class FlickrAPI(oauth.OAuth1API): |
236 | 243 | """ |
237 | 244 |
|
238 | 245 | API_URL = "https://api.flickr.com/services/rest/" |
239 | | - API_KEY = "90c368449018a0cb880ea4889cbb8681" |
240 | | - API_SECRET = "e4b83e319c11e9e1" |
| 246 | + # API_KEY = "" |
| 247 | + API_SECRET = "" |
241 | 248 | FORMATS = [ |
242 | 249 | ("o" , "Original" , None), |
243 | 250 | ("6k", "X-Large 6K" , 6144), |
@@ -282,6 +289,14 @@ class FlickrAPI(oauth.OAuth1API): |
282 | 289 | "10": "Public Domain Mark", |
283 | 290 | } |
284 | 291 |
|
| 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 | + |
285 | 300 | def __init__(self, extractor): |
286 | 301 | oauth.OAuth1API.__init__(self, extractor) |
287 | 302 |
|
@@ -489,7 +504,7 @@ def _pagination_sets(self, method, params): |
489 | 504 | def _extract_format(self, photo): |
490 | 505 | photo["description"] = photo["description"]["_content"].strip() |
491 | 506 | photo["views"] = text.parse_int(photo["views"]) |
492 | | - photo["date"] = self.parse_timestamp(photo["dateupload"]) |
| 507 | + photo["date"] = self.extractor.parse_timestamp(photo["dateupload"]) |
493 | 508 | photo["tags"] = photo["tags"].split() |
494 | 509 |
|
495 | 510 | self._extract_metadata(photo) |
|
0 commit comments