Kodi Community Forum
How to add Vietnamese Keyboard Layout - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: OS independent / Other (https://forum.kodi.tv/forumdisplay.php?fid=228)
+---- Thread: How to add Vietnamese Keyboard Layout (/showthread.php?tid=372916)

Pages: 1 2


RE: How to add Vietnamese Keyboard Layout - scott967 - 2023-04-25

(2023-04-08, 19:51)usphil Wrote: I wonder if you can put my first post back in Global Search. Because even though I have created a Vietnamese keyboard, I still want to search without accents.

I took a look at this and I don't see an easy way to do it.  Currently the search is done with database query via JSON-RPC.  I didn't see a way to search without diacriticals except by dumping the database and searching in the addon.  That seems to me to be a big performance problem.

scott s.
.


RE: How to add Vietnamese Keyboard Layout - usphil - 2023-04-28

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.")