yt-dlp-host-api 0.1.3__py3-none-any.whl → 0.2.1__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.
yt_dlp_host_api/client.py CHANGED
@@ -9,40 +9,48 @@ class Client:
9
9
  self.headers = {"X-API-Key": api_key, "Content-Type": "application/json"}
10
10
  self.send_task = self.SendTask(self)
11
11
 
12
- def get_video(self, url, video_format="bestvideo", audio_format="bestaudio", start_time=None, end_time=None, force_keyframes=False):
12
+ def get_video(self, url, video_format="bestvideo", audio_format="bestaudio", audio_language=None, output_format="mp4", start_time=None, end_time=None, force_keyframes=False):
13
13
  return self.send_task.get_video(
14
14
  url=url,
15
15
  video_format=video_format,
16
16
  audio_format=audio_format,
17
+ audio_language=audio_language,
18
+ output_format=output_format,
17
19
  start_time=start_time,
18
20
  end_time=end_time,
19
21
  force_keyframes=force_keyframes
20
22
  ).get_result()
21
23
 
22
- def get_audio(self, url, audio_format="bestaudio", start_time=None, end_time=None, force_keyframes=False):
24
+ def get_audio(self, url, audio_format="bestaudio", audio_language=None, output_format=None, start_time=None, end_time=None, force_keyframes=False):
23
25
  return self.send_task.get_audio(
24
26
  url=url,
25
27
  audio_format=audio_format,
28
+ audio_language=audio_language,
29
+ output_format=output_format,
26
30
  start_time=start_time,
27
31
  end_time=end_time,
28
32
  force_keyframes=force_keyframes
29
33
  ).get_result()
30
34
 
31
- def get_live_video(self, url, duration, start=0, video_format="bestvideo", audio_format="bestaudio"):
35
+ def get_live_video(self, url, duration, start=0, video_format="bestvideo", audio_format="bestaudio", audio_language=None, output_format="mp4"):
32
36
  return self.send_task.get_live_video(
33
37
  url=url,
34
38
  start=start,
35
39
  duration=duration,
36
40
  video_format=video_format,
37
- audio_format=audio_format
41
+ audio_format=audio_format,
42
+ audio_language=audio_language,
43
+ output_format=output_format
38
44
  ).get_result()
39
45
 
40
- def get_live_audio(self, url, duration, start=0, audio_format="bestaudio"):
46
+ def get_live_audio(self, url, duration, start=0, audio_format="bestaudio", audio_language=None, output_format=None):
41
47
  return self.send_task.get_live_audio(
42
48
  url=url,
43
49
  start=start,
44
50
  duration=duration,
45
- audio_format=audio_format
51
+ audio_format=audio_format,
52
+ audio_language=audio_language,
53
+ output_format=output_format
46
54
  ).get_result()
47
55
 
48
56
  def get_info(self, url):
@@ -86,8 +94,15 @@ class Client:
86
94
  def __init__(self, client):
87
95
  self.client = client
88
96
 
89
- def get_video(self, url, video_format="bestvideo", audio_format="bestaudio", start_time=None, end_time=None, force_keyframes=False):
90
- data = {"url": url, "video_format": video_format, "audio_format": audio_format, "force_keyframes": force_keyframes}
97
+ def get_video(self, url, video_format="bestvideo", audio_format="bestaudio", audio_language=None, output_format="mp4", start_time=None, end_time=None, force_keyframes=False):
98
+ data = {
99
+ "url": url,
100
+ "video_format": video_format,
101
+ "audio_format": audio_format,
102
+ "output_format": output_format,
103
+ "force_keyframes": force_keyframes
104
+ }
105
+ if audio_language is not None: data["audio_language"] = audio_language
91
106
  if start_time is not None: data["start_time"] = start_time
92
107
  if end_time is not None: data["end_time"] = end_time
93
108
 
@@ -96,8 +111,14 @@ class Client:
96
111
  raise APIError(response.json().get('error', 'Unknown error'))
97
112
  return Task(self.client, response.json()['task_id'], 'get_video')
98
113
 
99
- def get_audio(self, url, audio_format="bestaudio", start_time=None, end_time=None, force_keyframes=False):
100
- data = {"url": url, "audio_format": audio_format, "force_keyframes": force_keyframes}
114
+ def get_audio(self, url, audio_format="bestaudio", audio_language=None, output_format=None, start_time=None, end_time=None, force_keyframes=False):
115
+ data = {
116
+ "url": url,
117
+ "audio_format": audio_format,
118
+ "force_keyframes": force_keyframes
119
+ }
120
+ if audio_language is not None: data["audio_language"] = audio_language
121
+ if output_format is not None: data["output_format"] = output_format
101
122
  if start_time is not None: data["start_time"] = start_time
102
123
  if end_time is not None: data["end_time"] = end_time
103
124
 
@@ -106,15 +127,32 @@ class Client:
106
127
  raise APIError(response.json().get('error', 'Unknown error'))
107
128
  return Task(self.client, response.json()['task_id'], 'get_audio')
108
129
 
109
- def get_live_video(self, url, duration, start=0, video_format="bestvideo", audio_format="bestaudio"):
110
- data = {"url": url, "start": start, "duration": duration, "video_format": video_format, "audio_format": audio_format}
130
+ def get_live_video(self, url, duration, start=0, video_format="bestvideo", audio_format="bestaudio", audio_language=None, output_format="mp4"):
131
+ data = {
132
+ "url": url,
133
+ "start": start,
134
+ "duration": duration,
135
+ "video_format": video_format,
136
+ "audio_format": audio_format,
137
+ "output_format": output_format
138
+ }
139
+ if audio_language is not None: data["audio_language"] = audio_language
140
+
111
141
  response = requests.post(f"{self.client.host_url}/get_live_video", json=data, headers=self.client.headers)
112
142
  if response.status_code != 200:
113
143
  raise APIError(response.json().get('error', 'Unknown error'))
114
144
  return Task(self.client, response.json()['task_id'], 'get_video')
115
145
 
116
- def get_live_audio(self, url, duration, start=0, audio_format="bestaudio"):
117
- data = {"url": url, "start": start, "duration": duration, "audio_format": audio_format}
146
+ def get_live_audio(self, url, duration, start=0, audio_format="bestaudio", audio_language=None, output_format=None):
147
+ data = {
148
+ "url": url,
149
+ "start": start,
150
+ "duration": duration,
151
+ "audio_format": audio_format
152
+ }
153
+ if audio_language is not None: data["audio_language"] = audio_language
154
+ if output_format is not None: data["output_format"] = output_format
155
+
118
156
  response = requests.post(f"{self.client.host_url}/get_live_audio", json=data, headers=self.client.headers)
119
157
  if response.status_code != 200:
120
158
  raise APIError(response.json().get('error', 'Unknown error'))
yt_dlp_host_api/task.py CHANGED
@@ -58,11 +58,25 @@ class TaskResult:
58
58
  raise APIError("This method is only available for get_info tasks")
59
59
  url = self.get_file_url()
60
60
  if fields:
61
- url += "?"
62
- for field in fields:
63
- url += f'{field}&'
61
+ if isinstance(fields, str):
62
+ url += f"?{fields}"
63
+ else:
64
+ url += "?"
65
+ for field in fields:
66
+ url += f'{field}&'
67
+ url = url.rstrip('&')
64
68
  response = requests.get(url, headers=self.client.headers)
65
69
  if response.status_code != 200:
66
70
  raise APIError(response.json().get('error', 'Unknown error'))
67
71
  data = json.loads(response.text)
68
72
  return data
73
+
74
+ def get_qualities(self):
75
+ if self.status['task_type'] != 'get_info':
76
+ raise APIError("This method is only available for get_info tasks")
77
+ return self.get_json('qualities')
78
+
79
+ def get_languages(self):
80
+ if self.status['task_type'] != 'get_info':
81
+ raise APIError("This method is only available for get_info tasks")
82
+ return self.get_json('languages')
@@ -0,0 +1,306 @@
1
+ Metadata-Version: 2.4
2
+ Name: yt_dlp_host_api
3
+ Version: 0.2.1
4
+ Summary: A Python library for interacting with the yt-dlp-host API
5
+ Author-email: "Amadeus (Wasys)" <tubik.corp@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Vasysik/yt-dlp-host-api
8
+ Project-URL: Issues, https://github.com/Vasysik/yt-dlp-host-api/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests>=2.25.1
15
+ Dynamic: license-file
16
+
17
+ # [yt-dlp-host](https://github.com/Vasysik/yt-dlp-host) API Client
18
+
19
+ This is a Python library for interacting with the [yt-dlp-host](https://github.com/Vasysik/yt-dlp-host) API.
20
+
21
+ ## Installation
22
+
23
+ You can install the library using pip:
24
+
25
+ ```
26
+ pip install yt-dlp-host-api
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ Here's a basic example of how to use the library:
32
+
33
+ ```python
34
+ import yt_dlp_host_api
35
+
36
+ # Initialize the API client
37
+ api = yt_dlp_host_api.api('http://your-api-url.com')
38
+ client = api.get_client('YOUR_API_KEY')
39
+
40
+ # Download a complete video in MP4 format
41
+ client.get_video(url='https://youtu.be/1FPdtR_5KFo', output_format='mp4').save_file("test_video.mp4")
42
+ print("Video saved to test_video.mp4")
43
+
44
+ # Download a video in WebM format
45
+ client.get_video(url='https://youtu.be/1FPdtR_5KFo', output_format='webm').save_file("test_video.webm")
46
+ print("Video saved to test_video.webm")
47
+
48
+ # Download a video segment with precise cutting
49
+ client.get_video(
50
+ url='https://youtu.be/1FPdtR_5KFo',
51
+ output_format='mkv',
52
+ start_time="00:05:00",
53
+ end_time="00:10:00",
54
+ force_keyframes=True
55
+ ).save_file("precise_cut.mkv")
56
+ print("Precisely cut segment saved to precise_cut.mkv")
57
+
58
+ # Download a video segment with faster cutting at keyframes
59
+ client.get_video(
60
+ url='https://youtu.be/1FPdtR_5KFo',
61
+ output_format='mp4',
62
+ start_time="00:05:00",
63
+ end_time="00:10:00",
64
+ force_keyframes=False
65
+ ).save_file("keyframe_cut.mp4")
66
+ print("Keyframe-cut segment saved to keyframe_cut.mp4")
67
+
68
+ # Download a complete audio in MP3 format
69
+ client.get_audio(url='https://youtu.be/1FPdtR_5KFo', output_format='mp3').save_file("test_audio.mp3")
70
+ print("Audio saved to test_audio.mp3")
71
+
72
+ # Download audio in FLAC format (lossless)
73
+ client.get_audio(url='https://youtu.be/1FPdtR_5KFo', output_format='flac').save_file("test_audio.flac")
74
+ print("Audio saved to test_audio.flac")
75
+
76
+ # Get info with available qualities and languages
77
+ info_result = client.get_info(url='https://youtu.be/1FPdtR_5KFo')
78
+
79
+ # Get available qualities
80
+ qualities = info_result.get_qualities()
81
+ print("Available qualities:", qualities)
82
+
83
+ # Get available languages
84
+ languages = info_result.get_languages()
85
+ print("Available audio languages:", languages['languages']['audio'])
86
+ print("Available subtitle languages:", languages['languages']['subtitles'])
87
+
88
+ # Get specific fields from info
89
+ info_json = info_result.get_json(['title', 'duration', 'upload_date'])
90
+ print("Video info:", info_json)
91
+
92
+ # Admin operations (requires admin API key)
93
+ new_key = client.create_key("user_key", ["get_video", "get_audio", "get_info"])
94
+ keys = client.get_keys()
95
+ key = client.get_key("user_key")
96
+ client.delete_key("user_key")
97
+ ```
98
+
99
+ ## Features
100
+
101
+ - Download YouTube videos
102
+ - Download complete videos
103
+ - Download specific time segments
104
+ - Precise cutting with frame re-encoding
105
+ - Fast cutting at keyframes
106
+ - Choose video and audio quality
107
+ - Choose output format (MP4, MKV, WebM, AVI, MOV, FLV, 3GP)
108
+ - Select specific audio language or download all audio tracks
109
+ - Download YouTube audio
110
+ - Download complete audio
111
+ - Download specific time segments
112
+ - Choose audio quality
113
+ - Choose output format (MP3, M4A, Opus, FLAC, WAV, AAC, OGG)
114
+ - Select specific audio language
115
+ - Extract live stream segments
116
+ - Retrieve video information
117
+ - Get available video and audio qualities
118
+ - Get available audio and subtitle languages
119
+ - Filter specific fields from video metadata
120
+ - Checking client permissions
121
+ - Admin operations:
122
+ - Create new API keys
123
+ - List existing API keys
124
+ - Get API key by key name
125
+ - Delete API keys
126
+
127
+ ## API Reference
128
+
129
+ ### Client
130
+
131
+ - `client.get_video(url, video_format="bestvideo", audio_format="bestaudio", audio_language=None, output_format="mp4", start_time=None, end_time=None, force_keyframes=False)`: Get video with optional time segment selection and language preference
132
+ - `client.get_audio(url, audio_format="bestaudio", audio_language=None, output_format=None, start_time=None, end_time=None, force_keyframes=False)`: Get audio with optional time segment selection and language preference
133
+ - `client.get_live_video(url, duration, start=0, video_format="bestvideo", audio_format="bestaudio", audio_language=None, output_format="mp4")`: Get live video segment with language preference
134
+ - `client.get_live_audio(url, duration, start=0, audio_format="bestaudio", audio_language=None, output_format=None)`: Get live audio segment with language preference
135
+ - `client.get_info(url)`: Get video information
136
+ - `client.send_task.get_video(...)`: Initiate a video download task
137
+ - `client.send_task.get_audio(...)`: Initiate an audio download task
138
+ - `client.send_task.get_live_video(...)`: Initiate a live video download task
139
+ - `client.send_task.get_live_audio(...)`: Initiate a live audio download task
140
+ - `client.send_task.get_info(url)`: Initiate an info retrieval task
141
+ - `client.check_permissions(permissions)`: Check for all permissions in the list
142
+
143
+ ### Supported Output Formats
144
+
145
+ #### Video Formats
146
+ - **mp4** - MPEG-4 Part 14 (recommended)
147
+ - **mkv** - Matroska (supports multiple audio tracks)
148
+ - **webm** - WebM
149
+ - **avi** - Audio Video Interleave
150
+ - **mov** - QuickTime File Format
151
+ - **flv** - Flash Video
152
+ - **3gp** - 3GPP multimedia
153
+
154
+ #### Audio Formats
155
+ - **mp3** - MPEG Audio Layer III
156
+ - **m4a** - MPEG-4 Audio
157
+ - **opus** - Opus Audio
158
+ - **flac** - Free Lossless Audio Codec
159
+ - **wav** - Waveform Audio File Format
160
+ - **aac** - Advanced Audio Coding
161
+ - **ogg** - Ogg Vorbis
162
+
163
+ Note: If `output_format` is not specified for audio, the original format will be used.
164
+
165
+ ### Audio Language Support
166
+
167
+ The `audio_language` parameter allows you to specify which audio track to download:
168
+ - **None** (default): yt-dlp automatically selects the best available audio track
169
+ - **ISO Language Code** (e.g., "en", "ru", "es", "de", "fr", "ja"): Downloads the specific language audio track
170
+ - **"all"**: Downloads all available audio tracks (video will be saved in MKV format with multiple audio streams)
171
+
172
+ Examples:
173
+ ```python
174
+ # Default audio track (auto-selected by yt-dlp)
175
+ client.get_video(url='...', output_format='mp4')
176
+
177
+ # Specific language
178
+ client.get_video(url='...', audio_language='ru', output_format='mp4')
179
+
180
+ # All audio tracks
181
+ client.get_video(url='...', audio_language='all', output_format='mkv')
182
+ ```
183
+
184
+ ### Time Format
185
+
186
+ Time parameters (`start_time` and `end_time`) should be provided in the following format:
187
+ - "HH:MM:SS" (hours:minutes:seconds)
188
+
189
+ Examples:
190
+ - "00:05:00" - 5 minutes
191
+ - "01:30:45" - 1 hour, 30 minutes, and 45 seconds
192
+
193
+ ### Cutting Modes
194
+
195
+ The `force_keyframes` parameter determines how video/audio segments are cut:
196
+ - `force_keyframes=False` (default): Faster cutting that aligns to nearest keyframes. May not be exactly at specified timestamps but is much faster as it avoids re-encoding.
197
+ - `force_keyframes=True`: Precise cutting at exact timestamps. This requires re-encoding which takes longer but provides exact cuts.
198
+
199
+ ### Task
200
+
201
+ - `task.get_status()`: Get the current status of a task
202
+ - `task.get_result()`: Wait for and return the result of a task
203
+
204
+ ### TaskResult
205
+
206
+ - `result.get_file()`: Get the file content
207
+ - `result.get_file_url()`: Get the URL of the downloaded file
208
+ - `result.save_file(path)`: Save the downloaded file to the specified path
209
+ - `result.get_json(fields=None)`: Get the JSON data for info tasks (optionally filtered by fields)
210
+ - `result.get_qualities()`: Get available video and audio qualities (info tasks only)
211
+ - `result.get_languages()`: Get available audio and subtitle languages (info tasks only)
212
+
213
+ ### Admin
214
+
215
+ - `client.create_key(name, permissions)`: Create a new API key
216
+ - `client.get_keys()`: List all existing API keys
217
+ - `client.get_key(name)`: Get API key by key name
218
+ - `client.delete_key(name)`: Delete an API key
219
+
220
+ ## Advanced Examples
221
+
222
+ ### Checking available languages before downloading
223
+
224
+ ```python
225
+ import yt_dlp_host_api
226
+
227
+ api = yt_dlp_host_api.api('http://your-api-url.com')
228
+ client = api.get_client('YOUR_API_KEY')
229
+
230
+ # First, get video info to check available languages
231
+ info_result = client.get_info(url='https://youtu.be/1FPdtR_5KFo')
232
+ languages = info_result.get_languages()
233
+
234
+ print(f"Available audio languages: {languages['languages']['audio']}")
235
+ print(f"Available subtitle languages: {languages['languages']['subtitles']}")
236
+
237
+ # Download with a specific language if available
238
+ if 'ru' in languages['languages']['audio']:
239
+ client.get_video(
240
+ url='https://youtu.be/1FPdtR_5KFo',
241
+ audio_language='ru',
242
+ output_format='mp4'
243
+ ).save_file("video_russian.mp4")
244
+ print("Downloaded video with Russian audio")
245
+ ```
246
+
247
+ ### Getting video qualities information
248
+
249
+ ```python
250
+ import yt_dlp_host_api
251
+
252
+ api = yt_dlp_host_api.api('http://your-api-url.com')
253
+ client = api.get_client('YOUR_API_KEY')
254
+
255
+ info_result = client.get_info(url='https://youtu.be/1FPdtR_5KFo')
256
+ qualities = info_result.get_qualities()
257
+
258
+ # Display available video qualities
259
+ print("Available video qualities:")
260
+ for format_id, details in qualities['qualities']['video'].items():
261
+ print(f" Format {format_id}: {details['height']}p, {details['fps']}fps, {details['vcodec']}")
262
+
263
+ # Display available audio qualities
264
+ print("\nAvailable audio qualities:")
265
+ for format_id, details in qualities['qualities']['audio'].items():
266
+ print(f" Format {format_id}: {details['abr']}kbps, {details['acodec']}, language: {details.get('language', 'unknown')}")
267
+ ```
268
+
269
+ ### Downloading with specific quality selection
270
+
271
+ ```python
272
+ import yt_dlp_host_api
273
+
274
+ api = yt_dlp_host_api.api('http://your-api-url.com')
275
+ client = api.get_client('YOUR_API_KEY')
276
+
277
+ # Download 720p video with 128kbps audio
278
+ client.get_video(
279
+ url='https://youtu.be/1FPdtR_5KFo',
280
+ video_format='bestvideo[height<=720]',
281
+ audio_format='bestaudio[abr<=128]',
282
+ output_format='mp4'
283
+ ).save_file("video_720p_128k.mp4")
284
+ ```
285
+
286
+ ## Error Handling
287
+
288
+ The library uses exceptions to handle errors. Catch `yt_dlp_host_api.exceptions.APIError` to handle API-related errors.
289
+
290
+ ```python
291
+ import yt_dlp_host_api
292
+ from yt_dlp_host_api.exceptions import APIError
293
+
294
+ api = yt_dlp_host_api.api('http://your-api-url.com')
295
+ client = api.get_client('YOUR_API_KEY')
296
+
297
+ try:
298
+ result = client.get_video(url='https://youtu.be/invalid-url')
299
+ result.save_file("video.mp4")
300
+ except APIError as e:
301
+ print(f"API Error: {e}")
302
+ ```
303
+
304
+ ## Contributing
305
+
306
+ Contributions to yt-dlp-host-api are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue on the GitHub repository. Pull requests are also encouraged.
@@ -0,0 +1,10 @@
1
+ yt_dlp_host_api/__init__.py,sha256=RHx1BvH2Cy_dweEKo5sA-hdBOfBdY_2ds7srPuKGzWQ,41
2
+ yt_dlp_host_api/api.py,sha256=iLzWKoyiXeu0Y1Uky8PzpxxHTSMcTGzxlCRT121AKcM,196
3
+ yt_dlp_host_api/client.py,sha256=d0EUMGS-k4ndKG_xATDkg6hQgSUsSH_z_aDFkz95dp0,8126
4
+ yt_dlp_host_api/exceptions.py,sha256=U_70W1R_ZcUfKptUShGB5VPWQXwc5M29_sNC8pwwq8g,38
5
+ yt_dlp_host_api/task.py,sha256=pn0KcEfCDrSuE0DUnAF1YGpMnJL6vc3sXN2im1jBdeI,3244
6
+ yt_dlp_host_api-0.2.1.dist-info/licenses/LICENSE,sha256=-_Ad_xue4UymJ8jO-ZsSg0vmZ6SUm8WYdoEwHLyBUlc,1078
7
+ yt_dlp_host_api-0.2.1.dist-info/METADATA,sha256=6t-5ua00ltERunJqjlO1EaTOq_DPJtKEwNgBp5nbtu4,11261
8
+ yt_dlp_host_api-0.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ yt_dlp_host_api-0.2.1.dist-info/top_level.txt,sha256=Mn3FZuqLCHr47sRjhtEOz7lDl4lpsHkymWANORYp72s,16
10
+ yt_dlp_host_api-0.2.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,152 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: yt_dlp_host_api
3
- Version: 0.1.3
4
- Summary: A Python library for interacting with the yt-dlp-host API
5
- Author-email: "Amadeus (Wasys)" <tubik.corp@gmail.com>
6
- Project-URL: Homepage, https://github.com/Vasysik/yt-dlp-host-api
7
- Project-URL: Issues, https://github.com/Vasysik/yt-dlp-host-api/issues
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.8
12
- Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
- Requires-Dist: requests >=2.25.1
15
-
16
- # [yt-dlp-host](https://github.com/Vasysik/yt-dlp-host) API Client
17
-
18
- This is a Python library for interacting with the [yt-dlp-host](https://github.com/Vasysik/yt-dlp-host) API.
19
-
20
- ## Installation
21
-
22
- You can install the library using pip:
23
-
24
- ```
25
- pip install yt-dlp-host-api
26
- ```
27
-
28
- ## Usage
29
-
30
- Here's a basic example of how to use the library:
31
-
32
- ```python
33
- import yt_dlp_host_api
34
-
35
- # Initialize the API client
36
- api = yt_dlp_host_api.api('http://your-api-url.com')
37
- client = api.get_client('YOUR_API_KEY')
38
-
39
- # Download a complete video
40
- client.get_video(url='https://youtu.be/1FPdtR_5KFo').save_file("test_video.mp4")
41
- print("Video saved to test_video.mp4")
42
-
43
- # Download a video segment with precise cutting
44
- client.get_video(
45
- url='https://youtu.be/1FPdtR_5KFo',
46
- start_time="00:05:00",
47
- end_time="00:10:00",
48
- force_keyframes=True
49
- ).save_file("precise_cut.mp4")
50
- print("Precisely cut segment saved to precise_cut.mp4")
51
-
52
- # Download a video segment with faster cutting at keyframes
53
- client.get_video(
54
- url='https://youtu.be/1FPdtR_5KFo',
55
- start_time="00:05:00",
56
- end_time="00:10:00",
57
- force_keyframes=False
58
- ).save_file("keyframe_cut.mp4")
59
- print("Keyframe-cut segment saved to keyframe_cut.mp4")
60
-
61
- # Download a complete audio
62
- client.get_audio(url='https://youtu.be/1FPdtR_5KFo').save_file("test_audio.mp3")
63
- print("Audio saved to test_audio.mp3")
64
-
65
- # Get info
66
- info_json = client.get_info(url='https://youtu.be/1FPdtR_5KFo').get_json(['qualities', 'title'])
67
- print("Video info:", info_json)
68
-
69
- # Admin operations (requires admin API key)
70
- new_key = client.create_key("user_key", ["get_video", "get_audio", "get_info"])
71
- keys = client.get_keys()
72
- key = client.get_key("user_key")
73
- client.delete_key("user_key")
74
- ```
75
-
76
- ## Features
77
-
78
- - Download YouTube videos
79
- - Download complete videos
80
- - Download specific time segments
81
- - Precise cutting with frame re-encoding
82
- - Fast cutting at keyframes
83
- - Choose video and audio quality
84
- - Download YouTube audio
85
- - Download complete audio
86
- - Download specific time segments
87
- - Choose audio quality
88
- - Extract live stream segments
89
- - Retrieve video information
90
- - Checking client permissions
91
- - Admin operations:
92
- - Create new API keys
93
- - List existing API keys
94
- - Get API key by key name
95
- - Delete API keys
96
-
97
- ## API Reference
98
-
99
- ### Client
100
-
101
- - `client.get_video(url, video_format="bestvideo", audio_format="bestaudio", start_time=None, end_time=None, force_keyframes=False)`: Get video with optional time segment selection
102
- - `client.get_audio(url, audio_format="bestaudio", start_time=None, end_time=None, force_keyframes=False)`: Get audio with optional time segment selection
103
- - `client.get_live_video(url, duration, start=0, video_format="bestvideo", audio_format="bestaudio")`: Get live video segment
104
- - `client.get_live_audio(url, duration, start=0, audio_format="bestaudio")`: Get live audio segment
105
- - `client.get_info(url)`: Get video information
106
- - `client.send_task.get_video(url, video_format="bestvideo", audio_format="bestaudio", start_time=None, end_time=None, force_keyframes=False)`: Initiate a video download task
107
- - `client.send_task.get_audio(url, audio_format="bestaudio", start_time=None, end_time=None, force_keyframes=False)`: Initiate an audio download task
108
- - `client.send_task.get_live_video(url, duration, start=0, video_format="bestvideo", audio_format="bestaudio")`: Initiate a live video download task
109
- - `client.send_task.get_live_audio(url, duration, start=0, audio_format="bestaudio")`: Initiate a live audio download task
110
- - `client.send_task.get_info(url)`: Initiate an info retrieval task
111
- - `client.check_permissions(permissions)`: Check for all permissions in the list
112
-
113
- ### Time Format
114
-
115
- Time parameters (`start_time` and `end_time`) should be provided in the following format:
116
- - "HH:MM:SS" (hours:minutes:seconds)
117
- Examples:
118
- - "00:05:00" - 5 minutes
119
- - "01:30:45" - 1 hour, 30 minutes, and 45 seconds
120
-
121
- ### Cutting Modes
122
-
123
- The `force_keyframes` parameter determines how video/audio segments are cut:
124
- - `force_keyframes=False` (default): Faster cutting that aligns to nearest keyframes. May not be exactly at specified timestamps but is much faster as it avoids re-encoding.
125
- - `force_keyframes=True`: Precise cutting at exact timestamps. This requires re-encoding which takes longer but provides exact cuts.
126
-
127
- ### Task
128
-
129
- - `task.get_status()`: Get the current status of a task
130
- - `task.get_result()`: Wait for and return the result of a task
131
-
132
- ### TaskResult
133
-
134
- - `result.get_file()`: Get the file
135
- - `result.get_file_url()`: Get the URL of the downloaded file
136
- - `result.save_file(path)`: Save the downloaded file to the specified path
137
- - `result.get_json(fields=None)`: Get the JSON data for info tasks (optionally filtered by fields)
138
-
139
- ### Admin
140
-
141
- - `client.create_key(name, permissions)`: Create a new API key
142
- - `client.get_keys()`: List all existing API keys
143
- - `client.get_key(name)`: Get API key by key name
144
- - `client.delete_key(name)`: Delete an API key
145
-
146
- ## Error Handling
147
-
148
- The library uses exceptions to handle errors. Catch `yt_dlp_host_api.exceptions.APIError` to handle API-related errors.
149
-
150
- ## Contributing
151
-
152
- Contributions to yt-dlp-host-api are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue on the GitHub repository. Pull requests are also encouraged.
@@ -1,10 +0,0 @@
1
- yt_dlp_host_api/__init__.py,sha256=RHx1BvH2Cy_dweEKo5sA-hdBOfBdY_2ds7srPuKGzWQ,41
2
- yt_dlp_host_api/api.py,sha256=iLzWKoyiXeu0Y1Uky8PzpxxHTSMcTGzxlCRT121AKcM,196
3
- yt_dlp_host_api/client.py,sha256=NY_j4TthSV0xrCuv2JuzrpNkuHIsTnoOQuegLbIJHBI,6482
4
- yt_dlp_host_api/exceptions.py,sha256=U_70W1R_ZcUfKptUShGB5VPWQXwc5M29_sNC8pwwq8g,38
5
- yt_dlp_host_api/task.py,sha256=llgBAO_L1CajklMsbICdRpLdOV05Wi0oUh9NKj0bD0w,2674
6
- yt_dlp_host_api-0.1.3.dist-info/LICENSE,sha256=-_Ad_xue4UymJ8jO-ZsSg0vmZ6SUm8WYdoEwHLyBUlc,1078
7
- yt_dlp_host_api-0.1.3.dist-info/METADATA,sha256=geq0IJwW4ry9D-SIaD-wQsk8icTQqdmONgYEqGmc_Ws,5987
8
- yt_dlp_host_api-0.1.3.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
9
- yt_dlp_host_api-0.1.3.dist-info/top_level.txt,sha256=Mn3FZuqLCHr47sRjhtEOz7lDl4lpsHkymWANORYp72s,16
10
- yt_dlp_host_api-0.1.3.dist-info/RECORD,,