Here's how to recreate category_type from recorded table

For discussion related to MythTV which doesn't belong in another forum.

Moderator: Forum Moderators

Post Reply
wmorrison
Junior
Posts: 32
Joined: Sat Dec 01, 2018 12:05 am
United States of America

Here's how to recreate category_type from recorded table

Post by wmorrison » Thu Oct 03, 2019 4:36 am

In table program:
program.category_type is either 'movie', 'series', 'sports', or 'tvshow'.

But table recorded doesn't have this.

So once a show is recorded, and after a while the upcoming schedule has "rolled off" the data in table program, you can't join with it any more. Is that right? (My system hasn't been running long enough to see anything roll off the schedule.)

But, recorded.programid starts with two characters that correspond to the category_type. So you could do this:

Code: Select all

case
    when programid like 'MV%' then 'movie'
    when programid like 'EP%' then 'series'
    when programid like 'SP%' then 'sports'
    else 'tvshow'
end
I'm guessing that 'tvshow' should be the default. I haven't looked at the mythtv code to see how it's created. If that's wrong, please comment, but the basic approach seems to work.

So why do I care?

I'd like to set up a job that automatically changes the recording group for recordings, to make it easier to browse in "Watch Recordings". Hit m and select group filter.

My job will look at not just category_type, but also category and originalairdate, so it can do something like (pseudocode:)

Code: Select all

# don't auto-change anything except 'Default' so as to not interfere
# with manually-assigned recording groups, and to not resurrect deleted recordings
if (current) recording group is 'Default'
  if category is 'Documentary'
    move to documentaries recording group # irrespective whether is is a movie, series, etc.
  else if category_type is 'movie'
    move to movies recording group
  else if category_type is 'sports'
    move to sports recording group
  else if category_type is 'series'
    if originalairdate < current date - 6 month # whatever separates latest season from previous seasons
      move to oldseries recording group
    else
      move to newseries recording group
    fi
  else
    # tvshow
    move to other recording group
  fi
fi
Now the next thing is to find a way to script this. I can trigger a job in Setup->System Event Handlers.

I'm thinking "Recording started". I've already used it to echo some parameters into a log, and it seems all the data I need is already present when that event fires.

Next thing is to find an efficient way to run the queries. I know it can be scripted, just have to look at the myth database perl scripts, I just don't know if creating and discarding a database connection each time the script is run will cause problems. But it should only run in small clusters around the hour or half-hour mark when recordings usually start.

If anybody is familiar with scripting database jobs, or a way to share and reuse a connection, or maybe make it a stored procedure (I work with Oracle but am new to MySQL,) I could use some pointers.

Actually, if this job were run at the start of a recording, I could join with program to get category_type, but the case statement above could be useful to re-group existing older recordings where program.category_type no longer exists.

wmorrison
Junior
Posts: 32
Joined: Sat Dec 01, 2018 12:05 am
United States of America

Re: Here's how to recreate category_type from recorded table

Post by wmorrison » Thu Oct 03, 2019 12:56 pm

I'm new to MythTV, so I may not have the "optimal" approach yet.

I realized I could do the same as the above on the record table (being sure to not alter templates) before recordings even start.

I know you can change the recording group for individual rules. What I am trying to do is automate it so I can set up rules to automatically record shows that meet certain criteria, with no manual setup. To make my machine work kind of like an "on demand" system. Run out of new TV to watch? Browse for an interesting pre-recorded movie or documentary.

As far as I can tell so far, a recording rule can be configured for a specific recording group. I have not yet found if it's possible for the rule to set the recording group based on program attributes. If I missed that, please let me know.

User avatar
bill6502
Developer
Posts: 1377
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Here's how to recreate category_type from recorded table

Post by bill6502 » Thu Oct 03, 2019 6:07 pm

Not really clear why the recording rule solution isn't OK for you, but it's your computer;).
Don't recognize an "on demand" system either. There is a Services API available and you
can create rules programmatically if that's your goal. See https://www.mythtv.org/wiki/DVR_Service ... rdSchedule
(Add and Delete also exist.)

There is a Custom rule solution (not to be confused with Manual rules.) That allows the use of
SQL and you could make generic rules for Movies/Sports/... and set the Recording Group
for each there. Sound like you want to record everything in some specific categories.

User avatar
dizygotheca
Developer
Posts: 266
Joined: Wed Sep 03, 2014 9:02 am
Great Britain

Re: Here's how to recreate category_type from recorded table

Post by dizygotheca » Fri Oct 04, 2019 3:21 pm

program data for recordings is never lost: it's retained in the recordedprogram table

category_type is an odd thing: its mainly useful for treating episode/season numbers and duplicate scheduling.
category is probably a better property to use: its values come from your guide provider, so vary.

Are you familiar with "recording templates" ? https://lists.gt.net/mythtv/users/580130
The commit referenced in the thread contains the complete documentation.
So a "movie" template will automatically put "movie"-tagged programs in the right place.

You will need a script for more advanced processing such as 'old series'.
There's no problem with creating a database connection.
Nothing wrong with perl but python is probably better supported.
This is what I knocked up;

Code: Select all

#!/usr/bin/env python
# Assign recording group
# Invoke as a user job/system event like so:
# assign --chanid "%CHANID% --starttime %STARTTIMEISOUTC%"

from MythTV import Recorded
from optparse import OptionParser
from datetime import date, timedelta
import sys

parser = OptionParser(usage="usage: %prog --chanid=<> --starttime=<>")
parser.add_option("--chanid", action="store", type="int", dest="chanid", help="Channel ID")
parser.add_option("--starttime", action="store", type="string", dest="starttime", help="Recording starttime")
opts, args = parser.parse_args()

try:
	rec = Recorded((opts.chanid, opts.starttime)) # get recording
except:
	print "Unknown recording"
	sys.exit(1)

sixMonthsAgo = date.today() - timedelta(days=182)

if not rec.originalairdate:
	print "Not repeat", rec	
elif rec.originalairdate > sixMonthsAgo:
	print "Too new", rec	
else:
	rec.recgroup = "OldSeries" # should exist in table recgroups		
	rec.update() # Update db
	print "Moved", rec
Note:
1. It's safe but if the recording group doesn't already exist within Myth then it won't show up in some places (eg. "Change recording group" dialog)
2. Myth times are all UTC, which can be frustrating for CLI use. https://www.mythtv.org/wiki/Commercial_ ... one_Issues has some tips.

https://www.mythtv.org/wiki/MythTV_System_Events
https://www.mythtv.org/wiki/Python_Bindings Not up-to-date. Recorded fields tend to use db field names

wmorrison
Junior
Posts: 32
Joined: Sat Dec 01, 2018 12:05 am
United States of America

Re: Here's how to recreate category_type from recorded table

Post by wmorrison » Sun Oct 06, 2019 6:56 pm

Are you saying that a recording template can automatically assign a newly scheduled recording to a specific recording group, based on category_type and/or other fields?

If so, I think that's what I'm looking for.

User avatar
dizygotheca
Developer
Posts: 266
Joined: Wed Sep 03, 2014 9:02 am
Great Britain

Re: Here's how to recreate category_type from recorded table

Post by dizygotheca » Mon Oct 07, 2019 8:37 am

Yes. Originally I thought it was only the "category" but, looking again, it will match "category_type" as well.
https://github.com/MythTV/mythtv/commit/71c65b

Only those fields though. Others, such as "originalairdate", can only be accessed from a script.

Note that the script will be executed for every rule, so additional checks will be needed.
Executing it at recording start also means it will override/clobber anything the user has set, which may be confusing.
There is no "Recording Rule just created" system event.

wmorrison
Junior
Posts: 32
Joined: Sat Dec 01, 2018 12:05 am
United States of America

Re: Here's how to recreate category_type from recorded table

Post by wmorrison » Mon Oct 07, 2019 6:24 pm

Not as flexible as I had hoped, but it will do for now, for a few category/category_type values.

Template rule 'Documentary' with recording group 'Documentary' should group all documentaries regardless of category_type
Template rule 'movie' with recording group 'movie' should group all movies, except documentaries, which would be caught by the first template

That's about it since RecordingRule::LoadTemplate only looks at category and category_type to find a matching template. E.g. if I made a template for 'Comedy' recording group 'Comedy' it would take comedy movies out of the movie recording group. It already does that for documentary movies, but that's what I want.

I suppose I'll eventually get to modifying and compiling the source, but at the moment I just want to use it.

User avatar
bill6502
Developer
Posts: 1377
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Here's how to recreate category_type from recorded table

Post by bill6502 » Tue Oct 08, 2019 3:47 pm

To be clear, Templates are only used at new recording rule creation time. Changing a Template
doesn't affect existing rules or existing recorded metadata.

User avatar
dizygotheca
Developer
Posts: 266
Joined: Wed Sep 03, 2014 9:02 am
Great Britain

Re: Here's how to recreate category_type from recorded table

Post by dizygotheca » Wed Oct 09, 2019 10:00 am

category only holds a single value. So if it's been labelled "Comedy" then it isn't a movie (even though you may disagree). If there's no comedy template then it will use the default template.

Movie databases use multiple tags, such as "comedy/kids/sci-fi", but AFAIK guide providers don't support that for TV.

There's no need to create Recording Groups merely to organise by category. The "Change Filter" already allows you to filter by category over all rec groups.

Another way of browsing a single rec group by category is to change the "Group View" to show categories as well as, or instead of, titles. (Watch Recordings -> menu -> Change Group View).
If you're using custom rules to "automatically record shows that meet certain criteria" then show searches on it as well.

wmorrison
Junior
Posts: 32
Joined: Sat Dec 01, 2018 12:05 am
United States of America

Re: Here's how to recreate category_type from recorded table

Post by wmorrison » Thu Oct 10, 2019 9:36 pm

dizygotheca wrote:
Wed Oct 09, 2019 10:00 am
category only holds a single value. So if it's been labelled "Comedy" then it isn't a movie (even though you may disagree).
Right, but category_type could be 'movie'.
dizygotheca wrote:
Wed Oct 09, 2019 10:00 am
There's no need to create Recording Groups merely to organise by category. The "Change Filter" already allows you to filter by category over all rec groups.
You misunderstand. I'm not creating recording groups for each category. Just 'Documentary', which, while redundant now, I may rename/expand to include similar categories such as 'Biography.' (Because if you're in the mood for a documentary, you would probably also consider a biography.)

I've created a Movies recording group because that's not a category, and excluded category Documentary (and soon Biography) so it's only a list of "entertainment movies."

Basically, this is all to allow auto-recording of lots of programs, but hide them off in a few recording groups, so that when you go to "Watch Recordings" the Default list is only an uncluttered list of current series that record weekly. And if we feel like watching something else, there are only a few lists to choose from.

Personal preference, of course. While we were on cable, we would frequently search for something on demand, and if nothing, sometimes rent a Redbox. I'd like to have enough programming available to minimize the temptation to get a Redbox unless it's something we really want to watch.

I've set up my auto-record custom rules with a lower priority so that anything manually scheduled should take priority if there's a conflict.

Post Reply