From e7ca0790ed5b62d69002c3f4c7faea6d411f0791 Mon Sep 17 00:00:00 2001 From: olivierapivideo Date: Tue, 17 Aug 2021 09:33:58 +0000 Subject: [PATCH] Fix chunks size --- apivideo/__init__.py | 2 +- apivideo/api_client.py | 2 +- apivideo/configuration.py | 11 +++++++++-- setup.py | 2 +- test/{sample-mp4-file.mp4 => 10m.mp4} | Bin test/{sample.mp4 => 558k.mp4} | Bin test/test_integration_raw_statistics_api.py | 2 +- test/test_integration_videos_api.py | 6 +++--- 8 files changed, 16 insertions(+), 9 deletions(-) rename test/{sample-mp4-file.mp4 => 10m.mp4} (100%) rename test/{sample.mp4 => 558k.mp4} (100%) diff --git a/apivideo/__init__.py b/apivideo/__init__.py index 1eb7aa4..01166b4 100644 --- a/apivideo/__init__.py +++ b/apivideo/__init__.py @@ -9,7 +9,7 @@ """ -__version__ = "0.0.12" +__version__ = "0.0.13" # import ApiVideoClient from apivideo.auth_api_client import AuthenticatedApiClient diff --git a/apivideo/api_client.py b/apivideo/api_client.py index 9dce4dd..4d25174 100644 --- a/apivideo/api_client.py +++ b/apivideo/api_client.py @@ -75,7 +75,7 @@ def __init__(self, configuration=None, header_name=None, header_value=None, self.default_headers[header_name] = header_value self.cookie = cookie # Set default User-Agent. - self.user_agent = '"api.video client (python; v:0.0.12; )"' + self.user_agent = '"api.video client (python; v:0.0.13; )"' def __enter__(self): return self diff --git a/apivideo/configuration.py b/apivideo/configuration.py index a24ab60..c06ba54 100644 --- a/apivideo/configuration.py +++ b/apivideo/configuration.py @@ -23,6 +23,10 @@ 'minLength', 'pattern', 'maxItems', 'minItems' } +DEFAULT_CHUNK_SIZE = 50 * 1024 * 1024 +MIN_CHUNK_SIZE = 5 * 1024 * 1024 +MAX_CHUNK_SIZE = 128 * 1024 * 1024 + class Configuration(object): """ :param host: Base url @@ -85,7 +89,7 @@ def __init__(self, host=None, server_index=None, server_variables=None, server_operation_index=None, server_operation_variables=None, ssl_ca_cert=None, - chunk_size=1024 * 1024, + chunk_size=DEFAULT_CHUNK_SIZE, ): """Constructor """ @@ -192,6 +196,9 @@ def __init__(self, host=None, self.socket_options = None # chunk size for upload + if chunk_size < MIN_CHUNK_SIZE or chunk_size > MAX_CHUNK_SIZE: + raise ValueError( + "Invalid chunk size value. Must be greater than {0} bytes and lower than {1} bytes.".format(MIN_CHUNK_SIZE, MAX_CHUNK_SIZE)) self.chunk_size = chunk_size def __deepcopy__(self, memo): @@ -384,7 +391,7 @@ def to_debug_report(self): "OS: {env}\n"\ "Python Version: {pyversion}\n"\ "Version of the API: 1\n"\ - "SDK Package Version: 0.0.12".\ + "SDK Package Version: 0.0.13".\ format(env=sys.platform, pyversion=sys.version) def get_host_settings(self): diff --git a/setup.py b/setup.py index fa34dd1..be6e5f1 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ from setuptools import setup, find_packages # noqa: H301 NAME = "api.video" -VERSION = "0.0.12" +VERSION = "0.0.13" # To install the library, run the following # # python setup.py install diff --git a/test/sample-mp4-file.mp4 b/test/10m.mp4 similarity index 100% rename from test/sample-mp4-file.mp4 rename to test/10m.mp4 diff --git a/test/sample.mp4 b/test/558k.mp4 similarity index 100% rename from test/sample.mp4 rename to test/558k.mp4 diff --git a/test/test_integration_raw_statistics_api.py b/test/test_integration_raw_statistics_api.py index 3118246..08eb2b2 100644 --- a/test/test_integration_raw_statistics_api.py +++ b/test/test_integration_raw_statistics_api.py @@ -39,7 +39,7 @@ def test_list_video_sessions_metadata(self): Metadata(key="user", value='__user__') ])) - file = open("sample.mp4", "rb") + file = open("558k.mp4", "rb") self.videoApi.upload(video.video_id, file, _request_timeout=20) file.close() diff --git a/test/test_integration_videos_api.py b/test/test_integration_videos_api.py index 3882e1a..bc9e923 100644 --- a/test/test_integration_videos_api.py +++ b/test/test_integration_videos_api.py @@ -63,7 +63,7 @@ def listener(uploaded, total): public=True, tags=["bunny"])) - file = open("sample-mp4-file.mp4", "rb") + file = open("10m.mp4", "rb") self.api.upload(video.video_id, file, _request_timeout=20, _progress_listener=listener) file.close() self.api.delete(video.video_id) @@ -75,7 +75,7 @@ def test_upload_temporary_file(self): public=True, tags=["bunny"])) - file = open("sample.mp4", "rb") + file = open("558k.mp4", "rb") with tempfile.SpooledTemporaryFile(mode="wb") as temp: temp.write(file.read()) self.api.upload(video.video_id, temp, _request_timeout=20) @@ -89,7 +89,7 @@ def test_upload_chunks(self): public=True, tags=["bunny"])) - file = open("sample-mp4-file.mp4", "rb") + file = open("10m.mp4", "rb") self.api.upload(video.video_id, file, _request_timeout=20) file.close() self.api.delete(video.video_id) \ No newline at end of file