diff --git a/videodb/__about__.py b/videodb/__about__.py index 90f7f66..3cc2806 100644 --- a/videodb/__about__.py +++ b/videodb/__about__.py @@ -1,7 +1,8 @@ """ About information for videodb sdk""" -__version__ = "0.2.14" + +__version__ = "0.2.15" __title__ = "videodb" __author__ = "videodb" __email__ = "contact@videodb.io" diff --git a/videodb/__init__.py b/videodb/__init__.py index 6f13816..d1d3215 100644 --- a/videodb/__init__.py +++ b/videodb/__init__.py @@ -16,6 +16,10 @@ SubtitleBorderStyle, SubtitleStyle, TextStyle, + TranscodeMode, + ResizeMode, + VideoConfig, + AudioConfig, ) from videodb.client import Connection from videodb.exceptions import ( @@ -43,6 +47,10 @@ "TextStyle", "SceneExtractionType", "Segmenter", + "TranscodeMode", + "ResizeMode", + "VideoConfig", + "AudioConfig", ] diff --git a/videodb/_constants.py b/videodb/_constants.py index 0e80158..b98ddab 100644 --- a/videodb/_constants.py +++ b/videodb/_constants.py @@ -80,6 +80,7 @@ class ApiPath: web = "web" translate = "translate" dub = "dub" + transcode = "transcode" class Status: @@ -168,3 +169,28 @@ class TextStyle: tabsize: int = 4 x: Union[str, int] = "(main_w-text_w)/2" y: Union[str, int] = "(main_h-text_h)/2" + + +class TranscodeMode: + lightning = "lightning" + economy = "economy" + + +class ResizeMode: + crop = "crop" + fit = "fit" + pad = "pad" + + +@dataclass +class VideoConfig: + resolution: int = None + quality: int = 23 + framerate: int = None + aspect_ratio: str = None + resize_mode: str = ResizeMode.crop + + +@dataclass +class AudioConfig: + mute: bool = False diff --git a/videodb/client.py b/videodb/client.py index c4b511b..25ae399 100644 --- a/videodb/client.py +++ b/videodb/client.py @@ -8,6 +8,9 @@ from videodb.__about__ import __version__ from videodb._constants import ( ApiPath, + TranscodeMode, + VideoConfig, + AudioConfig, ) from videodb.collection import Collection @@ -212,6 +215,45 @@ def youtube_search( ) return search_data.get("results") + def transcode( + self, + source: str, + callback_url: str, + mode: TranscodeMode = TranscodeMode.economy, + video_config: VideoConfig = VideoConfig(), + audio_config: AudioConfig = AudioConfig(), + ) -> None: + """Transcode the video + + :param str source: URL of the video to transcode, preferably a downloadable URL + :param str callback_url: URL to receive the callback + :param TranscodeMode mode: Mode of the transcoding + :param VideoConfig video_config: Video configuration (optional) + :param AudioConfig audio_config: Audio configuration (optional) + :return: Transcode job ID + :rtype: str + """ + job_data = self.post( + path=f"{ApiPath.transcode}", + data={ + "source": source, + "callback_url": callback_url, + "mode": mode, + "video_config": video_config.__dict__, + "audio_config": audio_config.__dict__, + }, + ) + return job_data.get("job_id") + + def get_transcode_details(self, job_id: str) -> dict: + """Get the details of a transcode job. + + :param str job_id: ID of the transcode job + :return: Details of the transcode job + :rtype: dict + """ + return self.get(path=f"{ApiPath.transcode}/{job_id}") + def upload( self, file_path: str = None,