From 2a92852d5c3cf5332eb554eab911b03cf24cbb84 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 13 Jul 2023 13:37:44 +0000 Subject: [PATCH] [FIX] web_editor: suppress exceptions in get_video_thumbnail Error responses are already ignored, but connection errors would blow up the entire thing, which breaks `test_resequence_images` (and possibly others). Part-of: odoo/odoo#128497 --- addons/web_editor/tools.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/addons/web_editor/tools.py b/addons/web_editor/tools.py index 4a66907e0d2..f9da1b9a8bc 100644 --- a/addons/web_editor/tools.py +++ b/addons/web_editor/tools.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import base64 +import contextlib import re import requests @@ -137,17 +138,18 @@ def get_video_thumbnail(video_url): response = None platform, video_id = source[:2] - if platform == 'youtube': - response = requests.get(f'https://img.youtube.com/vi/{video_id}/0.jpg', timeout=10) - elif platform == 'vimeo': - res = requests.get(f'http://vimeo.com/api/oembed.json?url={video_url}', timeout=10) - if res.ok: - data = res.json() - response = requests.get(data['thumbnail_url'], timeout=10) - elif platform == 'dailymotion': - response = requests.get(f'https://www.dailymotion.com/thumbnail/video/{video_id}', timeout=10) - elif platform == 'instagram': - response = requests.get(f'https://www.instagram.com/p/{video_id}/media/?size=t', timeout=10) + with contextlib.suppress(requests.exceptions.RequestException): + if platform == 'youtube': + response = requests.get(f'https://img.youtube.com/vi/{video_id}/0.jpg', timeout=10) + elif platform == 'vimeo': + res = requests.get(f'http://vimeo.com/api/oembed.json?url={video_url}', timeout=10) + if res.ok: + data = res.json() + response = requests.get(data['thumbnail_url'], timeout=10) + elif platform == 'dailymotion': + response = requests.get(f'https://www.dailymotion.com/thumbnail/video/{video_id}', timeout=10) + elif platform == 'instagram': + response = requests.get(f'https://www.instagram.com/p/{video_id}/media/?size=t', timeout=10) if response and response.ok: return image_process(response.content)