Posts: 153
Joined: Mar 2014
Reputation:
2
There is indeed a performance issue. I added a piece of code that uses the unidecode to filter the returned results. It works OK but it takes about 20-30 seconds.
Can you change the search method according to the SQL query? I have tried directly querying the MyVideos121.db file and the results are returned almost instantly.
import unidecode
import sqlite3
def search_titles(query, titles):
query = unidecode.unidecode(query).lower()
matching_titles = [title for title in titles if query in unidecode.unidecode(title).lower()]
return matching_titles
def get_all_titles(cursor, table_name):
cursor.execute(f"SELECT c00 FROM {table_name}")
titles = [row[0] for row in cursor.fetchall()]
return titles
DB_FILE = r"C:\Users\usphil\AppData\Roaming\Kodi\userdata\Database\MyVideos121.db"
conn = sqlite3.connect(DB_FILE)
cursor = conn.cursor()
movie_titles = get_all_titles(cursor, 'movie')
tvshow_titles = get_all_titles(cursor, 'tvshow')
query = "Em La dinh menh" # Em Là Định Mệnh
matching_movie_titles = search_titles(query, movie_titles)
matching_tvshow_titles = search_titles(query, tvshow_titles)
if matching_movie_titles or matching_tvshow_titles:
if matching_movie_titles:
print("Matching movies:")
for title in matching_movie_titles:
print(f"- {title}")
if matching_tvshow_titles:
print("Matching TV shows:")
for title in matching_tvshow_titles:
print(f"- {title}")
else:
print("No matching titles found.")