Issue #93, clean up
This commit is contained in:
parent
286c65f9a2
commit
1a9fdd1a99
@ -17,20 +17,11 @@ SHOW_LST = [123456, 123456, 123456, 123456] # Show rating keys.
|
|||||||
USER_LST = ['Sam', 'Jakie', 'Blacktwin'] # Name of users
|
USER_LST = ['Sam', 'Jakie', 'Blacktwin'] # Name of users
|
||||||
|
|
||||||
|
|
||||||
class UserHIS(object):
|
|
||||||
def __init__(self, data=None):
|
|
||||||
d = data or {}
|
|
||||||
self.rating_key = d['rating_key']
|
|
||||||
|
|
||||||
|
|
||||||
class METAINFO(object):
|
class METAINFO(object):
|
||||||
def __init__(self, data=None):
|
def __init__(self, data=None):
|
||||||
d = data or {}
|
d = data or {}
|
||||||
self.title = d['title']
|
self.title = d['title']
|
||||||
media_info = d['media_info'][0]
|
self.file = d['file']
|
||||||
parts = media_info['parts'][0]
|
|
||||||
self.file_size = parts['file_size']
|
|
||||||
self.file = parts['file']
|
|
||||||
self.media_type = d['media_type']
|
self.media_type = d['media_type']
|
||||||
self.grandparent_title = d['grandparent_title']
|
self.grandparent_title = d['grandparent_title']
|
||||||
|
|
||||||
@ -46,7 +37,7 @@ def get_metadata(rating_key):
|
|||||||
r = requests.get(TAUTULLI_URL.rstrip('/') + '/api/v2', params=payload)
|
r = requests.get(TAUTULLI_URL.rstrip('/') + '/api/v2', params=payload)
|
||||||
response = r.json()
|
response = r.json()
|
||||||
|
|
||||||
res_data = response['response']['data']
|
res_data = response['response']['data']['metadata']
|
||||||
return METAINFO(data=res_data)
|
return METAINFO(data=res_data)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -68,7 +59,7 @@ def get_history(user, show, start, length):
|
|||||||
response = r.json()
|
response = r.json()
|
||||||
|
|
||||||
res_data = response['response']['data']['data']
|
res_data = response['response']['data']['data']
|
||||||
return [UserHIS(data=d) for d in res_data if d['watched_status'] == 1]
|
return [d['rating_key'] for d in res_data if d['watched_status'] == 1]
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.stderr.write("Tautulli API 'get_history' request failed: {0}.".format(e))
|
sys.stderr.write("Tautulli API 'get_history' request failed: {0}.".format(e))
|
||||||
@ -88,9 +79,9 @@ for user in USER_LST:
|
|||||||
try:
|
try:
|
||||||
if all([history]):
|
if all([history]):
|
||||||
start += count
|
start += count
|
||||||
for h in history:
|
for rating_key in history:
|
||||||
# Getting metadata of what was watched
|
# Getting metadata of what was watched
|
||||||
meta = get_metadata(h.rating_key)
|
meta = get_metadata(rating_key)
|
||||||
if not any(d['title'] == meta.title for d in meta_lst):
|
if not any(d['title'] == meta.title for d in meta_lst):
|
||||||
meta_dict = {
|
meta_dict = {
|
||||||
'title': meta.title,
|
'title': meta.title,
|
||||||
@ -115,12 +106,8 @@ for user in USER_LST:
|
|||||||
|
|
||||||
|
|
||||||
for meta_dict in meta_lst:
|
for meta_dict in meta_lst:
|
||||||
for key, value in meta_dict.items():
|
print("{} {} has been watched by {}".format(meta_dict['grandparent_title'].encode('UTF-8'),
|
||||||
if value == USER_LST:
|
meta_dict['title'].encode('UTF-8'),
|
||||||
print(u"{} {} has been watched by {}".format(meta_dict['grandparent_title'], meta_dict['title'],
|
|
||||||
" & ".join(USER_LST)))
|
" & ".join(USER_LST)))
|
||||||
delete_lst.append(meta_dict['file'])
|
print("Removing {}".format(meta_dict['file']))
|
||||||
|
os.remove(meta_dict['file'])
|
||||||
for x in delete_lst:
|
|
||||||
print("Removing {}".format(x))
|
|
||||||
os.remove(x)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user