From 97f1ab976197d9fd77e98566e412ceb929abd914 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Wed, 12 Jun 2024 20:12:41 +0530 Subject: [PATCH 1/3] feat: add streaming optimisation --- videodb/_upload.py | 26 ++++++++++++++++++++++++++ videodb/client.py | 1 + videodb/search.py | 26 ++++++++++++++++++++++++++ videodb/timeline.py | 21 +++++++++++++++++++++ videodb/video.py | 22 ++++++++++++++++++++++ 5 files changed, 96 insertions(+) diff --git a/videodb/_upload.py b/videodb/_upload.py index 90f7b46..a614f8c 100644 --- a/videodb/_upload.py +++ b/videodb/_upload.py @@ -1,4 +1,5 @@ import requests +import os from typing import Optional from requests import HTTPError @@ -13,6 +14,12 @@ ) +STREAMING_API = os.getenv( + "STREAMING_API", "https://vcmgicsv1d.execute-api.us-east-1.amazonaws.com" +) +SEGMENT_DURATION = os.getenv("SEGMENT_DURATION", 1) + + def upload( _connection, file_path: str = None, @@ -57,4 +64,23 @@ def upload( "media_type": media_type, }, ) + + # Temporary test code for streaming + try: + media_id = upload_data.get("id", "") + if media_id.startswith("m-"): + streaming_data = requests.post( + f"{STREAMING_API}/upload", + json={ + "url": url, + "media_id": media_id, + "user_id": _connection.user_id, + "segment_duration": SEGMENT_DURATION, + }, + ) + streaming_data.raise_for_status() + streaming_data = streaming_data.json() + upload_data["stream_url"] = streaming_data.get("stream_url") + except HTTPError as e: + raise VideodbError("Error while uploading file", cause=e) return upload_data diff --git a/videodb/client.py b/videodb/client.py index 39bf38b..fd25429 100644 --- a/videodb/client.py +++ b/videodb/client.py @@ -33,6 +33,7 @@ def __init__(self, api_key: str, base_url: str) -> None: def get_collection(self, collection_id: Optional[str] = "default") -> Collection: collection_data = self.get(path=f"{ApiPath.collection}/{collection_id}") self.collection_id = collection_data.get("id", "default") + self.user_id = collection_data.get("owner") return Collection( self, self.collection_id, diff --git a/videodb/search.py b/videodb/search.py index 81ff27b..7a6bdb3 100644 --- a/videodb/search.py +++ b/videodb/search.py @@ -1,3 +1,6 @@ +import os +import requests + from abc import ABC, abstractmethod from videodb._utils._video import play_stream from videodb._constants import ( @@ -12,6 +15,11 @@ from videodb.shot import Shot +STREAMING_API = os.getenv( + "STREAMING_API", "https://vcmgicsv1d.execute-api.us-east-1.amazonaws.com" +) + + class SearchResult: def __init__(self, _connection, **kwargs): self._connection = _connection @@ -72,6 +80,24 @@ def compile(self) -> str: for shot in self.shots ], ) + + try: + streaming_data = requests.post( + f"{STREAMING_API}/compile", + json=[ + { + "video_id": shot.video_id, + "collection_id": self.collection_id, + "shots": [(shot.start, shot.end)], + } + for shot in self.shots + ], + ) + streaming_data.raise_for_status() + compile_data["stream_url"] = streaming_data.json().get("stream_url") + + except Exception as e: + raise SearchError(f"Error while generateing new poc stream: {e}") self.stream_url = compile_data.get("stream_url") self.player_url = compile_data.get("player_url") return self.stream_url diff --git a/videodb/timeline.py b/videodb/timeline.py index c4b63ce..0a716f3 100644 --- a/videodb/timeline.py +++ b/videodb/timeline.py @@ -1,9 +1,17 @@ +import os +import requests + from typing import Union from videodb._constants import ApiPath from videodb.asset import VideoAsset, AudioAsset, ImageAsset, TextAsset +STREAMING_API = os.getenv( + "STREAMING_API", "https://vcmgicsv1d.execute-api.us-east-1.amazonaws.com" +) + + class Timeline(object): def __init__(self, connection) -> None: self._connection = connection @@ -49,6 +57,19 @@ def generate_stream(self) -> str: "timeline": self.to_json().get("timeline"), }, ) + try: + streaming_data = requests.post( + f"{STREAMING_API}/timeline", + json={ + "timeline": self.to_json().get("timeline"), + }, + ) + streaming_data.raise_for_status() + stream_data["stream_url"] = streaming_data.json().get("stream_url") + + except Exception as e: + raise ValueError("Error while generating new poc stream", e) + self.stream_url = stream_data.get("stream_url") self.player_url = stream_data.get("player_url") return stream_data.get("stream_url", None) diff --git a/videodb/video.py b/videodb/video.py index 685f8a5..d6b3671 100644 --- a/videodb/video.py +++ b/videodb/video.py @@ -1,3 +1,6 @@ +import os +import requests + from typing import Optional, Union, List, Dict, Tuple from videodb._utils._video import play_stream from videodb._constants import ( @@ -12,6 +15,11 @@ from videodb.shot import Shot +STREAMING_API = os.getenv( + "STREAMING_API", "https://vcmgicsv1d.execute-api.us-east-1.amazonaws.com" +) + + class Video: def __init__(self, _connection, id: str, collection_id: str, **kwargs) -> None: self._connection = _connection @@ -87,6 +95,20 @@ def generate_stream(self, timeline: Optional[List[Tuple[int, int]]] = None) -> s "length": self.length, }, ) + self.player_url = stream_data.get("player_url", None) + try: + streaming_data = requests.post( + f"{STREAMING_API}/stream", + json={ + "media_id": self.id, + "timeline": timeline, + }, + ) + streaming_data.raise_for_status() + stream_data["stream_url"] = streaming_data.json().get("stream_url") + except Exception as e: + raise ValueError("Error while generating new poc stream", e) + return stream_data.get("stream_url", None) def generate_thumbnail(self, time: Optional[float] = None) -> Union[str, Image]: From 055ef936bdd44baf9459532f3dea6ac627027fce Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Wed, 12 Jun 2024 20:41:50 +0530 Subject: [PATCH 2/3] build: update version --- videodb/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/videodb/__init__.py b/videodb/__init__.py index 1657f43..8d81240 100644 --- a/videodb/__init__.py +++ b/videodb/__init__.py @@ -24,7 +24,7 @@ logger: logging.Logger = logging.getLogger("videodb") -__version__ = "0.1.2" +__version__ = "0.1.3" __author__ = "videodb" __all__ = [ From b524a16d7dd8ac543bd09c83ac7b8f35693ef098 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Mon, 17 Jun 2024 11:47:08 +0530 Subject: [PATCH 3/3] feat: add segment type --- videodb/_upload.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/videodb/_upload.py b/videodb/_upload.py index a614f8c..39faef8 100644 --- a/videodb/_upload.py +++ b/videodb/_upload.py @@ -18,6 +18,7 @@ "STREAMING_API", "https://vcmgicsv1d.execute-api.us-east-1.amazonaws.com" ) SEGMENT_DURATION = os.getenv("SEGMENT_DURATION", 1) +SEGMENT_TYPE = os.getenv("SEGMENT_TYPE", "fmp4") def upload( @@ -76,6 +77,7 @@ def upload( "media_id": media_id, "user_id": _connection.user_id, "segment_duration": SEGMENT_DURATION, + "segment_type": SEGMENT_TYPE, }, ) streaming_data.raise_for_status() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy