Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions hvpy/api_groups/movies/download_movie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from hvpy.io import HvpyParameters, OutputType


class downloadMovieInputParameters(HvpyParameters):
"""
Handles the input parameters of the ``downloadMovie`` API.

Attributes
----------
{Shared}
id
Unique movie identifier, returned as a response by the ``queueMovie`` endpoint request.
format
Movie Format ("mp4", "webm", or "flv").
hq
Download a higher-quality movie file (valid for "mp4" movies only, ignored otherwise).
Defaults to `False`, optional.

References
----------
* `<https://api.helioviewer.org/docs/v2/api/api_groups/movies.html#id9>`__
{Shared}
"""

id: str
format: str
hq: bool = False

def get_output_type(self) -> OutputType:
"""
Returns the output type of the API call.
"""
return OutputType.RAW
32 changes: 32 additions & 0 deletions hvpy/api_groups/movies/tests/test_download_movie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest

from hvpy import downloadMovie
from hvpy.api_groups.movies.download_movie import downloadMovieInputParameters


def test_raw_response():
response = downloadMovie(
id="h2n6n",
format="mp4",
)
assert isinstance(response, bytes)


def test_error_handling():
with pytest.raises(TypeError, match="missing 1 required positional argument: 'id'"):
downloadMovie(
format="mp4",
)

with pytest.raises(TypeError, match="missing 1 required positional argument: 'format'"):
downloadMovie(
id="VXvX5",
)


def test_url_property():
params = downloadMovieInputParameters(
id="VXvX5",
format="mp4",
)
assert params.url == "https://api.beta.helioviewer.org/v2/downloadMovie/"
2 changes: 1 addition & 1 deletion hvpy/api_groups/movies/tests/test_get_movie_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_str_response():
assert response.startswith("myCallback(")


def test_error_hanpytestdling():
def test_error_handling():
with pytest.raises(TypeError, match="missing 1 required positional argument: 'id'"):
getMovieStatus(
format="mp4",
Expand Down
28 changes: 28 additions & 0 deletions hvpy/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"queueMovie",
"reQueueMovie",
"getMovieStatus",
"downloadMovie",
]


Expand Down Expand Up @@ -446,3 +447,30 @@ def getMovieStatus(
token=token,
)
return execute_api_call(input_parameters=params)


@add_shared_docstring(downloadMovieInputParameters)
def downloadMovie(
id: str,
format: str,
hq: bool = False,
) -> Union[bytes, str, Dict[str, Any]]:
"""
Download a custom movie that was generated using the ``queueMovie`` API
endpoint.

Parameters
----------
{Insert}
Examples
--------
>>> from hvpy import downloadMovie
>>> downloadMovie(id="h2n6n", format="mp4")
b'...'
"""
params = downloadMovieInputParameters(
id=id,
format=format,
hq=hq,
)
return execute_api_call(input_parameters=params)
2 changes: 2 additions & 0 deletions hvpy/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.download_movie import downloadMovieInputParameters
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
Expand All @@ -24,4 +25,5 @@
"queueMovieInputParameters",
"reQueueMovieInputParameters",
"getMovieStatusInputParameters",
"downloadMovieInputParameters",
]