FindDuplicateRecordings

From MythTV Official Wiki
Revision as of 00:46, 28 October 2010 by Muhgatus (talk | contribs) (Changed category)

Jump to: navigation, search

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

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
    l=[]
    for recording in db.searchRecorded(title=title):
        l.append((recording.starttime, recording))
    l.sort()
    l.reverse()
    while len(l) > 1:
        dt, recording = l.pop()
        recording.delete()
        deleted+=1
print 'Processed/Deleted: %3d/%3d' % (processed, deleted)