def _guess_mediatype(self, path): """Guess the mediatype of a file. Needs to be quick, as it's executed by the requesting thread in request_update(), and nothing will break if it isn't always accurate - so just checks filename. """ if filetypes.is_video_filename(path): mediatype = 'video' elif filetypes.is_audio_filename(path): mediatype = 'audio' else: mediatype = 'other' return mediatype
def _get_mediatype(muta, filename, info, tags): """This function is the sole determinant of an object's initial file_type, except when the file is not mutagen-compatible (in which case movie_data_program's data overrides anything set here). """ if 'fps' in info or 'gsst' in tags: mediatype = u'video' elif filetypes.is_video_filename(filename): mediatype = u'video' elif filetypes.is_audio_filename(filename): mediatype = u'audio' else: mediatype = None extension = os.path.splitext(filename)[-1].lstrip('.').lower() if hasattr(muta, 'mime') and (extension in UNRELIABLE_EXTENSIONS or not mediatype): mediatype = _mediatype_from_mime(muta.mime) or mediatype return mediatype
def scan_device_for_files(device): known_files = clean_database(device) device.database.set_bulk_mode(True) device.database.setdefault('sync', {}) for filename in fileutil.miro_allfiles(device.mount): short_filename = filename[len(device.mount):] ufilename = filename_to_unicode(short_filename) if os.path.normcase(ufilename) in known_files: continue if filetypes.is_video_filename(ufilename): item_type = 'video' elif filetypes.is_audio_filename(ufilename): item_type = 'audio' else: continue device.database[item_type][ufilename] = {} device.database.set_bulk_mode(False)
def gather_media_files(path): """Gather media files on the disk in a directory tree. This is used by the first time startup dialog. path -- absolute file path to search """ from miro import prefs from miro import app from miro.plat.utils import dirfilt parsed = 0 found = [] short_app_name = app.config.get(prefs.SHORT_APP_NAME) for root, dirs, files in os.walk(path): for f in files: parsed = parsed + 1 if (filetypes.is_video_filename(f) or filetypes.is_audio_filename(f)): found.append(os.path.join(root, f)) if short_app_name in dirs: dirs.remove(short_app_name) # Filter out naughty directories on a platform-specific basis # that we never want to be parsing. This is mainly useful on # Mac OS X where we do not want to descend into file packages. A bit # of a wart, long term solution is to write our own os.walk() shim # that is platform aware cleanly but right now it's not worth the # effort. dirfilt(root, dirs) if parsed > 1000: adjusted_parsed = int(parsed / 100.0) * 100 elif parsed > 100: adjusted_parsed = int(parsed / 10.0) * 10 else: adjusted_parsed = parsed yield adjusted_parsed, found
def scan_device_for_files(device): # XXX is this as_idle() safe? # prepare paths to add logging.debug('starting scan on %s', device.mount) known_files = clean_database(device) item_data = [] start = time.time() filenames = [] def _stop(): if not app.device_manager.running: # user quit, so we will too logging.debug('stopping scan on %s: user quit', device.mount) return True if not os.path.exists(device.mount): # device disappeared logging.debug('stopping scan on %s: disappeared', device.mount) return True if app.device_manager._is_hidden(device): # device no longer being # shown logging.debug('stopping scan on %s: hidden', device.mount) return True return False for filename in fileutil.miro_allfiles(device.mount): short_filename = filename[len(device.mount):] ufilename = filename_to_unicode(short_filename) item_type = None if os.path.normcase(short_filename) in known_files: continue if filetypes.is_video_filename(ufilename): item_type = u'video' elif filetypes.is_audio_filename(ufilename): item_type = u'audio' if item_type is not None: item_data.append((ufilename, item_type)) filenames.append(filename) if time.time() - start > 0.4: app.metadata_progress_updater.will_process_paths(filenames, device) yield # let other stuff run if _stop(): break start = time.time() filenames = [] if app.device_manager.running and os.path.exists(device.mount): # we don't re-check if the device is hidden because we still want to # save the items we found in that case yield # yield after prep work device.database.setdefault(u'sync', {}) logging.debug('scanned %s, found %i files (%i total)', device.mount, len(item_data), len(known_files) + len(item_data)) device.database.set_bulk_mode(True) start = time.time() for ufilename, item_type in item_data: i = item.DeviceItem(video_path=ufilename, file_type=item_type, device=device) device.database[item_type][ufilename] = i.to_dict() device.database.emit('item-added', i) if time.time() - start > 0.4: device.database.set_bulk_mode(False) # save the database yield # let other idle functions run if _stop(): break device.database.set_bulk_mode(True) start = time.time() device.database.set_bulk_mode(False)
def scan_device_for_files(device): # XXX is this as_idle() safe? # prepare paths to add logging.debug('starting scan on %s', device.mount) known_files = clean_database(device) item_data = [] start = time.time() def _continue(): if not app.device_manager.running: # user quit, so we will too logging.debug('stopping scan on %s: user quit', device.mount) return False if not os.path.exists(device.mount): # device disappeared logging.debug('stopping scan on %s: disappeared', device.mount) return False if app.device_manager._is_hidden(device): # device no longer being # shown logging.debug('stopping scan on %s: hidden', device.mount) return False return True for filename in fileutil.miro_allfiles(device.mount): short_filename = filename[len(device.mount):] ufilename = filename_to_unicode(short_filename) item_type = None if os.path.normcase(short_filename) in known_files: continue if filetypes.is_video_filename(ufilename): item_type = u'video' elif filetypes.is_audio_filename(ufilename): item_type = u'audio' if item_type is not None: item_data.append((ufilename, item_type)) app.metadata_progress_updater.will_process_path(filename, device) if time.time() - start > 0.4: yield # let other stuff run if not _continue(): break start = time.time() if app.device_manager.running and os.path.exists(device.mount): # we don't re-check if the device is hidden because we still want to # save the items we found in that case yield # yield after prep work device.database.setdefault(u'sync', {}) logging.debug('scanned %s, found %i files (%i total)', device.mount, len(item_data), len(known_files) + len(item_data)) device.database.set_bulk_mode(True) start = time.time() for ufilename, item_type in item_data: i = DeviceItem(video_path=ufilename, file_type=item_type, device=device) device.database[item_type][ufilename] = i.to_dict() device.database.emit('item-added', i) if time.time() - start > 0.4: device.database.set_bulk_mode(False) # save the database yield # let other idle functions run if not _continue(): break device.database.set_bulk_mode(True) start = time.time() device.database.set_bulk_mode(False)