[mythtv-users] Help needed for scripted recordings
Bill Meek
keemllib at gmail.com
Sun Mar 29 15:03:52 UTC 2020
On 3/29/20 9:34 AM, Klaas de Waal wrote:
> On Sat, 28 Mar 2020 at 20:41, Bill Meek <keemllib at gmail.com> wrote:
>
>> On 3/28/20 2:27 PM, Klaas de Waal wrote:
>>> File "./mythtv-record.py", line 1479, in delete_recordingid
>>> resp_dict = backend.send(endpoint=endpoint, rest=rest, opts=opts)
>>
>> Need to use postdata rather than rest, for example:
>>
>> postdata = {
>> 'RecordedId': recordedid,
>> 'ForceDelete': 'True',
>> 'AllowRerecord': 'True'
>> }
>>
>> resp_dict = backend.send(endpoint=endpoint, postdata=postdata,
>> opts=opts)
>>
>>
>> Yes this does work and it can actually delete a recording in progress.
> Problem is that it requires a recordedid but when I start the recording I
> get a recordid.
> As shown by the following:
>
> [klaas at modu MythTVPython]$ ./mythtv-record.py add --chanid 170858 --manual
> --starttime 2020-03-29T16:15:00 --type Single --title test2 --duration=60
> -1: 170858 NPO 1 Single Record test2 Start:2020-03-29T14:15:00Z
> End:2020-03-29T15:15:00Z Priority:0 Inactive:false Profile:Default
> RecGroup:Default PlayGroup:Default LastRecorded: Expire:true
>
> Added: "test2" (RecordId 3796).
>
> MariaDB [mythconverg]> select chanid,title,recordid,recordedid from
> recorded where recordid=3796;
> +--------+-------+----------+------------+
> | chanid | title | recordid | recordedid |
> +--------+-------+----------+------------+
> | 120081 | test2 | 3796 | 8896 |
> +--------+-------+----------+------------+
>
> [klaas at modu MythTVPython]$ ./mythtv-record.py delete --recordid 8896
> RecordingId "8896" has been deleted.
>
> My understanding is that the entry in table record is created when the
> recording is scheduled with the "mythtv-record.py add" command. This makes
> it possible to return the recordid.
> The entry in table recorded is created when the recording is started, which
> is usually later in time, so the "myth-record.py add" command cannot know
> this.
> So it looks that what I need is the incantation to delete a recording by
> recordid.
> Or a sql query to get the recordedid but that is not really how the
> ServicesAPI should work afaik.
Hi Klaas,
One option is to delete by ChanId and StartTime.
My solution was to get the recordings, find a match for the RecordId
and get the RecordedId from the result. Example:
def delete_recording(backend, recordid, title, args, opts):
''' Delete a single recording, lots of times '''
try:
resp_dict = backend.send(endpoint='Dvr/GetRecordedList',
rest='TitleRegEx={}'.format(title),
opts=opts)
except RuntimeError as error:
print('GetRecordedList Runtme Error: {}'.format(error))
rec_count = int(resp_dict['ProgramList']['Count'])
resp_dict = resp_dict['ProgramList']['Programs']
recordedid = -1
for index in range(rec_count):
if resp_dict[index]['Recording']['RecordId'] == recordid:
recordedid = resp_dict[index]['Recording']['RecordedId']
break
delete_one_rule(backend, recordid, opts)
if recordedid == -1:
print('No match for recordid {} in GetRecordedList'.format(recordid))
return
postdata = {
'RecordedId': recordedid,
'ForceDelete': 'True',
'AllowRerecord': 'True'
}
# What follows was my attempt to do multiple deletes in vcr.py. You don't
# need the loop, but it does do the delete by RecordedId. It also added
# two new switches (in my own copy) you could hard code the values:
for i in range(args.delete_attempts):
try:
resp_dict = backend.send(endpoint='Dvr/DeleteRecording',
postdata=postdata, opts=opts)
except RuntimeError as error:
print('Delete Recording Runtme Error: {} on attempt {}'
.format(error, i))
else:
if check_bool_response(resp_dict, 'Dvr/DeleteRecording'):
print('Deleted RecordedId: {} returned true on attempt {}'
.format(recordedid, i))
else:
print('Deleted RecordedId: {} returned false on attempt {}'
.format(recordedid, i))
time.sleep(args.delay_between_deletes)
New switches, if you like:
parser.add_argument('--delay_between_deletes', type=int, metavar='<n>',
default=10,
help='seconds between delete attempts (%(default)s)')
parser.add_argument('--delete_attempts', type=int, default=100,
metavar='<n>',
help='attempts to delete recording (%(default)s)')
--
Bill
More information about the mythtv-users
mailing list