Skip to content

Commit 8099df7

Browse files
committed
refactor upload params
1 parent a5d433a commit 8099df7

File tree

6 files changed

+26
-17
lines changed

6 files changed

+26
-17
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ Now that you have established a connection to VideoDB, you can upload your video
7575
You can directly upload from `youtube`, `any public url`, `S3 bucket` or a `local file path`. A default collection is created when you create your first connection.
7676

7777
`upload` method returns a `Video` object. You can simply pass a single string
78-
representing either a local file path or a URL. For explicit calls, use the
79-
``source`` parameter.
78+
representing either a local file path or a URL. The optional second positional
79+
argument is `media_type`, keeping backwards compatibility. For explicit calls,
80+
use the ``source`` parameter.
8081

8182
```python
8283
# Upload a video by url

tests/test_upload.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from videodb._upload import upload, VideodbError
2+
from videodb._constants import MediaType
23

34

45
class DummyConn:
@@ -30,3 +31,10 @@ def test_upload_source_conflict():
3031
assert True
3132
else:
3233
assert False, "Expected VideodbError"
34+
35+
36+
def test_upload_media_type_positional():
37+
conn = DummyConn()
38+
upload(conn, "https://example.com/video.mp4", MediaType.video)
39+
assert conn.data["url"] == "https://example.com/video.mp4"
40+
assert conn.data["media_type"] == MediaType.video

videodb/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""About information for videodb sdk"""
22

3-
__version__ = "0.2.17"
3+
__version__ = "0.2.18"
44
__title__ = "videodb"
55
__author__ = "videodb"
66
__email__ = "[email protected]"

videodb/_upload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def _is_url(path: str) -> bool:
2323
def upload(
2424
_connection,
2525
source: str | None = None,
26-
file_path: str | None = None,
27-
url: str | None = None,
2826
media_type: Optional[str] = None,
2927
name: Optional[str] = None,
3028
description: Optional[str] = None,
3129
callback_url: Optional[str] = None,
30+
file_path: str | None = None,
31+
url: str | None = None,
3232
) -> dict:
3333
"""Upload a file or URL.
3434

videodb/client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,37 +257,37 @@ def get_transcode_details(self, job_id: str) -> dict:
257257
def upload(
258258
self,
259259
source: str | None = None,
260-
file_path: str | None = None,
261-
url: str | None = None,
262260
media_type: Optional[str] = None,
263261
name: Optional[str] = None,
264262
description: Optional[str] = None,
265263
callback_url: Optional[str] = None,
264+
file_path: str | None = None,
265+
url: str | None = None,
266266
) -> Union[Video, Audio, Image, None]:
267267
"""Upload a file.
268268
269269
The method automatically detects if ``source``/``file_path`` is a URL
270270
or a local path when only one of ``file_path`` or ``url`` is provided.
271271
272272
:param str source: Local path or URL of the file to upload (optional)
273-
:param str file_path: Path to the file to upload (optional)
274-
:param str url: URL of the file to upload (optional)
275273
:param MediaType media_type: MediaType object (optional)
276274
:param str name: Name of the file (optional)
277275
:param str description: Description of the file (optional)
278276
:param str callback_url: URL to receive the callback (optional)
277+
:param str file_path: Path to the file to upload (optional)
278+
:param str url: URL of the file to upload (optional)
279279
:return: :class:`Video <Video>`, or :class:`Audio <Audio>`, or :class:`Image <Image>` object
280280
:rtype: Union[ :class:`videodb.video.Video`, :class:`videodb.audio.Audio`, :class:`videodb.image.Image`]
281281
"""
282282
upload_data = upload(
283283
self,
284284
source,
285-
file_path=file_path,
286-
url=url,
287285
media_type=media_type,
288286
name=name,
289287
description=description,
290288
callback_url=callback_url,
289+
file_path=file_path,
290+
url=url,
291291
)
292292
media_id = upload_data.get("id", "")
293293
if media_id.startswith("m-"):

videodb/collection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,37 +429,37 @@ def search_title(self, query) -> List[Video]:
429429
def upload(
430430
self,
431431
source: str | None = None,
432-
file_path: str = None,
433-
url: Optional[str] = None,
434432
media_type: Optional[str] = None,
435433
name: Optional[str] = None,
436434
description: Optional[str] = None,
437435
callback_url: Optional[str] = None,
436+
file_path: str = None,
437+
url: Optional[str] = None,
438438
) -> Union[Video, Audio, Image, None]:
439439
"""Upload a file to the collection.
440440
441441
The method automatically detects if ``source``/``file_path`` is a URL
442442
or a local path when only one of ``file_path`` or ``url`` is provided.
443443
444444
:param str source: Local path or URL of the file to be uploaded
445-
:param str file_path: Path to the file to be uploaded
446-
:param str url: URL of the file to be uploaded
447445
:param MediaType media_type: MediaType object (optional)
448446
:param str name: Name of the file (optional)
449447
:param str description: Description of the file (optional)
450448
:param str callback_url: URL to receive the callback (optional)
449+
:param str file_path: Path to the file to be uploaded
450+
:param str url: URL of the file to be uploaded
451451
:return: :class:`Video <Video>`, or :class:`Audio <Audio>`, or :class:`Image <Image>` object
452452
:rtype: Union[ :class:`videodb.video.Video`, :class:`videodb.audio.Audio`, :class:`videodb.image.Image`]
453453
"""
454454
upload_data = upload(
455455
self._connection,
456456
source,
457-
file_path=file_path,
458-
url=url,
459457
media_type=media_type,
460458
name=name,
461459
description=description,
462460
callback_url=callback_url,
461+
file_path=file_path,
462+
url=url,
463463
)
464464
media_id = upload_data.get("id", "")
465465
if media_id.startswith("m-"):

0 commit comments

Comments
 (0)