1 # Written by Arno Bakker
2 # see LICENSE.txt for license information
7 from BaseLib.Core.Utilities.unicode import unicode2str
8 if (sys.platform == 'win32'):
9 from BaseLib.Core.Utilities.win32regchecker import Win32RegChecker,HKLM
11 videoextdefaults = ['aac','asf','avi','dv','divx','flac','flc','flv','mkv','mpeg','mpeg4','mpegts','mpg4','mp3','mp4','mpg','mkv','mov','m4v','ogg','ogm', 'ogv', 'oga', 'ogx','qt', 'rm','swf','ts','vob','wmv','wav', 'webm']
12 # Ric: added svc ext. for enhancement layers
13 svcextdefaults = ['dat']
17 def win32_retrieve_video_play_command(ext,videourl):
18 """ Use the specified extension of to find the player in the Windows registry to play the url (or file)"""
19 registry = Win32RegChecker()
22 print >>sys.stderr,"videoplay: Looking for player for",unicode2str(videourl)
27 winfiletype = registry.readRootKey(ext)
29 print >>sys.stderr,"videoplay: winfiletype is",winfiletype,type(winfiletype)
30 if winfiletype is None or winfiletype == '':
31 # Darn.... Try this: (VLC seems to be the one messing the registry up in the
33 winfiletype = registry.readRootKey(ext,value_name="VLC.Backup")
34 if winfiletype is None or winfiletype == '':
38 print >>sys.stderr,"videoplay: Looking for player for ext",ext,"which is type",winfiletype
40 contenttype = registry.readRootKey(ext,value_name="Content Type")
42 playkey = winfiletype+"\shell\play\command"
43 urlopen = registry.readRootKey(playkey)
45 openkey = winfiletype+"\shell\open\command"
46 urlopen = registry.readRootKey(openkey)
50 # Default is e.g. "C:\Program Files\Windows Media Player\wmplayer.exe" /prefetch:7 /Play "%L"
52 suo = urlopen.strip() # spaces
55 # Hrrrr: Quicktime uses %1 instead of %L and doesn't seem to quote the program path
61 idx2 = suo.find('%2',idx)
63 # Hmmm, a trailer, let's get rid of it
65 suo = suo[:idx+3] # quoted
71 # St*pid quicktime doesn't properly quote the program path, e.g.
72 # C:\Program Files\Quicktime\bla.exe "%1" instead of
73 # "C:\Program Files\Quicktime\bla.exe" "%1"
75 if idx > 0 and (len(suo)-1) >= idx+2 and suo[idx-1] == '"' and suo[idx+2]=='"':
80 # I assume everthing till end is the program path
82 qprogpath = quote_program_path(progpath)
85 suo = qprogpath+suo[end:]
87 print >>sys.stderr,"videoplay: new urlopen is",suo
88 return [contenttype,suo.replace(replace,videourl)]
91 def win32_retrieve_playcmd_from_mimetype(mimetype,videourl):
92 """ Use the specified MIME type to find the player in the Windows registry to play the url (or file)"""
93 registry = Win32RegChecker()
96 print >>sys.stderr,"videoplay: Looking for player for",unicode2str(videourl)
97 if mimetype == '' or mimetype is None:
100 keyname = '\\SOFTWARE\\Classes\\MIME\\Database\\Content Type\\'+mimetype
101 valuename = 'Extension'
102 ext = registry.readKeyRecursively(HKLM,keyname,value_name=valuename)
104 print >>sys.stderr,"videoplay: ext winfiletype is",ext
105 if ext is None or ext == '':
108 print >>sys.stderr,"videoplay: Looking for player for mime",mimetype,"which is ext",ext
110 return win32_retrieve_video_play_command(ext,videourl)
113 def quote_program_path(progpath):
114 idx = progpath.find(' ')
116 # Contains spaces, should quote if it's really path
117 if not os.access(progpath,os.R_OK):
119 print >>sys.stderr,"videoplay: Could not find assumed progpath",progpath
121 return '"'+progpath+'"'