forked from recloudstream/cloudstream
[Feature] Filter search results by film quality
This commit is contained in:
parent
b5337a1cfb
commit
dce6f06368
6 changed files with 70 additions and 19 deletions
|
@ -253,6 +253,26 @@ object APIHolder {
|
||||||
allApis.filter { api -> api.supportedTypes.any { it in mediaTypeList } }
|
allApis.filter { api -> api.supportedTypes.any { it in mediaTypeList } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.filterSearchResultByFilmQuality(data: List<SearchResponse>): List<SearchResponse> {
|
||||||
|
// Filter results omitting entries with certain quality
|
||||||
|
if (data.isEmpty()) {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
val filteredSearchQuality = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
?.getStringSet(getString(R.string.pref_filter_search_quality_key), setOf())
|
||||||
|
?.mapNotNull { entry ->
|
||||||
|
entry.toIntOrNull() ?: return@mapNotNull null
|
||||||
|
} ?: listOf()
|
||||||
|
if (filteredSearchQuality.isNotEmpty()) {
|
||||||
|
return data.filter { item ->
|
||||||
|
val searchQualVal = item.quality?.ordinal ?: -1
|
||||||
|
//Log.i("filterSearch", "QuickSearch item => ${item.toJson()}")
|
||||||
|
!filteredSearchQuality.contains(searchQualVal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -586,24 +606,24 @@ data class HomePageList(
|
||||||
val isHorizontalImages: Boolean = false
|
val isHorizontalImages: Boolean = false
|
||||||
)
|
)
|
||||||
|
|
||||||
enum class SearchQuality {
|
enum class SearchQuality(value: Int?) {
|
||||||
//https://en.wikipedia.org/wiki/Pirated_movie_release_types
|
//https://en.wikipedia.org/wiki/Pirated_movie_release_types
|
||||||
Cam,
|
Cam(1),
|
||||||
CamRip,
|
CamRip(2),
|
||||||
HdCam,
|
HdCam(3),
|
||||||
Telesync, // TS
|
Telesync(4), // TS
|
||||||
WorkPrint,
|
WorkPrint(5),
|
||||||
Telecine, // TC
|
Telecine(6), // TC
|
||||||
HQ,
|
HQ(7),
|
||||||
HD,
|
HD(8),
|
||||||
HDR, // high dynamic range
|
HDR(9), // high dynamic range
|
||||||
BlueRay,
|
BlueRay(10),
|
||||||
DVD,
|
DVD(11),
|
||||||
SD,
|
SD(12),
|
||||||
FourK,
|
FourK(13),
|
||||||
UHD,
|
UHD(14),
|
||||||
SDR, // standard dynamic range
|
SDR(15), // standard dynamic range
|
||||||
WebRip
|
WebRip(16)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Add anything to here if you find a site that uses some specific naming convention*/
|
/**Add anything to here if you find a site that uses some specific naming convention*/
|
||||||
|
|
|
@ -16,6 +16,7 @@ import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import com.lagradost.cloudstream3.APIHolder.filterProviderByPreferredMedia
|
import com.lagradost.cloudstream3.APIHolder.filterProviderByPreferredMedia
|
||||||
|
import com.lagradost.cloudstream3.APIHolder.filterSearchResultByFilmQuality
|
||||||
import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
|
import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
|
||||||
import com.lagradost.cloudstream3.HomePageList
|
import com.lagradost.cloudstream3.HomePageList
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
|
@ -214,7 +215,7 @@ class QuickSearchFragment : Fragment() {
|
||||||
is Resource.Success -> {
|
is Resource.Success -> {
|
||||||
it.value.let { data ->
|
it.value.let { data ->
|
||||||
(quick_search_autofit_results?.adapter as? SearchAdapter?)?.updateList(
|
(quick_search_autofit_results?.adapter as? SearchAdapter?)?.updateList(
|
||||||
data
|
context?.filterSearchResultByFilmQuality(data) ?: data
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
searchExitIcon?.alpha = 1f
|
searchExitIcon?.alpha = 1f
|
||||||
|
|
|
@ -21,6 +21,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.lagradost.cloudstream3.*
|
import com.lagradost.cloudstream3.*
|
||||||
import com.lagradost.cloudstream3.APIHolder.filterProviderByPreferredMedia
|
import com.lagradost.cloudstream3.APIHolder.filterProviderByPreferredMedia
|
||||||
|
import com.lagradost.cloudstream3.APIHolder.filterSearchResultByFilmQuality
|
||||||
import com.lagradost.cloudstream3.APIHolder.getApiFromName
|
import com.lagradost.cloudstream3.APIHolder.getApiFromName
|
||||||
import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings
|
import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings
|
||||||
import com.lagradost.cloudstream3.APIHolder.getApiSettings
|
import com.lagradost.cloudstream3.APIHolder.getApiSettings
|
||||||
|
@ -429,9 +430,11 @@ class SearchFragment : Fragment() {
|
||||||
listLock.lock()
|
listLock.lock()
|
||||||
(search_master_recycler?.adapter as ParentItemAdapter?)?.apply {
|
(search_master_recycler?.adapter as ParentItemAdapter?)?.apply {
|
||||||
val newItems = list.map { ongoing ->
|
val newItems = list.map { ongoing ->
|
||||||
|
val dataList = if (ongoing.data is Resource.Success) ongoing.data.value else ArrayList()
|
||||||
|
val dataListFiltered = context?.filterSearchResultByFilmQuality(dataList) ?: dataList
|
||||||
val ongoingList = HomePageList(
|
val ongoingList = HomePageList(
|
||||||
ongoing.apiName,
|
ongoing.apiName,
|
||||||
if (ongoing.data is Resource.Success) ongoing.data.value else ArrayList()
|
dataListFiltered
|
||||||
)
|
)
|
||||||
ongoingList
|
ongoingList
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.view.View
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
|
import com.lagradost.cloudstream3.SearchQuality
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.ui.search.SearchResultBuilder
|
import com.lagradost.cloudstream3.ui.search.SearchResultBuilder
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
|
||||||
|
@ -125,5 +126,25 @@ class SettingsUI : PreferenceFragmentCompat() {
|
||||||
return@setOnPreferenceClickListener true
|
return@setOnPreferenceClickListener true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPref(R.string.pref_filter_search_quality_key)?.setOnPreferenceClickListener {
|
||||||
|
val names = enumValues<SearchQuality>().sorted().map { it.name }
|
||||||
|
val currentList = settingsManager.getStringSet(getString(R.string.pref_filter_search_quality_key), setOf())?.map {
|
||||||
|
it.toInt()
|
||||||
|
} ?: listOf()
|
||||||
|
|
||||||
|
activity?.showMultiDialog(
|
||||||
|
names,
|
||||||
|
currentList,
|
||||||
|
getString(R.string.pref_filter_search_quality),
|
||||||
|
{}) { selectedList ->
|
||||||
|
settingsManager.edit().putStringSet(
|
||||||
|
this.getString(R.string.pref_filter_search_quality_key),
|
||||||
|
selectedList.map { it.toString() }.toMutableSet()
|
||||||
|
).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
return@setOnPreferenceClickListener true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -54,6 +54,7 @@
|
||||||
<string name="override_site_key" translatable="false">override_site_key</string>
|
<string name="override_site_key" translatable="false">override_site_key</string>
|
||||||
<string name="redo_setup_key" translatable="false">redo_setup_key</string>
|
<string name="redo_setup_key" translatable="false">redo_setup_key</string>
|
||||||
<string name="filter_sub_lang_key" translatable="false">filter_sub_lang_key</string>
|
<string name="filter_sub_lang_key" translatable="false">filter_sub_lang_key</string>
|
||||||
|
<string name="pref_filter_search_quality_key" translatable="false">pref_filter_search_quality_key</string>
|
||||||
|
|
||||||
<!-- FORMAT MIGHT TRANSLATE, WILL CAUSE CRASH IF APPLIED WRONG -->
|
<!-- FORMAT MIGHT TRANSLATE, WILL CAUSE CRASH IF APPLIED WRONG -->
|
||||||
<string name="extra_info_format" formatted="true" translatable="false">%d %s | %sMB</string>
|
<string name="extra_info_format" formatted="true" translatable="false">%d %s | %sMB</string>
|
||||||
|
@ -261,6 +262,7 @@
|
||||||
<string name="show_fillers_settings">Show filler episode for anime</string>
|
<string name="show_fillers_settings">Show filler episode for anime</string>
|
||||||
<string name="show_trailers_settings">Show trailers</string>
|
<string name="show_trailers_settings">Show trailers</string>
|
||||||
<string name="kitsu_settings">Show posters from kitsu</string>
|
<string name="kitsu_settings">Show posters from kitsu</string>
|
||||||
|
<string name="pref_filter_search_quality">Hide selected video quality on Search results</string>
|
||||||
|
|
||||||
<string name="automatic_plugin_updates">Automatic plugin updates</string>
|
<string name="automatic_plugin_updates">Automatic plugin updates</string>
|
||||||
<string name="updates_settings">Show app updates</string>
|
<string name="updates_settings">Show app updates</string>
|
||||||
|
|
|
@ -50,4 +50,8 @@
|
||||||
android:title="@string/random_button_settings"
|
android:title="@string/random_button_settings"
|
||||||
android:summary="@string/random_button_settings_desc"
|
android:summary="@string/random_button_settings_desc"
|
||||||
app:defaultValue="false" />
|
app:defaultValue="false" />
|
||||||
|
<Preference
|
||||||
|
android:icon="@drawable/ic_baseline_filter_list_24"
|
||||||
|
android:key="@string/pref_filter_search_quality_key"
|
||||||
|
android:title="@string/pref_filter_search_quality" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
Reference in a new issue