forked from mdhiggins/sickbeard_mp4_automator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postCouchPotato.py
executable file
·72 lines (60 loc) · 2.48 KB
/
postCouchPotato.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
#!/usr/bin/env python
import sys
import os
import logging
from extensions import valid_tagging_extensions
from readSettings import ReadSettings
from mkvtomp4 import MkvtoMp4
from tmdb_mp4 import tmdb_mp4
from autoprocess import plex
from post_processor import PostProcessor
from logging.config import fileConfig
logpath = '/var/log/sickbeard_mp4_automator'
if os.name == 'nt':
logpath = os.path.dirname(sys.argv[0])
elif not os.path.isdir(logpath):
try:
os.mkdir(logpath)
except:
logpath = os.path.dirname(sys.argv[0])
fileConfig(os.path.join(os.path.dirname(sys.argv[0]), 'logging.ini'), defaults={'logfilename': os.path.join(logpath, 'index.log')})
log = logging.getLogger("CouchPotatoPostConversion")
log.info('MP4 Automator - Post processing script initialized')
settings = ReadSettings(os.path.dirname(sys.argv[0]), "autoProcess.ini")
converter = MkvtoMp4(settings)
imdbid = sys.argv[1]
inputfile = sys.argv[2]
original = sys.argv[3]
log.debug("IMDBID: %s" % imdbid)
log.debug("Input file path: %s" % inputfile)
log.debug("Original file name: %s" % original)
try:
log.info('Processing file: %s', inputfile)
if MkvtoMp4(settings).validSource(inputfile):
log.info('File is valid')
output = converter.process(inputfile, original=original)
if output:
# Tag with metadata
if settings.tagfile and output['output_extension'] in valid_tagging_extensions:
log.info('Tagging file with IMDB ID %s', imdbid)
try:
tagmp4 = tmdb_mp4(imdbid, original=original, language=settings.taglanguage)
tagmp4.setHD(output['x'], output['y'])
tagmp4.writeTags(output['output'], settings.artwork)
except:
log.error("Unable to tag file")
# QTFS
if settings.relocate_moov and output['output_extension'] in valid_tagging_extensions:
converter.QTFS(output['output'])
# Copy to additional locations
output_files = converter.replicate(output['output'])
# Run any post process scripts
if settings.postprocess:
post_processor = PostProcessor(output_files, log)
post_processor.setMovie(imdbid)
post_processor.run_scripts()
plex.refreshPlex(settings, 'movie', log)
else:
log.info('File %s is invalid, ignoring' % inputfile)
except:
log.exception('File processing failed: %s' % inputfile)