This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for autoplay via hyperpipe
- Loading branch information
Showing
12 changed files
with
180 additions
and
13 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
app/src/main/java/app/suhasdissa/vibeyou/backend/api/HyperpipeApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package app.suhasdissa.vibeyou.backend.api | ||
|
||
import app.suhasdissa.vibeyou.backend.models.hyper.NextSongsResponse | ||
import app.suhasdissa.vibeyou.utils.Pref | ||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull | ||
import retrofit2.http.GET | ||
import retrofit2.http.Path | ||
|
||
interface HyperpipeApi { | ||
/** | ||
* | ||
*/ | ||
@GET("https://{instance}/next/{videoId}") | ||
suspend fun getNext( | ||
@Path("instance") instance: String = Pref.sharedPreferences | ||
.getString(Pref.hyperpipeApiUrlKey, "") | ||
?.toHttpUrlOrNull() | ||
?.host.orEmpty(), | ||
@Path("videoId") videoId: String | ||
): NextSongsResponse | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/app/suhasdissa/vibeyou/backend/models/hyper/MediaSession.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package app.suhasdissa.vibeyou.backend.models.hyper | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class MediaSession( | ||
val album: String, | ||
val thumbnails: List<Thumbnail> | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/app/suhasdissa/vibeyou/backend/models/hyper/NextSongsResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package app.suhasdissa.vibeyou.backend.models.hyper | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class NextSongsResponse( | ||
val lyricsId: String, | ||
val mediaSession: MediaSession, | ||
val songs: List<Song> | ||
) |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/app/suhasdissa/vibeyou/backend/models/hyper/Song.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package app.suhasdissa.vibeyou.backend.models.hyper | ||
|
||
import androidx.core.net.toUri | ||
import app.suhasdissa.vibeyou.backend.data.Song | ||
import app.suhasdissa.vibeyou.backend.database.entities.SongEntity | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class Song( | ||
val id: String, | ||
val subtitle: String, | ||
val thumbnails: List<Thumbnail>, | ||
val title: String | ||
) { | ||
val asSong: Song get() { | ||
return Song( | ||
id = id, | ||
title = title, | ||
artistsText = subtitle, | ||
durationText = null, | ||
thumbnailUri = thumbnails.maxByOrNull { it.height }?.url?.toUri() | ||
) | ||
} | ||
|
||
val asSongEntity: SongEntity get() { | ||
return SongEntity( | ||
id = id, | ||
title = title, | ||
artistsText = subtitle, | ||
durationText = null, | ||
thumbnailUrl = thumbnails.maxByOrNull { it.height }?.url | ||
) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/app/suhasdissa/vibeyou/backend/models/hyper/Thumbnail.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package app.suhasdissa.vibeyou.backend.models.hyper | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class Thumbnail( | ||
val height: Int, | ||
val url: String, | ||
val width: Int | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/src/main/java/app/suhasdissa/vibeyou/ui/screens/settings/TextFieldPref.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package app.suhasdissa.vibeyou.ui.screens.settings | ||
|
||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.OutlinedTextField | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import androidx.core.content.edit | ||
import app.suhasdissa.vibeyou.utils.Pref | ||
|
||
@Composable | ||
fun TextFieldPref( | ||
key: String, | ||
defaultValue: String, | ||
title: String, | ||
onValueChange: (String) -> Unit = {} | ||
) { | ||
var value by remember { | ||
mutableStateOf(Pref.sharedPreferences.getString(key, defaultValue).orEmpty()) | ||
} | ||
|
||
OutlinedTextField( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = 8.dp), | ||
value = value, | ||
onValueChange = { | ||
value = it | ||
Pref.sharedPreferences.edit(true) { putString(key, it) } | ||
onValueChange(it) | ||
}, | ||
label = { | ||
Text(text = title) | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 16 additions & 3 deletions
19
app/src/main/java/app/suhasdissa/vibeyou/utils/RetrofitHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
package app.suhasdissa.vibeyou.utils | ||
|
||
import app.suhasdissa.vibeyou.backend.api.HyperpipeApi | ||
import app.suhasdissa.vibeyou.backend.api.PipedApi | ||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import retrofit2.Retrofit | ||
import retrofit2.create | ||
|
||
object RetrofitHelper { | ||
fun createPipedApi(): PipedApi { | ||
val json = Json { ignoreUnknownKeys = true } | ||
val json by lazy { | ||
Json { ignoreUnknownKeys = true } | ||
} | ||
|
||
fun createPipedApi(): PipedApi { | ||
val retrofit: Retrofit = Retrofit.Builder() | ||
.baseUrl("https://pipedapi.kavin.rocks/") | ||
.addConverterFactory(json.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
|
||
return retrofit.create(PipedApi::class.java) | ||
return retrofit.create() | ||
} | ||
|
||
fun createHyperpipeApi(): HyperpipeApi { | ||
val retrofit = Retrofit.Builder() | ||
.baseUrl("https://hyperpipeapi.onrender.com") | ||
.addConverterFactory(json.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
|
||
return retrofit.create() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters