2010-06-11, 08:16
This script walks through your tv shows and deletes those episodes that match the following criteria:
I store all my tv series in their own path, so the ignored path is useful for me when I don't want to delete certain episodes in an entire series.
Credit to mdpauley who I based some of my script off of one of his.
Anyone can use/modify this to their heart's content. It would be sweet if someone made a simple gui to modify ignored paths based on tv shows (ignore certain shows), and modify the older than date count.
There ARE more efficient ways of doing this, but I'm lazy and tired and had an itch to write this.
Also, if someone has had success using xbmc with more than one sound card enabled on the system PLEASE let me know :confused2:
- Has been watched
- Older than 20 days (easy to change)
- Not part of a "ignored path"
- Not the only episode in the series
I store all my tv series in their own path, so the ignored path is useful for me when I don't want to delete certain episodes in an entire series.
Credit to mdpauley who I based some of my script off of one of his.
Anyone can use/modify this to their heart's content. It would be sweet if someone made a simple gui to modify ignored paths based on tv shows (ignore certain shows), and modify the older than date count.
There ARE more efficient ways of doing this, but I'm lazy and tired and had an itch to write this.
Code:
import xbmc
import pprint
from urllib import quote_plus
import re
import datetime
# set any paths to ignore here
ignore_paths = []
#change the -20 to match whatever range you want
d = datetime.datetime.now() + datetime.timedelta(days=-20)
minusdays = d.strftime('%Y-%m-%d')
# this gets filled with stuff, leave alone
eps_to_remove = []
print "finding shows with more than one episode"
# find all shows with more than 1 episode
shows_sql = "select count(idEpisode), idShow from tvshowlinkepisode group by idShow;"
shows = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % ( quote_plus( shows_sql ), ) )
showsp=re.compile('<field>(.+?)</field><field>(.+?)</field>')
showmatch=showsp.findall(shows)
for epcount,showid in showmatch:
if epcount > 1:
print "searching show: %s" % showid
# now get the episodes for each show
eps_sql = "select tvshowlinkepisode.idEpisode from tvshowlinkepisode join episode on episode.idEpisode=tvshowlinkepisode.idEpisode where tvshowlinkepisode.idShow = %s" % showid
eps = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % ( quote_plus( eps_sql ), ) )
epsp=re.compile('<field>(.+?)</field>')
epsmatch=epsp.findall(eps)
# get all the episodes, storing all but the most recent
hi_ep = 0
hi_s = 0
hi_details = []
for epid in epsmatch:
print "searching episode: %s" % epid
# now get the episode details if the episode is older than specified limit
details_sql = "select episode.c12,episode.c13, episode.c05, files.playCount, files.strFilename, (select path.strpath from path where files.idpath = path.idpath) from files join episode on episode.idfile=files.idfile where episode.c05 <='"+minusdays+"' and episode.idEpisode = %s" % epid
# gives season,ep, playtime, playcount, file, path
records = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % ( quote_plus( details_sql ), ) )
p=re.compile('<field>(.+?)</field><field>(.+?)</field><field>(.+?)</field><field>(.+?)</field><field>(.+?)</field><field>(.+?)</field>')
match=p.findall(records)
for s,ep,playdate,playcount,file,path in match:
if hi_s == 0 and hi_ep == 0:
# first, make it hi and move on
print "ignoring first found episode"
hi_s = s
hi_ep = ep
hi_details = [s,ep,playdate,playcount,file,path]
elif s < hi_s:
# season is lower, just remove it
eps_to_remove.append([path,file])
elif s > hi_s:
# season is greater, just remove current hi
eps_to_remove.append([hi_details[5],hi_details[4]])
hi_s = s
hi_ep = ep
hi_details = [s,ep,playdate,playcount,file,path]
elif s == hi_s:
# seasons equal, test episodes
if ep < hi_ep:
# episode lower, just remove it
eps_to_remove.append([path,file])
else:
#episode is newer or equal, remove current hi
eps_to_remove.append([hi_details[5],hi_details[4]])
hi_s = s
hi_ep = ep
hi_details = [s,ep,playdate,playcount,file,path]
for path,file in eps_to_remove:
if path not in ignore_paths:
full = path + file
print "removing %s" % full
xbmc.executehttpapi("FileDelete(%s)" % full)
xbmc.executebuiltin('XBMC.updatelibrary(video)')
Also, if someone has had success using xbmc with more than one sound card enabled on the system PLEASE let me know :confused2: