Mailing List Archive

Finding gaps in the MythTV recording schedule to do maintenance in
I have a busy MythTV box, so when I need a few hours to do some
maintenance on it, such as changing tuner cards or rearranging the
drives, it can be a problem to work out when enough time will be
available. So I wrote myself a Python script called "gaps" that uses
the new API to get the recording schedule and find when there are gaps
in it. It takes one command line parameter which is the minimum
number of hours of gap needed. If there are no parameters given, it
will list all the gaps, no matter how small. The script is rather
rough and ready, but it works for me.

To use it, you need to also have the Utilties.py Python module
installed. You can download that from the Wiki Python API Examples
page. I just put a copy of the file in my /usr/local/bin directory.
Make sure you save the file as a UTF-8 encoded file.

Wiki Python API Examples page:
https://www.mythtv.org/wiki/Python_API_Examples

gaps script:
http://www.jsw.gen.nz/mythtv/gaps

Please let me know if you find any problems with it.
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Finding gaps in the MythTV recording schedule to do maintenance in [ In reply to ]
Stephen Worthington <stephen_agent@jsw.gen.nz> wrote:

> I have a busy MythTV box, so when I need a few hours to do some
> maintenance on it, such as changing tuner cards or rearranging the
> drives, it can be a problem to work out when enough time will be
> available. So I wrote myself a Python script called "gaps" that uses
> the new API to get the recording schedule and find when there are gaps
> in it.
...
> Please let me know if you find any problems with it.

