An implementation of yt-dlp for Godot 4.x that works on Linux, OSX and Windows.
This project provides a simple API for downloading videos from YouTube (and other websites).
ℹ️ Use v2.0.3 for Godot 3.x
- Automatic yt-dlp and ffmpeg setup (the latter only on Windows).
- Downloading single videos.
- Converting videos to audio.
- Tracking download progress. (yet to be implemented)
- Downloading playlists of videos. (yet to be implemented)
Clone the repository or download a release, place it into the addons/ folder in your project and enable the plugin. See the Godot Docs for a detailed guide.
If you're using Linux or exporting to Linux make sure that ffmpeg is installed on the system
Same goes for OSX (undocumented)
After enabling the plugin a YtDlp autoload singleton will be registered.
In order to use it you must first call the setup() method that will download all relevant depedencies (up-to-date yt-dlp and ffmpeg if using Windows).
You can check if YtDlp is ready by using the is_setup() method. You can also connect or await the setup_completed signal to be notified when YtDlp is ready to download.
if not YtDlp.is_setup():
YtDlp.setup()
await YtDlp.setup_completedTo download a video use the download(url) method, it will create a Download object that can be complemented using method chaining and started with start() method.
You can connect or await the download_completed signal, to be notified of when the download is completed.
You can check the status of a Download using the get_status() method.
# Downloads a video as audio and stores it to "user://audio/ok_computer.mp3"
var download := YtDlp.download("https://youtu.be/Ya5Fv6VTLYM") \
.set_destination("user://audio/") \
.set_file_name("ok_computer") \
.convert_to_audio(YtDlp.Audio.MP3) \
.start()
assert(download.get_status() == YtDlp.Download.Status.DOWNLOADING)
await download.download_completed
print("Download completed !")The only supported format in Godot (core) is Ogg Theora, which you won't get straight from YouTube. To actually playback the videos can use the following projects:
if not YtDlp.is_setup():
YtDlp.setup()
await YtDlp.setup_completed
var download := YtDlp.download("https://youtu.be/Ya5Fv6VTLYM") \
.set_destination("user://audio/") \
.set_file_name("ok_computer") \
.convert_to_audio(YtDlp.Audio.MP3) \
.start()
await download.download_completed
var stream = AudioStreamMP3.new()
var audio_file = FileAccess.open("user://audio/ok_computer.mp3", FileAccess.READ)
stream.data = audio_file.get_buffer(audio_file.get_length())
audio_file.close()
$AudioStreamPlayer.stream = stream
$AudioStreamPlayer.play()Important
Only available in the master branch
if not YtDlp.is_setup():
YtDlp.setup()
await YtDlp.setup_completed
var search: YtDlp.Search = YtDlp.search("Lemaitre RebMoe - OK Computer", 1)
await search.search_completed
var search_results = search.get_results()
var download := YtDlp.download(search_results[0].url) \
.set_destination("user://audio/") \
.set_file_name("ok_computer") \
.convert_to_audio(YtDlp.Audio.MP3) \
.start()
await download.download_completed
var stream = AudioStreamMP3.new()
var audio_file = FileAccess.open("user://audio/ok_computer.mp3", FileAccess.READ)
stream.data = audio_file.get_buffer(audio_file.get_length())
audio_file.close()
$AudioStreamPlayer.stream = stream
$AudioStreamPlayer.play()Fired when the setup is completed and YtDlp is ready to use
WEBM(default format)MP4
MP3(default format)FLACAACVORBISOPUSM4AWAV
Sets up the yt-dlp dependencies.
Creates a new Download with the target url.
Returns true if YtDlp is ready to use, else returns false
Fired when the download is completed.
READYDOWNLOADINGCOMPLETED
Sets the destination directory of a download.
Sets the file name of the downloaded file (without file extension).
Sets the format of the downloaded video.
Marks the download to be converted to audio.
Starts the download.
Returns the status of the download

