forked from mdhiggins/sickbeard_mp4_automator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadSettings.py
649 lines (589 loc) · 28.8 KB
/
readSettings.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
import os
import sys
import locale
try:
import configparser
except ImportError:
import ConfigParser as configparser
import logging
from extensions import *
from babelfish import Language
class ReadSettings:
def __init__(self, directory, filename, logger=None):
# Setup logging
if logger:
log = logger
else:
log = logging.getLogger(__name__)
# Setup encoding to avoid UTF-8 errors
if sys.version[0] == '2':
SYS_ENCODING = None
try:
locale.setlocale(locale.LC_ALL, "")
SYS_ENCODING = locale.getpreferredencoding()
except (locale.Error, IOError):
pass
# For OSes that are poorly configured just force UTF-8
if not SYS_ENCODING or SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
SYS_ENCODING = 'UTF-8'
if not hasattr(sys, "setdefaultencoding"):
reload(sys)
try:
# pylint: disable=E1101
# On non-unicode builds this will raise an AttributeError, if encoding type is not valid it throws a LookupError
sys.setdefaultencoding(SYS_ENCODING)
except:
log.exception("Sorry, your environment is not setup correctly for utf-8 support. Please fix your setup and try again")
sys.exit("Sorry, your environment is not setup correctly for utf-8 support. Please fix your setup and try again")
log.info(sys.executable)
# Default settings for SickBeard
sb_defaults = {'host': 'localhost',
'port': '8081',
'ssl': "False",
'api_key': '',
'web_root': '',
'username': '',
'password': ''}
# Default MP4 conversion settings
mp4_defaults = {'ffmpeg': 'ffmpeg.exe',
'ffprobe': 'ffprobe.exe',
'threads': 'auto',
'output_directory': '',
'copy_to': '',
'move_to': '',
'output_extension': 'mp4',
'output_format': 'mp4',
'delete_original': 'True',
'relocate_moov': 'True',
'ios-audio': 'True',
'ios-first-track-only': 'False',
'ios-audio-filter': '',
'max-audio-channels': '',
'audio-language': '',
'audio-default-language': '',
'audio-codec': 'ac3',
'audio-filter': '',
'audio-channel-bitrate': '256',
'video-codec': 'h264, x264',
'video-bitrate': '',
'video-max-width': '',
'h264-max-level': '',
'aac_adtstoasc': 'False',
'use-qsv-decoder-with-encoder': 'True',
'subtitle-codec': 'mov_text',
'subtitle-language': '',
'subtitle-default-language': '',
'subtitle-encoding': '',
'convert-mp4': 'False',
'fullpathguess': 'True',
'tagfile': 'True',
'tag-language': 'en',
'download-artwork': 'poster',
'download-subs': 'False',
'embed-subs': 'True',
'sub-providers': 'addic7ed, podnapisi, thesubdb, opensubtitles',
'permissions': '777',
'post-process': 'False',
'pix-fmt': ''}
# Default settings for CouchPotato
cp_defaults = {'host': 'localhost',
'port': '5050',
'username': '',
'password': '',
'apikey': '',
'delay': '65',
'method': 'renamer',
'delete_failed': 'False',
'ssl': 'False',
'web_root': ''}
# Default settings for Sonarr
sonarr_defaults = {'host': 'localhost',
'port': '8989',
'apikey': '',
'ssl': 'False',
'web_root': ''}
# Default uTorrent settings
utorrent_defaults = {'couchpotato-label': 'couchpotato',
'sickbeard-label': 'sickbeard',
'sickrage-label': 'sickrage',
'sonarr-label': 'sonarr',
'bypass-label': 'bypass',
'convert': 'True',
'webui': 'False',
'action_before': 'stop',
'action_after': 'removedata',
'host': 'http://localhost:8080/',
'username': '',
'password': '',
'output_directory': ''}
# Default SAB settings
sab_defaults = {'convert': 'True',
'Sickbeard-category': 'sickbeard',
'Sickrage-category': 'sickrage',
'Couchpotato-category': 'couchpotato',
'Sonarr-category': 'sonarr',
'Bypass-category': 'bypass',
'output_directory': ''}
# Default Sickrage Settings
sr_defaults = {'host': 'localhost',
'port': '8081',
'ssl': "False",
'api_key': '',
'web_root': '',
'username': '',
'password': ''}
# Default deluge settings
deluge_defaults = {'couchpotato-label': 'couchpotato',
'sickbeard-label': 'sickbeard',
'sickrage-label': 'sickrage',
'sonarr-label': 'sonarr',
'bypass-label': 'bypass',
'convert': 'True',
'host': 'localhost',
'port': '58846',
'username': '',
'password': '',
'output_directory': ''}
# Default Plex Settings
plex_defaults = {'host': 'localhost',
'port': '32400',
'refresh': 'true',
'token': ''}
defaults = {'SickBeard': sb_defaults, 'CouchPotato': cp_defaults, 'Sonarr': sonarr_defaults, 'MP4': mp4_defaults, 'uTorrent': utorrent_defaults, 'SABNZBD': sab_defaults, 'Sickrage': sr_defaults, 'Deluge': deluge_defaults, 'Plex': plex_defaults}
write = False # Will be changed to true if a value is missing from the config file and needs to be written
config = configparser.SafeConfigParser()
configFile = os.path.join(directory, filename)
if os.path.isfile(configFile):
config.read(configFile)
else:
log.error("Config file not found, creating %s." % configFile)
# config.filename = filename
write = True
# Make sure all sections and all keys for each section are present
for s in defaults:
if not config.has_section(s):
config.add_section(s)
write = True
for k in defaults[s]:
if not config.has_option(s, k):
config.set(s, k, defaults[s][k])
write = True
# If any keys are missing from the config file, write them
if write:
self.writeConfig(config, configFile)
# Read relevant MP4 section information
section = "MP4"
self.ffmpeg = os.path.normpath(self.raw(config.get(section, "ffmpeg"))) # Location of FFMPEG.exe
self.ffprobe = os.path.normpath(self.raw(config.get(section, "ffprobe"))) # Location of FFPROBE.exe
self.threads = config.get(section, "threads") # Number of FFMPEG threads
try:
if int(self.threads) < 1:
self.threads = "auto"
except:
self.threads = "auto"
self.output_dir = config.get(section, "output_directory")
if self.output_dir == '':
self.output_dir = None
else:
self.output_dir = os.path.normpath(self.raw(self.output_dir)) # Output directory
self.copyto = config.get(section, "copy_to") # Directories to make copies of the final product
if self.copyto == '':
self.copyto = None
else:
self.copyto = self.copyto.split('|')
for i in range(len(self.copyto)):
self.copyto[i] = os.path.normpath(self.copyto[i])
if not os.path.isdir(self.copyto[i]):
try:
os.makedirs(self.copyto[i])
except:
log.exception("Error making directory %s." % (self.copyto[i]))
self.moveto = config.get(section, "move_to") # Directory to move final product to
if self.moveto == '':
self.moveto = None
else:
self.moveto = os.path.normpath(self.moveto)
if not os.path.isdir(self.moveto):
try:
os.makedirs(self.moveto)
except:
log.exception("Error making directory %s." % (self.moveto))
self.moveto = None
self.output_extension = config.get(section, "output_extension") # Output extension
self.output_format = config.get(section, "output_format") # Output format
if self.output_format not in valid_formats:
self.output_format = 'mov'
self.delete = config.getboolean(section, "delete_original") # Delete original file
self.relocate_moov = config.getboolean(section, "relocate_moov") # Relocate MOOV atom to start of file
if self.relocate_moov:
try:
import qtfaststart
except:
log.error("Please install QTFastStart via PIP, relocate_moov will be disabled without this module.")
self.relocate_moov = False
self.acodec = config.get(section, "audio-codec").lower() # Gets the desired audio codec, if no valid codec selected, default to AC3
if self.acodec == '':
self.acodec == ['ac3']
else:
self.acodec = self.acodec.lower().replace(' ', '').split(',')
self.abitrate = config.get(section, "audio-channel-bitrate")
try:
self.abitrate = int(self.abitrate)
except:
self.abitrate = 256
log.warning("Audio bitrate was invalid, defaulting to 256 per channel.")
if self.abitrate > 256:
log.warning("Audio bitrate >256 may create errors with common codecs.")
self.afilter = config.get(section, "audio-filter").lower().strip() # Audio filter
if self.afilter == '':
self.afilter = None
self.iOS = config.get(section, "ios-audio") # Creates a second audio channel if the standard output methods are different from this for iOS compatability
if self.iOS == "" or self.iOS.lower() in ['false', 'no', 'f', '0']:
self.iOS = False
else:
if self.iOS.lower() in ['true', 'yes', 't', '1']:
self.iOS = ['aac']
else:
self.iOS = self.iOS.lower().replace(' ', '').split(',')
self.iOSFirst = config.getboolean(section, "ios-first-track-only") # Enables the iOS audio option only for the first track
self.iOSfilter = config.get(section, "ios-audio-filter").lower().strip() # iOS audio filter
if self.iOSfilter == '':
self.iOSfilter = None
self.downloadsubs = config.getboolean(section, "download-subs") # Enables downloading of subtitles from the internet sources using subliminal
if self.downloadsubs:
try:
import subliminal
except Exception as e:
self.downloadsubs = False
log.exception("Subliminal is not installed, automatically downloading of subs has been disabled.")
self.subproviders = config.get(section, 'sub-providers').lower()
if self.subproviders == '':
self.downloadsubs = False
log.warning("You must specifiy at least one subtitle provider to downlaod subs automatically, subtitle downloading disabled.")
else:
self.subproviders = self.subproviders.lower().replace(' ', '').split(',')
self.embedsubs = config.getboolean(section, 'embed-subs')
self.permissions = config.get(section, 'permissions')
try:
self.permissions = int(self.permissions, 8)
except:
self.log.exception("Invalid permissions, defaulting to 777.")
self.permissions = int("0777", 8)
try:
self.postprocess = config.getboolean(section, 'post-process')
except:
self.postprocess = False
self.aac_adtstoasc = config.getboolean(section, 'aac_adtstoasc')
# Setup variable for maximum audio channels
self.maxchannels = config.get(section, 'max-audio-channels')
if self.maxchannels == "":
self.maxchannels = None
else:
try:
self.maxchannels = int(self.maxchannels)
except:
log.exception("Invalid number of audio channels specified.")
self.maxchannels = None
if self.maxchannels is not None and self.maxchannels < 1:
log.warning("Must have at least 1 audio channel.")
self.maxchannels = None
self.vcodec = config.get(section, "video-codec")
if self.vcodec == '':
self.vcodec == ['h264', 'x264']
else:
self.vcodec = self.vcodec.lower().replace(' ', '').split(',')
self.vbitrate = config.get(section, "video-bitrate")
if self.vbitrate == '':
self.vbitrate = None
else:
try:
self.vbitrate = int(self.vbitrate)
if not (self.vbitrate > 0):
self.vbitrate = None
log.warning("Video bitrate must be greater than 0, defaulting to no video bitrate cap.")
except:
log.exception("Invalid video bitrate, defaulting to no video bitrate cap.")
self.vbitrate = None
self.vwidth = config.get(section, "video-max-width")
if self.vwidth == '':
self.vwidth = None
else:
try:
self.vwidth = int(self.vwidth)
except:
log.exception("Invalid video width, defaulting to none.")
self.vwidth = None
self.h264_level = config.get(section, "h264-max-level")
if self.h264_level == '':
self.h264_level = None
else:
try:
self.h264_level = float(self.h264_level)
except:
log.exception("Invalid h264 level, defaulting to none.")
self.h264_level = None
self.qsv_decoder = config.getboolean(section, "use-qsv-decoder-with-encoder") # Use Intel QuickSync Decoder when using QuickSync Encoder
self.pix_fmt = config.get(section, "pix-fmt").strip().lower()
if self.pix_fmt == '':
self.pix_fmt = None
else:
self.pix_fmt = self.pix_fmt.replace(' ', '').split(',')
self.awl = config.get(section, 'audio-language').strip().lower() # List of acceptable languages for audio streams to be carried over from the original file, separated by a comma. Blank for all
if self.awl == '':
self.awl = None
else:
self.awl = self.awl.replace(' ', '').split(',')
self.scodec = config.get(section, 'subtitle-codec').strip().lower()
if not self.scodec or self.scodec == "":
if self.embedsubs:
self.scodec = ['mov_text']
else:
self.scodec = ['srt']
log.warning("Invalid subtitle codec, defaulting to '%s'." % self.scodec)
else:
self.scodec = self.scodec.replace(' ', '').split(',')
if self.embedsubs:
if len(self.scodec) > 1:
log.warning("Can only embed one subtitle type, defaulting to 'mov_text'.")
self.scodec = ['mov_text']
if self.scodec[0] not in valid_internal_subcodecs:
log.warning("Invalid interal subtitle codec %s, defaulting to 'mov_text'." % self.scodec[0])
self.scodec = ['mov_text']
else:
for codec in self.scodec:
if codec not in valid_external_subcodecs:
log.warning("Invalid external subtitle codec %s, ignoring." % codec)
self.scodec.remove(codec)
if len(self.scodec) == 0:
log.warning("No valid subtitle formats found, defaulting to 'srt'.")
self.scodec = ['srt']
self.swl = config.get(section, 'subtitle-language').strip().lower() # List of acceptable languages for subtitle streams to be carried over from the original file, separated by a comma. Blank for all
if self.swl == '':
self.swl = None
else:
self.swl = self.swl.replace(' ', '').split(',')
self.subencoding = config.get(section, 'subtitle-encoding').strip().lower()
if self.subencoding == '':
self.subencoding = None
self.adl = config.get(section, 'audio-default-language').strip().lower() # What language to default an undefinied audio language tag to. If blank, it will remain undefined. This is useful for single language releases which tend to leave things tagged as und
if self.adl == "" or len(self.adl) > 3:
self.adl = None
self.sdl = config.get(section, 'subtitle-default-language').strip().lower() # What language to default an undefinied subtitle language tag to. If blank, it will remain undefined. This is useful for single language releases which tend to leave things tagged as und
if self.sdl == ""or len(self.sdl) > 3:
self.sdl = None
# Prevent incompatible combination of settings
if self.output_dir == "" and self.delete is False:
log.error("You must specify an alternate output directory if you aren't going to delete the original file.")
sys.exit()
# Create output directory if it does not exist
if self.output_dir is not None:
if not os.path.isdir(self.output_dir):
os.makedirs(self.output_dir)
self.processMP4 = config.getboolean(section, "convert-mp4") # Determine whether or not to reprocess mp4 files or just tag them
self.fullpathguess = config.getboolean(section, "fullpathguess") # Guess using the full path or not
self.tagfile = config.getboolean(section, "tagfile") # Tag files with metadata
self.taglanguage = config.get(section, "tag-language").strip().lower() # Language to tag files
if len(self.taglanguage) > 2:
try:
babel = Language(self.taglanguage)
self.taglanguage = babel.alpha2
except:
log.exception("Unable to set tag language, defaulting to English.")
self.taglanguage = 'en'
elif len(self.taglanguage) < 2:
log.exception("Unable to set tag language, defaulting to English.")
self.taglanguage = 'en'
self.artwork = config.get(section, "download-artwork").lower() # Download and embed artwork
if self.artwork == "poster":
self.artwork = True
self.thumbnail = False
elif self.artwork == "thumb" or self.artwork == "thumbnail":
self.artwork = True
self.thumbnail = True
else:
self.thumbnail = False
try:
self.artwork = config.getboolean(section, "download-artwork")
except:
self.artwork = True
self.log.error("Invalid download-artwork value, defaulting to 'poster'.")
# Read relevant CouchPotato section information
section = "CouchPotato"
self.CP = {}
self.CP['host'] = config.get(section, "host")
self.CP['port'] = config.get(section, "port")
self.CP['username'] = config.get(section, "username")
self.CP['password'] = config.get(section, "password")
self.CP['apikey'] = config.get(section, "apikey")
self.CP['delay'] = config.get(section, "delay")
self.CP['method'] = config.get(section, "method")
self.CP['web_root'] = config.get(section, "web_root")
try:
self.CP['delay'] = float(self.CP['delay'])
except ValueError:
self.CP['delay'] = 60
try:
self.CP['delete_failed'] = config.getboolean(section, "delete_failed")
except (configparser.NoOptionError, ValueError):
self.CP['delete_failed'] = False
try:
if config.getboolean(section, 'ssl'):
self.CP['protocol'] = "https://"
else:
self.CP['protocol'] = "http://"
except (configparser.NoOptionError, ValueError):
self.CP['protocol'] = "http://"
# Read relevant uTorrent section information
section = "uTorrent"
self.uTorrent = {}
self.uTorrent['cp'] = config.get(section, "couchpotato-label").lower()
self.uTorrent['sb'] = config.get(section, "sickbeard-label").lower()
self.uTorrent['sr'] = config.get(section, "sickrage-label").lower()
self.uTorrent['sonarr'] = config.get(section, "sonarr-label").lower()
self.uTorrent['bypass'] = config.get(section, "bypass-label").lower()
try:
self.uTorrent['convert'] = config.getboolean(section, "convert")
except:
self.uTorrent['convert'] = False
self.uTorrent['output_dir'] = config.get(section, "output_directory")
if self.uTorrent['output_dir'] == '':
self.uTorrent['output_dir'] = None
else:
self.uTorrent['output_dir'] = os.path.normpath(self.raw(self.uTorrent['output_dir'])) # Output directory
self.uTorrentWebUI = config.getboolean(section, "webui")
self.uTorrentActionBefore = config.get(section, "action_before").lower()
self.uTorrentActionAfter = config.get(section, "action_after").lower()
self.uTorrentHost = config.get(section, "host").lower()
self.uTorrentUsername = config.get(section, "username")
self.uTorrentPassword = config.get(section, "password")
# Read relevant Deluge section information
section = "Deluge"
self.deluge = {}
self.deluge['cp'] = config.get(section, "couchpotato-label").lower()
self.deluge['sb'] = config.get(section, "sickbeard-label").lower()
self.deluge['sr'] = config.get(section, "sickrage-label").lower()
self.deluge['sonarr'] = config.get(section, "sonarr-label").lower()
self.deluge['bypass'] = config.get(section, "bypass-label").lower()
try:
self.deluge['convert'] = config.getboolean(section, "convert")
except:
self.deluge['convert'] = False
self.deluge['host'] = config.get(section, "host").lower()
self.deluge['port'] = config.get(section, "port")
self.deluge['user'] = config.get(section, "username")
self.deluge['pass'] = config.get(section, "password")
self.deluge['output_dir'] = config.get(section, "output_directory")
if self.deluge['output_dir'] == '':
self.deluge['output_dir'] = None
else:
self.deluge['output_dir'] = os.path.normpath(self.raw(self.deluge['output_dir'])) # Output directory
# Read relevant Sonarr section information
section = "Sonarr"
self.Sonarr = {}
self.Sonarr['host'] = config.get(section, "host")
self.Sonarr['port'] = config.get(section, "port")
self.Sonarr['apikey'] = config.get(section, "apikey")
self.Sonarr['ssl'] = config.get(section, "ssl")
self.Sonarr['web_root'] = config.get(section, "web_root")
# Read Sickbeard section information
section = "SickBeard"
self.Sickbeard = {}
self.Sickbeard['host'] = config.get(section, "host") # Server Address
self.Sickbeard['port'] = config.get(section, "port") # Server Port
self.Sickbeard['api_key'] = config.get(section, "api_key") # Sickbeard API key
self.Sickbeard['web_root'] = config.get(section, "web_root") # Sickbeard webroot
self.Sickbeard['ssl'] = config.getboolean(section, "ssl") # SSL
self.Sickbeard['user'] = config.get(section, "username")
self.Sickbeard['pass'] = config.get(section, "password")
# Read Sickrage section information
section = "Sickrage"
self.Sickrage = {}
self.Sickrage['host'] = config.get(section, "host") # Server Address
self.Sickrage['port'] = config.get(section, "port") # Server Port
self.Sickrage['api_key'] = config.get(section, "api_key") # Sickbeard API key
self.Sickrage['web_root'] = config.get(section, "web_root") # Sickbeard webroot
self.Sickrage['ssl'] = config.getboolean(section, "ssl") # SSL
self.Sickrage['user'] = config.get(section, "username")
self.Sickrage['pass'] = config.get(section, "password")
# Read SAB section information
section = "SABNZBD"
self.SAB = {}
try:
self.SAB['convert'] = config.getboolean(section, "convert") # Convert
except:
self.SAB['convert'] = False
self.SAB['cp'] = config.get(section, "Couchpotato-category").lower()
self.SAB['sb'] = config.get(section, "Sickbeard-category").lower()
self.SAB['sr'] = config.get(section, "Sickrage-category").lower()
self.SAB['sonarr'] = config.get(section, "Sonarr-category").lower()
self.SAB['bypass'] = config.get(section, "Bypass-category").lower()
self.SAB['output_dir'] = config.get(section, "output_directory")
if self.SAB['output_dir'] == '':
self.SAB['output_dir'] = None
else:
self.SAB['output_dir'] = os.path.normpath(self.raw(self.SAB['output_dir'])) # Output directory
# Read Plex section information
section = "Plex"
self.Plex = {}
self.Plex['host'] = config.get(section, "host")
self.Plex['port'] = config.get(section, "port")
try:
self.Plex['refresh'] = config.getboolean(section, "refresh")
except:
self.Plex['refresh'] = False
self.Plex['token'] = config.get(section, "token")
if self.Plex['token'] == '':
self.Plex['token'] = None
# Pass the values on
self.config = config
self.configFile = configFile
def getRefreshURL(self, tvdb_id):
config = self.config
section = "SickBeard"
protocol = "http://" # SSL
try:
if config.getboolean(section, "ssl"):
protocol = "https://"
except (configparser.NoOptionError, ValueError):
pass
host = config.get(section, "host") # Server Address
port = config.get(section, "port") # Server Port
api_key = config.get(section, "api_key") # Sickbeard API key
web_root = config.get(section, "web_root") # Sickbeard webroot
sickbeard_url = protocol + host + ":" + port + web_root + "/api/" + api_key + "/?cmd=show.refresh&tvdbid=" + str(tvdb_id)
return sickbeard_url
def writeConfig(self, config, cfgfile):
fp = open(cfgfile, "wb")
try:
config.write(fp)
except IOError:
pass
fp.close()
def raw(self, text):
escape_dict = {'\a': r'\a',
'\b': r'\b',
'\c': r'\c',
'\f': r'\f',
'\n': r'\n',
'\r': r'\r',
'\t': r'\t',
'\v': r'\v',
'\'': r'\'',
'\"': r'\"',
'\0': r'\0',
'\1': r'\1',
'\2': r'\2',
'\3': r'\3',
'\4': r'\4',
'\5': r'\5',
'\6': r'\6',
'\7': r'\7',
'\8': r'\8',
'\9': r'\9'}
output = ''
for char in text:
try:
output += escape_dict[char]
except KeyError:
output += char
return output