forked from mdhiggins/sickbeard_mp4_automator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postConversion.py
executable file
·77 lines (62 loc) · 2.54 KB
/
postConversion.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
#!/usr/bin/env python
import os
import sys
import json
import urllib
import struct
import logging
from log import getLogger
from readSettings import ReadSettings
from autoprocess import plex
from metadata import Metadata, MediaType
from mkvtomp4 import MkvtoMp4
from post_processor import PostProcessor
from logging.config import fileConfig
log = getLogger("SickbeardPostProcess")
log.info("Sickbeard extra script post processing started.")
settings = ReadSettings()
if len(sys.argv) > 4:
inputfile = sys.argv[1]
original = sys.argv[2]
tvdb_id = int(sys.argv[3])
season = int(sys.argv[4])
episode = int(sys.argv[5])
converter = MkvtoMp4(settings)
log.debug("Input file: %s." % inputfile)
log.debug("Original name: %s." % original)
log.debug("TVDB ID: %s." % tvdb_id)
log.debug("Season: %s episode: %s." % (season, episode))
info = converter.isValidSource(inputfile)
if info:
log.info("Processing %s." % inputfile)
output = converter.process(inputfile, original=original, info=info)
if output:
# Tag with metadata
try:
tag = Metadata(MediaType.TV, tvdbid=tvdb_id, season=season, episode=episode, original=original, language=settings.taglanguage)
if settings.tagfile:
log.info("Tagging %s with ID %s season %s episode %s." % (inputfile, tvdb_id, season, episode))
tag.setHD(output['x'], output['y'])
tag.writeTags(output['output'], settings.artwork, settings.thumbnail)
except:
log.exception("Unable to tag file")
# QTFS
if settings.relocate_moov:
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.setTV(tag.tmdbid, tag.season, tag.episode)
post_processor.run_scripts()
try:
refresh = json.load(urllib.urlopen(settings.getRefreshURL(tvdb_id)))
for item in refresh:
log.debug(refresh[item])
except (IOError, ValueError):
log.exception("Couldn't refresh Sickbeard, check your autoProcess.ini settings.")
plex.refreshPlex(settings, 'show', log)
else:
log.error("Not enough command line arguments present %s." % len(sys.argv))
sys.exit()