added multiple search engines
This commit is contained in:
parent
6b83fd7f46
commit
5b1992a554
8 changed files with 71 additions and 26 deletions
|
|
@ -96,7 +96,7 @@ class ActiveDownloadAdapter(onItemClickListener: OnItemClickListener, activity:
|
|||
}
|
||||
|
||||
val formatNote = card.findViewById<Chip>(R.id.format_note)
|
||||
formatNote.text = item.format.format_note
|
||||
formatNote.text = item.format.format_note.uppercase()
|
||||
|
||||
val codec = card.findViewById<Chip>(R.id.codec)
|
||||
val codecText =
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application
|
|||
erroredDownloads = repository.erroredDownloads
|
||||
|
||||
val videoFormat = getApplication<App>().resources.getStringArray(R.array.video_formats)
|
||||
val videoContainer = sharedPreferences.getString("video_format", getApplication<App>().resources.getString(R.string.defaultValue))
|
||||
val videoContainer = sharedPreferences.getString("video_format", "Default")
|
||||
|
||||
defaultVideoFormats = mutableListOf()
|
||||
videoFormat.forEach {
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
private var clearCache: Preference? = null
|
||||
private var incognito: SwitchPreferenceCompat? = null
|
||||
private var preferredDownloadType : ListPreference? = null
|
||||
private var searchEngine : ListPreference? = null
|
||||
private var downloadCard: SwitchPreferenceCompat? = null
|
||||
private var meteredNetwork: SwitchPreferenceCompat? = null
|
||||
private var apiKey: EditTextPreference? = null
|
||||
|
|
@ -108,6 +109,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
clearCache = findPreference("clear_cache")
|
||||
incognito = findPreference("incognito")
|
||||
preferredDownloadType = findPreference("preferred_download_type")
|
||||
searchEngine = findPreference("search_engine")
|
||||
downloadCard = findPreference("download_card")
|
||||
meteredNetwork = findPreference("metered_networks")
|
||||
apiKey = findPreference("api_key")
|
||||
|
|
@ -174,6 +176,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
|
||||
editor.putBoolean("incognito", incognito!!.isChecked)
|
||||
editor.putString("preferred_download_type", preferredDownloadType!!.value)
|
||||
editor.putString("search_engine", searchEngine!!.value)
|
||||
editor.putBoolean("download_card", downloadCard!!.isChecked)
|
||||
editor.putBoolean("metered_networks", meteredNetwork!!.isChecked)
|
||||
editor.putString("api_key", apiKey!!.text)
|
||||
|
|
@ -294,6 +297,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
editor.apply()
|
||||
true
|
||||
}
|
||||
searchEngine!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||
editor.putString("search_engine", newValue.toString())
|
||||
editor.apply()
|
||||
true
|
||||
}
|
||||
downloadCard!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||
val enable = newValue as Boolean
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.deniscerri.ytdlnis.R
|
|||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.deniscerri.ytdlnis.database.models.ResultItem
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.yausername.youtubedl_android.YoutubeDL
|
||||
|
|
@ -64,8 +65,9 @@ class InfoUtil(private val context: Context) {
|
|||
fun search(query: String): ArrayList<ResultItem?> {
|
||||
init()
|
||||
items = ArrayList()
|
||||
val searchEngine = sharedPreferences.getString("search_engine", "ytsearch")
|
||||
return if (key!!.isEmpty()) {
|
||||
if (useInvidous) searchFromInvidous(query) else getFromYTDL(query)
|
||||
if (useInvidous && searchEngine == "ytsearch") searchFromInvidous(query) else getFromYTDL(query)
|
||||
} else searchFromKey(query)
|
||||
}
|
||||
|
||||
|
|
@ -555,6 +557,7 @@ class InfoUtil(private val context: Context) {
|
|||
fun getFromYTDL(query: String): ArrayList<ResultItem?> {
|
||||
init()
|
||||
items = ArrayList()
|
||||
val searchEngine = sharedPreferences.getString("search_engine", "ytsearch")
|
||||
try {
|
||||
val request = YoutubeDLRequest(query)
|
||||
request.addOption("--flat-playlist")
|
||||
|
|
@ -562,7 +565,7 @@ class InfoUtil(private val context: Context) {
|
|||
request.addOption("--skip-download")
|
||||
request.addOption("-R", "1")
|
||||
request.addOption("--socket-timeout", "5")
|
||||
if (!query.contains("http")) request.addOption("--default-search", "ytsearch25")
|
||||
if (!query.contains("http")) request.addOption("--default-search", "${searchEngine}25")
|
||||
|
||||
val cookiesFile = File(context.cacheDir, "cookies.txt")
|
||||
if (cookiesFile.exists()){
|
||||
|
|
@ -607,7 +610,7 @@ class InfoUtil(private val context: Context) {
|
|||
var playlistTitle: String? = ""
|
||||
if (jsonObject.has("playlist_title")) playlistTitle = jsonObject.getString("playlist_title")
|
||||
if(playlistTitle.equals(query)) playlistTitle = ""
|
||||
val formatsInJSON = if (jsonObject.has("formats")) jsonObject.getJSONArray("formats") else null
|
||||
val formatsInJSON = if (jsonObject.has("formats") && jsonObject.get("formats") is JsonArray) jsonObject.getJSONArray("formats") else null
|
||||
val formats : ArrayList<Format> = ArrayList()
|
||||
if (formatsInJSON != null) {
|
||||
for (f in 0 until formatsInJSON.length()){
|
||||
|
|
|
|||
|
|
@ -143,29 +143,25 @@ class DownloadWorker(
|
|||
if (audioQualityId.isBlank() || audioQualityId == "0" || audioQualityId == context.getString(R.string.best_quality)) audioQualityId = ""
|
||||
else if (audioQualityId == context.getString(R.string.worst_quality)) audioQualityId = "worstaudio"
|
||||
|
||||
if (audioQualityId.isNotBlank()){
|
||||
request.addOption("-f", audioQualityId)
|
||||
val ext = downloadItem.format.container
|
||||
if (audioQualityId.isBlank() || ext == "Default") request.addOption("-x")
|
||||
request.addOption("-f", audioQualityId)
|
||||
|
||||
val ext = downloadItem.format.container
|
||||
if(ext != "Default" && ext != "webm"){
|
||||
val codec = when(downloadItem.format.container){
|
||||
"aac" -> "aac"
|
||||
"mp3" -> "libmp3lame"
|
||||
"flac" -> "flac"
|
||||
"opus" -> "libopus"
|
||||
else -> ""
|
||||
}
|
||||
Log.e("aa", codec)
|
||||
if (codec.isEmpty()){
|
||||
request.addOption("-x")
|
||||
}else{
|
||||
request.addOption("--remux-video", ext)
|
||||
request.addOption("--ppa", "VideoRemuxer:-vn -c:a $codec")
|
||||
}
|
||||
if(ext != "webm"){
|
||||
val codec = when(downloadItem.format.container){
|
||||
"aac" -> "aac"
|
||||
"mp3" -> "libmp3lame"
|
||||
"flac" -> "flac"
|
||||
"opus" -> "libopus"
|
||||
else -> ""
|
||||
}
|
||||
Log.e("aa", codec)
|
||||
if (codec.isEmpty()){
|
||||
request.addOption("-x")
|
||||
}else{
|
||||
request.addOption("--remux-video", ext)
|
||||
request.addOption("--ppa", "VideoRemuxer:-vn -c:a $codec")
|
||||
}
|
||||
|
||||
}else{
|
||||
request.addOption("-x")
|
||||
}
|
||||
|
||||
request.addOption("--embed-metadata")
|
||||
|
|
|
|||
|
|
@ -125,4 +125,30 @@
|
|||
<item>invidious</item>
|
||||
<item>yt-dlp</item>
|
||||
</array>
|
||||
|
||||
<array name="search_engines">
|
||||
<item>YouTube</item>
|
||||
<item>Nico video</item>
|
||||
<item>PRX Series</item>
|
||||
<item>PRX Stories</item>
|
||||
<item>Rokfin</item>
|
||||
<item>Yahoo screen</item>
|
||||
<item>Soundcloud</item>
|
||||
<item>Google Video</item>
|
||||
<item>Bilibili</item>
|
||||
<item>Netverse</item>
|
||||
</array>
|
||||
|
||||
<array name="search_engines_values">
|
||||
<item>ytsearch</item>
|
||||
<item>nicosearch</item>
|
||||
<item>PRX Series</item>
|
||||
<item>PRX Stories</item>
|
||||
<item>rkfnsearch</item>
|
||||
<item>yvsearch</item>
|
||||
<item>scsearch</item>
|
||||
<item>gvsearch</item>
|
||||
<item>bilisearch</item>
|
||||
<item>netsearch</item>
|
||||
</array>
|
||||
</resources>
|
||||
|
|
@ -214,4 +214,6 @@
|
|||
<string name="format_source">Formats Source</string>
|
||||
<string name="video_recommendations">Video Recommendations</string>
|
||||
<string name="video_recommendations_summary">Get Recommended Youtube Videos on the Home Screen from Invidious</string>
|
||||
<string name="preferred_search_engine">Preferred Search Engine</string>
|
||||
<string name="preferred_search_engine_summary">The search engine to use for in-app searches</string>
|
||||
</resources>
|
||||
|
|
@ -83,6 +83,15 @@
|
|||
app:summary="@string/preferred_download_type_summary"
|
||||
app:title="@string/preferred_download_type" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="ytsearch"
|
||||
android:entries="@array/search_engines"
|
||||
android:entryValues="@array/search_engines_values"
|
||||
android:icon="@drawable/baseline_manage_search_24"
|
||||
app:key="search_engine"
|
||||
app:summary="@string/preferred_search_engine_summary"
|
||||
app:title="@string/preferred_search_engine" />
|
||||
|
||||
<EditTextPreference
|
||||
android:icon="@drawable/ic_key"
|
||||
app:key="api_key"
|
||||
|
|
|
|||
Loading…
Reference in a new issue