#!/usr/bin/python import MySQLdb, os, re if not os.path.exists("/usr/bin/totem-video-thumbnailer"): raise "This script requires totem-video-thumbnailer" # read DB connection parameters fp = open("/etc/mythtv/mysql.txt") DB = {} for line in fp: if line.find("=") != -1: k,v = line.strip().split("=",1) DB[k] = v required_keys = ["DBHostName", "DBUserName", "DBName", "DBPassword"] for k in required_keys: if not DB.has_key(k): raise "Missing MySQL connection detail: %s" % k # connect to database con = MySQLdb.connect(DB["DBHostName"], DB["DBUserName"], DB["DBPassword"], DB["DBName"]) crs = con.cursor() # get location where thumbnails are stored sql = "select data from settings where value = 'VideoArtworkDir';" crs.execute(sql) VIDEO_DIR = crs.fetchone()[0] # get all files without covers cmd = 'totem-video-thumbnailer -j -s 600 "%s" "%s" >/dev/null 2>&1' sql = "select intid, filename from videometadata where coverfile = 'No Cover';" crs.execute(sql) VIDEOS = [] while 1: data = crs.fetchone() if not data: break intid, filename = data parts = filename.split(os.sep) output = re.sub("[^a-z0-9_]","_","_".join(parts[-2:]).lower()) + ".jpg" full_output = os.path.join(VIDEO_DIR, output) if os.path.exists(full_output): pass else: cmd_exec = cmd % (filename, full_output) print "Thumbnailing", os.path.split(filename)[1] os.system(cmd_exec) VIDEOS.append((intid,full_output)) sql = "update videometadata set coverfile = %s where intid = %s limit 1;" for intid, thumbnail in VIDEOS: crs.execute(sql, (thumbnail, intid)) print "Added %s to database" % thumbnail