Skip to content

dinaraparanid/YtDlp-kt

Repository files navigation

YtDlp-kt

This library is a kotlin wrapper for YtDlp command line project.

Setup

To integrate a library into your build.gradle:

  1. Add the JitPack repository to your build file
allprojects {
    repositories {
        // ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency
dependencies {
    implementation 'com.github.dinaraparanid:YtDlp-kt:v1.0.0.0'
}

For other configuration go here

Example

import com.dinaraparanid.ytdlp_kt.YtDlp
import com.dinaraparanid.ytdlp_kt.YtDlpRequest

suspend fun main() {
    YtDlp.updateAsync().join() // or YtDlp.update()

    val videoUrl = "https://www.youtube.com/watch?v=K0HSD_i2DvA"

    val request = YtDlpRequest(videoUrl).apply {
        setOption("--audio-format", "mp3")
        setOption("--socket-timeout", "1")
        setOption("--retries", "infinite")
        setOption("--extract-audio")
        setOption("--format", "best")
    }

    assert(YtDlp.execute(request) == YtDlp.executeAsync(request).await())
    assert(YtDlp.getVideoData(videoUrl) == YtDlp.getVideoDataAsync(videoUrl).await())
}