[mythtv] Format of new post-0.25 config.xml
Raymond Wagner
raymond at wagnerrp.com
Sat Jun 2 19:43:58 UTC 2012
On 6/2/2012 13:33, Brian J. Murrell wrote:
> On 12-06-02 12:35 PM, Michael T. Dean wrote:
>>
>> And, speaking of which, there are a lot of already-written scripts
>> available to do most of the things with MythTV that people are likely to
>> need to do in external scripts. So, what exactly are your scripts
>> doing?
>
> Here's a good example of one of the one-liners I previously mentioned:
>
> ------
> #!/bin/bash
>
> . ~/.mythtv/mysql.txt
>
> ORIG_AIR_DATE_OFFSET=60
>
> echo "Premiers"
> echo "--------"
> mysql -h $DBHostName -u $DBUserName -p$DBPassword $DBName << EOF | tr '\200-\377' '@' | sed -e 's/ / /g' | while IFS=" " read c si t s st; do if [ "$si" = "1" ]; then si="A"; else si="D"; fi; if [ "$c" = "callsign" ]; then si="S"; fi; printf "%1.1s/%-8.8s %-40.40s %-30.30s %-19.19s\n" "$si" "$c" "$t" "$s" "$st"; done
> SELECT c.callsign, c.sourceid, program.title, program.subtitle, program.starttime FROM program LEFT JOIN channel as c ON program.chanid = c.chanid LEFT JOIN record as r ON program.title = r.title AND program.subtitle = r.subtitle WHERE c.channum IS NOT NULL AND r.title IS NULL AND program.starttime > NOW() AND program.first > 0 AND program.programid LIKE "EP%0001" AND ABS(DATEDIFF(DATE(program.starttime),program.originalairdate)) < $ORIG_AIR_DATE_OFFSET ORDER BY program.starttime, program.title
> EOF
> ------
This is a perfect example of one of those one-liners that shouldn't be,
as I'm having a tough time figuring out what the hell it is I'm even
looking at. Just because you _can_ put programming blocks on one line
using a semicolon as a separator, doesn't mean you should.
>> Are you sure there aren't already-written scripts that use the
>> bindings that do what you want?
>
> I don't know. It was probably easier to just write that than the time
> it would have taken to hunt down an existing script.
Taking a stab at what I think that is supposed to do, I can give you this...
------
#!/usr/bin/env python
import MythTV
import functools
import datetime
@functools.total_ordering
class MySort( object ):
def __lt__(self, other):
if self.starttime == other.starttime:
return self.title < other.title
return self.starttime < other.starttime
def __eq__(self, other):
if (self.starttime == other.starttime) and \
(self.title == other.title):
return True
return False
class MyGuide( MySort, MythTV.Guide ):
def pprint(self):
chan = MythTV.Channel(self.chanid)
print "{0}/{1:<8} {2.title:<40} {2.subtitle:<30}
{2.starttime}".format("A" if chan.sourceid==1 else "D", chan.callsign, self)
MythTV.MythDB.searchGuide.handler = MyGuide
now = datetime.datetime.now()
past = now - datetime.timedelta(days=60)
db = MythTV.MythDB()
for prog in sorted(db.searchGuide(first=True, startafter=now,
custom=(("programid LIKE ?","EP%0001"),("originalairdate>?", past)))):
prog.pprint()
------
Of course your script has some strange linking to the recording rules,
where you match title and subtitle to the rule, but then you require the
rule's title be NULL, which I can only assume means you're matching
against some custom rule. In that case, matching against a rule
manually in the database is absolutely the wrong way to do things, as
you should be hitting the backend directly, and pulling the scheduler's
upcoming recordings list for that rule. Since the scheduler is only
going to return what matched the custom rule, we can omit all of our own
database filtering, and just display the response.
------
#!/usr/bin/env python
import MythTV
rules = [r.recordid for r in MythTV.Record.getAllEntries() if r.title is
None]
for prog in MythTV.MythBE().getUpcomingRecordings():
if prog.recordid not in rules:
continue
chan = MythTV.Channel(prog.chanid)
print "{0}/{1.callsign:<8} {1.title:<40} {1.subtitle:<30}
{1.starttime}".format("A" if chan.sourceid==1 else "D", prog)
------
More information about the mythtv-dev
mailing list