2015-03-05, 14:39
Hi,
I've written this script to manager my kodi thumbnails and it does exactly what I want. I hope it will do what you want also.
Brian.
#!/usr/bin/python
# filename: flush.py
# As a safeguard stop kodi before use.
import sqlite3
import sys
import os
# Set up home directory
home = os.getenv("HOME")
count = 0
# Connect sqlite3 to database
try:
conn = sqlite3.connect(home + '/.kodi/userdata/Database/Textures13.db')
choice = conn.execute("SELECT DISTINCT url from texture") # get distinct entries from database
for row in choice: # as a guide to which to flush
print row[0]
category = raw_input("Please select a keyword from above list for which category to flush >>> ")
cursor = conn.execute("SELECT id, url, cachedurl, imagehash, lasthashcheck from texture")
# read database
for row in cursor: # loop through all entries in database
target = row[1] # get url as target
if category in target: # test if target contains our category
record = row[0] # yes, get record id number
print "Deleting record no.", record
conn.execute("DELETE from texture where id=?",(record,)) # delete this entry
conn.commit() # commit change
file = home + '/.kodi/userdata/Thumbnails/' + row[2] # get cachedurl filename
if os.path.exists(file): # make sure it exists
print "Removing file ", file
os.remove(file) # remove file
count += 1 # count how many thumbnails have been removed
print "Number of thumbnails removed ", count
# Failed to open database, report error
except sqlite3.Error as e:
print "Error %s:" % e.args[0]
sys.exit(1)
# That's all folks
finally:
if conn:
conn.close()
I've written this script to manager my kodi thumbnails and it does exactly what I want. I hope it will do what you want also.
Brian.
#!/usr/bin/python
# filename: flush.py
# As a safeguard stop kodi before use.
import sqlite3
import sys
import os
# Set up home directory
home = os.getenv("HOME")
count = 0
# Connect sqlite3 to database
try:
conn = sqlite3.connect(home + '/.kodi/userdata/Database/Textures13.db')
choice = conn.execute("SELECT DISTINCT url from texture") # get distinct entries from database
for row in choice: # as a guide to which to flush
print row[0]
category = raw_input("Please select a keyword from above list for which category to flush >>> ")
cursor = conn.execute("SELECT id, url, cachedurl, imagehash, lasthashcheck from texture")
# read database
for row in cursor: # loop through all entries in database
target = row[1] # get url as target
if category in target: # test if target contains our category
record = row[0] # yes, get record id number
print "Deleting record no.", record
conn.execute("DELETE from texture where id=?",(record,)) # delete this entry
conn.commit() # commit change
file = home + '/.kodi/userdata/Thumbnails/' + row[2] # get cachedurl filename
if os.path.exists(file): # make sure it exists
print "Removing file ", file
os.remove(file) # remove file
count += 1 # count how many thumbnails have been removed
print "Number of thumbnails removed ", count
# Failed to open database, report error
except sqlite3.Error as e:
print "Error %s:" % e.args[0]
sys.exit(1)
# That's all folks
finally:
if conn:
conn.close()