2018-08-16 02:01:49 +00:00
from get_argv import config_dir
2017-12-05 00:01:10 +00:00
import os
import sqlite3
# Check if database exist
2018-08-16 02:01:49 +00:00
if os . path . exists ( os . path . join ( config_dir , ' db/bazarr.db ' ) ) == True :
2017-12-05 00:01:10 +00:00
# Open database connection
2018-08-16 02:01:49 +00:00
db = sqlite3 . connect ( os . path . join ( config_dir , ' db/bazarr.db ' ) , timeout = 30 )
2017-12-05 00:01:10 +00:00
c = db . cursor ( )
2018-01-10 16:44:47 +00:00
# Execute tables modifications
2017-12-05 00:01:10 +00:00
try :
c . execute ( ' alter table table_settings_providers add column " username " " text " ' )
except :
pass
2018-01-10 16:44:47 +00:00
else :
c . execute ( ' UPDATE table_settings_providers SET username= " " ' )
2017-12-05 00:01:10 +00:00
try :
c . execute ( ' alter table table_settings_providers add column " password " " text " ' )
except :
pass
2018-01-10 16:44:47 +00:00
else :
c . execute ( ' UPDATE table_settings_providers SET password= " " ' )
2017-12-19 01:24:04 +00:00
try :
c . execute ( ' alter table table_shows add column " audio_language " " text " ' )
except :
pass
2018-01-23 04:25:58 +00:00
try :
c . execute ( ' CREATE TABLE `table_settings_notifier` (`name` TEXT, `url` TEXT, `enabled` INTEGER); ' )
except :
pass
else :
providers = [ ' Boxcar ' , ' Faast ' , ' Growl ' , ' Join ' , ' KODI ' , ' Mattermost ' , ' Notify My Android ' , ' Prowl ' , ' Pushalot ' , ' PushBullet ' , ' Pushjet ' , ' Pushover ' , ' Rocket.Chat ' , ' Slack ' , ' Super Toasty ' , ' Telegram ' , ' Twitter ' , ' XBMC ' ]
for provider in providers :
c . execute ( ' INSERT INTO `table_settings_notifier` (name, enabled) VALUES (?, ?); ' , ( provider , ' 0 ' ) )
2018-04-21 12:40:33 +00:00
try :
c . execute ( ' alter table table_shows add column " sortTitle " " text " ' )
except :
pass
2018-04-23 13:18:26 +00:00
try :
2018-04-24 14:48:52 +00:00
c . execute ( ' CREATE TABLE " table_movies " ( `tmdbId` TEXT NOT NULL UNIQUE, `title` TEXT NOT NULL, `path` TEXT NOT NULL UNIQUE, `languages` TEXT, `subtitles` TEXT, `missing_subtitles` TEXT, `hearing_impaired` TEXT, `radarrId` INTEGER NOT NULL UNIQUE, `overview` TEXT, `poster` TEXT, `fanart` TEXT, " audio_language " " text " , `sceneName` TEXT, PRIMARY KEY(`tmdbId`) ) ' )
except :
pass
try :
c . execute ( ' CREATE TABLE " table_history_movie " ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, `action` INTEGER NOT NULL, `radarrId` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `description` TEXT NOT NULL ) ' )
2018-04-23 13:18:26 +00:00
except :
pass
2018-07-23 22:06:10 +00:00
try :
2018-08-02 23:11:34 +00:00
c . execute ( ' DELETE FROM table_settings_notifier WHERE rowid > 24 ' ) #Modify this if we add more notification provider
2018-08-10 23:28:47 +00:00
rows = c . execute ( ' SELECT name FROM table_settings_notifier WHERE name = " Discord " ' ) . fetchall ( )
2018-08-10 23:36:43 +00:00
if len ( rows ) == 0 :
2018-08-10 23:28:47 +00:00
providers = [ ' Discord ' , ' E-Mail ' , ' Emby ' , ' IFTTT ' , ' Stride ' , ' Windows ' ]
for provider in providers :
c . execute ( ' INSERT INTO `table_settings_notifier` (name, enabled) VALUES (?, ?); ' , ( provider , ' 0 ' ) )
2018-08-02 23:11:34 +00:00
except :
2018-08-10 23:28:47 +00:00
pass
2018-07-23 22:06:10 +00:00
2018-07-30 02:39:37 +00:00
try :
2018-08-23 19:58:15 +00:00
c . execute ( ' CREATE TABLE `system` ( `configured` TEXT, `updated` TEXT) ' )
c . execute ( ' INSERT INTO `system` (configured, updated) VALUES (?, ?); ' , ( ' 0 ' , ' 0 ' ) )
2018-08-02 23:11:34 +00:00
except :
pass
2018-08-27 00:53:02 +00:00
try :
c . execute ( ' alter table table_movies add column " failedAttempts " " text " ' )
c . execute ( ' alter table table_episodes add column " failedAttempts " " text " ' )
except :
pass
2018-08-11 00:16:47 +00:00
2017-12-05 00:01:10 +00:00
# Commit change to db
db . commit ( )
2018-03-27 02:24:40 +00:00
try :
c . execute ( ' alter table table_episodes add column " scene_name " TEXT ' )
db . commit ( )
except :
pass
else :
from scheduler import execute_now
2018-08-23 19:58:15 +00:00
from get_settings import get_general_settings
2018-05-27 03:01:57 +00:00
integration = get_general_settings ( )
2018-08-23 19:58:15 +00:00
if integration [ 12 ] is True :
2018-08-09 03:43:13 +00:00
execute_now ( ' sync_episodes ' )
2018-08-23 19:58:15 +00:00
if integration [ 13 ] is True :
2018-08-09 03:43:13 +00:00
execute_now ( ' update_movies ' )
try :
c . execute ( ' alter table table_episodes add column " monitored " TEXT ' )
db . commit ( )
except :
pass
else :
from scheduler import execute_now
2018-08-23 19:58:15 +00:00
from get_settings import get_general_settings
2018-08-09 03:43:13 +00:00
integration = get_general_settings ( )
2018-08-23 19:58:15 +00:00
if integration [ 12 ] is True :
2018-08-09 03:43:13 +00:00
execute_now ( ' sync_episodes ' )
try :
c . execute ( ' alter table table_movies add column " monitored " TEXT ' )
db . commit ( )
except :
pass
else :
from scheduler import execute_now
2018-08-23 19:58:15 +00:00
from get_settings import get_general_settings
2018-08-09 03:43:13 +00:00
integration = get_general_settings ( )
2018-08-23 19:58:15 +00:00
if integration [ 13 ] is True :
2018-08-09 03:43:13 +00:00
execute_now ( ' update_movies ' )
db . close ( )