With these two php files you are able to create your own Youtube to MP3 API with ability to search also. See the wiki for examples.
Parameter | Required | Type | Description |
---|---|---|---|
youtubelink | Yes | string | The full youtubelink of the video you want to download. |
format | No (default = mp3) | string: mp3 or mp4 | The format to download |
delete | No | string | The youtubeid of which you want it to be deleted from storage on the server |
Parameter | Required | Type | Description |
---|---|---|---|
delete | Yes | string | The youtubeid that has to be deleted from storage on the server |
format | No (default = mp3 & mp4) | string: mp3 or mp4, leave empty to remove all | The format of the video that has to be deleted |
youtube.com/v/{vidid}
youtube.com/vi/{vidid}
youtube.com/?v={vidid}
youtube.com/?vi={vidid}
youtube.com/watch?v={vidid}
youtube.com/watch?vi={vidid}
youtu.be/{vidid}
Parameter | Required | Type | Description |
---|---|---|---|
q | Yes | string | The query term to search for video's |
max_results | No | integer | The max results of search results u want to get |
Parameter | Type | Description |
---|---|---|
error | boolean | Whether or not an error occured |
message | string | A simple message or the error message |
Parameter | Type | Description |
---|---|---|
error | boolean | false |
youtube_id | string | The youtube identifier |
title | string | The title of the video that got converted |
alt_title | string | A secondary title of the video |
duration | integer | The duration of the video that got converted (in seconds) |
file | string | The streamlink or downloadable mp3 file |
uploaded_at | object | A Date object |
Parameter | Type | Description |
---|---|---|
error | boolean | Whether or not an error occured |
message | string | An error message |
results | array | An array with MAX_RESULTS entries. Each entry has: the video id, the channel name of the video, the video title and the full url to the video |
First we install the dependencies on the server, then website.
- Install ffmpeg (+ libmp3lame - see wiki for tutorial)
- install youtube-dl
- Get a google developer api key
- Go to your webserver files to run composer into
- Run
composer create-project michaelbelgium/youtube-to-mp3 [directoryname]
- wheredirectoryname
is .. a directory where people can access the API from.
define("MAX_RESULTS", 10); //max search results
define("API_KEY", ""); //google api key
define("DOWNLOAD_FOLDER", "download/"); //the folder where files are accessable to download
define("DOWNLOAD_MAX_LENGTH", 0); //max video duration (in seconds) to be able to download, set to 0 to disable
define("LOG", false); //enable logging
You can deploy this API using docker-compose.yml
and the Dockerfile
to build from. Please add your google API Key to docker-compose.yml
.
It will expose port 80 from the container, out to port 80 on the host. This can also be changed using the same file.
Put docker-compose.yml and Dockerfile together in a new, empty folder. Then, run the following command to get it running
sudo docker-compose up -d
To stop:
sudo docker-compose down