Skip to content

Instantly share code, notes, and snippets.

@blacktwin
Last active March 27, 2018 05:23
Show Gist options
  • Save blacktwin/17b58156f69cc52026b71fe4d5afea05 to your computer and use it in GitHub Desktop.
Save blacktwin/17b58156f69cc52026b71fe4d5afea05 to your computer and use it in GitHub Desktop.
Pull poster images from Imgur and places them inside Shows root folder.
'''
Pull poster images from Imgur and places them inside Shows root folder.
/path/to/show/Show.jpg
Skips download if showname.jpg exists or if show does not exist.
'''
import requests
import urllib
import os
## Edit ##
# Imgur info
CLIENT_ID = 'xxxxx' # PlexPy Settings > Notifications > Imgur Client ID
ALBUM_ID = '7JeSw' # http://imgur.com/a/7JeSw <--- 7JeSw is the ablum_id
# Local info
SHOW_PATH = 'D:\\Shows\\'
## /Edit ##
class IMGURINFO(object):
def __init__(self, data=None):
d = data or {}
self.link = d['link']
self.description = d['description']
def get_imgur():
url = "https://api.imgur.com/3/album/{ALBUM_ID}/images".format(ALBUM_ID=ALBUM_ID)
headers = {'authorization': 'Client-ID {}'.format(CLIENT_ID)}
r = requests.get(url, headers=headers)
imgur_dump = r.json()
return[IMGURINFO(data=d) for d in imgur_dump['data']]
for x in get_imgur():
# Check if Show directory exists
if os.path.exists(os.path.join(SHOW_PATH, x.description)):
# Check if Show poster (show.jpg) exists
if os.path.exists((os.path.join(SHOW_PATH, x.description, x.description))):
print("Poster for {} was already downloaded or filename already exists, skipping.".format(x.description))
else:
print("Downloading poster for {}.".format(x.description))
urllib.urlretrieve(x.link, '{}.jpg'.format((os.path.join(SHOW_PATH, x.description, x.description))))
else:
print("{} - {} did not match your library.".format(x.description, x.link))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment