yt-dlp-host-api 0.0.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/__init__.py +2 -0
- yt_dlp_host_api/api.py +8 -0
- yt_dlp_host_api/client.py +68 -0
- yt_dlp_host_api/exceptions.py +2 -0
- yt_dlp_host_api/task.py +67 -0
- yt_dlp_host_api-0.0.1.dist-info/LICENSE +19 -0
- yt_dlp_host_api-0.0.1.dist-info/METADATA +101 -0
- yt_dlp_host_api-0.0.1.dist-info/RECORD +10 -0
- yt_dlp_host_api-0.0.1.dist-info/WHEEL +5 -0
- yt_dlp_host_api-0.0.1.dist-info/top_level.txt +1 -0
yt_dlp_host_api/api.py
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
import requests
|
2
|
+
from .task import Task
|
3
|
+
from .exceptions import APIError
|
4
|
+
|
5
|
+
class Client:
|
6
|
+
def __init__(self, host_url, api_key):
|
7
|
+
self.host_url = host_url
|
8
|
+
self.api_key = api_key
|
9
|
+
self.headers = {"X-API-Key": api_key, "Content-Type": "application/json"}
|
10
|
+
self.send_task = self.SendTask(self)
|
11
|
+
self.admin = self.Admin(self)
|
12
|
+
|
13
|
+
def get_video(self, url, quality="best"):
|
14
|
+
return self.send_task.get_video(url=url, quality=quality).get_result()
|
15
|
+
|
16
|
+
def get_audio(self, url):
|
17
|
+
return self.send_task.get_audio(url=url).get_result()
|
18
|
+
|
19
|
+
def get_info(self, url):
|
20
|
+
return self.send_task.get_info(url=url).get_result()
|
21
|
+
|
22
|
+
class SendTask:
|
23
|
+
def __init__(self, client):
|
24
|
+
self.client = client
|
25
|
+
|
26
|
+
def get_video(self, url, quality="best"):
|
27
|
+
data = {"url": url, "quality": quality}
|
28
|
+
response = requests.post(f"{self.client.host_url}/get_video", json=data, headers=self.client.headers)
|
29
|
+
if response.status_code != 200:
|
30
|
+
raise APIError(response.json().get('error', 'Unknown error'))
|
31
|
+
return Task(self.client, response.json()['task_id'], 'get_video')
|
32
|
+
|
33
|
+
def get_audio(self, url):
|
34
|
+
data = {"url": url}
|
35
|
+
response = requests.post(f"{self.client.host_url}/get_audio", json=data, headers=self.client.headers)
|
36
|
+
if response.status_code != 200:
|
37
|
+
raise APIError(response.json().get('error', 'Unknown error'))
|
38
|
+
return Task(self.client, response.json()['task_id'], 'get_audio')
|
39
|
+
|
40
|
+
def get_info(self, url):
|
41
|
+
data = {"url": url}
|
42
|
+
response = requests.post(f"{self.client.host_url}/get_info", json=data, headers=self.client.headers)
|
43
|
+
if response.status_code != 200:
|
44
|
+
raise APIError(response.json().get('error', 'Unknown error'))
|
45
|
+
return Task(self.client, response.json()['task_id'], 'get_info')
|
46
|
+
|
47
|
+
class Admin:
|
48
|
+
def __init__(self, client):
|
49
|
+
self.client = client
|
50
|
+
|
51
|
+
def create_key(self, name, permissions):
|
52
|
+
data = {"name": name, "permissions": permissions}
|
53
|
+
response = requests.post(f"{self.client.host_url}/create_key", json=data, headers=self.client.headers)
|
54
|
+
if response.status_code != 201:
|
55
|
+
raise APIError(response.json().get('error', 'Unknown error'))
|
56
|
+
return response.json()
|
57
|
+
|
58
|
+
def delete_key(self, name):
|
59
|
+
response = requests.delete(f"{self.client.host_url}/delete_key/{name}", headers=self.client.headers)
|
60
|
+
if response.status_code != 200:
|
61
|
+
raise APIError(response.json().get('error', 'Unknown error'))
|
62
|
+
return response.json()
|
63
|
+
|
64
|
+
def list_keys(self):
|
65
|
+
response = requests.get(f"{self.client.host_url}/list_keys", headers=self.client.headers)
|
66
|
+
if response.status_code != 200:
|
67
|
+
raise APIError(response.json().get('error', 'Unknown error'))
|
68
|
+
return response.json()
|
yt_dlp_host_api/task.py
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
import requests
|
2
|
+
import json
|
3
|
+
import time
|
4
|
+
from .exceptions import APIError
|
5
|
+
|
6
|
+
class Task:
|
7
|
+
def __init__(self, client, task_id, task_type):
|
8
|
+
self.client = client
|
9
|
+
self.task_id = task_id
|
10
|
+
self.task_type = task_type
|
11
|
+
|
12
|
+
def get_status(self):
|
13
|
+
response = requests.get(f"{self.client.host_url}/status/{self.task_id}", headers=self.client.headers)
|
14
|
+
if response.status_code != 200:
|
15
|
+
raise APIError(response.json().get('error', 'Unknown error'))
|
16
|
+
return response.json()
|
17
|
+
|
18
|
+
def get_result(self, max_retries=360, delay=1):
|
19
|
+
for _ in range(max_retries):
|
20
|
+
status = self.get_status()
|
21
|
+
if status['status'] == 'completed':
|
22
|
+
return TaskResult(self.client, status)
|
23
|
+
elif status['status'] == 'error':
|
24
|
+
raise APIError(f"Task failed: {status.get('error', 'Unknown error')}")
|
25
|
+
elif status['status'] in ['waiting', 'processing']:
|
26
|
+
time.sleep(delay)
|
27
|
+
else:
|
28
|
+
raise APIError(f"Unknown task status: {status['status']}")
|
29
|
+
|
30
|
+
raise APIError(f"Task did not complete within the expected time (waited {max_retries * delay} seconds)")
|
31
|
+
|
32
|
+
class TaskResult:
|
33
|
+
def __init__(self, client, status):
|
34
|
+
self.client = client
|
35
|
+
self.status = status
|
36
|
+
|
37
|
+
def get_file(self):
|
38
|
+
url = self.get_file_url()
|
39
|
+
response = requests.get(url, headers=self.client.headers)
|
40
|
+
if response.status_code != 200:
|
41
|
+
raise APIError(response.json().get('error', 'Unknown error'))
|
42
|
+
return response.content
|
43
|
+
|
44
|
+
def get_file_url(self):
|
45
|
+
return f"{self.client.host_url}{self.status['file']}"
|
46
|
+
|
47
|
+
def save_file(self, path):
|
48
|
+
url = self.get_file_url()
|
49
|
+
response = requests.get(url, headers=self.client.headers)
|
50
|
+
if response.status_code != 200:
|
51
|
+
raise APIError(response.json().get('error', 'Unknown error'))
|
52
|
+
with open(path, 'wb') as f:
|
53
|
+
f.write(response.content)
|
54
|
+
|
55
|
+
def get_json(self, fields=None):
|
56
|
+
if self.status['task_type'] != 'get_info':
|
57
|
+
raise APIError("This method is only available for get_info tasks")
|
58
|
+
url = self.get_file_url()
|
59
|
+
if fields:
|
60
|
+
url += "?"
|
61
|
+
for field in fields:
|
62
|
+
url += f'{field}&'
|
63
|
+
response = requests.get(url, headers=self.client.headers)
|
64
|
+
if response.status_code != 200:
|
65
|
+
raise APIError(response.json().get('error', 'Unknown error'))
|
66
|
+
data = json.loads(response.text)
|
67
|
+
return data
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2024 yt-dlp-host-api
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
@@ -0,0 +1,101 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: yt_dlp_host_api
|
3
|
+
Version: 0.0.1
|
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 API Client
|
17
|
+
|
18
|
+
This is a Python library for interacting with the 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 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 audio
|
44
|
+
client.get_audio(url='https://youtu.be/1FPdtR_5KFo').save_file("test_audio.mp3")
|
45
|
+
print("Audio saved to test_audio.mp3")
|
46
|
+
|
47
|
+
# Get info
|
48
|
+
info_json = client.get_info(url='https://youtu.be/1FPdtR_5KFo').get_json(['qualities', 'title'])
|
49
|
+
print("Video info:", info_json)
|
50
|
+
|
51
|
+
# Admin operations (requires admin API key)
|
52
|
+
new_key = client.admin.create_key("user_key", ["get_video", "get_info"])
|
53
|
+
keys = client.admin.list_keys()
|
54
|
+
client.admin.delete_key("user_key")
|
55
|
+
```
|
56
|
+
|
57
|
+
## Features
|
58
|
+
|
59
|
+
- Download YouTube videos
|
60
|
+
- Retrieve video information
|
61
|
+
- Admin operations:
|
62
|
+
- Create new API keys
|
63
|
+
- List existing API keys
|
64
|
+
- Delete API keys
|
65
|
+
|
66
|
+
## API Reference
|
67
|
+
|
68
|
+
### Client
|
69
|
+
|
70
|
+
- `client.get_video(url, quality='best')`: Simple way to get the result of get_video
|
71
|
+
- `client.get_audio(url)`: Simple way to get the result of get_audio
|
72
|
+
- `client.get_info(url)`: Simple way to get the result of get_info
|
73
|
+
- `client.send_task.get_video(url, quality='best')`: Initiates a get_video task
|
74
|
+
- `client.send_task.get_audio(url, quality='best')`: Initiates a get_audio task
|
75
|
+
- `client.send_task.get_info(url)`: Initiates a get_info task
|
76
|
+
|
77
|
+
### Task
|
78
|
+
|
79
|
+
- `task.get_status()`: Get the current status of a task
|
80
|
+
- `task.get_result()`: Wait for and return the result of a task
|
81
|
+
|
82
|
+
### TaskResult
|
83
|
+
|
84
|
+
- `result.get_file()`: Get the file
|
85
|
+
- `result.get_file_url()`: Get the URL of the downloaded file
|
86
|
+
- `result.save_file(path)`: Save the downloaded file to the specified path
|
87
|
+
- `result.get_json(fields=None)`: Get the JSON data for info tasks (optionally filtered by fields)
|
88
|
+
|
89
|
+
### Admin
|
90
|
+
|
91
|
+
- `client.admin.create_key(name, permissions)`: Create a new API key
|
92
|
+
- `client.admin.list_keys()`: List all existing API keys
|
93
|
+
- `client.admin.delete_key(name)`: Delete an API key
|
94
|
+
|
95
|
+
## Error Handling
|
96
|
+
|
97
|
+
The library uses exceptions to handle errors. Catch `yt_dlp_host_api.exceptions.APIError` to handle API-related errors.
|
98
|
+
|
99
|
+
## Contributing
|
100
|
+
|
101
|
+
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=WhwA4kg7mTelvqW9pB4Xpzif4LMM3lWNjiTvBfmh74M,3094
|
4
|
+
yt_dlp_host_api/exceptions.py,sha256=U_70W1R_ZcUfKptUShGB5VPWQXwc5M29_sNC8pwwq8g,38
|
5
|
+
yt_dlp_host_api/task.py,sha256=aS96ZZik0rRiLwLx1mXm9GeF9lgEOOkCW-Qp-gHmgCo,2612
|
6
|
+
yt_dlp_host_api-0.0.1.dist-info/LICENSE,sha256=-_Ad_xue4UymJ8jO-ZsSg0vmZ6SUm8WYdoEwHLyBUlc,1078
|
7
|
+
yt_dlp_host_api-0.0.1.dist-info/METADATA,sha256=DmsLsNzCkfvRvnvJlxB1soZl2qFis-g4YfNmmkNKAsQ,3293
|
8
|
+
yt_dlp_host_api-0.0.1.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
|
9
|
+
yt_dlp_host_api-0.0.1.dist-info/top_level.txt,sha256=Mn3FZuqLCHr47sRjhtEOz7lDl4lpsHkymWANORYp72s,16
|
10
|
+
yt_dlp_host_api-0.0.1.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
yt_dlp_host_api
|