Ticket #3313: episode_title_db.diff
File episode_title_db.diff, 3.2 KB (added by , 17 years ago) |
---|
-
mythvideo/mythvideo/scripts/imdbpy.py
9 9 10 10 This wrapper script is written by 11 11 Pekka JÀÀskelÀinen (gmail: pekka.jaaskelainen). 12 """ 12 """ 13 13 14 import os 14 15 import sys 15 16 import optparse 16 17 import re 18 import socket 19 import shlex 17 20 18 21 try: 19 22 import imdb … … 22 25 "from (http://imdbpy.sourceforge.net/?page=download)" 23 26 sys.exit(1) 24 27 28 try: 29 import MySQLdb 30 db_support = True 31 except: 32 db_support = False 25 33 34 db = None 35 episode_title_format = '%(series_title)s S%(season)02d E%(episode)02d %(episode_title)s' 26 36 37 def init_db(): 38 global db 39 try: 40 config = shlex.shlex(open(os.path.expanduser('~/.mythtv/mysql.txt'))) 41 except: 42 print "Error opening ~/.mythtv/mysql.txt" 43 return False 44 45 46 token = config.get_token() 47 db_host = db_user = db_password = None 48 while token != config.eof and (db_host == None or db_user == None or db_password == None): 49 if token == "DBHostName": 50 if config.get_token() == "=": 51 db_host = config.get_token() 52 elif token == "DBUserName": 53 if config.get_token() == "=": 54 db_user = config.get_token() 55 elif token == "DBPassword": 56 if config.get_token() == "=": 57 db_password = config.get_token() 58 59 token = config.get_token() 60 db = MySQLdb.connect(user=db_user, host=db_host, passwd=db_password, 61 db="mythconverg") 62 return True 63 64 def mythtv_setting(value, hostname = '%'): 65 """ 66 Returns the value for the given MythTV setting. 67 68 Returns None if the settings was not found. If multiple rows are 69 found (multiple hostnames), returns the value of the first one. 70 """ 71 global db 72 c = db.cursor() 73 c.execute(""" 74 SELECT data 75 FROM settings 76 WHERE value LIKE(%s) AND hostname LIKE(%s) LIMIT 1""", 77 (value, hostname)) 78 row = c.fetchone() 79 c.close() 80 81 if row is not None: 82 return row[0] 83 else: 84 return None 85 27 86 def detect_series_title(search_string): 28 87 """ 29 88 Detects a series episode title. … … 175 234 genres = None 176 235 countries = None 177 236 178 episode_title_format = '%(series_title)s S%(season)02d E%(episode)02d %(episode_title)s'179 180 237 def __init__(self): 181 238 pass 182 239 … … 190 247 metadata = "" 191 248 if self.series_episode == True and self.season is not None and \ 192 249 self.episode is not None: 193 metadata += 'Title:' + self.episode_title_format % \250 metadata += 'Title:' + episode_title_format % \ 194 251 { 195 252 'series_title': self.series_title, 196 253 'season': int(self.season), … … 316 373 return None 317 374 318 375 def main(): 376 global episode_title_format 377 319 378 p = optparse.OptionParser() 320 379 p.add_option('--version', '-v', action="store_true", default=False, 321 380 help="display 1-line describing name, version, author etc") … … 345 404 episodes.""" 346 405 sys.exit(0) 347 406 407 if db_support: 408 if init_db(): 409 episode_title_format_setting = mythtv_setting('VideoEpisodeTitleFormat', socket.gethostname()) 410 if episode_title_format_setting: 411 episode_title_format = episode_title_format_setting 412 348 413 if options.movie_search is not None: 349 414 results = title_search(options.movie_search.decode("utf8")) 350 415 for result in results: