forked from blacktwin/JBOPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plex_imgur_dl.py
54 lines (39 loc) · 1.58 KB
/
plex_imgur_dl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/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))