Update of /cvsroot/freevo/freevo/src/video
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8163
Modified Files:
videoitem.py
Log Message:
restructure and add docs
Index: videoitem.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/video/videoitem.py,v
retrieving revision 1.149
retrieving revision 1.150
diff -C2 -d -r1.149 -r1.150
*** videoitem.py 28 Aug 2004 17:18:07 -0000 1.149
--- videoitem.py 14 Sep 2004 20:07:04 -0000 1.150
***************
*** 5,8 ****
--- 5,13 ----
# $Id$
#
+ # This file contains a VideoItem. A VideoItem can not only hold a simple
+ # video file, it can also store variants of the same video and subitems
+ # if the video is splitted into several files. DVD and VCD are also
+ # VideoItems.
+ #
# Notes:
#
***************
*** 11,14 ****
--- 16,22 ----
# -----------------------------------------------------------------------
# $Log$
+ # Revision 1.150 2004/09/14 20:07:04 dischi
+ # restructure and add docs
+ #
# Revision 1.149 2004/08/28 17:18:07 dischi
# fix multiple files in one video when replaying
***************
*** 54,60 ****
import os
- import re
- import md5
- import time
import copy
--- 62,65 ----
***************
*** 65,68 ****
--- 70,74 ----
import configure
import plugin
+ import util.videothumb
from gui import PopupBox, AlertBox, ConfirmBox
***************
*** 70,73 ****
--- 76,82 ----
from event import *
+ from database import tv_show_informations, discset_informations
+
+
class VideoItem(MediaItem):
def __init__(self, url, parent, info=None, parse=True):
***************
*** 100,120 ****
# find image for tv show and build new title
! if config.VIDEO_SHOW_REGEXP_MATCH(self.name) and not self.network_play and \
! config.VIDEO_SHOW_DATA_DIR:
!
show_name = config.VIDEO_SHOW_REGEXP_SPLIT(self.name)
if show_name[0] and show_name[1] and show_name[2] and show_name[3]:
! self.name = show_name[0] + u" " + show_name[1] + u"x" + show_name[2]
+\
! u" - " + show_name[3]
image = util.getimage((config.VIDEO_SHOW_DATA_DIR + \
show_name[0].lower()))
if self.filename and not image:
! image = util.getimage(os.path.dirname(self.filename) + '/' + \
show_name[0].lower())
-
if image:
self.image = 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()]
--- 109,125 ----
# find image for tv show and build new title
! if config.VIDEO_SHOW_REGEXP_MATCH(self.name) and not \
! self.network_play and config.VIDEO_SHOW_DATA_DIR:
show_name = config.VIDEO_SHOW_REGEXP_SPLIT(self.name)
if show_name[0] and show_name[1] and show_name[2] and show_name[3]:
! self.name = show_name[0] + u" " + show_name[1] + u"x" + \
! show_name[2] + u" - " + show_name[3]
image = util.getimage((config.VIDEO_SHOW_DATA_DIR + \
show_name[0].lower()))
if self.filename and not image:
! image = util.getimage(os.path.dirname(self.filename)+'/'+ \
show_name[0].lower())
if image:
self.image = image
if tv_show_informations.has_key(show_name[0].lower()):
tvinfo = tv_show_informations[show_name[0].lower()]
***************
*** 124,128 ****
self.skin_fxd = tvinfo[3]
self.mplayer_options = tvinfo[2]
-
self.tv_show = True
self.show_name = show_name
--- 129,132 ----
***************
*** 130,139 ****
self.tv_show_ep = show_name[3]
-
# extra infos in discset_informations
if parent and parent.media:
fid = parent.media.id + \
self.filename[len(os.path.join(parent.media.mountdir,"")):]
- from video import discset_informations
if discset_informations.has_key(fid):
self.mplayer_options = discset_informations[fid]
--- 134,141 ----
***************
*** 240,246 ****
Returns the string how to sort this item
"""
! if mode == 'date' and self.mode == 'file' and os.path.isfile(self.filename):
! return u'%s%s' % (os.stat(self.filename).st_ctime,
Unicode(self.filename))
!
if self.name.find(u"The ") == 0:
return self.name[4:]
--- 242,249 ----
Returns the string how to sort this item
"""
! if mode == 'date' and self.mode == 'file' and \
! os.path.isfile(self.filename):
! return u'%s%s' % (os.stat(self.filename).st_ctime,
! Unicode(self.filename))
if self.name.find(u"The ") == 0:
return self.name[4:]
***************
*** 248,261 ****
! # ------------------------------------------------------------------------
! # actions:
! def actions(self):
"""
! return a list of possible actions on this item.
"""
!
! self.possible_player = []
for p in plugin.getbyname(plugin.VIDEO_PLAYER, True):
rating = p.rate(self) * 10
--- 251,314 ----
! def _set_next_available_subitem(self):
! """
! select the next available subitem. Loops on each subitem and checks if
! the needed media is really there.
! If the media is there, sets self.current_subitem to the given subitem
! and returns 1.
! If no media has been found, we set self.current_subitem to None.
! If the search for the next available subitem did start from the
! beginning of the list, then we consider that no media at all was
! available for any subitem: we return 0.
! If the search for the next available subitem did not start from the
! beginning of the list, then we consider that at least one media
! had been found in the past: we return 1.
! """
! if hasattr(self, 'conf_select_this_item'):
! # XXX bad hack, clean me up
! self.current_subitem = self.conf_select_this_item
! del self.conf_select_this_item
! return True
!
! cont = 1
! from_start = 0
! si = self.current_subitem
! while cont:
! if not si:
! # No subitem selected yet: take the first one
! si = self.subitems[0]
! from_start = 1
! else:
! pos = self.subitems.index(si)
! # Else take the next one
! if pos < len(self.subitems)-1:
! # Let's get the next subitem
! si = self.subitems[pos+1]
! else:
! # No next subitem
! si = None
! cont = 0
! if si:
! if (si.media_id or si.media):
! # If the file is on a removeable media
! if util.check_media(si.media_id):
! self.current_subitem = si
! return 1
! elif si.media and util.check_media(si.media.id):
! self.current_subitem = si
! return 1
! else:
! # if not, it is always available
! self.current_subitem = si
! return 1
! self.current_subitem = None
! return not from_start
! def _get_possible_player(self):
"""
! return a list of possible player for this item
"""
! possible_player = []
for p in plugin.getbyname(plugin.VIDEO_PLAYER, True):
rating = p.rate(self) * 10
***************
*** 264,279 ****
if hasattr(self, 'force_player') and p.name == self.force_player:
rating += 100
! self.possible_player.append((rating, p))
- self.possible_player.sort(lambda l, o: -cmp(l[0], o[0]))
! self.player = None
! self.player_rating = 0
if not self.possible_player:
return []
self.player_rating, self.player = self.possible_player[0]
if self.url.startswith('dvd://') and self.url[-1] == '/':
if self.player_rating >= 20:
--- 317,345 ----
if hasattr(self, 'force_player') and p.name == self.force_player:
rating += 100
! possible_player.append((rating, p))
! possible_player.sort(lambda l, o: -cmp(l[0], o[0]))
! return possible_player
!
!
! # ------------------------------------------------------------------------
! # actions:
! def actions(self):
! """
! return a list of possible actions on this item.
! """
! self.possible_player = self._get_possible_player()
if not self.possible_player:
+ self.player = None
+ self.player_rating = 0
return []
self.player_rating, self.player = self.possible_player[0]
+ # For DVD and VCD check if the rating is >= 20. If it is and the url
+ # ends with '/', the user should get the DVD/VCD menu from the player.
+ # If not, we need to show the title menu.
if self.url.startswith('dvd://') and self.url[-1] == '/':
if self.player_rating >= 20:
***************
*** 294,311 ****
items = [ (self.play, _('Play')) ]
if len(self.possible_player) > 1:
! items.append((self.play_alternate, _('Play with alternate player')))
if self.network_play:
items.append((self.play_max_cache, _('Play with maximum cache')))
items += configure.get_items(self)
!
if self.variants and len(self.variants) > 1:
items = [ (self.show_variants, _('Show variants')) ] + items
! if self.mode == 'file' and not self.variants and not self.subitems and \
(not self.image or not self.image.endswith('raw')):
! items.append((self.create_thumbnail, _('Create Thumbnail'),
'create_thumbnail'))
!
return items
--- 360,384 ----
items = [ (self.play, _('Play')) ]
if len(self.possible_player) > 1:
! items.append((self.play_alternate,
! _('Play with alternate player')))
+ # Network play can get a larger cache
if self.network_play:
items.append((self.play_max_cache, _('Play with maximum cache')))
+ # Add the configure stuff (e.g. set audio language)
items += configure.get_items(self)
!
! # If there are variants, make it possible to show them. This is
! # always the default action then.
if self.variants and len(self.variants) > 1:
items = [ (self.show_variants, _('Show variants')) ] + items
! # Add thumbnail option
! if self.mode == 'file' and not self.variants and \
! not self.subitems and \
(not self.image or not self.image.endswith('raw')):
! items.append((self.create_thumbnail, _('Create Thumbnail'),
! 'create_thumbnail'))
return items
***************
*** 315,323 ****
show a list of variants in a menu
"""
! if not self.menuw:
! self.menuw = menuw
! m = menu.Menu(self.name, self.variants, reload_func=None,
theme=self.skin_fxd)
m.item_types = 'video'
! self.menuw.pushmenu(m)
--- 388,424 ----
show a list of variants in a menu
"""
! m = menu.Menu(self.name, self.variants, reload_func=None,
! theme=self.skin_fxd)
m.item_types = 'video'
! menuw.pushmenu(m)
!
!
! def dvd_vcd_title_menu(self, arg=None, menuw=None):
! """
! Generate special menu for DVD/VCD/SVCD content
! """
! # delete the submenu that got us here
! menuw.delete_submenu(False)
!
! # build a menu
! items = []
! for title in range(len(self.info['tracks'])):
! i = copy.copy(self)
! i.parent = self
! i.set_url(self.url + str(title+1), False)
! i.info = copy.copy(self.info)
! # copy the attributes from mmpython about this track
! i.info.mmdata = self.info.mmdata['tracks'][title]
! i.info.set_variables(self.info.get_variables())
! i.info_type = 'track'
! i.possible_player = []
! i.files = None
! i.name = Unicode(_('Play Title %s')) % (title+1)
! items.append(i)
!
! moviemenu = menu.Menu(self.name, items, umount_all = 1,
! theme=self.skin_fxd)
! moviemenu.item_types = 'video'
! menuw.pushmenu(moviemenu)
***************
*** 326,333 ****
create a thumbnail as image icon
"""
- import util.videothumb
pop = PopupBox(text=_('Please wait....'))
pop.show()
-
util.videothumb.snapshot(self.filename)
pop.destroy()
--- 427,432 ----
***************
*** 341,344 ****
--- 440,444 ----
"""
self.play(menuw=menuw, arg='-cache 65536')
+
def play_alternate(self, arg=None, menuw=None):
***************
*** 349,453 ****
- def set_next_available_subitem(self):
- """
- select the next available subitem. Loops on each subitem and checks if
- the needed media is really there.
- If the media is there, sets self.current_subitem to the given subitem
- and returns 1.
- If no media has been found, we set self.current_subitem to None.
- If the search for the next available subitem did start from the
- beginning of the list, then we consider that no media at all was
- available for any subitem: we return 0.
- If the search for the next available subitem did not start from the
- beginning of the list, then we consider that at least one media
- had been found in the past: we return 1.
- """
- if hasattr(self, 'conf_select_this_item'):
- # XXX bad hack, clean me up
- self.current_subitem = self.conf_select_this_item
- del self.conf_select_this_item
- return True
-
- cont = 1
- from_start = 0
- si = self.current_subitem
- while cont:
- if not si:
- # No subitem selected yet: take the first one
- si = self.subitems[0]
- from_start = 1
- else:
- pos = self.subitems.index(si)
- # Else take the next one
- if pos < len(self.subitems)-1:
- # Let's get the next subitem
- si = self.subitems[pos+1]
- else:
- # No next subitem
- si = None
- cont = 0
- if si:
- if (si.media_id or si.media):
- # If the file is on a removeable media
- if util.check_media(si.media_id):
- self.current_subitem = si
- return 1
- elif si.media and util.check_media(si.media.id):
- self.current_subitem = si
- return 1
- else:
- # if not, it is always available
- self.current_subitem = si
- return 1
- self.current_subitem = None
- return not from_start
-
-
def play(self, arg=None, menuw=None, alternateplayer=False):
"""
play the item.
"""
! # try:
! # self.player.stop()
! # except:
! # print 'FIXME: stop only when running'
!
! if not self.possible_player:
! for p in plugin.getbyname(plugin.VIDEO_PLAYER, True):
! rating = p.rate(self) * 10
! if config.VIDEO_PREFERED_PLAYER == p.name:
! rating += 1
! if hasattr(self, 'force_player') and p.name == self.force_player:
! rating += 100
! self.possible_player.append((rating, p))
!
! self.possible_player.sort(lambda l, o: -cmp(l[0], o[0]))
!
! if alternateplayer:
! self.possible_player.reverse()
!
! if not self.possible_player:
! return
!
! self.player_rating, self.player = self.possible_player[0]
if self.parent:
self.parent.current_item = self
! if not self.menuw:
self.menuw = menuw
!
! # if we have variants, play the first one as default
if self.variants:
self.variants[0].play(arg, menuw)
return
- # if we have subitems (a movie with more than one file),
- # we start playing the first that is physically available
if self.subitems:
self.error_in_subitem = 0
self.last_error_msg = ''
self.current_subitem = None
! result = self.set_next_available_subitem()
if self.current_subitem: # 'result' is always 1 in this case
# The media is available now for playing
--- 449,482 ----
def play(self, arg=None, menuw=None, alternateplayer=False):
"""
play the item.
"""
! # set the current_item of the parent to this one
! # to make playlists possible
if self.parent:
self.parent.current_item = self
! # make sure we have a menuw and a self.menuw. This bad code
! # is needed because of all the subitems and variants and they
! # can be called without a menuw sometimes.
! if menuw:
self.menuw = menuw
! else:
! menuw = self.menuw
!
if self.variants:
+ # if we have variants, play the first one as default
self.variants[0].play(arg, menuw)
return
if self.subitems:
+ # if we have subitems (a movie with more than one file),
+ # we start playing the first that is physically available
self.error_in_subitem = 0
self.last_error_msg = ''
self.current_subitem = None
! result = self._set_next_available_subitem()
if self.current_subitem: # 'result' is always 1 in this case
# The media is available now for playing
***************
*** 456,468 ****
if self.current_subitem.mplayer_options:
if self.mplayer_options:
! self.current_subitem.mplayer_options += ' ' +
self.mplayer_options
else:
self.current_subitem.mplayer_options = self.mplayer_options
! # When playing a subitem, the menu must be hidden. If it is not,
! # the playing will stop after the first subitem, since the
# PLAY_END/USER_END event is not forwarded to the parent
# videoitem.
# And besides, we don't need the menu between two subitems.
! self.last_error_msg = self.current_subitem.play(arg, self.menuw)
if self.last_error_msg:
self.error_in_subitem = 1
--- 485,499 ----
if self.current_subitem.mplayer_options:
if self.mplayer_options:
! mo = self.current_subitem.mplayer_options
! mo += ' ' + self.mplayer_options
! self.current_subitem.mplayer_options = mo
else:
self.current_subitem.mplayer_options = self.mplayer_options
! # When playing a subitem, the menu must be hidden. If it is
! # not, the playing will stop after the first subitem, since the
# PLAY_END/USER_END event is not forwarded to the parent
# videoitem.
# And besides, we don't need the menu between two subitems.
! self.last_error_msg=self.current_subitem.play(arg, menuw)
if self.last_error_msg:
self.error_in_subitem = 1
***************
*** 476,490 ****
_('Please insert the media.')) %
self.name, handler=self.play ).show()
return
- # normal plackback of one file
if self.url.startswith('file://'):
file = self.filename
if self.media_id:
! mountdir, file = util.resolve_media_mountdir(self.media_id,file)
if mountdir:
util.mount(mountdir)
else:
! self.menuw.show()
ConfirmBox(text=(_('No media found for "%s".\n')+
_('Please insert the media.')) % file,
--- 507,526 ----
_('Please insert the media.')) %
self.name, handler=self.play ).show()
+ # done, everything else is handled in 'play' of the subitem
return
if self.url.startswith('file://'):
+ # normal playback of one file
file = self.filename
if self.media_id:
! # This file is on a media with media_id as id. Check
! # if this media is inserted somewere
! mountdir,file = util.resolve_media_mountdir(self.media_id,file)
if mountdir:
+ # Found, mount the disc
util.mount(mountdir)
else:
! # Not found, show box so the user can insert the
! # correct disc. Callback is this function again
ConfirmBox(text=(_('No media found for "%s".\n')+
_('Please insert the media.')) % file,
***************
*** 493,504 ****
elif self.media:
util.mount(os.path.dirname(self.filename))
! elif self.mode in ('dvd', 'vcd') and not self.filename and not self.media:
media = util.check_media(self.media_id)
if media:
self.media = media
else:
! self.menuw.show()
ConfirmBox(text=(_('No media found for "%s".\n')+
_('Please insert the media.')) % self.url,
--- 529,545 ----
elif self.media:
+ # mount 'our' media
util.mount(os.path.dirname(self.filename))
! elif self.mode in ('dvd', 'vcd') and not self.filename and \
! not self.media:
! # DVD/VCD playing a no media defined. We need to search if the
! # disc is inserted somewere.
media = util.check_media(self.media_id)
if media:
self.media = media
else:
! # Not found, show box so the user can insert the
! # correct disc. Callback is this function again
ConfirmBox(text=(_('No media found for "%s".\n')+
_('Please insert the media.')) % self.url,
***************
*** 506,522 ****
return
if self.player_rating < 10:
AlertBox(text=_('No player for this item found')).show()
return
!
mplayer_options = self.mplayer_options.split(' ')
if not mplayer_options:
mplayer_options = []
-
if arg:
mplayer_options += arg.split(' ')
self.plugin_eventhandler(PLAY, menuw)
!
error = self.player.play(mplayer_options, self)
--- 547,577 ----
return
+ # get the correct player for this item and check the
+ # rating if the player can play this item or not
+ if not self.possible_player:
+ self.possible_player = _get_possible_player()
+
+ if alternateplayer:
+ self.possible_player.reverse()
+
+ if not self.possible_player:
+ return
+
+ self.player_rating, self.player = self.possible_player[0]
if self.player_rating < 10:
AlertBox(text=_('No player for this item found')).show()
return
!
! # put together the mplayer options for this file
mplayer_options = self.mplayer_options.split(' ')
if not mplayer_options:
mplayer_options = []
if arg:
mplayer_options += arg.split(' ')
+ # call all our plugins to let them know we will play
self.plugin_eventhandler(PLAY, menuw)
!
! # call the player to play the item
error = self.player.play(mplayer_options, self)
***************
*** 547,608 ****
- def dvd_vcd_title_menu(self, arg=None, menuw=None):
- """
- Generate special menu for DVD/VCD/SVCD content
- """
- if not self.menuw:
- self.menuw = menuw
-
- # delete the submenu that got us here
- self.menuw.delete_submenu(False)
-
- # XXX only one track, play it
- # XXX disabled, it makes it impossible to set languages
- # if len(self.info['tracks']) == 1:
- # i=copy.copy(self)
- # i.parent = self
- # i.possible_player = []
- # i.set_url(self.url + '1', False)
- # i.play(menuw = self.menuw)
- # return
-
- # build a menu
- items = []
- for title in range(len(self.info['tracks'])):
- i = copy.copy(self)
- i.parent = self
- i.set_url(self.url + str(title+1), False)
- i.info = copy.copy(self.info)
- # copy the attributes from mmpython about this track
- i.info.mmdata = self.info.mmdata['tracks'][title]
- i.info.set_variables(self.info.get_variables())
- i.info_type = 'track'
- i.possible_player = []
- i.files = None
- i.name = Unicode(_('Play Title %s')) % (title+1)
- items.append(i)
-
- moviemenu = menu.Menu(self.name, items, umount_all = 1, theme=self.skin_fxd)
- moviemenu.item_types = 'video'
- self.menuw.pushmenu(moviemenu)
-
-
- def settings(self, arg=None, menuw=None):
- """
- create a menu with 'settings'
- """
- confmenu = configure.get_menu(self, self.menuw)
- menuw.pushmenu(confmenu)
-
-
def eventhandler(self, event, menuw=None):
"""
eventhandler for this item
"""
! # when called from mplayer.py, there is no menuw
! if not menuw:
! menuw = self.menuw
!
! if self.plugin_eventhandler(event, menuw):
return True
--- 602,610 ----
def eventhandler(self, event, menuw=None):
"""
eventhandler for this item
"""
! if self.plugin_eventhandler(event):
return True
***************
*** 610,627 ****
if self.subitems and not self.variants:
if event == PLAY_END:
! self.set_next_available_subitem()
# Loop until we find a subitem which plays without error
while self.current_subitem:
_debug_('playing next item')
! error = self.current_subitem.play(menuw=menuw)
if error:
self.last_error_msg = error
self.error_in_subitem = 1
! self.set_next_available_subitem()
else:
return True
if self.error_in_subitem:
# No more subitems to play, and an error occured
- self.menuw.show()
AlertBox(text=self.last_error_msg).show()
--- 612,628 ----
if self.subitems and not self.variants:
if event == PLAY_END:
! self._set_next_available_subitem()
# Loop until we find a subitem which plays without error
while self.current_subitem:
_debug_('playing next item')
! error = self.current_subitem.play()
if error:
self.last_error_msg = error
self.error_in_subitem = 1
! self._set_next_available_subitem()
else:
return True
if self.error_in_subitem:
# No more subitems to play, and an error occured
AlertBox(text=self.last_error_msg).show()
***************
*** 633,650 ****
if self.player:
self.player.stop()
! self.settings(menuw=menuw)
! menuw.show()
return True
! # show configure menu
! # if event == MENU:
! # import gui.widgets.MenuBox
! # menuw = gui.widgets.MenuBox.MenuBox()
! # self.settings(menuw=menuw)
! # menuw.show()
! # return True
!
! # give the event to the next eventhandler in the list
! if isstring(self.parent):
! self.parent = None
! return MediaItem.eventhandler(self, event, menuw)
--- 634,640 ----
if self.player:
self.player.stop()
! confmenu = configure.get_menu(self, self.menuw)
! self.menuw.pushmenu(confmenu)
return True
! return MediaItem.eventhandler(self, event)
-------------------------------------------------------
This SF.Net email is sponsored by: thawte's Crypto Challenge Vl
Crack the code and win a Sony DCRHC40 MiniDV Digital Handycam
Camcorder. More prizes in the weekly Lunch Hour Challenge.
Sign up NOW http://ad.doubleclick.net/clk;10740251;10262165;m
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog