forked from jkirkcaldy/plex-utills
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_files.py
41 lines (36 loc) · 1.36 KB
/
check_files.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
#!/usr/bin/python
import os
import sys
import time
from configparser import ConfigParser
from plexapi.server import PlexServer
import re
config_object = ConfigParser()
config_object.read("config/config.ini")
server = config_object["PLEXSERVER"]
options = config_object["OPTIONS"]
baseurl = (server["PLEX_URL"])
token = (server["TOKEN"])
plex = PlexServer(baseurl, token)
plexlibrary = (server["FILMSLIBRARY"])
films = plex.library.section(plexlibrary)
ppath = (server["PLEXPATH"])
mpath = (server["MOUNTEDPATH"])
xdays = int(options["CHECK_FILES_HISTORY"])
xsize = 100000000
now = time.time()
for i in films.search():
dir = os.path.dirname(re.sub(ppath, mpath, i.media[0].parts[0].file))
for root, dirs, files in os.walk(dir):
for name in files:
filename = os.path.join(root, name)
if os.stat(filename).st_mtime > now - (xdays * 86400):
if os.stat(filename).st_size > xsize:
print('checking', i.title)
command = "ffmpeg -v error -i \"" + filename + "\" -c:v rawvideo -map 0:1 -f null - 2>&1"
output = os.popen(command).read()
print(output)
if output.lower().find('error') == -1:
print(i.title, 'is OK!')
else:
print('Oh Bugger!', filename, 'is completely buggered')