[mythtv-users] dump/import watched show list?

Raymond Wagner raymond at wagnerrp.com
Wed Apr 21 17:38:35 UTC 2010


On 4/21/2010 09:55, Robert wrote:
> I can cook up the script myself, if someone who knows the database schema

Ideally, you should never have to touch the schema.  The official python 
bindings in 0.23 are set up such that this should all be do-able without 
touching any SQL.

> (a) dumping recorded shows

Information for recorded shows are handled by the Recorded class.  You 
can dump a list of all recordings using 'Recorded().getAllEntries()'.  
Normally, you can serialize Python objects with 'pickle', but the 
database connection in that class prevents that from working.  You can 
dump a list of values to a file, which you can then read back in and import.

 >>> from MythTV import Recorded
 >>> recs = Recorded().getAllEntries()
 >>> origrec = recs[0]
 >>> origdata = origrec.values()
 >>> newrec = Recorded(raw=origdata)

Note that these classes were intended to be backed by the database, so 
their behavior may be a bit unpredictable if there is no matching 
recording in the connected database.

> (b) finding and deleting those shows.
>    

Several search functions are available from the MythDB class, so you can 
use the imported 'newrec' to search, and then delete the results.

 >>> from MythTV import MythDB
 >>> db = MythDB()
 >>> matches = db.searchRecorded(title=newrec.title, 
subtitle=newrec.subtitle, description=newrec.description)
 >>> for match in matches:
 >>>     match.delete()

Now how do you mark things that have already recorded at home to never 
record at your parent's in the first place?  You want to use OldRecorded 
and searchOldRecorded.  Since you're creating new, rather than 
importing, it's a bit more difficult.  You also will only want to 
concern yourself with 'Recorded' and 'NeverRecord' entries.

 >>> from MythDB import MythDB
 >>> db = MythDB()
 >>> matches = []
 >>> m1 = db.searchOldRecorded(title='Some Show',custom=('recstatus=%s',-3))
 >>> if m1 is not None:
 >>>    matches += m1
 >>> m2 = db.searchOldRecorded(title='Some Show',custom=('recstatus=%s',11))
 >>> if m2 is not None:
 >>>    matches += m2

Now search for existing, and insert if necessary.

 >>> match = matches[0]
 >>> if db.searchOldRecorded(title=match.title, subtitle=match.subtitle, 
description=match.description)) is None:
 >>>    OldRecorded().create(zip(OldRecorded().keys(), match.values()))


More information about the mythtv-users mailing list