+def get_rawpixel_data(url):
+ photo_id = re.search(r'/(\d+)/', url).group(1)
+
+ s = requests.Session()
+ cookies = settings.RAWPIXEL_SESSION
+
+ token = s.post(
+ 'https://www.rawpixel.com/api/v1/user/session',
+ cookies=cookies
+ ).json()['token']
+
+ h = {'X-CSRF-Token': token, 'Accept': 'application/json'}
+
+ data = s.get(
+ f'https://www.rawpixel.com/api/v1/image/data/{photo_id}',
+ headers=h, cookies=cookies).json()
+ download_url = s.post(
+ f'https://www.rawpixel.com/api/v1/image/download/{photo_id}/original',
+ headers=h, cookies=cookies
+ ).json()['downloadUrl']
+
+ title = data['metadata']['title'].rsplit('|', 1)[0].strip()
+
+ return {
+ 'title': title,
+ 'author': ', '.join(data['metadata']['artist_names']),
+ 'source_url': data['url'],
+ 'download_url': download_url,
+ 'license_url': data['metadata']['licenseUrl'],
+ 'license_name': data['metadata']['license'],
+ }
+