From 776ed2c05a752ba8447e4ae77427681162c902d5 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Sat, 1 Oct 2022 11:34:07 +0530 Subject: [PATCH 1/6] use res['title'] to rename the file --- hvpy/helpers.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hvpy/helpers.py b/hvpy/helpers.py index 1cd7e95..a93bdc8 100644 --- a/hvpy/helpers.py +++ b/hvpy/helpers.py @@ -59,7 +59,7 @@ def createMovie( Default is `False`. filename The path to save the file to. - Optional, will default to ``f"{res['id']}_{startTime.date()}_{endTime.date()}.{format}"``. + Optional, will default to ``f"{res['title']}.{format}"``. hq Download a higher-quality movie file (valid for "mp4" movies only, ignored otherwise). Default is `False`, optional. @@ -94,12 +94,13 @@ def createMovie( hq = input_params.pop("hq") timeout = input_params.pop("timeout") res = queueMovie(**input_params) + id = res["id"] if res.get("error"): raise RuntimeError(res["error"]) timeout_counter = time.time() + 60 * timeout # Default 5 minutes while True: status = getMovieStatus( - id=res["id"], + id=id, format=format, token=res["token"], ) @@ -112,12 +113,15 @@ def createMovie( if status["status"] == 3: raise RuntimeError(status["error"]) binary_data = downloadMovie( - id=res["id"], + id=id, format=format, hq=hq, ) if filename is None: - filename = f"{res['id']}_{startTime.date()}_{endTime.date()}.{format}" + title = getMovieStatus(id=id, format=format, token=res["token"],)[ + "title" + ].replace(" ", "_") + filename = f"{title}.{format}" else: filename = f"{filename}.{format}" save_file( From d15f8324384f802a7e036f56019382b726fc8354 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Mon, 3 Oct 2022 23:29:14 +0530 Subject: [PATCH 2/6] filename tweaks --- hvpy/helpers.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hvpy/helpers.py b/hvpy/helpers.py index a93bdc8..dba21e8 100644 --- a/hvpy/helpers.py +++ b/hvpy/helpers.py @@ -104,6 +104,11 @@ def createMovie( format=format, token=res["token"], ) + if filename is None: + title = status["title"].replace(" ", "_") + filename = f"{title}.{format}" + else: + filename = f"{filename}.{format}" if status["status"] in [0, 1]: time.sleep(3) if status["status"] == 2: @@ -117,13 +122,6 @@ def createMovie( format=format, hq=hq, ) - if filename is None: - title = getMovieStatus(id=id, format=format, token=res["token"],)[ - "title" - ].replace(" ", "_") - filename = f"{title}.{format}" - else: - filename = f"{filename}.{format}" save_file( data=binary_data, filename=filename, From 9748a90ad0b11dae5ebeaf334a5a53367aa399c5 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Tue, 4 Oct 2022 11:55:58 +0530 Subject: [PATCH 3/6] fix failing test --- hvpy/helpers.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hvpy/helpers.py b/hvpy/helpers.py index dba21e8..e337515 100644 --- a/hvpy/helpers.py +++ b/hvpy/helpers.py @@ -98,17 +98,15 @@ def createMovie( if res.get("error"): raise RuntimeError(res["error"]) timeout_counter = time.time() + 60 * timeout # Default 5 minutes + title = "" while True: status = getMovieStatus( id=id, format=format, token=res["token"], ) - if filename is None: - title = status["title"].replace(" ", "_") - filename = f"{title}.{format}" - else: - filename = f"{filename}.{format}" + if status.get("title"): + title = status["title"] if status["status"] in [0, 1]: time.sleep(3) if status["status"] == 2: @@ -122,6 +120,10 @@ def createMovie( format=format, hq=hq, ) + if filename is not None: + filename = f"{filename}.{format}" + else: + filename = f"{title}.{format}" save_file( data=binary_data, filename=filename, From 37133d76384d29071eba6927b49488a49a7cb9d3 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Tue, 4 Oct 2022 12:03:30 +0530 Subject: [PATCH 4/6] minimize the changes --- hvpy/helpers.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hvpy/helpers.py b/hvpy/helpers.py index e337515..1e39358 100644 --- a/hvpy/helpers.py +++ b/hvpy/helpers.py @@ -94,14 +94,13 @@ def createMovie( hq = input_params.pop("hq") timeout = input_params.pop("timeout") res = queueMovie(**input_params) - id = res["id"] if res.get("error"): raise RuntimeError(res["error"]) timeout_counter = time.time() + 60 * timeout # Default 5 minutes title = "" while True: status = getMovieStatus( - id=id, + id=res["id"], format=format, token=res["token"], ) @@ -116,14 +115,14 @@ def createMovie( if status["status"] == 3: raise RuntimeError(status["error"]) binary_data = downloadMovie( - id=id, + id=res["id"], format=format, hq=hq, ) - if filename is not None: - filename = f"{filename}.{format}" - else: + if filename is None: filename = f"{title}.{format}" + else: + filename = f"{filename}.{format}" save_file( data=binary_data, filename=filename, From 53084721c7315e169ead69d6352997ab4e590d85 Mon Sep 17 00:00:00 2001 From: akash5100 Date: Fri, 7 Oct 2022 21:00:22 +0530 Subject: [PATCH 5/6] Change the get title condition, moved it into the condition when status is equal to 2 --- hvpy/helpers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hvpy/helpers.py b/hvpy/helpers.py index 1e39358..069a097 100644 --- a/hvpy/helpers.py +++ b/hvpy/helpers.py @@ -104,11 +104,10 @@ def createMovie( format=format, token=res["token"], ) - if status.get("title"): - title = status["title"] if status["status"] in [0, 1]: time.sleep(3) if status["status"] == 2: + title = status["title"] break if time.time() > timeout_counter: raise RuntimeError(f"Exceeded timeout of {timeout} minutes.") From 54c9a334163274c825de1f4537212d328be2a22d Mon Sep 17 00:00:00 2001 From: akash5100 Date: Fri, 7 Oct 2022 23:14:19 +0530 Subject: [PATCH 6/6] change the getJP2Header example to pass the failing test --- hvpy/facade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvpy/facade.py b/hvpy/facade.py index 0609ef9..bae5c23 100644 --- a/hvpy/facade.py +++ b/hvpy/facade.py @@ -66,7 +66,7 @@ def getJP2Header( -------- >>> from hvpy import getJP2Header >>> getJP2Header(id=7654321,callback="xml_header") - 'xml_header(\\\'116...')' + 'xml_header(\\\'...')' """ params = getJP2HeaderInputParameters(id=id, callback=callback) return execute_api_call(input_parameters=params)