mixpeek 0.11.2__py3-none-any.whl → 0.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. mixpeek/__init__.py +9 -1
  2. mixpeek/_hooks/__init__.py +5 -0
  3. mixpeek/_hooks/registration.py +13 -0
  4. mixpeek/_hooks/sdkhooks.py +76 -0
  5. mixpeek/_hooks/types.py +94 -0
  6. mixpeek/_version.py +12 -0
  7. mixpeek/assets.py +1561 -0
  8. mixpeek/basesdk.py +350 -0
  9. mixpeek/collections.py +1029 -0
  10. mixpeek/featureextractors.py +205 -0
  11. mixpeek/features.py +1181 -0
  12. mixpeek/health.py +167 -0
  13. mixpeek/httpclient.py +84 -0
  14. mixpeek/ingest.py +831 -0
  15. mixpeek/interactions.py +221 -0
  16. mixpeek/models/__init__.py +751 -0
  17. mixpeek/models/actionusage.py +16 -0
  18. mixpeek/models/apierror.py +22 -0
  19. mixpeek/models/apikey.py +25 -0
  20. mixpeek/models/apikeyupdate.py +49 -0
  21. mixpeek/models/assetfeatures.py +55 -0
  22. mixpeek/models/assetresponse.py +166 -0
  23. mixpeek/models/assets_model_searchquery.py +21 -0
  24. mixpeek/models/assetupdate.py +28 -0
  25. mixpeek/models/availableindexesresponse.py +23 -0
  26. mixpeek/models/availablemodels.py +12 -0
  27. mixpeek/models/boolindexparams.py +18 -0
  28. mixpeek/models/collectionmodel.py +70 -0
  29. mixpeek/models/collectionresult.py +73 -0
  30. mixpeek/models/create_api_key_organizations_users_user_email_api_keys_postop.py +23 -0
  31. mixpeek/models/create_collection_collections_postop.py +62 -0
  32. mixpeek/models/create_interaction_features_search_interactions_postop.py +59 -0
  33. mixpeek/models/createcollectionrequest.py +59 -0
  34. mixpeek/models/createnamespacerequest.py +62 -0
  35. mixpeek/models/datetimeindexparams.py +18 -0
  36. mixpeek/models/dateusage.py +22 -0
  37. mixpeek/models/db_model_paginationresponse.py +59 -0
  38. mixpeek/models/db_model_taskresponse.py +20 -0
  39. mixpeek/models/delete_api_key_organizations_users_user_email_api_keys_key_name_deleteop.py +23 -0
  40. mixpeek/models/delete_asset_assets_asset_id_deleteop.py +57 -0
  41. mixpeek/models/delete_collection_collections_collection_deleteop.py +59 -0
  42. mixpeek/models/delete_feature_features_feature_id_deleteop.py +57 -0
  43. mixpeek/models/delete_interaction_features_search_interactions_interaction_id_deleteop.py +59 -0
  44. mixpeek/models/delete_namespace_namespaces_namespace_deleteop.py +18 -0
  45. mixpeek/models/delete_user_organizations_users_user_email_deleteop.py +16 -0
  46. mixpeek/models/denseembedding.py +16 -0
  47. mixpeek/models/embeddingrequest.py +59 -0
  48. mixpeek/models/embeddingresponse.py +64 -0
  49. mixpeek/models/errormessage.py +13 -0
  50. mixpeek/models/errorresponse.py +21 -0
  51. mixpeek/models/facedetectsettings.py +52 -0
  52. mixpeek/models/featureextractionembeddingrequest.py +54 -0
  53. mixpeek/models/featureresponse.py +74 -0
  54. mixpeek/models/features_model_paginationresponse.py +59 -0
  55. mixpeek/models/featureupdaterequest.py +21 -0
  56. mixpeek/models/filtercondition.py +74 -0
  57. mixpeek/models/floatindexparams.py +18 -0
  58. mixpeek/models/full_asset_update_assets_asset_id_putop.py +69 -0
  59. mixpeek/models/full_feature_update_features_feature_id_putop.py +69 -0
  60. mixpeek/models/geoindexparams.py +18 -0
  61. mixpeek/models/get_asset_assets_asset_id_getop.py +73 -0
  62. mixpeek/models/get_asset_with_features_assets_asset_id_features_getop.py +73 -0
  63. mixpeek/models/get_collection_collections_collection_getop.py +59 -0
  64. mixpeek/models/get_feature_features_feature_id_getop.py +70 -0
  65. mixpeek/models/get_interaction_features_search_interactions_interaction_id_getop.py +59 -0
  66. mixpeek/models/get_namespace_namespaces_namespace_getop.py +18 -0
  67. mixpeek/models/get_task_tasks_task_id_getop.py +57 -0
  68. mixpeek/models/get_user_organizations_users_user_email_getop.py +16 -0
  69. mixpeek/models/groupbyoptions.py +71 -0
  70. mixpeek/models/groupbyoptionsasset.py +71 -0
  71. mixpeek/models/groupedassetdata.py +18 -0
  72. mixpeek/models/healthcheckresponse.py +13 -0
  73. mixpeek/models/httpvalidationerror.py +21 -0
  74. mixpeek/models/imagedescribesettings.py +82 -0
  75. mixpeek/models/imagedetectsettings.py +53 -0
  76. mixpeek/models/imagereadsettings.py +71 -0
  77. mixpeek/models/imagesettings.py +79 -0
  78. mixpeek/models/ingest_image_url_ingest_images_url_postop.py +59 -0
  79. mixpeek/models/ingest_text_ingest_text_postop.py +59 -0
  80. mixpeek/models/ingest_video_url_ingest_videos_url_postop.py +59 -0
  81. mixpeek/models/inputtype.py +11 -0
  82. mixpeek/models/integerindexparams.py +24 -0
  83. mixpeek/models/interactionresponse.py +87 -0
  84. mixpeek/models/interactiontype.py +11 -0
  85. mixpeek/models/jsonimageoutputsettings.py +55 -0
  86. mixpeek/models/jsontextoutputsettings.py +55 -0
  87. mixpeek/models/jsonvideooutputsettings.py +55 -0
  88. mixpeek/models/keywordindexparams.py +21 -0
  89. mixpeek/models/kill_task_tasks_task_id_deleteop.py +57 -0
  90. mixpeek/models/list_assets_assets_postop.py +77 -0
  91. mixpeek/models/list_collections_collections_getop.py +65 -0
  92. mixpeek/models/list_features_features_postop.py +79 -0
  93. mixpeek/models/list_interactions_features_search_interactions_getop.py +96 -0
  94. mixpeek/models/listassetsrequest.py +75 -0
  95. mixpeek/models/listassetsresponse.py +22 -0
  96. mixpeek/models/listcollectionsresponse.py +22 -0
  97. mixpeek/models/listfeaturesrequest.py +77 -0
  98. mixpeek/models/listfeaturesresponse.py +22 -0
  99. mixpeek/models/logicaloperator_input.py +88 -0
  100. mixpeek/models/logicaloperator_output.py +103 -0
  101. mixpeek/models/logodetectsettings.py +52 -0
  102. mixpeek/models/modality.py +13 -0
  103. mixpeek/models/modeldetails.py +57 -0
  104. mixpeek/models/namespaceresponse.py +54 -0
  105. mixpeek/models/organizationmodel.py +45 -0
  106. mixpeek/models/partial_asset_update_assets_asset_id_patchop.py +69 -0
  107. mixpeek/models/payloadindexconfig.py +94 -0
  108. mixpeek/models/payloadindextype.py +17 -0
  109. mixpeek/models/payloadschematype.py +15 -0
  110. mixpeek/models/percolaterequest.py +57 -0
  111. mixpeek/models/permission.py +10 -0
  112. mixpeek/models/processimageurlinput.py +99 -0
  113. mixpeek/models/processtextinput.py +94 -0
  114. mixpeek/models/processvideourlinput.py +99 -0
  115. mixpeek/models/querysettings.py +56 -0
  116. mixpeek/models/rerankingoptions.py +47 -0
  117. mixpeek/models/search_assets_assets_search_postop.py +59 -0
  118. mixpeek/models/search_features_features_search_postop.py +96 -0
  119. mixpeek/models/search_model_searchquery_input.py +76 -0
  120. mixpeek/models/searchassetsrequest.py +78 -0
  121. mixpeek/models/searchinteraction.py +82 -0
  122. mixpeek/models/searchquery_output.py +79 -0
  123. mixpeek/models/searchrequestfeatures_input.py +151 -0
  124. mixpeek/models/searchrequestfeatures_output.py +151 -0
  125. mixpeek/models/sortoption.py +28 -0
  126. mixpeek/models/sparseembedding.py +21 -0
  127. mixpeek/models/tasks_model_taskresponse.py +24 -0
  128. mixpeek/models/taskstatus.py +16 -0
  129. mixpeek/models/textindexparams.py +31 -0
  130. mixpeek/models/textsettings.py +61 -0
  131. mixpeek/models/tokenizertype.py +11 -0
  132. mixpeek/models/update_api_key_organizations_users_user_email_api_keys_key_name_patchop.py +30 -0
  133. mixpeek/models/update_collection_collections_collection_putop.py +74 -0
  134. mixpeek/models/update_namespace_namespaces_namespace_putop.py +28 -0
  135. mixpeek/models/updateassetrequest.py +60 -0
  136. mixpeek/models/updatenamespacerequest.py +26 -0
  137. mixpeek/models/usage.py +18 -0
  138. mixpeek/models/usermodel_input.py +36 -0
  139. mixpeek/models/usermodel_output.py +36 -0
  140. mixpeek/models/uuidindexparams.py +21 -0
  141. mixpeek/models/validationerror.py +26 -0
  142. mixpeek/models/vectormodel.py +11 -0
  143. mixpeek/models/vectortype.py +9 -0
  144. mixpeek/models/videodescribesettings.py +82 -0
  145. mixpeek/models/videodetectsettings.py +53 -0
  146. mixpeek/models/videoreadsettings.py +71 -0
  147. mixpeek/models/videosettings.py +101 -0
  148. mixpeek/models/videotranscriptionsettings.py +69 -0
  149. mixpeek/namespaces.py +1143 -0
  150. mixpeek/organizations.py +1508 -0
  151. mixpeek/py.typed +1 -0
  152. mixpeek/sdk.py +135 -0
  153. mixpeek/sdkconfiguration.py +45 -0
  154. mixpeek/searchinteractions.py +647 -0
  155. mixpeek/tasks.py +387 -0
  156. mixpeek/types/__init__.py +21 -0
  157. mixpeek/types/basemodel.py +39 -0
  158. mixpeek/utils/__init__.py +97 -0
  159. mixpeek/utils/annotations.py +55 -0
  160. mixpeek/utils/enums.py +34 -0
  161. mixpeek/utils/eventstreaming.py +238 -0
  162. mixpeek/utils/forms.py +202 -0
  163. mixpeek/utils/headers.py +136 -0
  164. mixpeek/utils/logger.py +27 -0
  165. mixpeek/utils/metadata.py +118 -0
  166. mixpeek/utils/queryparams.py +205 -0
  167. mixpeek/utils/requestbodies.py +66 -0
  168. mixpeek/utils/retries.py +217 -0
  169. mixpeek/utils/security.py +174 -0
  170. mixpeek/utils/serializers.py +215 -0
  171. mixpeek/utils/url.py +155 -0
  172. mixpeek/utils/values.py +134 -0
  173. mixpeek-0.13.dist-info/METADATA +439 -0
  174. mixpeek-0.13.dist-info/RECORD +176 -0
  175. {mixpeek-0.11.2.dist-info → mixpeek-0.13.dist-info}/WHEEL +1 -2
  176. py.typed +1 -0
  177. mixpeek/client.py +0 -27
  178. mixpeek/endpoints/__init__.py +0 -0
  179. mixpeek/endpoints/collections.py +0 -86
  180. mixpeek/endpoints/embed.py +0 -66
  181. mixpeek/endpoints/index.py +0 -51
  182. mixpeek/endpoints/register.py +0 -34
  183. mixpeek/endpoints/search.py +0 -44
  184. mixpeek/endpoints/tasks.py +0 -26
  185. mixpeek/endpoints/tools.py +0 -138
  186. mixpeek/exceptions.py +0 -13
  187. mixpeek-0.11.2.dist-info/METADATA +0 -375
  188. mixpeek-0.11.2.dist-info/RECORD +0 -15
  189. mixpeek-0.11.2.dist-info/top_level.txt +0 -1
