bazarr/bazarr/database.py

60 lines
1.9 KiB
Python
Raw Normal View History

import os
2019-10-22 02:13:37 +00:00
from sqlite3worker import Sqlite3Worker
2019-10-27 03:17:14 +00:00
from six import string_types
from get_args import args
from helper import path_replace, path_replace_movie, path_replace_reverse, path_replace_reverse_movie
2019-10-25 02:35:04 +00:00
database = Sqlite3Worker(os.path.join(args.config_dir, 'db', 'bazarr.db'), max_queue_size=256, as_dict=True)
2019-10-24 16:14:21 +00:00
class SqliteDictConverter:
def __init__(self):
2019-10-28 00:45:15 +00:00
self.keys_insert = tuple()
self.keys_update = tuple()
self.values = tuple()
self.question_marks = tuple()
2019-10-26 18:52:22 +00:00
def convert(self, values_dict):
2019-10-24 16:14:21 +00:00
if type(values_dict) is dict:
2019-10-28 00:45:15 +00:00
temp_keys = list()
temp_values = list()
for item in values_dict.items():
temp_keys.append(item[0])
temp_values.append(item[1])
self.keys_insert = ','.join(temp_keys)
self.keys_update = ','.join([k + '=?' for k in temp_keys])
self.values = tuple(temp_values)
self.question_marks = ','.join(list('?'*len(values_dict)))
2019-10-24 16:14:21 +00:00
return self
else:
pass
dict_converter = SqliteDictConverter()
2019-10-26 18:52:22 +00:00
class SqliteDictPathMapper:
def __init__(self):
pass
def path_replace(self, values_dict):
2019-10-27 01:16:59 +00:00
if type(values_dict) is list:
for item in values_dict:
item['path'] = path_replace(item['path'])
elif type(values_dict) is dict:
values_dict['path'] = path_replace(values_dict['path'])
2019-10-27 03:17:14 +00:00
else:
return path_replace(values_dict)
2019-10-26 18:52:22 +00:00
def path_replace_movie(self, values_dict):
2019-10-27 01:16:59 +00:00
if type(values_dict) is list:
for item in values_dict:
item['path'] = path_replace_movie(item['path'])
elif type(values_dict) is dict:
values_dict['path'] = path_replace_movie(values_dict['path'])
2019-10-27 03:17:14 +00:00
else:
return path_replace(values_dict)
2019-10-26 18:52:22 +00:00
dict_mapper = SqliteDictPathMapper()