config.py 123 KB
Newer Older
echel0n's avatar
echel0n committed
1
2
3
# Author: echel0n <[email protected]>
# URL: https://tv
# Git: https://github.com/V/git
4
#
echel0n's avatar
echel0n committed
5
# This file is part of 
6
#
echel0n's avatar
echel0n committed
7
# is free software: you can redistribute it and/or modify
8
9
10
11
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
echel0n's avatar
echel0n committed
12
# is distributed in the hope that it will be useful,
13
14
15
16
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
echel0n's avatar
echel0n committed
18
# along with   If not, see <http://www.gnu.org/licenses/>.
19
20
21

from __future__ import unicode_literals

22
import base64
echel0n's avatar
echel0n committed
23
import datetime
24
import gettext
25
26
import os
import os.path
27
import random
28
import re
echel0n's avatar
v8.8.1    
echel0n committed
29
import sys
echel0n's avatar
echel0n committed
30
import uuid
echel0n's avatar
echel0n committed
31
from ast import literal_eval
32
from itertools import izip, cycle
33

echel0n's avatar
echel0n committed
34
import rarfile
echel0n's avatar
echel0n committed
35
from apscheduler.triggers.interval import IntervalTrigger
36
from configobj import ConfigObj
37
38

import sickrage
39
from sickrage.core.common import SD, WANTED, SKIPPED, Quality
echel0n's avatar
echel0n committed
40
from sickrage.core.helpers import makeDir, generate_secret, auto_type, get_lan_ip, \
echel0n's avatar
echel0n committed
41
    extract_zipfile, try_int, checkbox_to_value, generateApiKey, backupVersionedFile
42
from sickrage.core.searchers import get_backlog_cycle_time
43
from sickrage.core.websession import WebSession
44

45

46
class Config(object):
47
    def __init__(self):
48
49
        self.loaded = False

50
        self.config_obj = None
echel0n's avatar
echel0n committed
51
        self.config_version = 11
echel0n's avatar
echel0n committed
52

echel0n's avatar
echel0n committed
53
        self.encryption_secret = ""
echel0n's avatar
echel0n committed
54
        self.encryption_version = 2
55

56
57
        self.app_id = ""

58
        self.debug = False
echel0n's avatar
echel0n committed
59

60
        self.last_db_compact = 0
61

62
63
64
        self.log_size = 1048576
        self.log_nr = 5

65
66
        self.enable_api_providers_cache = False

echel0n's avatar
echel0n committed
67
        self.enable_upnp = True
68
69
70
71
72
73
74
75
76
77
78
79
        self.version_notify = True
        self.auto_update = True
        self.notify_on_update = True
        self.notify_on_login = False
        self.pip_path = ""
        self.git_reset = True
        self.git_username = ""
        self.git_password = ""
        self.git_path = ""
        self.git_autoissues = False
        self.git_newver = False
        self.socket_timeout = 30
echel0n's avatar
echel0n committed
80
        self.web_host = ""
81
        self.web_port = 8081
echel0n's avatar
echel0n committed
82
        self.web_external_port = 0
83
84
        self.web_log = False
        self.web_root = ""
85
86
        self.app_username = ""
        self.app_password = ""
87
        self.web_ipv6 = False
echel0n's avatar
echel0n committed
88
        self.web_cookie_secret = ""
89
90
91
92
93
94
95
96
97
        self.web_use_gzip = True
        self.handle_reverse_proxy = False
        self.proxy_setting = ""
        self.proxy_indexers = True
        self.ssl_verify = True
        self.enable_https = False
        self.https_cert = os.path.abspath(os.path.join(sickrage.PROG_DIR, 'server.crt'))
        self.https_key = os.path.abspath(os.path.join(sickrage.PROG_DIR, 'server.key'))
        self.api_key = ""
echel0n's avatar
echel0n committed
98
        self.api_root = ""
99
        self.indexer_default_language = 'en'
echel0n's avatar
echel0n committed
100
        self.ep_default_deleted_status = None
101
102
103
104
105
106
107
108
109
110
111
112
        self.launch_browser = False
        self.showupdate_stale = True
        self.root_dirs = ""
        self.cpu_preset = "NORMAL"
        self.anon_redirect = 'http://nullrefer.com/?'
        self.download_url = ""
        self.trash_remove_show = False
        self.trash_rotate_logs = False
        self.sort_article = False
        self.display_all_seasons = True
        self.default_page = "home"
        self.use_listview = False
echel0n's avatar
echel0n committed
113
        self.processor_follow_symlinks = False
echel0n's avatar
echel0n committed
114
115
116
        self.quality_default = None
        self.status_default = None
        self.status_default_after = None
117
118
119
120
121
122
        self.flatten_folders_default = False
        self.subtitles_default = False
        self.indexer_default = 0
        self.indexer_timeout = 120
        self.scene_default = False
        self.anime_default = False
123
        self.skip_downloaded_default = False
124
125
        self.naming_multi_ep = False
        self.naming_anime_multi_ep = False
echel0n's avatar
echel0n committed
126
127
        self.naming_pattern = ""
        self.naming_abd_pattern = ""
128
        self.naming_custom_abd = False
