forked from blacktwin/JBOPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_plex_log.py
79 lines (59 loc) · 2.22 KB
/
check_plex_log.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Run script by itself. Will look for WARN code followed by /library/metadata/ str in Plex logs.
This is find files that are corrupt or having playback issues.
I corrupted a file to test.
"""
from __future__ import print_function
from __future__ import unicode_literals
from builtins import object
import requests
import sys
# ## EDIT THESE SETTINGS ##
TAUTULLI_APIKEY = 'XXXXXXXX' # Your Tautulli API key
TAUTULLI_URL = 'http://localhost:8181/' # Your Tautulli URL
lib_met = []
err_title = []
class PlexLOG(object):
def __init__(self, data=None):
self.error_msg = []
for e, f, g in data[0::1]:
if f == 'WARN' and 'of key /library/metadata' in g:
self.error_msg += [[f] + [g]]
class UserHIS(object):
def __init__(self, data=None):
data = data or {}
self.title = [d['full_title'] for d in data]
def get_plex_log():
# Get the user IP list from Tautulli
payload = {'apikey': TAUTULLI_APIKEY,
'cmd': 'get_plex_log'}
try:
r = requests.get(TAUTULLI_URL.rstrip('/') + '/api/v2', params=payload)
response = r.json()
res_data = response['response']['data']['data']
return PlexLOG(data=res_data)
except Exception as e:
sys.stderr.write("Tautulli API 'get_plex_log' request failed: {0}.".format(e))
def get_history(key):
# Get the user IP list from Tautulli
payload = {'apikey': TAUTULLI_APIKEY,
'cmd': 'get_history',
'rating_key': key}
try:
r = requests.get(TAUTULLI_URL.rstrip('/') + '/api/v2', params=payload)
response = r.json()
res_data = response['response']['data']['data']
return UserHIS(data=res_data)
except Exception as e:
sys.stderr.write("Tautulli API 'get_history' request failed: {0}.".format(e))
if __name__ == '__main__':
p_log = get_plex_log()
for co, msg in p_log.error_msg:
lib_met += [(msg.split('/library/metadata/'))[1].split(r'\n')[0]]
for i in lib_met:
his = get_history(int(i))
err_title += [x.encode('UTF8') for x in his.title]
err_title = ''.join((set(err_title)))
print(err_title + ' is having playback issues')