diff --git a/hvpy/api_groups/movies/get_movie_status.py b/hvpy/api_groups/movies/get_movie_status.py new file mode 100644 index 0000000..c74c5fc --- /dev/null +++ b/hvpy/api_groups/movies/get_movie_status.py @@ -0,0 +1,45 @@ +from typing import Optional + +from hvpy.io import HvpyParameters, OutputType + + +class getMovieStatusInputParameters(HvpyParameters): + """ + Handles the input parameters of the ``getMovieStatus`` API. + + Attributes + ---------- + {Shared} + id + Unique movie identifier, returned as a response by the ``queueMovie`` endpoint request. + format + Movie format. + verbose + Optionally include extra metadata in the response. + Defaults to `False`. + callback + Wrap the response object in a function call of your choosing. + Default is `None` (no wrapping), optional. + token + API token. + Defaults to `None`. + + References + ---------- + * ``__ + {Shared} + """ + + id: str + format: str + verbose: Optional[bool] = False + callback: Optional[str] = None + token: Optional[str] = None + + def get_output_type(self) -> OutputType: + """ + Returns the output type of the API call. + """ + if self.callback is not None: + return OutputType.STRING + return OutputType.JSON diff --git a/hvpy/api_groups/movies/re_queue_movie.py b/hvpy/api_groups/movies/re_queue_movie.py new file mode 100644 index 0000000..8cff69d --- /dev/null +++ b/hvpy/api_groups/movies/re_queue_movie.py @@ -0,0 +1,32 @@ +from typing import Optional + +from hvpy.io import HvpyParameters, OutputType + + +class reQueueMovieInputParameters(HvpyParameters): + """ + Handles the input parameters of the ``reQueueMovie`` API. + + Attributes + ---------- + {Shared} + id + Unique movie identifier, returned as a response by the ``queueMovie`` endpoint request. + force + Boolean to force the re-queueing of the movie. + Defaults to `False`, optional. + + References + ---------- + * ``__ + {Shared} + """ + + id: str + force: Optional[bool] = False + + def get_output_type(self) -> OutputType: + """ + Returns the output type of the API call. + """ + return OutputType.JSON diff --git a/hvpy/api_groups/movies/tests/test_get_movie_status.py b/hvpy/api_groups/movies/tests/test_get_movie_status.py new file mode 100644 index 0000000..977bfba --- /dev/null +++ b/hvpy/api_groups/movies/tests/test_get_movie_status.py @@ -0,0 +1,48 @@ +import pytest + +from hvpy import getMovieStatus +from hvpy.api_groups.movies.get_movie_status import getMovieStatusInputParameters + + +def test_json_response(): + response = getMovieStatus( + id="VXvX5", + format="mp4", + ) + assert response["url"] is not None + assert response["status"] is not None + + +def test_str_response(): + response = getMovieStatus( + id="VXvX5", + format="mp4", + callback="myCallback", + ) + assert response.startswith("myCallback(") + + +def test_error_hanpytestdling(): + with pytest.raises(TypeError, match="missing 1 required positional argument: 'id'"): + getMovieStatus( + format="mp4", + verbose=False, + callback=None, + token=None, + ) + + with pytest.raises(TypeError, match="missing 1 required positional argument: 'format'"): + getMovieStatus( + id="VXvX5", + verbose=False, + callback=None, + token=None, + ) + + +def test_url_property(): + params = getMovieStatusInputParameters( + id="VXvX5", + format="mp4", + ) + assert params.url == "https://api.helioviewer.org/v2/getMovieStatus/" diff --git a/hvpy/api_groups/movies/tests/test_re_queue_movie.py b/hvpy/api_groups/movies/tests/test_re_queue_movie.py new file mode 100644 index 0000000..de6fa19 --- /dev/null +++ b/hvpy/api_groups/movies/tests/test_re_queue_movie.py @@ -0,0 +1,22 @@ +import pytest + +from hvpy import reQueueMovie +from hvpy.api_groups.movies.re_queue_movie import reQueueMovieInputParameters + + +def test_json_response(): + response = reQueueMovie(id="gxRN5", force=True) + assert response["id"] is not None + assert response["eta"] is not None + assert response["queue"] is not None + assert response["token"] is not None + + +def test_error_handling(): + with pytest.raises(TypeError, match="missing 1 required positional argument: 'id'"): + reQueueMovie() + + +def test_url_property(): + params = reQueueMovieInputParameters(id="gxRN5") + assert params.url == "https://api.helioviewer.org/v2/reQueueMovie/" diff --git a/hvpy/facade.py b/hvpy/facade.py index b3b1bd9..a7d1548 100644 --- a/hvpy/facade.py +++ b/hvpy/facade.py @@ -16,6 +16,8 @@ "takeScreenshot", "downloadScreenshot", "queueMovie", + "reQueueMovie", + "getMovieStatus", ] @@ -382,3 +384,57 @@ def queueMovie( reqObservationDate=reqObservationDate, ) return execute_api_call(input_parameters=params) + + +@add_shared_docstring(reQueueMovieInputParameters) +def reQueueMovie( + id: str, + force: Optional[bool] = False, +) -> Union[bytes, str, Dict[str, Any]]: + """ + Re-generate a custom movie that is no longer cached on the server. + + Parameters + ---------- + {Insert} + Examples + -------- + >>> from hvpy import reQueueMovie + >>> reQueueMovie(id="gxRN5", force=True) + {'id': 'gxRN5', 'eta': 274, 'queue': 0, 'token': '...'} + """ + params = reQueueMovieInputParameters( + id=id, + force=force, + ) + return execute_api_call(input_parameters=params) + + +@add_shared_docstring(getMovieStatusInputParameters) +def getMovieStatus( + id: str, + format: str, + verbose: Optional[bool] = False, + callback: Optional[str] = None, + token: Optional[str] = None, +) -> Union[bytes, str, Dict[str, Any]]: + """ + Get the status of a movie. + + Parameters + ---------- + {Insert} + Examples + -------- + >>> from hvpy import getMovieStatus + >>> getMovieStatus(id="VXvX5", format="mp4") + {'frameRate': 15, 'numFrames': 300, 'startDate': '2014-02-03 20:26:16', 'status': 2, 'endDate': '2014-02-05 20:16:40', 'width': 846, 'height': 820, 'title': 'SDO AIA 1600 (2014-02-03 20:26:16 - 20:16:40 UTC)', 'thumbnails': {'icon': '...', 'small': '...', 'medium': '...', 'large': '...', 'full': '...'}, 'url': '...', 'statusLabel': 'Completed'} + """ + params = getMovieStatusInputParameters( + id=id, + format=format, + verbose=verbose, + callback=callback, + token=token, + ) + return execute_api_call(input_parameters=params) diff --git a/hvpy/parameters.py b/hvpy/parameters.py index 8dda465..52f67ca 100644 --- a/hvpy/parameters.py +++ b/hvpy/parameters.py @@ -3,7 +3,9 @@ from hvpy.api_groups.jpeg2000.get_jpx import getJPXInputParameters from hvpy.api_groups.jpeg2000.get_jpx_closest_to_mid_point import getJPXClosestToMidPointInputParameters from hvpy.api_groups.jpeg2000.get_status import getStatusInputParameters +from hvpy.api_groups.movies.get_movie_status import getMovieStatusInputParameters from hvpy.api_groups.movies.queue_movie import queueMovieInputParameters +from hvpy.api_groups.movies.re_queue_movie import reQueueMovieInputParameters from hvpy.api_groups.official_clients.get_closest_image import getClosestImageInputParameters from hvpy.api_groups.official_clients.get_data_sources import getDataSourcesInputParameters from hvpy.api_groups.screenshots.download_screenshot import downloadScreenshotInputParameters @@ -20,4 +22,6 @@ "takeScreenshotInputParameters", "downloadScreenshotInputParameters", "queueMovieInputParameters", + "reQueueMovieInputParameters", + "getMovieStatusInputParameters", ]