echel0n's avatar
echel0n committed
129
        self.naming_sports_pattern = ""
130
        self.naming_custom_sports = False
echel0n's avatar
echel0n committed
131
        self.naming_anime_pattern = ""
132
133
134
        self.naming_custom_anime = False
        self.naming_force_folders = False
        self.naming_strip_year = False
echel0n's avatar
echel0n committed
135
        self.naming_anime = ""
136
137
        self.use_nzbs = False
        self.use_torrents = False
echel0n's avatar
echel0n committed
138
139
        self.nzb_method = ""
        self.nzb_dir = ""
140
        self.usenet_retention = 500
echel0n's avatar
echel0n committed
141
142
        self.torrent_method = ""
        self.torrent_dir = ""
143
144
145
146
        self.download_propers = False
        self.enable_rss_cache = True
        self.enable_rss_cache_valid_shows = False
        self.torrent_file_to_magnet = False
147
        self.download_unverified_magnet_link = False
echel0n's avatar
echel0n committed
148
        self.proper_searcher_interval = ""
149
150
151
152
153
154
155
156
        self.allow_high_priority = False
        self.sab_forced = False
        self.randomize_providers = False
        self.min_autopostprocessor_freq = 1
        self.min_daily_searcher_freq = 10
        self.min_backlog_searcher_freq = 10
        self.min_version_updater_freq = 1
        self.min_subtitle_searcher_freq = 1
echel0n's avatar
echel0n committed
157
        self.min_failed_snatch_age = 1
158
159
160
161
162
        self.backlog_days = 7
        self.add_shows_wo_dir = False
        self.create_missing_show_dirs = False
        self.rename_episodes = False
        self.airdate_episodes = False
echel0n's avatar
echel0n committed
163
        self.file_timestamp_timezone = ""
164
165
166
        self.process_automatically = False
        self.no_delete = False
        self.keep_processed_dir = False
echel0n's avatar
echel0n committed
167
        self.process_method = ""
168
        self.delrarcontents = False
echel0n's avatar
echel0n committed
169
        self.delete_non_associated_files = False
170
171
172
        self.move_associated_files = False
        self.postpone_if_sync_files = True
        self.nfo_rename = True
echel0n's avatar
echel0n committed
173
        self.tv_download_dir = ""
174
        self.unpack = False
175
        self.unpack_dir = ""
176
        self.skip_removed_files = False
echel0n's avatar
echel0n committed
177
        self.allowed_extensions = ""
178
        self.nzbs = False
echel0n's avatar
echel0n committed
179
180
        self.nzbs_uid = ""
        self.nzbs_hash = ""
181
182
        self.omgwtfnzbs = False
        self.newzbin = False
echel0n's avatar
echel0n committed
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
        self.newzbin_username = ""
        self.newzbin_password = ""
        self.sab_username = ""
        self.sab_password = ""
        self.sab_apikey = ""
        self.sab_category = ""
        self.sab_category_backlog = ""
        self.sab_category_anime = ""
        self.sab_category_anime_backlog = ""
        self.sab_host = ""
        self.nzbget_username = ""
        self.nzbget_password = ""
        self.nzbget_category = ""
        self.nzbget_category_backlog = ""
        self.nzbget_category_anime = ""
        self.nzbget_category_anime_backlog = ""
        self.nzbget_host = ""
200
201
        self.nzbget_use_https = False
        self.nzbget_priority = 100
echel0n's avatar
echel0n committed
202
203
204
205
206
        self.torrent_username = ""
        self.torrent_password = ""
        self.torrent_host = ""
        self.torrent_path = ""
        self.torrent_seed_time = ""
207
208
        self.torrent_paused = False
        self.torrent_high_bandwidth = False
echel0n's avatar
echel0n committed
209
210
        self.torrent_label = ""
        self.torrent_label_anime = ""
211
        self.torrent_verify_cert = False
echel0n's avatar
echel0n committed
212
213
        self.torrent_rpcurl = ""
        self.torrent_auth_type = ""
214
215
216
217
218
219
220
221
        self.use_kodi = False
        self.kodi_always_on = True
        self.kodi_notify_onsnatch = False
        self.kodi_notify_ondownload = False
        self.kodi_notify_onsubtitledownload = False
        self.kodi_update_library = False
        self.kodi_update_full = False
        self.kodi_update_onlyfirst = False
echel0n's avatar
echel0n committed
222
223
224
        self.kodi_host = ""
        self.kodi_username = ""
        self.kodi_password = ""
225
226
227
228
229
        self.use_plex = False
        self.plex_notify_onsnatch = False
        self.plex_notify_ondownload = False
        self.plex_notify_onsubtitledownload = False
        self.plex_update_library = False
echel0n's avatar
echel0n committed
230
231
232
233
234
        self.plex_server_host = ""
        self.plex_server_token = ""
        self.plex_host = ""
        self.plex_username = ""
        self.plex_password = ""
235
        self.use_plex_client = False
echel0n's avatar
echel0n committed
236
237
        self.plex_client_username = ""
        self.plex_client_password = ""
238
        self.use_emby = False
echel0n's avatar
echel0n committed
239
240
241
        self.emby_notify_onsnatch = False
        self.emby_notify_ondownload = False
        self.emby_notify_onsubtitledownload = False
