#! /usr/bin/env python ''' Name: mythtv_rerecord_check.py Author: Kane Tse Purpose: This Python script is intended for use to detect zero-length recordings, delete them from MythTV (database and filesystem?) and re-schedule for recording. Version: 0.1-alpha Usage: It is intended for use as a cron job. Warning: This script is an untested alpha-release. Use at your own risk. Requirements: Intended for use with Python bindings for MythTV-0.24 Date Written: 2011-03-06 Bugs: If the tuner is not functioning properly, the call to reschedule may result in the attempting to recording the same show on the same non-working tuner. This may be a good thing if the buggy tuner is functionning intermittently. ''' import MythTV import os from MythTV import MythBE backend = MythBE() recording_count = 0 deleted_recording_count = 0; for recording in backend.getRecordings(): recording_count = recording_count+1 path1 = backend.getCheckfile(recording) if os.path.getsize(path1) == 0: print "WARNING: Program (" + recording.title + "/" + recording.subtitle + "): " + path1 + " has a size of " + os.path.getsize(path1) + " bytes." forgetRecording(recording) delete_recording_returnCode = backend.deleteRecording(recording) if (delete_recording_returnCode == -1): print "Recording has been deleted from database." deleted_recording_count = deleted_recording_count+1 else: print "An error has occurred while attempting to delete the recording." if (deleted_recording_count > 0): # At least one recording has failed. Rescheduling... backend.reschedule() # print "Finished checking " + str(recording_count) + " recordings."