|
I am using videodb as well Wrote a plugin to integrate on mysql level , still work in progress ( for over a year now :-) ) Any ideas help in making it more usable is welcome , i stuck in event processing so no search functionality yet Alex M [EMAIL PROTECTED] wrote: OK, i take a look into this.On Dec 3, 2007, at 2:23 PM, [EMAIL PROTECTED] wrote: |
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# appletrailers.py - Plugin for streaming trailers from apple.com
# -----------------------------------------------------------------------
#
# Notes:
# Add "plugin.activate('video.appletrailers')" in local_conf.py
# to activate
# Todo:
#
# -----------------------------------------------------------------------
# Copyright (C) 2006 Pierre Ossman
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------
#rating
import os
import re
import config
import plugin
import menu
import stat
import time
import string
import util.fileops
import util.misc
from item import Item
from video.videoitem import VideoItem
from gui.ProgressBox import ProgressBox
import MySQLdb
import plugin
_thumbs_dir = "/var/cache/freevo/videodb"
_mysql_host="storage1"
_mysql_user="videodb"
_mysql_passwd="videodb"
_mysql_db="videodb"
cachedir = os.path.join(config.FREEVO_CACHEDIR, 'videodb')
if not os.path.isdir(cachedir):
os.mkdir(cachedir,
stat.S_IMODE(os.stat(config.FREEVO_CACHEDIR)[stat.ST_MODE]))
def _dbfetch(sqlstm):
try:
connection = MySQLdb.connect(_mysql_host,
_mysql_user,
_mysql_passwd,
_mysql_db)
cursor = connection.cursor()
cursor.execute( sqlstm )
except MySQLdb.OperationalError, message:
errorMessage = "Error %d:\n%s" % (message[ 0 ], message[ 1 ] )
print errorMessage
return
else:
data = cursor.fetchall()
fields = cursor.description
cursor.close()
connection.close()
return data
def FetchAssoc(sqlstm) :
print "FetchAssoc:"+sqlstm+"\n"
try:
connection = MySQLdb.connect(_mysql_host,
_mysql_user,
_mysql_passwd,
_mysql_db)
cursor = connection.cursor()
cursor.execute( sqlstm )
except MySQLdb.OperationalError, message:
errorMessage = "Error %d:\n%s" % (message[ 0 ], message[ 1 ] )
print errorMessage
return
else:
data = cursor.fetchall()
if data == None :
return None
desc = cursor.description
videos=[]
for d in data:
dict = {}
for (name, value) in zip(desc, d) :
dict[name[0]] = value
videos.append(dict)
return videos
#--------------------------------------------------------
_vdb_by_genere = {
'type' : "vdb_movies",
'display_name' : "Browse by Title",
'menu_name' : "Choose a Title",
'sql_value' : "videodata.id,videodata.title,videodata.filename,videodata.plot,videodata.year,videodata.imgurl,videodata.custom2",
'sql' : "FROM videodata,videogenre,genres WHERE videodata.id=videogenre.video_id AND videogenre.genre_id=genres.id AND videodata.mediatype < 50 AND genres.name=",
'post_sql' : "ORDER BY videodata.title"
}
_vdb_geners = {
'type' : "sql_menu",
'display_name' : "Browse by Genre",
'menu_name' : "Choose a Genre",
'sql_value' : "name",
'sql' : "FROM genres",
'next' : _vdb_by_genere
}
#-------------------------------------------------------
_vdb_by_year = {
'type' : "vdb_movies",
'display_name' : "Browse by Title",
'menu_name' : "Choose a Title",
'sql_value' : "id,title,filename,plot,year,imgurl,custom2",
'sql' : "FROM videodata WHERE mediatype < 50 AND year=",
'post_sql' : "ORDER BY title"
}
_vdb_years = {
'type' : "sql_menu",
'display_name' : "Browse by Year",
'menu_name' : "Choose a Year",
'sql_value' : "year",
'sql' : "FROM videodata where year > 0 GROUP BY year ORDER BY year DESC",
'next' : _vdb_by_year
}
#------------------------------------------------------
_byname = [
("num","^[0-9]"),
("ABC","^[ABCabc]"),
("DEF","^[DEFdef]"),
("GHI","^[GHIghi]"),
("JKL","^[JKLjkl]"),
("MNO","^[MNOmno]"),
("PQRS","^[PQRSpqrs]"),
("TUV","^[TUVtuv]"),
("WXYZ","^[WXZwxy]")
]
_vdb_by_name = {
'type' : "vdb_movies",
'display_name' : "Browse by Title",
'menu_name' : "Choose a Title",
'sql_value' : "id,title,filename,plot,year,imgurl,custom2",
'sql' : "FROM videodata WHERE mediatype < 50 AND title RLIKE ",
'post_sql' : "ORDER BY title"
}
_vdb_names = {
'type' : "sql_list_menu",
'display_name' : "Browse by Title",
'menu_name' : "Choose a Title",
'dbout' : _byname,
'next' : _vdb_by_name
}
#------------------------------------------------------------------
_vdb_by_new = {
'type' : "vdb_movies",
'display_name' : "Browse by New",
'menu_name' : "Choose a Title",
'sql_value' : "id,title,filename,plot,year,imgurl,custom2",
'sql' : "FROM videodata WHERE mediatype < 50 ORDER BY lastupdate DESC LIMIT 100 "
}
#----------------------------------------------------------------
_chars = ["","[ABCabc]","[DEFdef]","[GHIghi]","[JKLjkl]","[MNOmno]","[PQRSpqrs]","[TUVtuv]"]
_vdb_by_name = {
'type' : "vdb_search",
'display_name' : "Search by actor",
'menu_name' : "Choose a Title",
'sql_value' : "Name",
'sql' : "FROM actors WHERE name RLIKE "
}
class PluginInterface(plugin.MainMenuPlugin):
"""
A freevo interface to videodb
plugin.activate('video.videodb')
"""
def __init__(self):
plugin.MainMenuPlugin.__init__(self)
self.display_type = 'video'
def items(self, parent):
return [ BrowseBy(parent) ]
class VdbVideoItem(VideoItem):
def __init__(self, title, parent):
VideoItem.__init__(self, title['filename'], parent)
cd = re.compile('cd1*', re.IGNORECASE)
m = cd.search( title['filename'] )
if m:
print 'Match found: ', m.group()
recd = re.compile('(cd)(1)*', re.IGNORECASE)
self.subitems.append(VideoItem(title['filename'], self))
for i in range(2, 6):
nextcd = recd.sub(r'\g<1>'+str(i),title['filename'])
if os.path.isfile(nextcd):
print "Adding"+ nextcd
self.subitems.append(VideoItem(nextcd, self))
print "Missing:" + nextcd
print "\n \n TITLE: " + title['title'] + " -- " + title['custom2']
self.name = title['title']
if ( title['imgurl'] != "" ):
self.image = os.path.join( cachedir , str(title['id']) + ".jpg")
if not os.path.isfile(self.image):
print "Downloading image for movie:" + str(title['id']) + "\n"
os.system ('wget %s -O %s 2> /dev/null' % ( title['imgurl'],self.image ))
self.info["plot"] = util.format_text(title['plot'])
self.info["year"] = util.format_text(str(title['year']))
self.info["rating"] = util.format_text(str(title['custom2']))
# self.info["genre"] = util.format_text(title['genre'])
self.type = 'video'
self.display_type='video'
class BrowseBySql(Item):
def __init__(self, parent,sqldata,name=None,sqlparam=None):
Item.__init__(self, parent)
self.display_type = 'video'
self.sqldata=sqldata
print "_BrowseBySql_init"
print self.sqldata
self.description = sqldata['display_name']
dbdata = []
if name :
self.name = name
else:
self.name = self.sqldata['display_name']
self.sqlparam = sqlparam
if self.sqldata['type'] == "sql_menu" :
dbdata=_dbfetch("SELECT count(*) " + self.sqldata['sql'] )
self.description = dbdata[0][0]
if self.sqldata['type'] == "vdb_movies" :
if self.sqlparam:
dbdata=_dbfetch("SELECT count(*) " + self.sqldata['sql'] + " " + str(self.sqlparam))
else:
dbdata=_dbfetch("SELECT count(*) " + self.sqldata['sql'] )
self.description = dbdata[0][0]
print "\n"
def actions(self):
print "BrowseBySql actions...\n"
return [ (self.make_menu, 'Titles') ]
def make_menu(self, arg=None, menuw=None):
print "_BrowseBySql_makemenu"
print self.sqldata
print "\n"
dbdata=[]
items=[]
if self.sqldata['type'] == "sql_menu" :
dbdata=_dbfetch("SELECT "+ self.sqldata['sql_value'] + " " + self.sqldata['sql'] )
for data in dbdata:
nextmenu=self.sqldata['next']
# nextmenu['display_name']=str(data[0])
items.append(BrowseBySql(self,sqldata=nextmenu,name = str(data[0]),sqlparam = "'"+str(data[0])+"'"))
menuw.pushmenu(menu.Menu(_(self.sqldata['menu_name']), items,item_types = self.display_type , force_skin_layout = -1))
if self.sqldata['type'] == "sql_list_menu" :
dbdata = self.sqldata['dbout']
for data in dbdata:
nextmenu=self.sqldata['next']
# nextmenu['display_name']=str(data[0])
items.append(BrowseBySql(self,sqldata=nextmenu,name = str(data[0]),sqlparam = "'"+str(data[1])+"'" ))
menuw.pushmenu(menu.Menu(_(self.sqldata['menu_name']), items,item_types = self.display_type , force_skin_layout = -1))
if self.sqldata['type'] == "vdb_movies" :
if self.sqlparam:
dbdata=FetchAssoc("SELECT "+ self.sqldata['sql_value'] + " " + self.sqldata['sql'] + " " + str(self.sqlparam) + " " + self.sqldata['post_sql'])
else:
dbdata=FetchAssoc("SELECT "+ self.sqldata['sql_value'] + " " + self.sqldata['sql'] )
for data in dbdata:
items.append(VdbVideoItem(data,self))
menuw.pushmenu(menu.Menu(_(self.sqldata['display_name']), items,item_types = self.display_type , force_skin_layout = -1))
class BrowseBy(Item):
def __init__(self, parent):
Item.__init__(self, parent)
self.name = 'VideoDB'
self.display_type='video'
self.type = 'dir'
self.skin_display_type = parent.display_type
def actions(self):
return [ (self.make_menu, 'Browse by') ]
def make_menu(self, arg=None, menuw=None):
menuw.pushmenu(menu.Menu('Video DB',
[ BrowseBySql(self,_vdb_by_new),
BrowseBySql(self,_vdb_years),
BrowseBySql(self,_vdb_geners),
BrowseBySql(self, _vdb_names) ],item_types = self.display_type , force_skin_layout = -1))
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ Freevo-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/freevo-devel