echel0n's avatar
echel0n committed
242
243
        self.emby_host = ""
        self.emby_apikey = ""
244
245
246
247
        self.use_growl = False
        self.growl_notify_onsnatch = False
        self.growl_notify_ondownload = False
        self.growl_notify_onsubtitledownload = False
echel0n's avatar
echel0n committed
248
249
        self.growl_host = ""
        self.growl_password = ""
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
        self.use_freemobile = False
        self.freemobile_notify_onsnatch = False
        self.freemobile_notify_ondownload = False
        self.freemobile_notify_onsubtitledownload = False
        self.freemobile_id = ""
        self.freemobile_apikey = ""
        self.use_telegram = False
        self.telegram_notify_onsnatch = False
        self.telegram_notify_ondownload = False
        self.telegram_notify_onsubtitledownload = False
        self.telegram_id = ""
        self.telegram_apikey = ""
        self.use_prowl = False
        self.prowl_notify_onsnatch = False
        self.prowl_notify_ondownload = False
        self.prowl_notify_onsubtitledownload = False
echel0n's avatar
echel0n committed
266
        self.prowl_api = ""
267
268
269
270
271
        self.prowl_priority = 0
        self.use_twitter = False
        self.twitter_notify_onsnatch = False
        self.twitter_notify_ondownload = False
        self.twitter_notify_onsubtitledownload = False
echel0n's avatar
echel0n committed
272
273
274
275
        self.twitter_username = ""
        self.twitter_password = ""
        self.twitter_prefix = ""
        self.twitter_dmto = ""
276
        self.twitter_usedm = False
echel0n's avatar
echel0n committed
277
278
279
280
281
282
283
284
        self.use_twilio = False
        self.twilio_notify_onsnatch = False
        self.twilio_notify_ondownload = False
        self.twilio_notify_onsubtitledownload = False
        self.twilio_phone_sid = ""
        self.twilio_account_sid = ""
        self.twilio_auth_token = ""
        self.twilio_to_number = ""
285
286
287
288
        self.use_boxcar2 = False
        self.boxcar2_notify_onsnatch = False
        self.boxcar2_notify_ondownload = False
        self.boxcar2_notify_onsubtitledownload = False
echel0n's avatar
echel0n committed
289
        self.boxcar2_accesstoken = ""
290
291
292
293
        self.use_pushover = False
        self.pushover_notify_onsnatch = False
        self.pushover_notify_ondownload = False
        self.pushover_notify_onsubtitledownload = False
echel0n's avatar
echel0n committed
294
295
296
297
        self.pushover_userkey = ""
        self.pushover_apikey = ""
        self.pushover_device = ""
        self.pushover_sound = ""
298
299
300
301
302
        self.use_libnotify = False
        self.libnotify_notify_onsnatch = False
        self.libnotify_notify_ondownload = False
        self.libnotify_notify_onsubtitledownload = False
        self.use_nmj = False
echel0n's avatar
echel0n committed
303
304
305
        self.nmj_host = ""
        self.nmj_database = ""
        self.nmj_mount = ""
306
        self.use_anidb = False
echel0n's avatar
echel0n committed
307
308
        self.anidb_username = ""
        self.anidb_password = ""
309
310
311
312
        self.anidb_use_mylist = False
        self.anime_split_home = False
        self.use_synoindex = False
        self.use_nmjv2 = False
echel0n's avatar
echel0n committed
313
314
315
        self.nmjv2_host = ""
        self.nmjv2_database = ""
        self.nmjv2_dbloc = ""
316
317
318
319
320
        self.use_synologynotifier = False
        self.synologynotifier_notify_onsnatch = False
        self.synologynotifier_notify_ondownload = False
        self.synologynotifier_notify_onsubtitledownload = False
        self.use_slack = False
echel0n's avatar
echel0n committed
321
322
323
        self.slack_notify_onsnatch = False
        self.slack_notify_ondownload = False
        self.slack_notify_onsubtitledownload = False
324
325
326
327
328
329
        self.slack_webhook = ""
        self.use_discord = False
        self.discord_notify_onsnatch = False
        self.discord_notify_ondownload = False
        self.discord_notify_onsubtitledownload = False
        self.discord_webhook = ""
echel0n's avatar
echel0n committed
330
331
        self.discord_name = ""
        self.discord_avatar_url = ""
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
        self.discord_tts = False
        self.use_trakt = False
        self.trakt_username = ""
        self.trakt_oauth_token = ""
        self.trakt_remove_watchlist = False
        self.trakt_remove_serieslist = False
        self.trakt_remove_show_from_sickrage = False
        self.trakt_sync_watchlist = False
        self.trakt_method_add = False
        self.trakt_start_paused = False
        self.trakt_use_recommended = False
        self.trakt_sync = False
        self.trakt_sync_remove = False
        self.trakt_default_indexer = 1
        self.trakt_timeout = 30
        self.trakt_blacklist_name = ""
        self.use_pytivo = False
        self.pytivo_notify_onsnatch = False
        self.pytivo_notify_ondownload = False
        self.pytivo_notify_onsubtitledownload = False
        self.pytivo_update_library = False
