def _search_file(self): if self.mode == 'ever': return date = self.session['last_file_search'] if date and date > datetime.utcnow() - DELTA_FILE_SEARCH: return media_ = Media.search(**self) files = [] for res in media_: files.extend(res.get('files', [])) if media_ and files: if self.mode == 'inc': self._add_next('episode') src = self.get('src') if src: Media.update({'_id': {'$in': [m['_id'] for m in media_]}}, {'$set': {'src': src}}, safe=True) MSearch.remove({'_id': self._id}, safe=True) logger.info('removed %s search "%s": found files %s', self.category, self._get_query(), files) return True MSearch.update({'_id': self._id}, {'$set': {'session.last_file_search': datetime.utcnow()}}, safe=True)
def update_media(): for res in Media.find({'files': {'$exists': True}}, timeout=False): mtime = get_mtime(res['files']) if mtime: Media.update({'_id': res['_id']}, {'$set': {'date': mtime}}, safe=True)