Saturday, May 06, 2006

Script that shows all recordings titles, filenames

Full-text version of this script is at:
http://www.donnlee.com/static/mythtv/mythrecordings.py.txt

#!/usr/bin/python

import sys
import re
import MySQLdb

MYTHDIR = '/mythtv/recordings'

def GetSQLdict(sql):
try:
db = MySQLdb.Connect(host="localhost", port=3306, user="root", passwd=
"mypass", db="mythconverg")
c=db.cursor(MySQLdb.cursors.DictCursor)
except:
return 'FAILED'
# Execute the SQL query.
try:
c.execute(sql)
except:
return 'FAILED'
# Get results as a dictionary. Column names are dict keys.
Results = c.fetchall()
db.close()
return Results

sql = "SELECT chanid,starttime,endtime,title,subtitle,description FROM recor
dedprogram order by starttime desc"
Results = GetSQLdict(sql)

for r in Results:
chanid = r['chanid']
starttime = str(r['starttime'])
endtime = str(r['endtime'])
title = r['title']
subtitle = r['subtitle']
description = r['description']

# Remove hyphen, colon, space, and '.00' from time values.
p_starttime = re.sub(r'[-: ]|\.00', '', starttime)
p_endtime = re.sub(r'[-: ]|\.00', '', endtime)

f = '%s/%s_%s_%s.nuv' % (MYTHDIR, chanid, p_starttime, p_endtime)

print '%s' % starttime
print "%s - %s" % (title, subtitle)
print description
print f
print

# End.

2 Comments:

At 10:32 AM, Blogger Dave said...

I am not a python person... but I DO know it is space sensative... and have a feeling the formating was lost when posted. Is it possible to post a link to a properly formated file?
Thanks a ton!
Dave

 
At 2:33 PM, Blogger Donn Lee said...

Dave,
You are absolutely correct. I hate how html absorbs multiple spaces into just one space character. I have republished my python script at http://www.donnlee.com/static/mythtv/mythrecordings.py.txt

Enjoy,
Donn

 

Post a Comment

<< Home