Librarian in regular requirements.
[redakcja.git] / apps / cover / utils.py
index 80ee0b7..51aee19 100755 (executable)
@@ -38,8 +38,16 @@ def get_flickr_data(url):
         re_license = re.compile(r'https?://creativecommons.org/licenses/([^/]*)/([^/]*)/.*')
         m = re_license.match(license_url)
         if not m:
-            raise FlickrError('License does not look like CC: %s' % license_url)
-        license_name = 'CC %s %s' % (m.group(1).upper(), m.group(2))
+            re_pd = re.compile(r'https?://creativecommons.org/publicdomain/([^/]*)/([^/]*)/.*')
+            m = re_pd.match(license_url)
+            if not m:
+                raise FlickrError('License does not look like CC: %s' % license_url)
+            if m.group(1).lower() == 'zero':
+                license_name = 'Public domain (CC0 %s)' % m.group(2)
+            else:
+                license_name = 'Public domain'
+        else:
+            license_name = 'CC %s %s' % (m.group(1).upper(), m.group(2))
     m = re.search(r'<a[^>]* class="owner-name [^>]*>([^<]*)<', html)
     if m:
         author = "%s@Flickr" % m.group(1)
@@ -52,7 +60,7 @@ def get_flickr_data(url):
     m = re.search(r'modelExport: (\{.*\})', html)
     try:
         assert m
-        download_url = 'https:' + json.loads(m.group(1))['photo-models'][0]['sizes']['o']['url']
+        download_url = 'https:' + json.loads(m.group(1))['main']['photo-models'][0]['sizes']['o']['url']
     except (AssertionError, ValueError, IndexError, KeyError):
         raise FlickrError('Error reading image URL.')
     return {