2018-08-16 10:01:49 +08:00
|
|
|
from get_argv import config_dir
|
|
|
|
|
2017-09-19 18:43:14 +08:00
|
|
|
import sqlite3
|
2017-10-20 20:59:21 +08:00
|
|
|
import os
|
2018-08-16 04:51:46 +08:00
|
|
|
from subliminal import provider_manager
|
2017-09-19 18:43:14 +08:00
|
|
|
|
|
|
|
# Get providers list from subliminal
|
|
|
|
providers_list = sorted(provider_manager.names())
|
|
|
|
|
|
|
|
# Open database connection
|
2018-08-16 10:01:49 +08:00
|
|
|
db = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30)
|
2017-09-19 18:43:14 +08:00
|
|
|
c = db.cursor()
|
|
|
|
|
2018-04-23 20:06:30 +08:00
|
|
|
# Remove unsupported providers
|
|
|
|
providers_in_db = c.execute('SELECT name FROM table_settings_providers').fetchall()
|
|
|
|
for provider_in_db in providers_in_db:
|
|
|
|
if provider_in_db[0] not in providers_list:
|
|
|
|
c.execute('DELETE FROM table_settings_providers WHERE name = ?', (provider_in_db[0], ))
|
|
|
|
|
|
|
|
# Commit changes to database table
|
|
|
|
db.commit()
|
|
|
|
|
2017-09-19 18:43:14 +08:00
|
|
|
# Insert providers in database table
|
|
|
|
for provider_name in providers_list:
|
|
|
|
c.execute('''INSERT OR IGNORE INTO table_settings_providers(name) VALUES(?)''', (provider_name, ))
|
|
|
|
|
|
|
|
# Commit changes to database table
|
|
|
|
db.commit()
|
|
|
|
|
|
|
|
# Close database connection
|
|
|
|
db.close()
|