def chkVideoDir(pathname, deep=False): log.trace('Checking Directory: %s' % pathname) global FilesWithIssues _files_checked = 0 _file_count = countFiles(pathname) if _file_count == 0: log.warn('Path contains no video content, Stopping scan. Path: {}'.format(pathname)) return {} log.info('Number of Files in Tree: %s' % _file_count) if os.path.isdir(pathname): for root, dirs, files in os.walk(os.path.abspath(pathname), followlinks=False): dirs = sorted(dirs) files = sorted(files) for fname in files: fq_fname = os.path.join(root, fname) rc = chkVideoFile(fq_fname, deep) if deep and rc[0] > 0: FilesWithIssues[fq_fname] = rc[1] elif rc > 0: FilesWithIssues[fq_fname] = 'Errors Found' log.verbose('File has issues: %s' % fq_fname) _files_checked += 1 quotient, remainder = divmod(_files_checked, 250) if remainder == 0: log.info('Files Checked: %2.2f%% - %5s of %5s Number of Errors: %s' % (_files_checked / _file_count, _files_checked, _file_count, len(FilesWithIssues))) log.info('Files Checked: %2.2f%% - %5s of %5s Number of Errors: %s' % (_files_checked / _file_count, _files_checked, _file_count, len(FilesWithIssues))) return FilesWithIssues
def reset_folders(self, pathname): log.trace('reset_folders: Pathname Requested: {}'.format(pathname)) _files_checked = 0 _total_files = countFiles(pathname, self.settings.MediaExt, self.settings.ExcludeList) if _total_files == 0: log.warn('Path contains no video content, Stopping scan. Path: {}'. format(pathname)) return (4) log.info("==== Begin Scan: {} ====".format(pathname)) dir_count = 0 dir_skipped = 0 for _root, _dirs, _files in os.walk(os.path.abspath(pathname), followlinks=False): dir_count += 1 _last_date = None if _dirs != []: _dirs.sort() _dirs_temp = sorted(_dirs) for _dir in _dirs_temp: if self.ignored(_dir): dir_skipped += 1 _dirs.remove(_dir) log.trace('Removing Dir: %s' % _dir) for _file in _files: _ext = os.path.splitext(_file)[1][1:] if _ext.lower() not in self.settings.MediaExt: continue _files_checked += 1 _fq_name = os.path.join(_root, _file) _mod_date = os.path.getmtime(_fq_name) if _last_date < _mod_date or _last_date == None: _last_date = _mod_date if _last_date: os.utime(_root, (_last_date, _last_date)) elif _dirs == []: os.utime(_root, None) message = 'Files Checked: %2.2f%% %5d of %5d' % ( ((_files_checked) / _total_files) * 100, (_files_checked), _total_files) log.info(message)
def reset_folders(self, pathname): log.trace('reset_folders: Pathname Requested: {}'.format(pathname)) _files_checked = 0 _total_files = countFiles(pathname, self.settings.MediaExt, self.settings.ExcludeList) if _total_files == 0: log.warn('Path contains no video content, Stopping scan. Path: {}'.format(pathname)) return(4) log.info("==== Begin Scan: {} ====".format(pathname)) dir_count = 0 dir_skipped = 0 for _root, _dirs, _files in os.walk(os.path.abspath(pathname), followlinks=False): dir_count += 1 _last_date = None if _dirs != []: _dirs.sort() _dirs_temp = sorted(_dirs) for _dir in _dirs_temp: if self.ignored(_dir): dir_skipped += 1 _dirs.remove(_dir) log.trace('Removing Dir: %s' % _dir) for _file in _files: _ext = os.path.splitext(_file)[1][1:] if _ext.lower() not in self.settings.MediaExt: continue _files_checked += 1 _fq_name = os.path.join(_root, _file) _mod_date = os.path.getmtime(_fq_name) if _last_date < _mod_date or _last_date == None: _last_date = _mod_date if _last_date: os.utime(_root, (_last_date, _last_date)) elif _dirs == []: os.utime(_root, None) message = 'Files Checked: %2.2f%% %5d of %5d' % (((_files_checked) / _total_files) * 100, (_files_checked), _total_files) log.info(message)
def chkVideoDir(pathname, deep=False): log.trace('Checking Directory: %s' % pathname) global FilesWithIssues _files_checked = 0 _file_count = countFiles(pathname) if _file_count == 0: log.warn( 'Path contains no video content, Stopping scan. Path: {}'.format( pathname)) return {} log.info('Number of Files in Tree: %s' % _file_count) if os.path.isdir(pathname): for root, dirs, files in os.walk(os.path.abspath(pathname), followlinks=False): dirs = sorted(dirs) files = sorted(files) for fname in files: fq_fname = os.path.join(root, fname) rc = chkVideoFile(fq_fname, deep) if deep and rc[0] > 0: FilesWithIssues[fq_fname] = rc[1] elif rc > 0: FilesWithIssues[fq_fname] = 'Errors Found' log.verbose('File has issues: %s' % fq_fname) _files_checked += 1 quotient, remainder = divmod(_files_checked, 250) if remainder == 0: log.info( 'Files Checked: %2.2f%% - %5s of %5s Number of Errors: %s' % (_files_checked / _file_count, _files_checked, _file_count, len(FilesWithIssues))) log.info('Files Checked: %2.2f%% - %5s of %5s Number of Errors: %s' % (_files_checked / _file_count, _files_checked, _file_count, len(FilesWithIssues))) return FilesWithIssues
def ScanSeriesLibrary(self): log.trace('ScanSeriesLibrary: Start') FilesToBeAdded = [] Files_Loaded = 0 Files_Processed = 0 Files_Already_Processed = 0 Files_Non_Video = 0 Files_with_Errors = 0 File_Count = countFiles(self.settings.SeriesDir, exclude_list=self.settings.ExcludeList) log.info('Number of File to be Checked: %s' % File_Count) for _root, _dirs, _files in os.walk(self.settings.SeriesDir): if _dirs is not None: _dirs.sort() for _dir in _dirs[:]: # Process Enbedded Directories if self._ignored(_dir): _dirs.remove(_dir) for _file_name in _files: quotient, remainder = divmod(Files_Processed, 250) if remainder == 0: self.db.commit() log.info('Checked: %2.2f%% - %5s of %5s Errors: %s Present: %s Non-Video: %s ' \ % ((Files_Processed/ File_Count)*100, Files_Processed, File_Count, Files_with_Errors, Files_Already_Processed, Files_Non_Video ) ) Files_Processed += 1 _fq_name = os.path.join(_root, _file_name) log.trace('Processing File: %s' % _fq_name) try: _ext = os.path.splitext(_file_name)[1][1:] if _ext not in self.settings.MediaExt: Files_Non_Video += 1 continue _file_details = self.fileparser.getFileDetails(_fq_name) self.load_entry(_file_details) Files_Loaded += 1 except InvalidFilename: log.info('Skipping Series Not Found: {}'.format(_fq_name)) Files_with_Errors += 1 continue except DuplicateRecord: Files_Already_Processed += 1 continue self.db.commit() log.info('Complete: Files Checked: %5s Number of Errors: %s' % (Files_Processed, Files_with_Errors ) )
def ScanSeriesLibrary(self, type_scan, user_list): log.trace('ScanSeriesLibrary: Start') user_profiles = config.GetSubscribers() for user in config.Users: if user_list and user not in user_list: continue user_profile = user_profiles[user] Files_Loaded = 0 Files_Processed = 0 source_directory = os.path.join(config.SubscriptionDir, user, type_scan) File_Count = countFiles(source_directory, exclude_list=config.ExcludeList) log.info('{:5s} - Number of File to be Checked: {}'.format(user, File_Count)) for _symlink_dir in os.listdir(source_directory): target_dir = os.path.join(config.SeriesDir, _symlink_dir) if not os.path.isdir(target_dir): raise UnexpectedErrorOccured('Series Library referenced in setting NOT FOUND: {}'.format(target_dir)) sys.exit(1) for _root, _dirs, _files in os.walk(target_dir): if _dirs != None: _dirs.sort() for _exclude_dir in config.ExcludeList: try: _index = _dirs.index(_exclude_dir) _dirs.pop(_index) logger.TRACE('Removing Dir: %s' % _exclude_dir) except: continue for _file_name in _files: Files_Processed += 1 _fq_name = os.path.join(_root, _file_name) log.trace('Processing File: %s' % _fq_name) try: _file_ext = os.path.splitext(_fq_name)[1][1:].lower() if _file_ext in config.MediaExt: load_entry(user, _fq_name) Files_Loaded += 1 else: continue log.info('Skipping Non-VIdeo File: {}'.format(_fq_name)) except DuplicateRecord: Files_Loaded += 1 quotient, remainder = divmod(Files_Processed, 250) if remainder == 0: db.commit() log.info('%-5s - Files Checked: %2.2f%% %5s of %5s Number of Errors: %s' % (user, Files_Processed/ File_Count, Files_Processed, File_Count, Files_Processed - Files_Loaded ) ) db.commit() log.info('{:5s} - Complete: Files Checked: {:5n} Number of Errors: {}'.format(user, Files_Processed, Files_Processed - Files_Loaded ) )
def ScanSeriesLibrary(self): log.trace('ScanSeriesLibrary: Start') FilesToBeAdded = [] Files_Loaded = 0 Files_Processed = 0 Files_Already_Processed = 0 Files_Non_Video = 0 Files_with_Errors = 0 File_Count = countFiles(self.settings.SeriesDir, exclude_list=self.settings.ExcludeList) log.info('Number of File to be Checked: %s' % File_Count) for _root, _dirs, _files in os.walk(self.settings.SeriesDir): if _dirs is not None: _dirs.sort() for _dir in _dirs[:]: # Process Enbedded Directories if self._ignored(_dir): _dirs.remove(_dir) for _file_name in _files: quotient, remainder = divmod(Files_Processed, 250) if remainder == 0: self.db.commit() log.info('Checked: %2.2f%% - %5s of %5s Errors: %s Present: %s Non-Video: %s ' \ % ((Files_Processed/ File_Count)*100, Files_Processed, File_Count, Files_with_Errors, Files_Already_Processed, Files_Non_Video ) ) Files_Processed += 1 _fq_name = os.path.join(_root, _file_name) log.trace('Processing File: %s' % _fq_name) try: _ext = os.path.splitext(_file_name)[1][1:] if _ext not in self.settings.MediaExt: Files_Non_Video += 1 continue _file_details = self.fileparser.getFileDetails(_fq_name) self.load_entry(_file_details) Files_Loaded += 1 except InvalidFilename: log.info('Skipping Series Not Found: {}'.format(_fq_name)) Files_with_Errors += 1 continue except DuplicateRecord: Files_Already_Processed += 1 continue self.db.commit() log.info('Complete: Files Checked: %5s Number of Errors: %s' % (Files_Processed, Files_with_Errors))
def ScanSeriesLibrary(self, type_scan, user_list): log.trace('ScanSeriesLibrary: Start') user_profiles = config.GetSubscribers() for user in config.Users: if user_list and user not in user_list: continue user_profile = user_profiles[user] Files_Loaded = 0 Files_Processed = 0 source_directory = os.path.join(config.SubscriptionDir, user, type_scan) File_Count = countFiles(source_directory, exclude_list=config.ExcludeList) log.info('{:5s} - Number of File to be Checked: {}'.format( user, File_Count)) for _symlink_dir in os.listdir(source_directory): target_dir = os.path.join(config.SeriesDir, _symlink_dir) if not os.path.isdir(target_dir): raise UnexpectedErrorOccured( 'Series Library referenced in setting NOT FOUND: {}'. format(target_dir)) sys.exit(1) for _root, _dirs, _files in os.walk(target_dir): if _dirs != None: _dirs.sort() for _exclude_dir in config.ExcludeList: try: _index = _dirs.index(_exclude_dir) _dirs.pop(_index) logger.TRACE('Removing Dir: %s' % _exclude_dir) except: continue for _file_name in _files: Files_Processed += 1 _fq_name = os.path.join(_root, _file_name) log.trace('Processing File: %s' % _fq_name) try: _file_ext = os.path.splitext( _fq_name)[1][1:].lower() if _file_ext in config.MediaExt: load_entry(user, _fq_name) Files_Loaded += 1 else: continue log.info('Skipping Non-VIdeo File: {}'.format( _fq_name)) except DuplicateRecord: Files_Loaded += 1 quotient, remainder = divmod(Files_Processed, 250) if remainder == 0: db.commit() log.info( '%-5s - Files Checked: %2.2f%% %5s of %5s Number of Errors: %s' % (user, Files_Processed / File_Count, Files_Processed, File_Count, Files_Processed - Files_Loaded)) db.commit() log.info( '{:5s} - Complete: Files Checked: {:5n} Number of Errors: {}' .format(user, Files_Processed, Files_Processed - Files_Loaded))