@@ -6,12 +6,8 @@ import dev.typetype.server.models.SearchPageResponse
66import kotlinx.coroutines.Dispatchers
77import kotlinx.coroutines.withContext
88import kotlinx.coroutines.withTimeout
9- import org.schabi.newpipe.extractor.InfoItem
10- import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage
119import org.schabi.newpipe.extractor.NewPipe
1210import org.schabi.newpipe.extractor.search.SearchInfo
13- import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem
14- import org.schabi.newpipe.extractor.stream.StreamInfoItem
1511
1612class PipePipeSearchService : SearchService {
1713
@@ -48,10 +44,11 @@ class PipePipeSearchService : SearchService {
4844 selectedContentFilter.ifEmpty { null },
4945 selectedSortFilter.ifEmpty { null },
5046 )
47+ val contentKind = contentFilter.toSearchContentKind(selectedContentFilter)
5148 if (page == null ) {
52- SearchInfo .getInfo(service, queryHandler).toPageResponse( )
49+ SearchInfo .getInfo(service, queryHandler).toSearchPageResponse().filteredBy(contentKind )
5350 } else {
54- SearchInfo .getMoreItems(service, queryHandler, page).toPageResponse( )
51+ SearchInfo .getMoreItems(service, queryHandler, page).toSearchPageResponse().filteredBy(contentKind )
5552 }
5653 }
5754 }
@@ -79,22 +76,6 @@ class PipePipeSearchService : SearchService {
7976 )
8077 }
8178
82- private fun SearchInfo.toPageResponse (): SearchPageResponse = SearchPageResponse (
83- items = relatedItems.filterIsInstance<StreamInfoItem >().map { it.toVideoItem() },
84- nextpage = nextPage?.toCursor(),
85- searchSuggestion = searchSuggestion?.takeIf { it.isNotBlank() },
86- isCorrectedSearch = isCorrectedSearch,
87- playlists = relatedItems.filterIsInstance<PlaylistInfoItem >().map { it.toPlaylistResultItem() },
88- )
89-
90- private fun InfoItemsPage<InfoItem>.toPageResponse (): SearchPageResponse = SearchPageResponse (
91- items = items.filterIsInstance<StreamInfoItem >().map { it.toVideoItem() },
92- nextpage = nextPage?.toCursor(),
93- searchSuggestion = null ,
94- isCorrectedSearch = false ,
95- playlists = items.filterIsInstance<PlaylistInfoItem >().map { it.toPlaylistResultItem() },
96- )
97-
9879 private companion object {
9980 const val YOUTUBE_SERVICE_ID = 0
10081 }
0 commit comments