+ duration = None
+ if DB is None:
+ duration = me._duration(title, start_chapter, end_chapter)
+ else:
+ st = OS.stat(OS.path.join(ROOT, me.fn))
+ duration = None
+ c = DB.cursor()
+ c.execute("""
+ SELECT device, inode, size, mtime, duration FROM duration
+ WHERE path = ? AND title = ? AND
+ start_chapter = ? AND end_chapter = ?
+ """, [me.fn, title, start_chapter is None and -1 or start_chapter,
+ end_chapter is None and -1 or end_chapter])
+ row = c.fetchone()
+ foundp = False
+ if row is None:
+ duration = me._duration(title, start_chapter, end_chapter)
+ c.execute("""
+ INSERT OR REPLACE INTO duration
+ (path, title, start_chapter, end_chapter,
+ device, inode, size, mtime, duration)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
+ """, [me.fn, title, start_chapter is None and -1 or start_chapter,
+ end_chapter is None and -1 or end_chapter,
+ st.st_dev, st.st_ino, st.st_size, st.st_mtime,
+ duration])
+ else:
+ dev, ino, sz, mt, d = row
+ if (dev, ino, sz, mt) == \
+ (st.st_dev, st.st_ino, st.st_size, st.st_mtime):
+ duration = d
+ else:
+ duration = me._duration(title, start_chapter, end_chapter)
+ c.execute("""
+ UPDATE duration
+ SET device = ?, inode = ?, size = ?, mtime = ?, duration = ?
+ WHERE path = ? AND title = ? AND
+ start_chapter = ? AND end_chapter = ?
+ """, [st.st_dev, st.st_dev, st.st_size, st.st_mtime, duration,
+ me.fn, title, start_chapter is None and -1 or start_chapter,
+ end_chapter is None and -1 or end_chapter])
+ DB.commit()