#!/usr/bin/env python3 # -*- coding: utf-8 -*- ############################################################################## # myth-delete-missing # # Delete database entries for recordings where there is no recording file. # Optionally set the recording to re-record if there is an existing recording # rule for it. Optionally create a "record one episode" recording rule if # there is no existing recording rule. SQL can be used to select which # recordings to look at to see if the recording file is missing. # # Author: J S Worthington # ############################################################################## import argparse import logging import logging.handlers import MythTV import os import sys import MythTV.services_api.send as api import MythTV.services_api.utilities as util try: import requests except ImportError: exit('Install python3-requests') extra_help = ''' Notes: 1) This program has only been tested on MythTV v32. 2) Warning: Beta software - please test with care. If you have problems, please email me or post on the MythTV users mailing list. Take a copy of all console output (especially any tracebacks), and a copy of the myth-delete-missing.py.log file. 3) Due to lack of time I have not yet got the 'drc' action working - the code to add a 'record once' recording rule does not work yet. So until it does any recording table entries without matching recording files that also do not have a matching record table entry will not be deleted. How to use: Run this program first with only the 'l' (list) action (or no action, which defaults to 'l'). Check the output to see what deleting would be done and make sure that it will be doing what you want. If there are any recordings that will not be handled as you would like, exclude them by using some SQL with the -s or -f option, and try the 'l' action again to check the results. When you are ready to actually try doing the deletes, DO A FULL DATABASE BACKUP FIRST (using mythconverg_backup.pl), and make sure you know where to find the backup file. Choose a time when mythbackend will not be busy for a long enough time for you to do a backup, try the deletes, and then if necessary restore the database using mythconverg_restore.pl. You can use my gaps program to find a large enough gap: http://www.jsw.gen.nz/mythtv/gaps On Ubuntu, a restore command looks something like this: /usr/share/mythtv/mythconverg_restore.pl --drop_database --create_database --directory=/usr/lib/mythtv/db_backups --filename= Some example SQL phrases to use with the -s or -f options: Exclude specific recordings by recordedid: where not recordedid in (12345, 78901, 19007) Only delete one specific recording: where recordedid=77863 Only delete where the title matches a search string: where title like '%who do you think you are%' Only delete recordings earlier than 2018-17-06 UTC: where starttime<'2018-17-06 00:00' Only delete recordings earlier than 2018-17-06 MST where starttime