echel0n's avatar
echel0n committed
353
354
355
        self.pytivo_host = ""
        self.pytivo_share_name = ""
        self.pytivo_tivo_name = ""
356
357
358
359
        self.use_nma = False
        self.nma_notify_onsnatch = False
        self.nma_notify_ondownload = False
        self.nma_notify_onsubtitledownload = False
echel0n's avatar
echel0n committed
360
        self.nma_api = ""
361
362
363
364
365
        self.nma_priority = 0
        self.use_pushalot = False
        self.pushalot_notify_onsnatch = False
        self.pushalot_notify_ondownload = False
        self.pushalot_notify_onsubtitledownload = False
echel0n's avatar
echel0n committed
366
        self.pushalot_authorizationtoken = ""
367
368
369
370
        self.use_pushbullet = False
        self.pushbullet_notify_onsnatch = False
        self.pushbullet_notify_ondownload = False
        self.pushbullet_notify_onsubtitledownload = False
echel0n's avatar
echel0n committed
371
372
        self.pushbullet_api = ""
        self.pushbullet_device = ""
373
374
375
376
        self.use_email = False
        self.email_notify_onsnatch = False
        self.email_notify_ondownload = False
        self.email_notify_onsubtitledownload = False
echel0n's avatar
echel0n committed
377
        self.email_host = ""
378
379
        self.email_port = 25
        self.email_tls = False
echel0n's avatar
echel0n committed
380
381
382
383
        self.email_user = ""
        self.email_password = ""
        self.email_from = ""
        self.email_list = ""
384
385
386
        self.gui_lang = ""
        self.gui_static_dir = os.path.join(sickrage.PROG_DIR, 'core', 'webserver', 'static')
        self.gui_views_dir = os.path.join(sickrage.PROG_DIR, 'core', 'webserver', 'views')
echel0n's avatar
echel0n committed
387
388
        self.home_layout = ""
        self.history_layout = ""
389
390
        self.history_limit = 0
        self.display_show_specials = False
echel0n's avatar
echel0n committed
391
        self.coming_eps_layout = ""
392
        self.coming_eps_display_paused = False
echel0n's avatar
echel0n committed
393
394
        self.coming_eps_sort = ""
        self.coming_eps_missed_range = ""
395
396
        self.fuzzy_dating = False
        self.trim_zero = False
echel0n's avatar
echel0n committed
397
398
399
400
401
402
403
        self.date_preset = ""
        self.time_preset = ""
        self.time_preset_w_seconds = ""
        self.timezone_display = ""
        self.theme_name = ""
        self.poster_sortby = ""
        self.poster_sortdir = ""
404
405
        self.filter_row = True
        self.use_subtitles = False
echel0n's avatar
echel0n committed
406
407
408
409
        self.subtitles_languages = ""
        self.subtitles_dir = ""
        self.subtitles_services_list = ""
        self.subtitles_services_enabled = ""
410
411
412
413
        self.subtitles_history = False
        self.embedded_subtitles_all = False
        self.subtitles_hearing_impaired = False
        self.subtitles_multi = False
echel0n's avatar
echel0n committed
414
415
416
417
418
419
420
421
422
        self.subtitles_extra_scripts = []
        self.addic7ed_user = ""
        self.addic7ed_pass = ""
        self.opensubtitles_user = ""
        self.opensubtitles_pass = ""
        self.legendastv_user = ""
        self.legendastv_pass = ""
        self.itasa_user = ""
        self.itasa_pass = ""
423
        self.delete_failed = False
echel0n's avatar
echel0n committed
424
425
426
427
428
        self.extra_scripts = []
        self.require_words = ""
        self.ignore_words = ""
        self.ignored_subs_list = ""
        self.sync_files = ""
429
430
431
        self.calendar_unprotected = False
        self.calendar_icons = False
        self.no_restart = False
432
        self.allowed_video_file_exts = []
echel0n's avatar
echel0n committed
433
        self.thetvdb_apitoken = ""
434
435
436
437
438
439
440
441
442
443
444
445
446
447
        self.trakt_api_key = '5c65f55e11d48c35385d9e8670615763a605fad28374c8ae553a7b7a50651ddd'
        self.trakt_api_secret = 'b53e32045ac122a445ef163e6d859403301ffe9b17fb8321d428531b69022a82'
        self.trakt_app_id = '4562'
        self.trakt_oauth_url = 'https://trakt.tv/'
        self.trakt_api_url = 'https://api.trakt.tv/'
        self.fanart_api_key = '9b3afaf26f6241bdb57d6cc6bd798da7'
        self.shows_recent = []

        self.autopostprocessor_freq = None
        self.daily_searcher_freq = None
        self.backlog_searcher_freq = None
        self.version_updater_freq = None
        self.subtitle_searcher_freq = None
        self.showupdate_hour = None
echel0n's avatar
echel0n committed
448
449

        self.use_failed_snatcher = False
echel0n's avatar
echel0n committed
450
        self.failed_snatch_age = None
451

echel0n's avatar
echel0n committed
452
        self.quality_sizes = {}
453

echel0n's avatar
echel0n committed
454
        self.custom_providers = ""
455
456
457
458
459
460
461
462
463
464
465

        self.git_remote = "origin"
        self.git_remote_url = "https://git.sickrage.ca/SiCKRAGE/sickrage"

        self.random_user_agent = False

        self.fanart_background = True
        self.fanart_background_opacity = 0.4

        self.unrar_tool = rarfile.UNRAR_TOOL
        self.unrar_alt_tool = rarfile.ALT_TOOL
echel0n's avatar
echel0n committed
466

467
468
        self.view_changelog = False

469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
    @property
    def defaults(self):
        return {
            'Providers': {
                'custom_providers': '',
                'providers_order': []
            },
            'NZBs': {
                'nzbs': False,
                'nzbs_uid': '',
                'nzbs_hash': ''
            },
            'Growl': {
                'growl_host': '',
                'use_growl': False,
                'growl_notify_ondownload': False,
                'growl_notify_onsubtitledownload': False,
                'growl_notify_onsnatch': False,
                'growl_password': ''
            },
            'Slack': {
echel0n's avatar
echel0n committed
490
491
492
                'slack_notify_onsnatch': False,
                'slack_notify_ondownload': False,
                'slack_notify_onsubtitledownload': False,
493
                'use_slack': False,
echel0n's avatar
echel0n committed
494
                'slack_webhook': ''
495
496
497
498
499
500
501
502
503
504
505
506
            },
            'TELEGRAM': {
                'telegram_notify_ondownload': False,
                'telegram_apikey': '',
                'telegram_id': '',
                'use_telegram': False,
                'telegram_notify_onsnatch': False,
                'telegram_notify_onsubtitledownload': False
            },
            'GUI': {
                'coming_eps_display_paused': False,
                'display_show_specials': True,
507
                'gui_lang': '',
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
                'history_limit': '100',
                'poster_sortdir': 1,
                'coming_eps_missed_range': 7,
                'date_preset': '%x',
                'fuzzy_dating': False,
                'fanart_background': True,
                'home_layout': 'poster',
                'coming_eps_layout': 'banner',
                'coming_eps_sort': 'date',
                'poster_sortby': 'name',
                'time_preset': '%I:%M:%S%p',
                'trim_zero': False,
                'fanart_background_opacity': 0.4,
                'history_layout': 'detailed',
                'filter_row': True,
                'timezone_display': 'local',
                'theme_name': 'dark'
            },
            'NMA': {
                'nma_notify_onsubtitledownload': False,
                'use_nma': False,
                'nma_notify_onsnatch': False,
                'nma_priority': '0',
                'nma_api': '',
                'nma_notify_ondownload': False
            },
            'Prowl': {
                'prowl_notify_ondownload': False,
                'prowl_api': '',
                'prowl_priority': '0',
                'prowl_notify_onsubtitledownload': False,
                'prowl_notify_onsnatch': False,
                'use_prowl': False
            },
            'Synology': {
                'use_synoindex': False
            },
            'Newzbin': {
                'newzbin': False,
                'newzbin_password': '',
                'newzbin_username': ''
            },
            'Trakt': {
                'trakt_remove_serieslist': False,
                'trakt_remove_show_from_sickrage': False,
                'trakt_use_recommended': False,
                'trakt_sync': False,
                'use_trakt': False,
                'trakt_blacklist_name': '',
                'trakt_start_paused': False,
                'trakt_sync_remove': False,
                'trakt_username': '',
                'trakt_oauth_token': '',
                'trakt_method_add': 0,
                'trakt_remove_watchlist': False,
                'trakt_sync_watchlist': False,
                'trakt_timeout': 30,
                'trakt_default_indexer': 1
            },
            'NMJv2': {
                'nmjv2_dbloc': '',
                'nmjv2_database': '',
                'nmjv2_host': '',
                'use_nmjv2': False
            },
            'SABnzbd': {
                'sab_forced': False,
                'sab_category': 'tv',
                'sab_apikey': '',
                'sab_category_anime': 'anime',
                'sab_category_backlog': 'tv',
                'sab_host': '',
                'sab_password': '',
                'sab_username': '',
                'sab_category_anime_backlog': 'anime'
            },
            'Plex': {
                'plex_update_library': False,
                'plex_server_host': '',
                'plex_host': '',
                'plex_password': '',
                'plex_notify_onsubtitledownload': False,
                'plex_notify_onsnatch': False,
                'plex_username': '',
                'plex_notify_ondownload': False,
                'plex_server_token': '',
echel0n's avatar
echel0n committed
594
595
596
597
                'use_plex': False,
                'use_plex_client': False,
                'plex_client_username': '',
                'plex_client_password': ''
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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
            },
            'TORRENT': {
                'torrent_verify_cert': False,
                'torrent_paused': False,
                'torrent_host': '',
                'torrent_label_anime': '',
                'torrent_path': '',
                'torrent_auth_type': '',
                'torrent_rpcurl': 'transmission',
                'torrent_username': '',
                'torrent_label': '',
                'torrent_password': '',
                'torrent_high_bandwidth': False,
                'torrent_seed_time': 0
            },
            'Pushalot': {
                'pushalot_notify_onsubtitledownload': False,
                'pushalot_authorizationtoken': '',
                'pushalot_notify_onsnatch': False,
                'pushalot_notify_ondownload': False,
                'use_pushalot': False
            },
            'Pushover': {
                'pushover_notify_ondownload': False,
                'pushover_sound': 'pushover',
                'use_pushover': False,
                'pushover_notify_onsubtitledownload': False,
                'pushover_device': '',
                'pushover_apikey': '',
                'pushover_userkey': '',
                'pushover_notify_onsnatch': False
            },
            'Email': {
                'email_notify_onsnatch': False,
                'email_list': '',
                'email_password': '',
                'email_tls': False,
                'use_email': False,
                'email_notify_ondownload': False,
                'email_port': 25,
                'email_notify_onsubtitledownload': False,
                'email_user': '',
                'email_from': '',
                'email_host': ''
            },
            'KODI': {
                'kodi_update_onlyfirst': False,
                'kodi_notify_onsnatch': False,
                'kodi_notify_ondownload': False,
                'kodi_host': '',
                'kodi_username': '',
                'kodi_always_on': True,
                'kodi_update_library': False,
                'use_kodi': False,
                'kodi_password': '',
                'kodi_update_full': False,
                'kodi_notify_onsubtitledownload': False
            },
            'Quality': {
                'sizes': Quality.qualitySizes
            },
            'FreeMobile': {
                'freemobile_notify_onsnatch': False,
                'freemobile_notify_onsubtitledownload': False,
                'freemobile_notify_ondownload': False,
                'freemobile_apikey': '',
                'freemobile_id': '',
                'use_freemobile': False
            },
            'Discord': {
echel0n's avatar
echel0n committed
668
669
670
671
672
673
674
675
                'discord_notify_onsubtitledownload': False,
                'discord_notify_ondownload': False,
                'discord_notify_onsnatch': False,
                'discord_webhook': '',
                'use_discord': False,
                'discord_name': '',
                'discord_avatar_url': '',
                'discord_tts': False
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
            },
            'SynologyNotifier': {
                'synologynotifier_notify_onsnatch': False,
                'synologynotifier_notify_ondownload': False,
                'use_synologynotifier': False,
                'synologynotifier_notify_onsubtitledownload': False
            },
            'ANIDB': {
                'anidb_use_mylist': False,
                'use_anidb': False,
                'anidb_password': '',
                'anidb_username': ''
            },
            'Blackhole': {
                'nzb_dir': '',
                'torrent_dir': ''
            },
            'General': {
echel0n's avatar
echel0n committed
694
                'app_id': self.app_id or str(uuid.uuid4()),
695
                'enable_api_providers_cache': True,
696
697
698
699
700
701
702
703
704
                'log_size': 1048576,
                'calendar_unprotected': False,
                'https_key': os.path.abspath(os.path.join(sickrage.PROG_DIR, 'server.key')),
                'allow_high_priority': True,
                'anon_redirect': 'http://nullrefer.com/?',
                'indexer_timeout': 120,
                'web_use_gzip': True,
                'dailysearch_frequency': 40,
                'ignore_words': 'german,french,core2hd,dutch,swedish,reenc,MrLss',
echel0n's avatar
echel0n committed
705
                'api_key': self.api_key or generateApiKey(),
706
707
                'check_propers_interval': 'daily',
                'nzb_method': 'blackhole',
echel0n's avatar
echel0n committed
708
                'web_cookie_secret': self.web_cookie_secret or generate_secret(),
709
                'ssl_verify': True,
echel0n's avatar
echel0n committed
710
                'encryption_secret': self.encryption_secret or generate_secret(),
echel0n's avatar
echel0n committed
711
                'enable_upnp': True,
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
                'version_notify': True,
                'web_root': '',
                'add_shows_wo_dir': False,
                'debug': True,
                'indexer_default': 0,
                'use_torrents': True,
                'display_all_seasons': True,
                'usenet_retention': 500,
                'download_propers': True,
                'pip_path': 'pip',
                'del_rar_contents': False,
                'process_method': 'copy',
                'file_timestamp_timezone': 'network',
                'auto_update': True,
                'tv_download_dir': '',
                'naming_custom_abd': False,
728
                'skip_downloaded_default': False,
729
730
731
732
733
734
735
736
737
738
739
740
                'naming_sports_pattern': '%SN - %A-D - %EN',
                'create_missing_show_dirs': False,
                'trash_rotate_logs': False,
                'airdate_episodes': False,
                'notify_on_update': True,
                'https_cert': os.path.abspath(os.path.join(sickrage.PROG_DIR, 'server.crt')),
                'git_autoissues': False,
                'backlog_days': 7,
                'root_dirs': '',
                'naming_pattern': 'Season %0S/%SN - S%0SE%0E - %EN',
                'sort_article': False,
                'handle_reverse_proxy': False,
741
742
                'app_username': '',
                'app_password': '',
743
744
745
746
747
748
749
750
751
752
                'postpone_if_sync_files': True,
                'cpu_preset': 'NORMAL',
                'nfo_rename': True,
                'naming_anime_multi_ep': 1,
                'use_nzbs': False,
                'web_ipv6': False,
                'anime_default': False,
                'default_page': 'home',
                'update_frequency': 1,
                'download_url': '',
echel0n's avatar
echel0n committed
753
                'encryption_version': self.encryption_version,
754
755
                'showupdate_hour': 3,
                'enable_rss_cache': True,
756
                'enable_rss_cache_valid_shows': False,
757
                'torrent_file_to_magnet': False,
758
                'download_unverified_magnet_link': False,
echel0n's avatar
echel0n committed
759
                'status_default': SKIPPED,
760
761
762
763
764
                'naming_anime': 3,
                'naming_custom_sports': False,
                'naming_anime_pattern': 'Season %0S/%SN - S%0SE%0E - %EN',
                'naming_custom_anime': False,
                'randomize_providers': False,
echel0n's avatar
echel0n committed
765
                'web_host': get_lan_ip(),
echel0n's avatar
echel0n committed
766
                'config_version': self.config_version,
767
768
769
770
                'process_automatically': False,
                'git_path': 'git',
                'sync_files': '!sync,lftp-pget-status,part,bts,!qb',
                'web_port': 8081,
echel0n's avatar
echel0n committed
771
                'web_external_port': self.web_external_port or random.randint(49152, 65536),
772
773
                'launch_browser': False,
                'unpack': False,
774
                'unpack_dir': "",
echel0n's avatar
echel0n committed
775
                'delete_non_associated_files': True,
776
777
778
779
780
781
782
783
784
785
786
787
788
789
                'move_associated_files': False,
                'naming_multi_ep': 1,
                'random_user_agent': False,
                'torrent_method': 'blackhole',
                'use_listview': False,
                'trash_remove_show': False,
                'enable_https': False,
                'no_delete': False,
                'naming_abd_pattern': '%SN - %A.D - %EN',
                'socket_timeout': 30,
                'proxy_setting': '',
                'backlog_frequency': 21,
                'notify_on_login': False,
                'rename_episodes': True,
echel0n's avatar
echel0n committed
790
                'quality_default': SD,
791
792
793
794
795
796
797
798
799
                'git_username': '',
                'extra_scripts': '',
                'flatten_folders_default': False,
                'indexerDefaultLang': 'en',
                'autopostprocessor_frequency': 10,
                'showupdate_stale': True,
                'git_password': '',
                'ep_default_deleted_status': 6,
                'no_restart': False,
800
801
802
803
804
805
806
                'allowed_video_file_exts': [
                    'avi', 'mkv', 'mpg', 'mpeg', 'wmv',
                    'ogm', 'mp4', 'iso', 'img', 'divx',
                    'm2ts', 'm4v', 'ts', 'flv', 'f4v',
                    'mov', 'rmvb', 'vob', 'dvr-ms', 'wtv',
                    'ogv', '3gp', 'webm', 'tp'
                ],
807
808
809
810
811
812
813
814
815
                'require_words': '',
                'naming_strip_year': False,
                'proxy_indexers': True,
                'web_log': False,
                'log_nr': 5,
                'git_newver': False,
                'git_reset': True,
                'scene_default': False,
                'skip_removed_files': False,
echel0n's avatar
echel0n committed
816
                'status_default_after': WANTED,
817
818
819
                'last_db_compact': 0,
                'ignored_subs_list': 'dk,fin,heb,kor,nor,nordic,pl,swe',
                'calendar_icons': False,
echel0n's avatar
echel0n committed
820
821
                'keep_processed_dir': True,
                'processor_follow_symlinks': False,
822
823
                'allowed_extensions': 'srt,nfo,srr,sfv',
                'view_changelog': False
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
            },
            'NZBget': {
                'nzbget_host': '',
                'nzbget_category_anime': 'anime',
                'nzbget_use_https': False,
                'nzbget_password': 'tegbzn6789',
                'nzbget_category': 'tv',
                'nzbget_priority': 100,
                'nzbget_category_anime_backlog': 'anime',
                'nzbget_username': 'nzbget',
                'nzbget_category_backlog': 'tv'
            },
            'Emby': {
                'use_emby': False,
                'emby_apikey': '',
echel0n's avatar
echel0n committed
839
840
841
842
                'emby_host': '',
                'emby_notify_onsubtitledownload': False,
                'emby_notify_ondownload': False,
                'emby_notify_onsnatch': False,
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
            },
            'pyTivo': {
                'pytivo_share_name': '',
                'pytivo_notify_ondownload': False,
                'pytivo_tivo_name': '',
                'pytivo_notify_onsnatch': False,
                'pytivo_host': '',
                'pytivo_notify_onsubtitledownload': False,
                'pyTivo_update_library': False,
                'use_pytivo': False
            },
            'theTVDB': {
                'thetvdb_apitoken': ''
            },
            'Pushbullet': {
                'pushbullet_device': '',
                'use_pushbullet': False,
                'pushbullet_notify_ondownload': False,
                'pushbullet_notify_onsubtitledownload': False,
                'pushbullet_notify_onsnatch': False,
                'pushbullet_api': ''
            },
            'Libnotify': {
                'libnotify_notify_onsubtitledownload': False,
                'libnotify_notify_onsnatch': False,
                'libnotify_notify_ondownload': False,
                'use_libnotify': False
            },
            'Boxcar2': {
                'use_boxcar2': False,
                'boxcar2_notify_onsnatch': False,
                'boxcar2_notify_ondownload': False,
                'boxcar2_accesstoken': '',
                'boxcar2_notify_onsubtitledownload': False
            },
            'FailedDownloads': {
                'delete_failed': False
            },
echel0n's avatar
echel0n committed
881
            'FailedSnatches': {
echel0n's avatar
echel0n committed
882
                'use_failed_snatcher': False,
echel0n's avatar
echel0n committed
883
884
                'failed_snatch_age': 2
            },
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
            'NMJ': {
                'nmj_host': '',
                'nmj_mount': '',
                'use_nmj': False,
                'nmj_database': ''
            },
            'Twitter': {
                'twitter_username': '',
                'use_twitter': False,
                'twitter_password': '',
                'twitter_notify_ondownload': False,
                'twitter_notify_onsubtitledownload': False,
                'twitter_notify_onsnatch': False,
                'twitter_prefix': 'SiCKRAGE',
                'twitter_dmto': '',
                'twitter_usedm': False
            },
            'Twilio': {
                'use_twilio': False,
                'twilio_notify_onsnatch': False,
                'twilio_notify_ondownload': False,
                'twilio_notify_onsubtitledownload': False,
                'twilio_phone_sid': '',
                'twilio_account_sid': '',
                'twilio_auth_token': '',
                'twilio_to_number': '',
            },
            'Subtitles': {
                'itasa_password': '',
                'opensubtitles_username': '',
                'subtitles_services_list': '',
                'subtitles_history': False,
                'legendastv_password': '',
                'subtitles_hearing_impaired': False,
                'addic7ed_password': '',
                'subtitles_languages': '',
                'embedded_subtitles_all': False,
                'subtitles_finder_frequency': 1,
                'subtitles_default': False,
                'subtitles_multi': True,
                'subtitles_services_enabled': '',
                'itasa_username': '',
                'subtitles_dir': '',
                'addic7ed_username': '',
                'opensubtitles_password': '',
                'subtitles_extra_scripts': '',
                'use_subtitles': False,
                'legendastv_username': ''
            },
            'ANIME': {
                'anime_split_home': False
            }
        }