Apart from me having an ancient version of MythTV :-(


In the past I've looked at things slightly differently - as in decide when I'd like to do maintenance and then work out whether I can do it. Seeing existing gaps would probably help - but it's more normal to think "I've got a couple of hours today, can I do ..."

I never actually got as far as doing it, but I was thinking of adding dummy muxes & channels so that I could create a manual recording per tuner card and thus force the scheduler to look for alternative showings of anything scheduled during my planned maintenance window. With the way muxes are, and multi-rec, it's really hard (impossible ?) to force this without some dummy channels. I could then look at upcoming recordings - if there's no conflicts then I'm OK, if there are conflicts then there's something the scheduler can't work around and I need to decide whether to amend my plans or accept missing the recording.
Given how many of the things I record have multiple showings, just looking at what's scheduled now isn't usually that good an indication of whether the system can be safely taken down - at least without quite a bit of interpretation and knowledge of which programs could be recorded at a different time.

_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Finding gaps in the MythTV recording schedule to do maintenance in [ In reply to ]
On 04/19/2017 06:55 AM, Simon Hobson wrote:
> I never actually got as far as doing it, but I was thinking of adding dummy muxes & channels so that I could create a manual recording per tuner card and thus force the scheduler to look for alternative showings of anything scheduled during my planned maintenance window. With the way muxes are, and multi-rec, it's really hard (impossible ?) to force this without some dummy channels.

You can always set one-time "don't record" overrides for the shows
scheduled during the period that tell MythTV to skip that showing. It
would be a lot easier than creating dummy muxes or otherwise messing
with things that affect/could affect the system even when you don't need it.

Mike
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Finding gaps in the MythTV recording schedule to do maintenance in [ In reply to ]
Michael T. Dean <mtdean@thirdcontact.com> wrote:

>> I never actually got as far as doing it, but I was thinking of adding dummy muxes & channels so that I could create a manual recording per tuner card and thus force the scheduler to look for alternative showings of anything scheduled during my planned maintenance window. With the way muxes are, and multi-rec, it's really hard (impossible ?) to force this without some dummy channels.
>
> You can always set one-time "don't record" overrides for the shows scheduled during the period that tell MythTV to skip that showing. It would be a lot easier than creating dummy muxes or otherwise messing with things that affect/could affect the system even when you don't need it.

Except that it's not quite as quick and simple as that, and more work to undo if plans change.

Some of the programs I record are shown several times, some more than once in a day, and then there's the +1 channels. So yes, I could whizz down Mythweb's Upcoming Recordings screen clicking the Don't record buttons - but then it'll come back having rescheduled many of them on the +1 channel. Not to mention those programs that suddenly appear having been rescheduled into the now available times instead of the later showings they had been scheduled for.
If I change my mind, I then have to find all the over-ride rules and delete them.

The biggest objection though is that if there's a program which doesn't have another showing in the listings, it just won't get recorded if I create a "don't record this showing" over-ride rule. That's the whole point - wanting to know if there are any of these which would mean picking another time to do the maintenance.

_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Finding gaps in the MythTV recording schedule to do maintenance in [ In reply to ]
On Wed, 19 Apr 2017 22:34:48 +1200, you wrote:

>I have a busy MythTV box, so when I need a few hours to do some
>maintenance on it, such as changing tuner cards or rearranging the
>drives, it can be a problem to work out when enough time will be
>available. So I wrote myself a Python script called "gaps" that uses
>the new API to get the recording schedule and find when there are gaps
>in it. It takes one command line parameter which is the minimum
>number of hours of gap needed. If there are no parameters given, it
>will list all the gaps, no matter how small. The script is rather
>rough and ready, but it works for me.
>
>To use it, you need to also have the Utilties.py Python module
>installed. You can download that from the Wiki Python API Examples
>page. I just put a copy of the file in my /usr/local/bin directory.
>Make sure you save the file as a UTF-8 encoded file.
>
>Wiki Python API Examples page:
>https://www.mythtv.org/wiki/Python_API_Examples
>
>gaps script:
>http://www.jsw.gen.nz/mythtv/gaps
>
>Please let me know if you find any problems with it.

I have just put a slightly updated version of the "gaps" script on my
web server. It seems that Python is quite permissive in what it will
accept for a time duration (datetime.timedelta), so I am now allowing
a floating point number on the command line for the number of hours
minimum gap size to search for.
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Finding gaps in the MythTV recording schedule to do maintenance in [ In reply to ]
On 20/04/17 17:07, Stephen Worthington wrote:
> On Wed, 19 Apr 2017 22:34:48 +1200, you wrote:
>
>> I have a busy MythTV box, so when I need a few hours to do some
>> maintenance on it, such as changing tuner cards or rearranging the
>> drives, it can be a problem to work out when enough time will be
>> available. So I wrote myself a Python script called "gaps" that uses
>> the new API to get the recording schedule and find when there are gaps
>> in it. It takes one command line parameter which is the minimum
>> number of hours of gap needed. If there are no parameters given, it
>> will list all the gaps, no matter how small. The script is rather
>> rough and ready, but it works for me.
>>
>> To use it, you need to also have the Utilties.py Python module
>> installed. You can download that from the Wiki Python API Examples
>> page. I just put a copy of the file in my /usr/local/bin directory.
>> Make sure you save the file as a UTF-8 encoded file.
>>
>> Wiki Python API Examples page:
>> https://www.mythtv.org/wiki/Python_API_Examples
>>
>> gaps script:
>> http://www.jsw.gen.nz/mythtv/gaps
>>
>> Please let me know if you find any problems with it.
> I have just put a slightly updated version of the "gaps" script on my
> web server. It seems that Python is quite permissive in what it will
> accept for a time duration (datetime.timedelta), so I am now allowing
> a floating point number on the command line for the number of hours
> minimum gap size to search for.
> _______________________________________________
>
Thanks Stephen, this is quite good!

I had one issue getting this to work, I run 0.27, 0.28 and master
simultaneously on the one server so I have moved the services api ports
in mythtv-setup so they don't conflict. Utilities.py is hardcoded to use
port 6544 (which is the default). Once I changed that to the backend
services port I wanted it worked perfectly Unfortunately I don't know
python but if I get some spare time I might try and see what it would
take to get Utilities.py to pull the port from the database using a
found config.xml. Maybe it could pull the host as well, although I think
your gaps.py script is coded to localhost only. I'm just thinking out loud.

Thankyou again for putting this together and sharing!
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Finding gaps in the MythTV recording schedule to do maintenance in [ In reply to ]
On 04/22/2017 07:28 PM, Mark Perkins wrote:
...
>>
> Thanks Stephen, this is quite good!
>
> I had one issue getting this to work, I run 0.27, 0.28 and master
> simultaneously on the one server so I have moved the services api ports
> in mythtv-setup so they don't conflict. Utilities.py is hardcoded to use
> port 6544 (which is the default). Once I changed that to the backend
> services port I wanted it worked perfectly Unfortunately I don't know
> python but if I get some spare time I might try and see what it would
> take to get Utilities.py to pull the port from the database using a
> found config.xml. Maybe it could pull the host as well, although I think
> your gaps.py script is coded to localhost only. I'm just thinking out loud.
>
> Thankyou again for putting this together and sharing!

The Utilities.Send() function defaults to 6544. See this for an example
of how to pass command line arguments:

https://www.mythtv.org/wiki/Python_API_Examples#Working_program_using_the_Dvr.2FGetUpcomingList_endpoint

Or, you can just add the port to this line, if you don't want
to pass it as a command line argument:

resp_dict = api.Send(host=HOST, port=1234, endpoint='Dvr/GetUpcomingList')

--
Bill
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Finding gaps in the MythTV recording schedule to do maintenance in [ In reply to ]
On 23/04/17 10:18, Bill Meek wrote:
> ...
> The Utilities.Send() function defaults to 6544. See this for an example
> of how to pass command line arguments:
>
> https://www.mythtv.org/wiki/Python_API_Examples#Working_program_using_the_Dvr.2FGetUpcomingList_endpoint
>
> Or, you can just add the port to this line, if you don't want
> to pass it as a command line argument:
>
> resp_dict = api.Send(host=HOST, port=1234,
> endpoint='Dvr/GetUpcomingList')
>
Ah, thanks Bill for the correction - my mistake.

So that probably makes it a lot simpler. So if I wanted a command line
like this:
gaps.py --duration 2 --host 127.0.0.1 --port 6544

or
gaps.py -d 2 -n 127.0.0.1 -p 6544

this patch might do the trick?

--- gaps.py 2017-04-23 12:32:53.453284798 +0930
+++ gaps.py 2017-04-23 12:45:00.064720363 +0930
@@ -15,8 +15,11 @@
import datetime
import dateutil.parser
import sys
+import getopt

HOST = 'localhost'
+PORT = '6544'
+min_duration = datetime.timedelta(0)

class RecStatus(IntEnum):
Pending = -15
@@ -87,17 +90,23 @@
# Main
##############################################################################

-args = len(sys.argv)
-if args > 2:
- print('Error - too many command line arguments!')
- exit(2)
-elif args == 2:
- min_duration = datetime.timedelta(0, 0, 0, 0, 0, float(sys.argv[1]))
- print('Searching for a minimum duration of '+str(min_duration))
-else:
- min_duration = datetime.timedelta(0)
+try:
+ opts, args =
getopt.getopt(sys.argv[1:],"hd:n:p:",["help","duration=","host=","port="])
+except getopt.GetoptError:
+ print('gaps.py -d <duration> -n <host> -p <port>')
+ sys.exit(2)
+for opt, arg in opts:
+ if opt in ("-h", "--help"):
+ print('gaps.py -d <duration> -n <host> -p <port>')
+ sys.exit()
+ elif opt in ("-d", "--duration"):
+ min_duration = datetime.timedelta(0, 0, 0, 0, 0, float(arg))
+ elif opt in ("-n", "--host"):
+ HOST = arg
+ elif opt in ("-p", "--port"):
+ PORT = arg

-resp_dict = api.Send(host=HOST, endpoint='Dvr/GetUpcomingList')
+resp_dict = api.Send(host=HOST, port=PORT, endpoint='Dvr/GetUpcomingList')

if list(resp_dict.keys())[0] in ['Abort', 'Warning']:
print('GetUpcomingList failed')



Seems to work for me anyway (sample size = 1).
$ /usr/local/bin/gaps.py -d 5.1 -n 192.168.1.101 -p 6546
Gap: start=Tue 2017-04-25 00:50:00+09:30 end=2017-04-25
05:58:00+09:30 duration=5:08:00
Gap: start=Wed 2017-04-26 00:45:00+09:30 end=2017-04-26
05:58:00+09:30 duration=5:13:00
End of scheduled recordings end=2017-04-30 02:10:00+09:30

$ /usr/local/bin/gaps.py --duration 5.1 --host 192.168.1.101 --port 6546
Gap: start=Tue 2017-04-25 00:50:00+09:30 end=2017-04-25
05:58:00+09:30 duration=5:08:00
Gap: start=Wed 2017-04-26 00:45:00+09:30 end=2017-04-26
05:58:00+09:30 duration=5:13:00
End of scheduled recordings end=2017-04-30 02:10:00+09:30
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Finding gaps in the MythTV recording schedule to do maintenance in [ In reply to ]
On Sun, 23 Apr 2017 03:17:34 +0000, you wrote:

>
>
>On 23/04/17 10:18, Bill Meek wrote:
>> ...
>> The Utilities.Send() function defaults to 6544. See this for an example
>> of how to pass command line arguments:
>>
>> https://www.mythtv.org/wiki/Python_API_Examples#Working_program_using_the_Dvr.2FGetUpcomingList_endpoint
>>
>> Or, you can just add the port to this line, if you don't want
>> to pass it as a command line argument:
>>
>> resp_dict = api.Send(host=HOST, port=1234,
>> endpoint='Dvr/GetUpcomingList')
>>
>Ah, thanks Bill for the correction - my mistake.
>
>So that probably makes it a lot simpler. So if I wanted a command line
>like this:
>gaps.py --duration 2 --host 127.0.0.1 --port 6544
>
>or
>gaps.py -d 2 -n 127.0.0.1 -p 6544
>
>this patch might do the trick?
>
>--- gaps.py 2017-04-23 12:32:53.453284798 +0930
>+++ gaps.py 2017-04-23 12:45:00.064720363 +0930
>@@ -15,8 +15,11 @@
> import datetime
> import dateutil.parser
> import sys
>+import getopt
>
> HOST = 'localhost'
>+PORT = '6544'
>+min_duration = datetime.timedelta(0)
>
> class RecStatus(IntEnum):
> Pending = -15
>@@ -87,17 +90,23 @@
> # Main
> ##############################################################################
>
>-args = len(sys.argv)
>-if args > 2:
>- print('Error - too many command line arguments!')
>- exit(2)
>-elif args == 2:
>- min_duration = datetime.timedelta(0, 0, 0, 0, 0, float(sys.argv[1]))
>- print('Searching for a minimum duration of '+str(min_duration))
>-else:
>- min_duration = datetime.timedelta(0)
>+try:
>+ opts, args =
>getopt.getopt(sys.argv[1:],"hd:n:p:",["help","duration=","host=","port="])
>+except getopt.GetoptError:
>+ print('gaps.py -d <duration> -n <host> -p <port>')
>+ sys.exit(2)
>+for opt, arg in opts:
>+ if opt in ("-h", "--help"):
>+ print('gaps.py -d <duration> -n <host> -p <port>')
>+ sys.exit()
>+ elif opt in ("-d", "--duration"):
>+ min_duration = datetime.timedelta(0, 0, 0, 0, 0, float(arg))
>+ elif opt in ("-n", "--host"):
>+ HOST = arg
>+ elif opt in ("-p", "--port"):
>+ PORT = arg
>
>-resp_dict = api.Send(host=HOST, endpoint='Dvr/GetUpcomingList')
>+resp_dict = api.Send(host=HOST, port=PORT, endpoint='Dvr/GetUpcomingList')
>
> if list(resp_dict.keys())[0] in ['Abort', 'Warning']:
> print('GetUpcomingList failed')
>
>
>
>Seems to work for me anyway (sample size = 1).
>$ /usr/local/bin/gaps.py -d 5.1 -n 192.168.1.101 -p 6546
>Gap: start=Tue 2017-04-25 00:50:00+09:30 end=2017-04-25
>05:58:00+09:30 duration=5:08:00
>Gap: start=Wed 2017-04-26 00:45:00+09:30 end=2017-04-26
>05:58:00+09:30 duration=5:13:00
>End of scheduled recordings end=2017-04-30 02:10:00+09:30
>
>$ /usr/local/bin/gaps.py --duration 5.1 --host 192.168.1.101 --port 6546
>Gap: start=Tue 2017-04-25 00:50:00+09:30 end=2017-04-25
>05:58:00+09:30 duration=5:08:00
>Gap: start=Wed 2017-04-26 00:45:00+09:30 end=2017-04-26
>05:58:00+09:30 duration=5:13:00
>End of scheduled recordings end=2017-04-30 02:10:00+09:30

The getopt package is obsolete - it has been replaced by argparse. I
have uploaded a new version of gaps that does the above using
argparse, and also allows a second command line parameter giving the
number of minutes for the minimum duration. So to search for gaps of
10 minutes or more, the command would be "gaps 0 10". Both parameters
can be floating point numbers, so you could do something like "gaps
1.1 3.2" if you want, and it would search for a minimum gap duration
of 1h09m12s.

Here is the output of "gaps -h":

usage: gaps [-h] [-V] [-n HOST] [-p PORT] [hours] [minutes]

Find gaps in the MythTV recording schedule (Version: 1.3)

positional arguments:
hours Minimum gap duration to search for, in hours (floating
point
allowed)
minutes Minimum gap duration to search for, in minutes
(floating point
allowed)

optional arguments:
-h, --help show this help message and exit
-V, --version
display the version number and exit
-n HOST, --host HOST
MythTV backend hostname (default: mypvr)
-p PORT, --port PORT
MythTV backend API port number (default: 6544)

Note that the default values for -n and -p have been looked up in the
database if possible, so the above output shows the default for -n as
"mypvr" which is the name of my main MythTV box. If access to the
database to look up the BackendStatusPort setting is not possible
there will be a warning message, and it will default to using
localhost and port 6544 instead, like the older versions.

I have also added a bit more error checking.
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Finding gaps in the MythTV recording schedule to do maintenance in [ In reply to ]
> The getopt package is obsolete - it has been replaced by argparse. I
> have uploaded a new version of gaps that does the above using
> argparse, and also allows a second command line parameter giving the
> number of minutes for the minimum duration. So to search for gaps of
> 10 minutes or more, the command would be "gaps 0 10". Both parameters
> can be floating point numbers, so you could do something like "gaps
> 1.1 3.2" if you want, and it would search for a minimum gap duration
> of 1h09m12s.
>
> Here is the output of "gaps -h":
>
> usage: gaps [-h] [-V] [-n HOST] [-p PORT] [hours] [minutes]
>
> Find gaps in the MythTV recording schedule (Version: 1.3)
>
> positional arguments:
> hours Minimum gap duration to search for, in hours (floating
> point
> allowed)
> minutes Minimum gap duration to search for, in minutes
> (floating point
> allowed)
>
> optional arguments:
> -h, --help show this help message and exit
> -V, --version
> display the version number and exit
> -n HOST, --host HOST
> MythTV backend hostname (default: mypvr)
> -p PORT, --port PORT
> MythTV backend API port number (default: 6544)
>
> Note that the default values for -n and -p have been looked up in the
> database if possible, so the above output shows the default for -n as
> "mypvr" which is the name of my main MythTV box. If access to the
> database to look up the BackendStatusPort setting is not possible
> there will be a warning message, and it will default to using
> localhost and port 6544 instead, like the older versions.
>
> I have also added a bit more error checking.
> _______________________________________________
Thankyou for making the requested changes Stephen, I have updated to
your version 1.3 and it all just works. Pulled the correct host and port
from the database and all. Very nice.
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-users
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org