diff --git a/shared/src/commonMain/kotlin/com/toasterofbread/spmp/service/playercontroller/openUri.kt b/shared/src/commonMain/kotlin/com/toasterofbread/spmp/service/playercontroller/openUri.kt index 776067929..87b3166d9 100644 --- a/shared/src/commonMain/kotlin/com/toasterofbread/spmp/service/playercontroller/openUri.kt +++ b/shared/src/commonMain/kotlin/com/toasterofbread/spmp/service/playercontroller/openUri.kt @@ -8,6 +8,7 @@ import com.toasterofbread.spmp.model.mediaitem.playlist.RemotePlaylistRef import com.toasterofbread.spmp.model.mediaitem.song.Song import com.toasterofbread.spmp.model.mediaitem.song.SongRef import com.toasterofbread.spmp.model.mediaitem.MediaItem +import com.toasterofbread.spmp.ui.layout.apppage.searchpage.SearchAppPage import java.net.URI import java.net.URISyntaxException @@ -19,27 +20,39 @@ suspend fun PlayerState.openUri(uri_string: String): Result { return failure("Unsupported host '${uri.host}'") } - val item: MediaItem - val path_parts: List = uri.path.split('/').filter { it.isNotBlank() } when (path_parts.firstOrNull()) { "channel" -> { val channel_id: String = path_parts.elementAtOrNull(1) ?: return failure("No channel ID") - item = ArtistRef(channel_id) + openItem(ArtistRef(channel_id)) } "watch" -> { val v_start: Int = (uri.query.indexOfOrNull("v=") ?: return failure("'v' query parameter not found")) + 2 val v_end: Int = uri.query.indexOfOrNull("&", v_start) ?: uri.query.length - item = SongRef(uri.query.substring(v_start, v_end)) + openItem(SongRef(uri.query.substring(v_start, v_end))) } "playlist" -> { val list_start: Int = (uri.query.indexOfOrNull("list=") ?: return failure("'list' query parameter not found")) + 5 val list_end: Int = uri.query.indexOfOrNull("&", list_start) ?: uri.query.length - item = RemotePlaylistRef(uri.query.substring(list_start, list_end)) + openItem(RemotePlaylistRef(uri.query.substring(list_start, list_end))) + } + "search" -> { + val q_start: Int = (uri.query.indexOfOrNull("q=") ?: return failure("'q' query parameter not found")) + 2 + val q_end: Int = uri.query.indexOfOrNull("&", q_start) ?: uri.query.length + val query: String = uri.query.substring(q_start, q_end) + + val search_page: SearchAppPage = app_page_state.Search + openAppPage(search_page) + + search_page.performSearch(query) } else -> return failure("Uri path not implemented") } + return Result.success(Unit) +} + +private suspend fun PlayerState.openItem(item: MediaItem) { item.loadData(context, populate_data = false, force = true) withPlayer { @@ -50,6 +63,4 @@ suspend fun PlayerState.openUri(uri_string: String): Result { openMediaItem(item) } } - - return Result.success(Unit) } diff --git a/shared/src/commonMain/kotlin/com/toasterofbread/spmp/ui/layout/apppage/searchpage/SearchAppPage.kt b/shared/src/commonMain/kotlin/com/toasterofbread/spmp/ui/layout/apppage/searchpage/SearchAppPage.kt index ed34bf1ba..ea647f915 100644 --- a/shared/src/commonMain/kotlin/com/toasterofbread/spmp/ui/layout/apppage/searchpage/SearchAppPage.kt +++ b/shared/src/commonMain/kotlin/com/toasterofbread/spmp/ui/layout/apppage/searchpage/SearchAppPage.kt @@ -265,6 +265,12 @@ class SearchAppPage(override val state: AppPageState, val context: AppContext): performSearch(current_filter?.let { SearchFilter(it, it.getDefaultParams()) }) } + fun performSearch(query: String) { + current_query = query + current_filter = null + performSearch() + } + fun performSearch(filter: SearchFilter?) { check(search_endpoint.isImplemented())