-
Notifications
You must be signed in to change notification settings - Fork 200
/
postSickbeard.py
executable file
·71 lines (60 loc) · 2.87 KB
/
postSickbeard.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
#!/usr/bin/env python3
import os
import sys
import json
try:
from urllib.request import urlopen
except ImportError:
from urllib import urlopen
import struct
from resources.log import getLogger
from resources.readsettings import ReadSettings
from resources.metadata import MediaType
from resources.mediaprocessor import MediaProcessor
log = getLogger("SickbeardPostProcess")
log.info("Sickbeard extra script post processing started.")
try:
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])
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))
mp = MediaProcessor(settings)
success = mp.fullprocess(inputfile, MediaType.TV, tvdbid=tvdb_id, season=season, episode=episode, original=original)
if success:
try:
protocol = "https://" if settings.Sickbeard['ssl'] else "http://"
host = settings.Sickbeard['host'] # Server Address
port = settings.Sickbeard['port'] # Server Port
apikey = settings.Sickbeard['apikey'] # Sickbeard API key
webroot = settings.Sickbeard['webroot'] # Sickbeard webroot
sickbeard_url = protocol + host + ":" + str(port) + webroot + "/api/" + apikey + "/?cmd=show.refresh&tvdbid=" + str(tvdb_id)
refresh = json.load(urlopen(sickbeard_url))
for item in refresh:
log.debug(refresh[item])
except (IOError, ValueError):
try:
log.debug("Sickbeard refresh failed, trying to fall back to Sickrage settings if available")
protocol = "https://" if settings.Sickrage['ssl'] else "http://"
host = settings.Sickrage['host'] # Server Address
port = settings.Sickrage['port'] # Server Port
apikey = settings.Sickrage['apikey'] # Sickbeard API key
webroot = settings.Sickrage['webroot'] # Sickbeard webroot
sickbeard_url = protocol + host + ":" + str(port) + webroot + "/api/" + apikey + "/?cmd=show.refresh&tvdbid=" + str(tvdb_id)
refresh = json.load(urlopen(sickbeard_url))
for item in refresh:
log.debug(refresh[item])
except (IOError, ValueError):
log.exception("Couldn't refresh Sickbeard/Sickrage, check your autoProcess.ini settings.")
else:
log.error("Not enough command line arguments present %s." % len(sys.argv))
sys.exit(1)
except:
log.exception("Unexpected exception.")
sys.exit(1)