In [1]:
import requests

from secret import GIPHY_API_KEY

In [2]:
payload = {'q': 'ryan gosling', 'api_key': GIPHY_API_KEY, 'limit': 5}

resp = requests.get('http://api.giphy.com/v1/gifs/search', params=payload)

resp.status_code


Out[2]:
200

In [3]:
payload = {'api_key': GIPHY_API_KEY}

resp = requests.get('http://api.giphy.com/v1/gifs/{}'.format('66Z5s4rg6bNHa'),
                    params=payload)

resp.status_code


Out[3]:
200

In [4]:
gif = resp.json()

gif['data'].keys()


Out[4]:
dict_keys(['type', 'id', 'slug', 'url', 'bitly_gif_url', 'bitly_url', 'embed_url', 'username', 'source', 'rating', 'content_url', 'source_tld', 'source_post_url', 'is_indexable', 'is_sticker', 'import_datetime', 'trending_datetime', 'images', 'title'])

In [5]:
for k, v in gif['data'].items():
    print(k, v)


type gif
id 66Z5s4rg6bNHa
slug reddit-supergirl-lots-66Z5s4rg6bNHa
url https://giphy.com/gifs/reddit-supergirl-lots-66Z5s4rg6bNHa
bitly_gif_url https://gph.is/1IZlOBX
bitly_url https://gph.is/1IZlOBX
embed_url https://giphy.com/embed/66Z5s4rg6bNHa
username 
source https://www.reddit.com/r/funny/comments/3h68dq/do_you_think_reddit_will_make_lots_of_supergirl/
rating g
content_url 
source_tld www.reddit.com
source_post_url https://www.reddit.com/r/funny/comments/3h68dq/do_you_think_reddit_will_make_lots_of_supergirl/
is_indexable 0
is_sticker 0
import_datetime 2015-08-18 09:15:35
trending_datetime 0000-00-00 00:00:00
images {'fixed_height_still': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200_s.gif', 'width': '355', 'height': '200'}, 'original_still': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy_s.gif', 'width': '700', 'height': '394'}, 'fixed_width': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200w.gif', 'width': '200', 'height': '113', 'size': '234709', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200w.mp4', 'mp4_size': '11161', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200w.webp', 'webp_size': '240904'}, 'fixed_height_small_still': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100_s.gif', 'width': '178', 'height': '100'}, 'fixed_height_downsampled': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200_d.gif', 'width': '355', 'height': '200', 'size': '209504', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200_d.webp', 'webp_size': '107982'}, 'preview': {'width': '428', 'height': '240', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-preview.mp4', 'mp4_size': '37677'}, 'fixed_height_small': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100.gif', 'width': '178', 'height': '100', 'size': '217228', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100.mp4', 'mp4_size': '9805', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100.webp', 'webp_size': '198098'}, 'downsized_still': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-downsized_s.gif', 'width': '500', 'height': '281', 'size': '91847'}, 'downsized': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-downsized.gif', 'width': '500', 'height': '281', 'size': '1929058'}, 'downsized_large': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.gif', 'width': '700', 'height': '394', 'size': '3929300'}, 'fixed_width_small_still': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100w_s.gif', 'width': '100', 'height': '56'}, 'preview_webp': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-preview.webp', 'width': '149', 'height': '84', 'size': '47720'}, 'fixed_width_still': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200w_s.gif', 'width': '200', 'height': '113'}, 'fixed_width_small': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100w.gif', 'width': '100', 'height': '56', 'size': '63338', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100w.mp4', 'mp4_size': '4622', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100w.webp', 'webp_size': '81308'}, 'downsized_small': {'width': '700', 'height': '394', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-downsized-small.mp4', 'mp4_size': '133557'}, 'fixed_width_downsampled': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200w_d.gif', 'width': '200', 'height': '113', 'size': '65964', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200w_d.webp', 'webp_size': '45850'}, 'downsized_medium': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.gif', 'width': '700', 'height': '394', 'size': '3929300'}, 'original': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.gif', 'width': '700', 'height': '394', 'size': '3929300', 'frames': '32', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.mp4', 'mp4_size': '36296', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.webp', 'webp_size': '1731290'}, 'fixed_height': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200.gif', 'width': '355', 'height': '200', 'size': '837878', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200.mp4', 'mp4_size': '24006', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200.webp', 'webp_size': '564292'}, 'looping': {'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-loop.mp4', 'mp4_size': '469494'}, 'original_mp4': {'width': '480', 'height': '270', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.mp4', 'mp4_size': '36296'}, 'preview_gif': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-preview.gif', 'width': '149', 'height': '84', 'size': '39511'}, '480w_still': {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/480w_s.jpg', 'width': '480', 'height': '270'}}
title melissa benoist yes GIF