939
    def change_gui_lang(self, lang):
echel0n's avatar
echel0n committed
940
941
        if lang:
            # Selected language
942
            gt = gettext.translation('messages', sickrage.LOCALE_DIR, languages=[lang], codeset='UTF-8')
echel0n's avatar
echel0n committed
943
944
945
            gt.install(unicode=True, names=["ngettext"])
        else:
            # System default language
946
            gettext.install('messages', sickrage.LOCALE_DIR, unicode=1, codeset='UTF-8', names=["ngettext"])
947

948
        self.gui_lang = lang
949

echel0n's avatar
echel0n committed
950
951
952
    def change_unrar_tool(self, unrar_tool, unrar_alt_tool):
        # Check for failed unrar attempt, and remove it
        # Must be done before unrar is ever called or the self-extractor opens and locks startup
953
        bad_unrar = os.path.join(sickrage.app.data_dir, 'unrar.exe')
echel0n's avatar
echel0n committed
954
955
956
957
        if os.path.exists(bad_unrar) and os.path.getsize(bad_unrar) == 447440:
            try:
                os.remove(bad_unrar)
            except OSError as e:
958
                sickrage.app.log.warning(
echel0n's avatar
echel0n committed
959
960
961
962
963
964
965
966
967
968
969
970
                    "Unable to delete bad unrar.exe file {}: {}. You should delete it manually".format(bad_unrar,
                                                                                                       e.strerror))

        try:
            rarfile.custom_check(unrar_tool)
        except (rarfile.RarCannotExec, rarfile.RarExecError, OSError, IOError):
            # Let's just return right now if the defaults work
            try:

                test = rarfile._check_unrar_tool()
                if test:
                    # These must always be set to something before returning
971
972
                    self.unrar_tool = rarfile.UNRAR_TOOL
                    self.alt_unrar_tool = rarfile.ALT_TOOL
echel0n's avatar
echel0n committed
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
                    return True
            except (rarfile.RarCannotExec, rarfile.RarExecError, OSError, IOError):
                pass

            if sys.platform == 'win32':
                # Look for WinRAR installations
                found = False
                winrar_path = 'WinRAR\\UnRAR.exe'
                # Make a set of unique paths to check from existing environment variables
                check_locations = {
                    os.path.join(location, winrar_path) for location in (
                    os.environ.get("ProgramW6432"), os.environ.get("ProgramFiles(x86)"),
                    os.environ.get("ProgramFiles"), re.sub(r'\s?\(x86\)', '', os.environ["ProgramFiles"])
                ) if location
                }
                check_locations.add(os.path.join(sickrage.PROG_DIR, 'unrar\\unrar.exe'))

                for check in check_locations:
                    if os.path.isfile(check):
                        # Can use it?
                        try:
                            rarfile.custom_check(check)
                            unrar_tool = check
                            found = True
                            break
                        except (rarfile.RarCannotExec, rarfile.RarExecError, OSError, IOError):
                            found = False

For faster browsing, not all history is shown. View entire blame