@@ -1,86 +0,0 @@
1
- import requests
2
-
3
- class Collections:
4
- def __init__(self, base_url, headers):
5
- self.base_url = base_url
6
- self.headers = headers
7
-
8
- def list_files(self, collection_id, randomize=False, page=1, page_size=10, filters=None, sort_by=None, sort_order="asc"):
9
- try:
10
- url = f"{self.base_url}collections/"
11
- data = {
12
- "collection_id": collection_id,
13
- "randomize": randomize,
14
- "page": page,
15
- "page_size": page_size,
16
- "filters": filters,
17
- "sort_by": sort_by,
18
- "sort_order": sort_order
19
- }
20
- response = requests.post(url, json=data, headers=self.headers)
21
- response.raise_for_status()
22
- return response.json()
23
- except requests.RequestException as e:
24
- return {"error": str(e)}
25
-
26
- def list_collections(self):
27
- try:
28
- url = f"{self.base_url}collections/"
29
- response = requests.get(url, headers=self.headers)
30
- response.raise_for_status()
31
- return response.json()
32
- except requests.RequestException as e:
33
- return {"error": str(e)}
34
-
35
- def search_files(self, query, collection_id, page=1, page_size=10, sort_by=None, sort_order="asc"):
36
- try:
37
- url = f"{self.base_url}collections/search"
38
- data = {
39
- "query": query,
40
- "collection_id": collection_id,
41
- "page": page,
42
- "page_size": page_size,
43
- "sort_by": sort_by,
44
- "sort_order": sort_order
45
- }
46
- response = requests.post(url, json=data, headers=self.headers)
47
- response.raise_for_status()
48
- return response.json()
49
- except requests.RequestException as e:
50
- return {"error": str(e)}
51
-
52
- def get_file_by_id(self, file_id):
53
- try:
54
- url = f"{self.base_url}collections/file/{file_id}"
55
- response = requests.get(url, headers=self.headers)
56
- response.raise_for_status()
57
- return response.json()
58
- except requests.RequestException as e:
59
- return {"error": str(e)}
60
-
61
- def get_full_file(self, file_id):
62
- try:
63
- url = f"{self.base_url}collections/file/{file_id}/full"
64
- response = requests.get(url, headers=self.headers)
65
- response.raise_for_status()
66
- return response.json()
67
- except requests.RequestException as e:
68
- return {"error": str(e)}
69
-
70
- def delete_file_by_id(self, file_id):
71
- try:
72
- url = f"{self.base_url}collections/file/{file_id}"
73
- response = requests.delete(url, headers=self.headers)
74
- response.raise_for_status()
75
- return response.json()
76
- except requests.RequestException as e:
77
- return {"error": str(e)}
78
-
79
- def delete_collection(self, collection_id):
80
- try:
81
- url = f"{self.base_url}collections/{collection_id}"
82
- response = requests.delete(url, headers=self.headers)
83
- response.raise_for_status()
84
- return response.json()
85
- except requests.RequestException as e:
86
- return {"error": str(e)}
@@ -1,66 +0,0 @@
1
- import requests
2
- #test
3
- class Embed:
4
- def __init__(self, base_url, headers):
5
- self.base_url = base_url
6
- self.headers = headers
7
-
8
- def video(self, model_id: str, input: str, input_type: str):
9
- try:
10
- url = f"{self.base_url}embed/"
11
- data = {
12
- "modality": "video",
13
- "model_id": model_id,
14
- "input": input,
15
- "input_type": input_type
16
- }
17
- response = requests.post(url, json=data, headers=self.headers)
18
- response.raise_for_status()
19
- return response.json()
20
- except requests.RequestException as e:
21
- return {"error": str(e)}
22
-
23
- def text(self, model_id: str, input: str, input_type: str):
24
- try:
25
- url = f"{self.base_url}embed/"
26
- data = {
27
- "modality": "text",
28
- "model_id": model_id,
29
- "input": input,
30
- "input_type": input_type
31
- }
32
- response = requests.post(url, json=data, headers=self.headers)
33
- response.raise_for_status()
34
- return response.json()
35
- except requests.RequestException as e:
36
- return {"error": str(e)}
37
-
38
- def image(self, model_id: str, input: str, input_type: str):
39
- try:
40
- url = f"{self.base_url}embed/"
41
- data = {
42
- "modality": "image",
43
- "model_id": model_id,
44
- "input": input,
45
- "input_type": input_type
46
- }
47
- response = requests.post(url, json=data, headers=self.headers)
48
- response.raise_for_status()
49
- return response.json()
50
- except requests.RequestException as e:
51
- return {"error": str(e)}
52
-
53
- def audio(self, model_id: str, input: str, input_type: str):
54
- try:
55
- url = f"{self.base_url}embed/"
56
- data = {
57
- "modality": "audio",
58
- "model_id": model_id,
59
- "input": input,
60
- "input_type": input_type
61
- }
62
- response = requests.post(url, json=data, headers=self.headers)
63
- response.raise_for_status()
64
- return response.json()
65
- except requests.RequestException as e:
66
- return {"error": str(e)}
@@ -1,51 +0,0 @@
1
- import requests
2
- from .tasks import Task
3
-
4
- class Index:
5
- def __init__(self, base_url, headers):
6
- self.base_url = base_url
7
- self.headers = headers
8
-
9
- def _prepare_data(self, base_data, metadata=None, video_settings=None, image_settings=None):
10
- if metadata is not None:
11
- base_data["metadata"] = metadata
12
- if video_settings is not None:
13
- base_data["video_settings"] = video_settings
14
- if image_settings is not None:
15
- base_data["image_settings"] = image_settings
16
- return base_data
17
-
18
- def url(self, target_url, collection_id, metadata=None, video_settings=None, image_settings=None):
19
- try:
20
- endpoint = f"{self.base_url}index/url"
21
- data = self._prepare_data({"url": target_url, "collection_id": collection_id}, metadata, video_settings, image_settings)
22
-
23
- response = requests.post(endpoint, json=data, headers=self.headers)
24
- response.raise_for_status()
25
- task_id = response.json().get("task_id")
26
- if task_id:
27
- return Task(self.base_url, self.headers, task_id)
28
- else:
29
- return response.json()
30
- except requests.RequestException as e:
31
- return {"error": str(e)}
32
-
33
- def upload(self, file_path, collection_id, metadata=None, settings=None):
34
- try:
35
- endpoint = f"{self.base_url}index/upload"
36
- data = self._prepare_data({"collection_id": collection_id}, metadata, settings)
37
-
38
- with open(file_path, 'rb') as file:
39
- files = [('file', (file.name, file, 'application/octet-stream'))]
40
- response = requests.post(endpoint, headers=self.headers, data=data, files=files)
41
-
42
- response.raise_for_status()
43
- task_id = response.json().get("task_id")
44
- if task_id:
45
- return Task(self.base_url, self.headers, task_id)
46
- else:
47
- return response.json()
48
- except requests.RequestException as e:
49
- return {"error": str(e)}
50
- except IOError as e:
51
- return {"error": f"File error: {str(e)}"}
@@ -1,34 +0,0 @@
1
- import requests
2
- from .tasks import Task
3
-
4
- class Register:
5
- def __init__(self, base_url, headers):
6
- self.base_url = base_url
7
- self.headers = headers
8
-
9
- def _prepare_data(self, base_data, metadata=None, settings=None):
10
- if metadata is not None:
11
- base_data["metadata"] = metadata
12
- if settings is not None:
13
- base_data["settings"] = settings
14
- return base_data
15
-
16
- def faces(self, file_path, collection_id, metadata=None, settings=None):
17
- try:
18
- endpoint = f"{self.base_url}register/faces"
19
- data = self._prepare_data({"collection_id": collection_id}, metadata, settings)
20
-
21
- with open(file_path, 'rb') as file:
22
- files = [('file', (file.name, file, 'application/octet-stream'))]
23
- response = requests.post(endpoint, headers=self.headers, data=data, files=files)
24
-
25
- response.raise_for_status()
26
- task_id = response.json().get("task_id")
27
- if task_id:
28
- return Task(self.base_url, self.headers, task_id)
29
- else:
30
- return response.json()
31
- except requests.RequestException as e:
32
- return {"error": str(e)}
33
- except IOError as e:
34
- return {"error": f"File error: {str(e)}"}
@@ -1,44 +0,0 @@
1
- import requests
2
- import os
3
- import json
4
-
5
- class Search:
6
- def __init__(self, base_url, headers):
7
- self.base_url = base_url
8
- self.headers = headers
9
-
10
- def text(self, query, model_id=None, filters=None, page=1, page_size=10):
11
- try:
12
- url = f"{self.base_url}search/text"
13
- data = {
14
- "query": query,
15
- "model_id": model_id,
16
- "filters": filters or {},
17
- "pagination": {
18
- "page": page,
19
- "page_size": page_size
20
- }
21
- }
22
- response = requests.post(url, json=data, headers=self.headers)
23
- response.raise_for_status()
24
- return response.json()
25
- except requests.RequestException as e:
26
- return {"error": str(e)}
27
-
28
- def url(self, target_url, model_id=None, filters=None, page=1, page_size=10):
29
- try:
30
- url = f"{self.base_url}search/url"
31
- data = {
32
- "url": target_url,
33
- "model_id": model_id,
34
- "filters": filters or {},
35
- "pagination": {
36
- "page": page,
37
- "page_size": page_size
38
- }
39
- }
40
- response = requests.post(url, json=data, headers=self.headers)
41
- response.raise_for_status()
42
- return response.json()
43
- except requests.RequestException as e:
44
- return {"error": str(e)}
@@ -1,26 +0,0 @@
1
- import requests
2
- import time
3
-
4
- class Task:
5
- def __init__(self, base_url, headers, task_id):
6
- self.base_url = base_url
7
- self.headers = headers
8
- self.task_id = task_id
9
-
10
- def get_task_status(self, task_id):
11
- try:
12
- endpoint = f"{self.base_url}tasks/{task_id}"
13
- response = requests.get(endpoint, headers=self.headers)
14
- response.raise_for_status()
15
- return response.json()
16
- except requests.RequestException as e:
17
- return {"error": str(e)}
18
-
19
- def wait_for_done(self, sleep_interval=2, callback=None):
20
- while True:
21
- status = self.get_task_status(self.task_id)
22
- if callback:
23
- callback(status)
24
- if status.get("status") == "DONE":
25
- return status
26
- time.sleep(sleep_interval)
@@ -1,138 +0,0 @@
1
- import subprocess
2
- import tempfile
3
- import os
4
- import base64
5
- from urllib.parse import urlparse
6
- from urllib.request import urlretrieve
7
- from tqdm import tqdm
8
- from PIL import Image
9
- import io
10
-
11
- class Tools:
12
- def __init__(self):
13
- self.video = self.Video(self)
14
- self.image = self.Image(self)
15
-
16
- class Image:
17
- def __init__(self, parent):
18
- pass
19
-
20
- def process(self, image_source: str):
21
- # Download image if it's a URL
22
- if urlparse(image_source).scheme in ('http', 'https'):
23
- with tempfile.NamedTemporaryFile(delete=False) as temp_file:
24
- urlretrieve(image_source, temp_file.name)
25
- image_source = temp_file.name
26
-
27
- # Open and process the image
28
- with Image.open(image_source) as img:
29
- # Convert image to RGB mode if it's not already
30
- if img.mode != 'RGB':
31
- img = img.convert('RGB')
32
-
33
- # Convert image to base64
34
- buffered = io.BytesIO()
35
- img.save(buffered, format="JPEG")
36
- base64_string = base64.b64encode(buffered.getvalue()).decode('utf-8')
37
-
38
- # Remove temporary file if it was created
39
- if urlparse(image_source).scheme in ('http', 'https'):
40
- os.unlink(image_source)
41
-
42
- return base64_string
43
-
44
- class Video:
45
- def __init__(self, parent):
46
- pass
47
-
48
- def process(self, video_source: str, chunk_interval: float, resolution: list):
49
- chunker = VideoChunker(video_source, chunk_interval, resolution)
50
-
51
- for chunk in chunker:
52
- data = {
53
- "base64_chunk": chunk["base64"],
54
- "start_time": chunk["start_time"],
55
- "end_time": chunk["end_time"]
56
- }
57
- yield data
58
-
59
-
60
- class VideoChunker:
61
- def __init__(self, video_source, chunk_interval, target_resolution):
62
- self.video_source = video_source
63
- self.chunk_interval = chunk_interval
64
- self.target_resolution = f"{target_resolution[0]}x{target_resolution[1]}"
65
- self.temp_dir = tempfile.mkdtemp()
66
- self.total_duration = None
67
- self.current_time = 0
68
-
69
- def __del__(self):
70
- self.cleanup()
71
-
72
- def cleanup(self):
73
- for file in os.listdir(self.temp_dir):
74
- os.remove(os.path.join(self.temp_dir, file))
75
- os.rmdir(self.temp_dir)
76
-
77
- def __iter__(self):
78
- return self
79
-
80
- def __next__(self):
81
- if self.total_duration is None:
82
- self._initialize_video()
83
-
84
- chunk = self._process_chunk()
85
- if chunk is None:
86
- raise StopIteration
87
- return chunk
88
-
89
- def _initialize_video(self):
90
- if urlparse(self.video_source).scheme in ('http', 'https'):
91
- print("Downloading video...")
92
- temp_file = os.path.join(self.temp_dir, 'temp_video')
93
- urlretrieve(self.video_source, temp_file)
94
- self.video_source = temp_file
95
-
96
- # Get video duration
97
- result = subprocess.run(['ffprobe', '-v', 'error', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', self.video_source], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
98
- self.total_duration = float(result.stdout)
99
-
100
- print(f"Total video duration: {self.total_duration:.2f} seconds")
101
- self.progress_bar = tqdm(total=100, desc="Processing video", unit="%")
102
-
103
- def _process_chunk(self):
104
- if self.current_time >= self.total_duration:
105
- return None
106
-
107
- start_time = self.current_time
108
- end_time = min(start_time + self.chunk_interval, self.total_duration)
109
-
110
- # Generate chunk using FFmpeg
111
- temp_output = os.path.join(self.temp_dir, f"chunk_{self.current_time}.mp4")
112
- subprocess.run([
113
- 'ffmpeg', '-y', '-i', self.video_source,
114
- '-ss', str(start_time), '-to', str(end_time),
115
- '-vf', f'scale={self.target_resolution}',
116
- '-c:v', 'libx264', '-preset', 'ultrafast',
117
- temp_output
118
- ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
119
-
120
- # Convert to base64
121
- with open(temp_output, 'rb') as f:
122
- base64_string = base64.b64encode(f.read()).decode('utf-8')
123
-
124
- # Remove temporary file
125
- os.remove(temp_output)
126
-
127
- # Update progress
128
- progress = (end_time / self.total_duration) * 100
129
- self.progress_bar.n = int(progress)
130
- self.progress_bar.refresh()
131
-
132
- self.current_time = end_time
133
-
134
- return {
135
- "base64": base64_string,
136
- "start_time": start_time,
137
- "end_time": end_time
138
- }
mixpeek/exceptions.py DELETED
@@ -1,13 +0,0 @@
1
- class MixpeekException(Exception):
2
- pass
3
-
4
- class AuthenticationError(MixpeekException):
5
- pass
6
-
7
- class BadRequestError(MixpeekException):
8
- pass
9
-
10
- class NotFoundError(MixpeekException):
11
- pass
12
-
13
- # Define more exceptions as needed