Difference between revisions of "FindDuplicateRecordings"

From MythTV Official Wiki
Jump to: navigation, search
m (let the sql bindings handle substitution, use some better search syntax, add 'safe' mode as default)
m
 
Line 50: Line 50:
  
 
[[Category:Python Scripts]]
 
[[Category:Python Scripts]]
 +
[[Category:Management Scripts]]

Latest revision as of 00:25, 30 May 2011

A Small script to automaticly remove duplicate recorded movies from mythtv. In order to identify the recordings to process, you have to change the CATEGORY variable if your EPG sets a different category by default for movies.

This script does not work for series, you will loose all your recordings!


Script.png FindDuplicateRecordings.py

#!/usr/bin/python

from MythTV import MythDB, MythLog
import sys

DODELETE=False
if len(sys.argv) == 2:
    if sys.argv[1] == '--delete':
        DODELETE=True

MINIMUM_LENGTH='1:15:00'
CATEGORY='spielfilm'

db=MythDB()

c=db.cursor()
c.execute('''\
select
  count(title), title, timediff(endtime,starttime) as length
from recorded
where
  subtime(timediff(endtime,starttime),%s) > 0 and
  category = %s
group by title having count(title) > 1;''', (MINIMUM_LENGTH, CATEGORY)
)

deleted=0
processed=0

for count, title, length in c:
    processed+=1
    if not DODELETE:
        print '%s:' % title
    for rec in sorted(db.searchRecorded(title=title), k=lambda x: x.starttime, reverse=True)[int(DODELETE):]:
        if DODELETE:
            rec.delete()
            deleted+=1
        else:
            print '    %s - %s' % (rec.chanid, rec.starttime.isoformat())
if DODELETE:
    print 'Processed/Deleted: %3d/%3d' % (processed, deleted)