fix: correct session and cookies file paths
- Session file: check /data/session-ig, /data/downloads/session-ig - Cookies: check /data/cookies.txt and /data/downloads/cookies.txt - Fix docker-compose SESSION_FILE path
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -42,20 +42,37 @@ class InstagramMonitor:
|
||||
|
||||
def login(self) -> bool:
|
||||
# Method 1: load existing instaloader session file
|
||||
if self._session_path.exists():
|
||||
# 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(self._session_path))
|
||||
logger.info("Session loaded from instaloader session file")
|
||||
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 invalid: {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}")
|
||||
|
||||
Reference in New Issue
Block a user