diff --git a/info.yaml b/info.yaml index f16dd98..2d74caa 100644 --- a/info.yaml +++ b/info.yaml @@ -1,5 +1,5 @@ title: "애니 다운로더" -version: "0.4.5" +version: "0.4.6" package_name: "anime_downloader" developer: "projectdx" description: "anime downloader" diff --git a/mod_anilife.py b/mod_anilife.py index 95e5e88..c3bae8a 100644 --- a/mod_anilife.py +++ b/mod_anilife.py @@ -1325,19 +1325,21 @@ class AniLifeQueueEntity(FfmpegQueueEntity): # Call parent's download_completed first (handles file move) super().download_completed() - # Update DB status - db_entity = ModelAniLifeItem.get_by_anilife_id(self.info["_id"]) - if db_entity is not None: - db_entity.status = "completed" - db_entity.completed_time = datetime.now() - # 메타데이터 동기화 - db_entity.filename = self.filename - db_entity.save_fullpath = getattr(self, 'save_fullpath', None) - db_entity.filesize = getattr(self, 'filesize', None) - db_entity.duration = getattr(self, 'duration', None) - db_entity.quality = getattr(self, 'quality', None) - db_entity.save() - logger.info(f"[Anilife] DB status updated to 'completed': {self.info.get('title', 'Unknown')}") + # Update DB status - wrap in app context since this runs in a thread + from framework import app + with app.app_context(): + db_entity = ModelAniLifeItem.get_by_anilife_id(self.info["_id"]) + if db_entity is not None: + db_entity.status = "completed" + db_entity.completed_time = datetime.now() + # 메타데이터 동기화 + db_entity.filename = self.filename + db_entity.save_fullpath = getattr(self, 'save_fullpath', None) + db_entity.filesize = getattr(self, 'filesize', None) + db_entity.duration = getattr(self, 'duration', None) + db_entity.quality = getattr(self, 'quality', None) + db_entity.save() + logger.info(f"[Anilife] DB status updated to 'completed': {self.info.get('title', 'Unknown')}") def prepare_extra(self): """ diff --git a/model_base.py b/model_base.py index b0a62f9..864d7ca 100644 --- a/model_base.py +++ b/model_base.py @@ -136,30 +136,32 @@ class AnimeQueueEntity(FfmpegQueueEntity): def _update_db_status(self): """Update DB status to completed - generic method for all sites.""" try: - # Get the web_list_model from module_logic - model_class = getattr(self.module_logic, 'web_list_model', None) - if model_class is None: - return - - # Try to find the DB entity - db_entity = None - info = getattr(self, 'info', {}) - - # Anilife uses _id - if hasattr(model_class, 'get_by_anilife_id') and info.get('_id'): - db_entity = model_class.get_by_anilife_id(info['_id']) - # Linkkf/Ohli24 might use different identifiers - elif hasattr(model_class, 'get_by_id') and info.get('db_id'): - db_entity = model_class.get_by_id(info['db_id']) - elif hasattr(model_class, 'get_by_content_code') and info.get('content_code'): - db_entity = model_class.query.filter_by(content_code=info['content_code'], episode_no=info.get('episode_no')).first() - - if db_entity is not None: - db_entity.status = "completed" - db_entity.completed_time = datetime.now() - db_entity.filename = getattr(self, 'filename', None) - db_entity.save() - logger.info(f"[{self.module_logic.name}] DB status updated to 'completed': {info.get('title', 'Unknown')}") + from framework import app + with app.app_context(): + # Get the web_list_model from module_logic + model_class = getattr(self.module_logic, 'web_list_model', None) + if model_class is None: + return + + # Try to find the DB entity + db_entity = None + info = getattr(self, 'info', {}) + + # Anilife uses _id + if hasattr(model_class, 'get_by_anilife_id') and info.get('_id'): + db_entity = model_class.get_by_anilife_id(info['_id']) + # Linkkf/Ohli24 might use different identifiers + elif hasattr(model_class, 'get_by_id') and info.get('db_id'): + db_entity = model_class.get_by_id(info['db_id']) + elif hasattr(model_class, 'get_by_content_code') and info.get('content_code'): + db_entity = model_class.query.filter_by(content_code=info['content_code'], episode_no=info.get('episode_no')).first() + + if db_entity is not None: + db_entity.status = "completed" + db_entity.completed_time = datetime.now() + db_entity.filename = getattr(self, 'filename', None) + db_entity.save() + logger.info(f"[{self.module_logic.name}] DB status updated to 'completed': {info.get('title', 'Unknown')}") except Exception as e: logger.error(f"Failed to update DB status: {e}")