Update of /cvsroot/freevo/freevo/src/video
In directory sc8-pr-cvs1:/tmp/cvs-serv28523
Modified Files:
__init__.py fxdimdb.py videoitem.py
Added Files:
fxdhandler.py
Log Message:
move the handler for fxd from xml_parser to fxdhandler
--- NEW FILE: fxdhandler.py ---
import fxditem
from videoitem import VideoItem
class MovieParser(fxditem.FXDItem):
"""
Class to parse a movie informations from a fxd file
"""
def __init__(self, parser, filename, parent, duplicate_check):
self.items = []
self.parent = parent
self.dirname = vfs.dirname(vfs.normalize(filename))
self.filename = filename
self.duplicate_check = duplicate_check
parser.set_handler('movie', self.parse)
parser.set_handler('disc-set', self.parse)
def parse(self, fxd, node):
"""
Callback from the fxd parser. Create a VideoItem (since it should handle
the information and use it's callback function to jump back into this
class to fill the structure in __init__. So we jump:
fxd -> MovieParser.parse -> VideoItem.__init__ -> MovieParser.XXX
"""
v = None
if node.name == 'movie':
v = VideoItem((fxd, node, self.parse_movie), self.parent, parse=False)
elif node.name == 'disc-set':
v = VideoItem((fxd, node, self.parse_disc_set), self.parent, parse=False)
if v:
v.xml_file = self.filename
self.items.append(v)
def parse_video_child(self, fxd, node):
"""
parse a subitem from <video>
"""
filename = fxd.gettext(node)
filename = vfs.join(self.dirname, filename)
mode = node.name
id = fxd.getattr(node, 'id')
media_id = fxd.getattr(node, 'media_id')
options = fxd.getattr(node, 'mplayer_options')
if mode == 'file':
# mark the files we include in the fxd in _fxd_covered_
if not hasattr(self.item, '_fxd_covered_'):
self.item._fxd_covered_ = []
if filename and not filename in self.item._fxd_covered_:
self.item._fxd_covered_.append(filename)
# remove them from the filelist (if given)
if filename in self.duplicate_check:
self.duplicate_check.remove(filename)
return id, filename, mode, media_id, options
def parse_movie(self, fxd, node, item):
"""
Callback from VideoItem for <movie>
<movie title>
<cover-img>file</cover-img>
<video>
<dvd|vcd|file id name media_id mplayer_options>file</>+
<variants>
<variant>
<part ref mplayer_options/>
<subtitle media_id>file</subtitle>
<audio media_id>file</audio>
</variant>
</variants>
<info>
</movie>
"""
self.item = item
item.name = fxd.getattr(node, 'title')
item.image = fxd.childcontent(node, 'cover-img')
if item.image:
item.image = vfs.join(self.dirname, item.image)
fxd.parse_info(fxd.get_children(node, 'info', 1), item, {'runtime': 'length'})
video = fxd.get_children(node, 'video')
if video:
mplayer_options = fxd.getattr(video[0], 'mplayer_options')
video = fxd.get_children(video[0], 'file') + \
fxd.get_children(video[0], 'vcd') + \
fxd.get_children(video[0], 'dvd')
variants = fxd.get_children(node, 'variants')
if variants:
variants = fxd.get_children(variants[0], 'variant')
if variants:
# a list of variants
id = {}
for v in video:
info = self.parse_video_child(fxd, v)
id[info[0]] = info
for variant in variants:
audio = fxd.get_children(variant, 'audio')
subtitle = fxd.get_children(variant, 'subtitle')
if audio:
audio = { 'media_id': fxd.getattr(audio[0], 'media_id'),
'file' : fxd.gettext(audio[0]) }
else:
audio = {}
if subtitle:
subtitle = { 'media_id': fxd.getattr(subtitle[0], 'media_id'),
'file' : fxd.gettext(subtitle[0]) }
else:
subtitle = {}
parts = fxd.get_children(variant, 'part')
if len(parts) == 1:
# a variant with one file
ref = fxd.getattr(parts[0] ,'ref')
v = VideoItem(id[ref][1], parent=item, parse=False)
v.mode, v.media_id, v.mplayer_options = id[ref][2:]
v.subtitle_file = subtitle
v.audio_file = audio
# global <video> mplayer_options
if mplayer_options:
v.mplayer_options += mplayer_options
else:
# a variant with a list of files
v = VideoItem('', parent=item, parse=False)
v.subtitle_file = subtitle
v.audio_file = audio
for p in parts:
ref = fxd.getattr(p ,'ref')
sub = VideoItem(id[ref][1], parent=v, parse=False)
sub.mode, sub.media_id, sub.mplayer_options = id[ref][2:]
# global <video> mplayer_options
if mplayer_options:
sub.mplayer_options += mplayer_options
v.subitems.append(sub)
v.name = fxd.getattr(variant, 'name')
item.variants.append(v)
elif len(video) == 1:
# only one file, this is directly for the item
id, item.filename, item.mode, item.media_id, \
item.mplayer_options = self.parse_video_child(fxd, video[0])
# global <video> mplayer_options
if mplayer_options:
item.mplayer_options += mplayer_options
else:
# a list of files
for s in video:
info = self.parse_video_child(fxd, s)
v = VideoItem(info[1], parent=item, parse=False)
v.mode, v.media_id, v.mplayer_options = info[2:]
# global <video> mplayer_options
if mplayer_options:
v.mplayer_options += mplayer_options
item.subitems.append(v)
def parse_disc_set(self, fxd, node, item):
"""
Callback from VideoItem for <disc-set>
"""
item.name = fxd.getattr(node, 'title')
item.image = fxd.childcontent(node, 'cover-img')
if item.image:
item.image = vfs.join(self.dirname, item.image)
fxd.parse_info(fxd.get_children(node, 'info', 1), item, {'runtime': 'length'})
item.rom_label = []
item.rom_id = []
for disc in fxd.get_children(node, 'disc'):
id = fxd.getattr(disc, 'media-id')
if id:
item.rom_id.append(id)
label = fxd.getattr(disc, 'label-regexp')
if label:
item.rom_label.append(label)
# what to do with the mplayer_options? We can't use them for
# one disc, or can we? And file_ops? Also only on a per disc base.
# So I ignore that we are in a disc right now and use the 'item'
item.mplayer_options = fxd.getattr(disc, 'mplayer_options')
for f in fxd.get_children(disc, 'file-opts'):
opt = { 'file-d': f.getattr(f, 'media-id'),
'mplayer_options': f.getattr(f, 'mplayer_options') }
item.files_options.append(opt)
# register this callback
fxditem.register(['video'], MovieParser)
Index: __init__.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/video/__init__.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** __init__.py 23 Nov 2003 17:01:34 -0000 1.12
--- __init__.py 24 Nov 2003 19:24:58 -0000 1.13
***************
*** 10,13 ****
--- 10,16 ----
# -----------------------------------------------------------------------
# $Log$
+ # Revision 1.13 2003/11/24 19:24:58 dischi
+ # move the handler for fxd from xml_parser to fxdhandler
+ #
# Revision 1.12 2003/11/23 17:01:34 dischi
# remove fxd stuff, it's handled by directory.py and FXDHandler now
***************
*** 42,56 ****
- import config
- import util
- import xml_parser
import os
import copy
from videoitem import VideoItem
- # handler for parse video informations from a fxd file
- FXDHandler = xml_parser.MovieParser
def cwd(parent, files):
--- 45,65 ----
import os
import copy
+ import re
+
+ import config
+ import util
from videoitem import VideoItem
+ # load the fxd part of video
+ import fxdhandler
+
+ # variables for the hashing function
+ fxd_database = {}
+ discset_informations = {}
+ tv_show_informations = {}
def cwd(parent, files):
***************
*** 65,69 ****
file_id = parent.media.id +
file[len(os.path.join(parent.media.mountdir,"")):]
try:
! x.mplayer_options = config.DISC_SET_INFORMATIONS_ID[file_id]
except KeyError:
pass
--- 74,78 ----
file_id = parent.media.id +
file[len(os.path.join(parent.media.mountdir,"")):]
try:
! x.mplayer_options = discset_informations[file_id]
except KeyError:
pass
***************
*** 93,94 ****
--- 102,163 ----
new_items += [ VideoItem(file, parent) ]
new_files.remove(file)
+
+
+
+
+ def hash_fxd_movie_database():
+ """
+ hash fxd movie files in some directories. This is used e.g. by the
+ rom drive plugin, but also for a directory and a videoitem.
+ """
+ import fxditem
+
+ global tv_show_informations
+ global discset_informations
+ global fxd_database
+
+ fxd_database['id'] = {}
+ fxd_database['label'] = []
+ discset_informations = {}
+ tv_show_informations = {}
+
+ if vfs.exists("/tmp/freevo-rebuild-database"):
+ try:
+ os.remove('/tmp/freevo-rebuild-database')
+ except OSError:
+ print '*********************************************************'
+ print
+ print '*********************************************************'
+ print 'ERROR: unable to remove /tmp/freevo-rebuild-database'
+ print 'please fix permissions'
+ print '*********************************************************'
+ print
+ return 0
+
+ _debug_("Building the xml hash database...",1)
+
+ files = []
+ if not config.ONLY_SCAN_DATADIR:
+ for name,dir in config.DIR_MOVIES:
+ files += util.recursefolders(dir,1,'*.fxd',1)
+ if config.OVERLAY_DIR:
+ for subdir in ('disc', 'disc-set'):
+ files += util.recursefolders(vfs.join(config.OVERLAY_DIR, subdir), 1,
'*.fxd', 1)
+
+ for info in fxditem.getitems(None, files, display_type='video'):
+ for i in info.rom_id:
+ fxd_database['id'][i] = info
+ for l in info.rom_label:
+ fxd_database['label'].append((re.compile(l), info))
+ for fo in info.files_options:
+ discset_informations[fo['file-id']] = fo['mplayer-options']
+
+ if config.TV_SHOW_DATA_DIR:
+ files = util.recursefolders(config.TV_SHOW_DATA_DIR,1,
+ '*'+config.SUFFIX_VIDEO_DEF_FILES[0],1)
+ for info in fxditem.getitems(None, files, display_type='video'):
+ k = vfs.splitext(vfs.basename(info.xml_file))[0]
+ tv_show_informations[k] = (info.image, info.info, info.mplayer_options,
file)
+
+ _debug_('done',1)
+ return 1
Index: fxdimdb.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/video/fxdimdb.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** fxdimdb.py 22 Nov 2003 20:35:50 -0000 1.21
--- fxdimdb.py 24 Nov 2003 19:24:59 -0000 1.22
***************
*** 12,15 ****
--- 12,18 ----
# -----------------------------------------------------------------------
# $Log$
+ # Revision 1.22 2003/11/24 19:24:59 dischi
+ # move the handler for fxd from xml_parser to fxdhandler
+ #
# Revision 1.21 2003/11/22 20:35:50 dischi
# use new vfs
***************
*** 64,68 ****
import util
- from xml_parser import parseMovieFile
from mmpython.disc.discinfo import cdrom_disc_id
#Constants
--- 67,70 ----
***************
*** 273,279 ****
else: self.append = False
! if self.append == True and \
! parseMovieFile(self.fxdfile + '.fxd', None, []) == []:
! raise FxdImdb_XML_Error("FXD file to be updated is invalid, please
correct it.")
if not vfs.isdir(vfs.dirname(self.fxdfile)):
--- 275,282 ----
else: self.append = False
! # XXX: add this back in without using parseMovieFile
! # if self.append == True and \
! # parseMovieFile(self.fxdfile + '.fxd', None, []) == []:
! # raise FxdImdb_XML_Error("FXD file to be updated is invalid, please
correct it.")
if not vfs.isdir(vfs.dirname(self.fxdfile)):
***************
*** 336,342 ****
#check fxd
! if parseMovieFile(self.fxdfile + '.fxd', None, []) == []:
! raise FxdImdb_XML_Error("""FXD file generated is invalid, please "+
! "post bugreport, tracebacks and fxd file.""")
except (IOError, FxdImdb_IO_Error), error:
raise FxdImdb_IO_Error('error saving the file: %s' % str(error))
--- 339,347 ----
#check fxd
! # XXX: add this back in without using parseMovieFile
! # if parseMovieFile(self.fxdfile + '.fxd', None, []) == []:
! # raise FxdImdb_XML_Error("""FXD file generated is invalid, please "+
! # "post bugreport, tracebacks and fxd
file.""")
!
except (IOError, FxdImdb_IO_Error), error:
raise FxdImdb_IO_Error('error saving the file: %s' % str(error))
Index: videoitem.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/video/videoitem.py,v
retrieving revision 1.96
retrieving revision 1.97
diff -C2 -d -r1.96 -r1.97
*** videoitem.py 23 Nov 2003 17:00:25 -0000 1.96
--- videoitem.py 24 Nov 2003 19:24:59 -0000 1.97
***************
*** 11,14 ****
--- 11,17 ----
# -----------------------------------------------------------------------
# $Log$
+ # Revision 1.97 2003/11/24 19:24:59 dischi
+ # move the handler for fxd from xml_parser to fxdhandler
+ #
# Revision 1.96 2003/11/23 17:00:25 dischi
# small change (the diff is mostly indention) needed for the new xml_parser
***************
*** 79,83 ****
from event import *
-
class VideoItem(Item):
def __init__(self, filename, parent, info=None, parse=True):
--- 82,85 ----
***************
*** 162,167 ****
show_name[0].lower()), self.image)
! if config.TV_SHOW_INFORMATIONS.has_key(show_name[0].lower()):
! tvinfo = config.TV_SHOW_INFORMATIONS[show_name[0].lower()]
for i in tvinfo[1]:
self.info[i] = tvinfo[1][i]
--- 164,170 ----
show_name[0].lower()), self.image)
! from video import tv_show_informations
! if tv_show_informations.has_key(show_name[0].lower()):
! tvinfo = tv_show_informations[show_name[0].lower()]
for i in tvinfo[1]:
self.info[i] = tvinfo[1][i]
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog