-
Notifications
You must be signed in to change notification settings - Fork 0
/
libmythtv.py
53 lines (42 loc) · 1.76 KB
/
libmythtv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 5 14:10:47 2013
@author: shanef
"""
import MySQLdb as mdb
from libtvshow import TVShow
class MythTV:
"""
Contains methods used for interacting with mythtv
"""
def __init__(self, settings):
self.__settings = settings
def retrieveepisodedata(self, inputfile):
"""
Retrieve the data that mythtv knows about the recorded file.
"""
con = mdb.connect(self.__settings.mythtvaddress(),
self.__settings.mythtvuser(),
self.__settings.mythtvpassword(),
self.__settings.mythtvdatabase())
with con:
cur = con.cursor(mdb.cursors.DictCursor)
cur.execute("select episode, season, title, subtitle, "
"description from mythconverg.recorded where "
"basename = '{0}'".format(inputfile))
result = cur.fetchone()
return TVShow(result['episode'], result['season'],
result['title'], result['subtitle'],
result['description'])
def fixmythtvepisodename(self, showname, episodetitle):
"""
Look for any prefixes listed in the configuration file. If there are
any and the episide title starts with the prefix, remove the prefix
from the episode title. The searching is done in the order that the
prefixes are listed in the configuration file.
"""
for prefix in self.__settings.getshowmythtvepisodeprefix(showname):
if episodetitle.lower().startswith(prefix.lower()):
return episodetitle[len(prefix):]
#didn't find anything so return the episode title
return episodetitle