In [6]:
for k, v in gif['data']['images'].items():
    print(k, v)


fixed_height_still {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200_s.gif', 'width': '355', 'height': '200'}
original_still {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy_s.gif', 'width': '700', 'height': '394'}
fixed_width {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200w.gif', 'width': '200', 'height': '113', 'size': '234709', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200w.mp4', 'mp4_size': '11161', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200w.webp', 'webp_size': '240904'}
fixed_height_small_still {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100_s.gif', 'width': '178', 'height': '100'}
fixed_height_downsampled {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200_d.gif', 'width': '355', 'height': '200', 'size': '209504', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200_d.webp', 'webp_size': '107982'}
preview {'width': '428', 'height': '240', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-preview.mp4', 'mp4_size': '37677'}
fixed_height_small {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100.gif', 'width': '178', 'height': '100', 'size': '217228', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100.mp4', 'mp4_size': '9805', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100.webp', 'webp_size': '198098'}
downsized_still {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-downsized_s.gif', 'width': '500', 'height': '281', 'size': '91847'}
downsized {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-downsized.gif', 'width': '500', 'height': '281', 'size': '1929058'}
downsized_large {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.gif', 'width': '700', 'height': '394', 'size': '3929300'}
fixed_width_small_still {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100w_s.gif', 'width': '100', 'height': '56'}
preview_webp {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-preview.webp', 'width': '149', 'height': '84', 'size': '47720'}
fixed_width_still {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200w_s.gif', 'width': '200', 'height': '113'}
fixed_width_small {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100w.gif', 'width': '100', 'height': '56', 'size': '63338', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100w.mp4', 'mp4_size': '4622', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/100w.webp', 'webp_size': '81308'}
downsized_small {'width': '700', 'height': '394', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-downsized-small.mp4', 'mp4_size': '133557'}
fixed_width_downsampled {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200w_d.gif', 'width': '200', 'height': '113', 'size': '65964', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200w_d.webp', 'webp_size': '45850'}
downsized_medium {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.gif', 'width': '700', 'height': '394', 'size': '3929300'}
original {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.gif', 'width': '700', 'height': '394', 'size': '3929300', 'frames': '32', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.mp4', 'mp4_size': '36296', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.webp', 'webp_size': '1731290'}
fixed_height {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200.gif', 'width': '355', 'height': '200', 'size': '837878', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200.mp4', 'mp4_size': '24006', 'webp': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/200.webp', 'webp_size': '564292'}
looping {'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-loop.mp4', 'mp4_size': '469494'}
original_mp4 {'width': '480', 'height': '270', 'mp4': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.mp4', 'mp4_size': '36296'}
preview_gif {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy-preview.gif', 'width': '149', 'height': '84', 'size': '39511'}
480w_still {'url': 'https://media2.giphy.com/media/66Z5s4rg6bNHa/480w_s.jpg', 'width': '480', 'height': '270'}

In [7]:
for k, v in gif['data']['images']['original'].items():
    print(k, v)


url https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.gif
width 700
height 394
size 3929300
frames 32
mp4 https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.mp4
mp4_size 36296
webp https://media2.giphy.com/media/66Z5s4rg6bNHa/giphy.webp
webp_size 1731290

In [8]:
image = gif['data']['images']['original']

In [9]:
import os.path
import shutil

import requests

def image_download(slug, url):
    extension = os.path.splitext(url)[1]
    
    resp = requests.get(url, stream=True)
    
    if not resp.ok:
        return False
    
    with open('./downloads/{0}{1}'.format(slug, extension), 'wb') as fobj:
        resp.raw.decode_content = True
        shutil.copyfileobj(resp.raw, fobj)

image_download('supergirl', image['url'])
image_download('supergirl', image['mp4'])
image_download('supergirl', image['webp'])

In [10]:
gif['meta']


Out[10]:
{'msg': 'OK', 'response_id': '5a3a808c666e5353599faf8b', 'status': 200}

In [11]:
gif['data'].keys()


Out[11]:
dict_keys(['type', 'id', 'slug', 'url', 'bitly_gif_url', 'bitly_url', 'embed_url', 'username', 'source', 'rating', 'content_url', 'source_tld', 'source_post_url', 'is_indexable', 'is_sticker', 'import_datetime', 'trending_datetime', 'images', 'title'])

In [12]:
gif['data']['slug']


Out[12]:
'reddit-supergirl-lots-66Z5s4rg6bNHa'

In [13]:
gif['data']['title']


Out[13]:
'melissa benoist yes GIF'

In [15]:
gif['data']['source']


Out[15]:
'https://www.reddit.com/r/funny/comments/3h68dq/do_you_think_reddit_will_make_lots_of_supergirl/'

In [17]:
gif['data']['content_url']


Out[17]:
''

In [ ]: