From eff0e04929f720298346be63cc12235c74daab57 Mon Sep 17 00:00:00 2001 From: blacktwin Date: Wed, 12 Jul 2017 14:23:31 -0400 Subject: [PATCH] Create plex_imgur_dl.py https://gist.github.com/blacktwin/17b58156f69cc52026b71fe4d5afea05 --- plex_imgur_dl.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 plex_imgur_dl.py diff --git a/plex_imgur_dl.py b/plex_imgur_dl.py new file mode 100644 index 0000000..f97b5ef --- /dev/null +++ b/plex_imgur_dl.py @@ -0,0 +1,48 @@ +''' +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))