| Trees | Indices | Help |
|
|---|
|
|
1 # -*- coding: utf-8 -*- 2 # Moovida - Home multimedia server 3 # Copyright (C) 2006-2009 Fluendo Embedded S.L. (www.fluendo.com). 4 # All rights reserved. 5 # 6 # This file is available under one of two license agreements. 7 # 8 # This file is licensed under the GPL version 3. 9 # See "LICENSE.GPL" in the root of this distribution including a special 10 # exception to use Moovida with Fluendo's plugins. 11 # 12 # The GPL part of Moovida is also available under a commercial licensing 13 # agreement from Fluendo. 14 # See "LICENSE.Moovida" in the root directory of this distribution package 15 # for details on that license. 16 17 from elisa.core.media_uri import MediaUri 18 from elisa.core.resource_manager import NoMatchingResourceProvider 19 from elisa.core import common 20 import os, platform 21 22 if platform.system() == 'Windows': 23 from win32com.shell import shellcon, shell 242620128 self.media_dir = {} 29 30 try: 31 if platform.system() == 'Windows': 32 self.media_dir = self.get_windows_media_directory() 33 else: 34 self.media_dir = self.get_linux_media_directory() 35 except Exception, e: 36 # if retrieving default directories fails log the error and go on 37 path = common.application.log_traceback() 38 common.application.warning("Retrieving default media directories " \ 39 "failed. Error logged at %s" % path) 40 41 self.refresh_directory_list()4244 try: 45 from elisa.extern.coherence import xdg 46 except ImportError: 47 return {} 48 49 media_dir = {} 50 xdg_mapping = {'audio': 'music', 51 'images': 'pictures', 52 'videos': 'video'} 53 home = os.path.expanduser("~") 54 55 xdg_content = xdg.xdg_content() 56 if xdg_content is None: 57 return {} 58 59 for d in xdg_content: 60 directory_path = d[0] 61 if os.path.normpath(directory_path) == home: 62 directory_path = None 63 64 key = xdg_mapping.get(d[2], d[2]) 65 media_dir[key] = directory_path 66 67 return media_dir6870 """ 71 return in a dict the multimedia directories in default encoding 72 """ 73 74 media_dir = {} 75 76 try: 77 not_uri = shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, 0, 0) 78 mydocs = MediaUri({'scheme': 'file', 'path': not_uri}).path 79 except: 80 # in worst case what? 81 mydocs = '' 82 83 try: 84 music_dir = shell.SHGetFolderPath(0, shellcon.CSIDL_MYMUSIC, 0, 0) 85 media_dir['music'] = MediaUri({'scheme': 'file', \ 86 'path': music_dir}).path 87 except: 88 media_dir['music'] = mydocs 89 90 try: 91 pictures_dir = shell.SHGetFolderPath(0, shellcon.CSIDL_MYPICTURES, 0, 0) 92 media_dir['pictures'] = MediaUri({'scheme': 'file', \ 93 'path': pictures_dir}).path 94 except: 95 media_dir['pictures'] = mydocs 96 97 try: 98 video_dir = shell.SHGetFolderPath(0, shellcon.CSIDL_MYVIDEO, 0, 0) 99 media_dir['video'] = MediaUri({'scheme': 'file', \ 100 'path': video_dir}).path 101 except: 102 media_dir['video'] = mydocs 103 104 return media_dir105107 108 directories = common.application.config.get_option(media_type, 109 section='directories', default=[]) 110 #do not display empty directories in the config 111 if "" in directories: 112 index = directories.remove("") 113 if '*default*' in directories and media_type in self.media_dir: 114 index = directories.index('*default*') 115 probed_directory_path = self.media_dir[media_type] 116 if probed_directory_path: 117 directories[index] = probed_directory_path 118 else: 119 directories.remove('*default*') 120 return directories121123 self.directories = {} 124 self.all_directories = [] 125 if media_type == 'music' or media_type == None: 126 self.directories['music'] = self.get_directories('music') 127 self.all_directories.extend(self.get_directories('music')) 128 if media_type == 'video' or media_type == None: 129 self.directories['video'] = self.get_directories('video') 130 self.all_directories.extend(self.get_directories('video')) 131 if media_type == 'pictures' or media_type == None: 132 self.directories['pictures'] = self.get_directories('pictures') 133 self.all_directories.extend(self.get_directories('pictures'))134136 if uri.path in self.directories[media_type]: 137 self.remove_directory(uri, media_type) 138 else: 139 self.add_directory(uri, media_type) 140 self.refresh_directory_list()141143 #music case 144 config = common.application.config 145 if media_type in self.media_dir.keys() and uri.path == self.media_dir[media_type]: 146 conf_uri = '*default*' 147 else: 148 conf_uri = uri.path 149 150 dir = self.get_directories(media_type) 151 152 if conf_uri not in dir: 153 dir.append(conf_uri) 154 config.set_option(media_type, dir, section='directories') 155 156 if media_type in ('music', 'pictures', 'video'): 157 resource_manager = common.application.resource_manager 158 # FIXME: hardcoded for the media scanner we have 159 # FIXME: we can not cancel it after it was added 160 scanner_uri = MediaUri("media_scanner://localhost/queue") 161 try: 162 resource_manager.put(uri, scanner_uri, section=media_type) 163 except NoMatchingResourceProvider: 164 # media scanner not running 165 pass166168 config = common.application.config 169 if media_type in self.media_dir.keys() and uri.path == self.media_dir[media_type]: 170 conf_uri = '*default*' 171 else: 172 conf_uri = uri.path 173 174 dir = self.get_directories(media_type) 175 176 update = False 177 if conf_uri in dir: 178 dir.remove(conf_uri) 179 update = True 180 if uri.path in dir: 181 dir.remove(uri.path) 182 update = True 183 if update == True: 184 config.set_option(media_type, dir, section='directories')185187 """ 188 Test whether a given URI is listed as a known media source. 189 All media types are searched. 190 191 @param uri: the URI of a source 192 @type uri: L{elisa.core.media_uri.MediaUri} 193 194 @return: C{True} if the URI is a known media source, C{False} otherwise 195 @rtype: C{bool} 196 """ 197 for media_type, directories in self.directories.iteritems(): 198 if uri.path in directories: 199 return True 200 return False
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Tue Dec 1 10:55:47 2009 | http://epydoc.sourceforge.net |