https://github.com/toasterofbread/ytm-kt
A Kotlin Multiplatform library for (unofficially) using the YouTube Music API, optionally with user authentication.
https://github.com/toasterofbread/ytm-kt
kotlin kotlin-library kotlin-multiplatform youtube-api youtube-music
Last synced: 29 days ago
JSON representation
A Kotlin Multiplatform library for (unofficially) using the YouTube Music API, optionally with user authentication.
- Host: GitHub
- URL: https://github.com/toasterofbread/ytm-kt
- Owner: toasterofbread
- License: apache-2.0
- Created: 2024-03-13T22:14:40.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-22T17:45:45.000Z (12 months ago)
- Last Synced: 2024-05-22T18:52:02.013Z (12 months ago)
- Topics: kotlin, kotlin-library, kotlin-multiplatform, youtube-api, youtube-music
- Language: Kotlin
- Homepage:
- Size: 298 KB
- Stars: 4
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ytm-kt
A Kotlin Multiplatform library for (unofficially) using the YouTube Music API, optionally with user authentication. This library was originally a part of [SpMp](https://github.com/toasterofbread/spmp).
## Setup
ytm-kt currently supports the following Kotlin targets:
- Android
- JVM (Desktop)
- Linux x86_64
- Linux arm64
- Windows x86_64
- Wasm#### Gradle:
1. Add the Maven Central repository to your dependency resolution configuration
```
repositories {
mavenCentral()
}
```2. Add the ytm-kt library dependency (replace `` with the desired ytm-kt [version](https://github.com/toasterofbread/ytm-kt/tags))
```
implementation("dev.toastbits.ytmkt:ytmkt:")
```## Usage
API endpoints are accessed through the [YtmApi](library/src/commonMain/kotlin/dev/toastbits/ytmkt/model/YtmApi.kt) interface. To use this interface, either implement it yourself or use one of the built-in implementations:
- [YoutubeiApi](library/src/commonMain/kotlin/dev/toastbits/ytmkt/impl/youtubei/YoutubeiApi.kt) - directly accesses YouTube's internal API via https://music.youtube.com/youtubei/v1/.
- [UnimplementedYtmApi](library/src/commonMain/kotlin/dev/toastbits/ytmkt/impl/unimplemented/UnimplementedYtmApi.kt) - contains dummy implementations of all APIs. Intended to be used as a base for custom API implementations.### Example usage
```
// Initialise the Youtubei api implementation
val api: YtmApi =
YoutubeiApi(
data_language = "en-GB" // The language we want data (such as song names) to be in
)// Download the home page recommendations feed
val song_feed_result: Result = api.SongFeed.getSongFeed()// Print feed row titles in our desired language
for (layout in song_feed_result.getOrThrow().layouts) {
val title_text: String = layout.title.getString("en-GB") // The language we want UI strings to be in
println("Layout $title_text has ${layout.items.size} items")
}
```#### See the [sample application](sample/src/commonMain/kotlin/dev/toastbits/sample/Sample.kt) for a more detailed example
## Documentation
TODO