2be0e376f8
Adds a basic `setup.cfg` file with configurations for flake8 and pylama, fixes some basic issues with essentially every file including: * Many, many, whitespace line cleanups * Several unused variables and imports * Missing coding and shabang lines * Minor style fixes to more closely align with PEP8 * Turn `print` into function calls for Python 2/3 compat * A few minor bugs * Things like using an undefined `i` in `stream_limiter_ban_email.py`
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
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' # Tautulli 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))
|