feat(bot): proactive cookie health-check + simpler user-facing errors
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 51s
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 51s
Add /cookies/check to youtube-downloader and instagram-downloader, polled every 30 min from bot.py; alerts the admin bot on healthy->broken transitions (with a 24h re-reminder cap while still broken) and on recovery. Also stop leaking raw exception text to end users - they now see a plain, friendly English message while the admin bot still gets full technical detail via notify_admin_error.
This commit is contained in:
parent
be1acaaf2b
commit
5092d882e5
3 changed files with 166 additions and 4 deletions
|
|
@ -200,6 +200,36 @@ def health():
|
|||
return jsonify({'status': 'ok', 'service': 'instagram-downloader'}), 200
|
||||
|
||||
|
||||
INSTAGRAM_COOKIE_TEST_URL = os.getenv(
|
||||
'INSTAGRAM_COOKIE_TEST_URL',
|
||||
'https://www.instagram.com/reel/Cvuh19eNWv_/' # стабильный публичный ролик (NASA)
|
||||
)
|
||||
|
||||
|
||||
@app.route('/cookies/check', methods=['POST'])
|
||||
def cookies_check():
|
||||
"""Проверяет, рабочие ли сейчас Instagram cookies (для проактивного мониторинга)."""
|
||||
cookies_file = Path(os.getenv('INSTAGRAM_COOKIES_FILE', 'instagram_cookies.txt'))
|
||||
if not cookies_file.exists():
|
||||
return jsonify({'cookies_present': False, 'cookies_valid': None,
|
||||
'detail': 'cookies file missing'}), 200
|
||||
|
||||
ydl_opts = {
|
||||
'quiet': True,
|
||||
'no_warnings': True,
|
||||
'socket_timeout': 20,
|
||||
'cookiefile': str(cookies_file.absolute()),
|
||||
'http_headers': {'Referer': 'https://www.instagram.com/'},
|
||||
}
|
||||
try:
|
||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
||||
ydl.extract_info(INSTAGRAM_COOKIE_TEST_URL, download=False)
|
||||
return jsonify({'cookies_present': True, 'cookies_valid': True, 'detail': ''}), 200
|
||||
except Exception as e:
|
||||
return jsonify({'cookies_present': True, 'cookies_valid': False,
|
||||
'detail': str(e)[-500:]}), 200
|
||||
|
||||
|
||||
@app.route('/download/stream', methods=['POST'])
|
||||
def download_stream():
|
||||
"""Скачивает видео с Instagram и возвращает бинарные данные"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue