diff --git a/cdp_backend/tests/conftest.py b/cdp_backend/tests/conftest.py index e1a96e8c..7e2e3100 100644 --- a/cdp_backend/tests/conftest.py +++ b/cdp_backend/tests/conftest.py @@ -40,6 +40,9 @@ def resources_dir() -> Path: # City of Versailles, Kentucky EXAMPLE_VIMEO = "https://vimeo.com/503166067" +# City of Chicago, Illinois +EXAMPLE_VIMEO_SHOWCASE = "https://vimeo.com/showcase/6277394/video/722690793" + @pytest.fixture def example_video(resources_dir: Path) -> Path: diff --git a/cdp_backend/tests/resources/example_video.mp4 b/cdp_backend/tests/resources/example_video.mp4 index 5dd374c1..884d1e6e 100644 Binary files a/cdp_backend/tests/resources/example_video.mp4 and b/cdp_backend/tests/resources/example_video.mp4 differ diff --git a/cdp_backend/tests/utils/test_file_utils.py b/cdp_backend/tests/utils/test_file_utils.py index 2f3c17a0..fe4f80ab 100644 --- a/cdp_backend/tests/utils/test_file_utils.py +++ b/cdp_backend/tests/utils/test_file_utils.py @@ -26,6 +26,7 @@ EXAMPLE_VIDEO_FILENAME, EXAMPLE_VIDEO_HD_FILENAME, EXAMPLE_VIMEO, + EXAMPLE_VIMEO_SHOWCASE, EXAMPLE_YOUTUBE_VIDEO_EMBEDDED, EXAMPLE_YOUTUBE_VIDEO_PARAMETER, EXAMPLE_YOUTUBE_VIDEO_SHORT, @@ -247,6 +248,7 @@ def test_convert_video_to_mp4( (EXAMPLE_YOUTUBE_VIDEO_PARAMETER, "XALBGkjkUPQ.mp4"), (EXAMPLE_YOUTUBE_VIDEO_SHORT, "XALBGkjkUPQ.mp4"), (EXAMPLE_VIMEO, Path("503166067") / "503166067.mp4"), + (EXAMPLE_VIMEO_SHOWCASE, Path("722690793") / "722690793.mp4"), (EXAMPLE_M3U8_PLAYLIST_URI, None), ], ) @@ -264,3 +266,13 @@ def test_remote_resource_copy( assert Path(actual_uri).is_file() os.remove(actual_uri) + + +def test_invalid_uri() -> None: + with pytest.raises(Exception) as e: + file_utils.resource_copy("https://vimeo.com/fakeuri") + assert e.type == ValueError + assert ( + str(e.value) + == "Could not extract video id from uri: 'https://vimeo.com/fakeuri'" + ) diff --git a/cdp_backend/utils/file_utils.py b/cdp_backend/utils/file_utils.py index cf4d18eb..69a081e3 100644 --- a/cdp_backend/utils/file_utils.py +++ b/cdp_backend/utils/file_utils.py @@ -4,6 +4,7 @@ import logging import math import random +import re from hashlib import sha256 from pathlib import Path from typing import Optional, Tuple, Union @@ -226,7 +227,14 @@ def vimeo_copy(uri: str, dst: Path, overwrite: bool = False) -> str: if dst.is_file() and not overwrite: raise FileExistsError(dst) - v = Vimeo(uri) + # 9 is the length of the video id; no other + # string of numbers in the URL has length 9 (thankfully) + match = re.findall(r"\d{9}", uri) + if len(match) == 0: + raise ValueError(f"Could not extract video id from uri: '{uri}'") + + vid = match[0] + v = Vimeo.from_video_id(video_id=vid) if len(v.streams) == 0: raise ValueError("File {} contains no downloadable streams", uri)