diff --git a/docker-compose.yml b/docker-compose.yml index a4985c4..8ff3597 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: - ./data:/data environment: - DOWNLOAD_DIR=/data/downloads - - SESSION_FILE=/data/session/session-ig + - SESSION_FILE=/data/session-ig logging: driver: json-file options: diff --git a/instagram_monitor.py b/instagram_monitor.py index 8985345..e87a77e 100644 --- a/instagram_monitor.py +++ b/instagram_monitor.py @@ -42,20 +42,37 @@ class InstagramMonitor: def login(self) -> bool: # Method 1: load existing instaloader session file - if self._session_path.exists(): - try: - self.loader.load_session_from_file(config.instagram_username, str(self._session_path)) - logger.info("Session loaded from instaloader session file") - return True - except Exception as e: - logger.warning(f"Session file invalid: {e}") + # Check configured path and also common alternatives + session_candidates = [ + self._session_path, + Path(config.download_dir).parent / "session-ig", + Path(config.download_dir) / "session-ig", + ] + for session_path in session_candidates: + if session_path.exists(): + try: + self.loader.load_session_from_file(config.instagram_username, str(session_path)) + logger.info(f"Session loaded from {session_path}") + return True + except Exception as e: + logger.warning(f"Session file {session_path} invalid: {e}") # Method 2: load cookies.txt exported from browser - cookies_path = Path(config.download_dir) / "cookies.txt" - if cookies_path.exists(): + # Check both download_dir and parent (/data/) since user may place file in either + cookies_candidates = [ + Path(config.download_dir) / "cookies.txt", + Path(config.download_dir).parent / "cookies.txt", + ] + cookies_path = None + for candidate in cookies_candidates: + if candidate.exists(): + cookies_path = candidate + break + + if cookies_path: try: self._load_cookies_from_txt(cookies_path) - logger.info("Session loaded from cookies.txt") + logger.info(f"Session loaded from {cookies_path}") return True except Exception as e: logger.warning(f"cookies.txt invalid or missing sessionid cookie: {e}")