make youtube playlist fetch only through yt-dlp

This commit is contained in:
deniscerri 2025-07-27 15:04:42 +02:00
parent df71ddaa27
commit 3d4e9b6df8
No known key found for this signature in database
GPG key ID: 95C43D517D830350
3 changed files with 37 additions and 35 deletions

View file

@ -189,41 +189,43 @@ class ResultRepository(private val resultDao: ResultDao, private val commandTemp
} }
private suspend fun getYoutubePlaylist(inputQuery: String, resetResults: Boolean, addToResults: Boolean) : List<ResultItem>{ private suspend fun getYoutubePlaylist(inputQuery: String, resetResults: Boolean, addToResults: Boolean) : List<ResultItem>{
val id = inputQuery.split("list=".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1].split("&").first() // val id = inputQuery.split("list=".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1].split("&").first()
val playlistURL = "https://youtube.com/playlist?list=${id}" // val playlistURL = "https://youtube.com/playlist?list=${id}"
if (resetResults) deleteAll() // if (resetResults) deleteAll()
val items = mutableListOf<ResultItem>() // val items = mutableListOf<ResultItem>()
val ytExtractorResult = if (isUsingNewPipeExtractorDataFetching()){ // val ytExtractorResult = if (isUsingNewPipeExtractorDataFetching()){
newPipeUtil.getPlaylistData(playlistURL) { // newPipeUtil.getPlaylistData(playlistURL) {
if (addToResults){ // if (addToResults){
runBlocking { // runBlocking {
val ids = resultDao.insertMultiple(it) // val ids = resultDao.insertMultiple(it)
ids.forEachIndexed { index, id -> // ids.forEachIndexed { index, id ->
it[index].id = id // it[index].id = id
} // }
} // }
} // }
items.addAll(it) // items.addAll(it)
// }
// }else {
// Result.failure(Throwable())
// }
//
// val response = if (ytExtractorResult.isSuccess){
// ytExtractorResult.getOrElse { items }
// }else{
//
// res
// }
val res = ytdlpUtil.getFromYTDL(inputQuery)
if (addToResults) {
val ids = resultDao.insertMultiple(res)
ids.forEachIndexed { index, id ->
res[index].id = id
} }
}else {
Result.failure(Throwable())
} }
val response = if (ytExtractorResult.isSuccess){ itemCount.value = res.size
ytExtractorResult.getOrElse { items } return res
}else{
val res = ytdlpUtil.getFromYTDL(playlistURL)
if (addToResults) {
val ids = resultDao.insertMultiple(res)
ids.forEachIndexed { index, id ->
res[index].id = id
}
}
res
}
itemCount.value = response.size
return response
} }
private suspend fun getYoutubeChannel(url: String, resetResults: Boolean, addToResults: Boolean) : List<ResultItem>{ private suspend fun getYoutubeChannel(url: String, resetResults: Boolean, addToResults: Boolean) : List<ResultItem>{

View file

@ -2450,6 +2450,8 @@ object UiUtil {
@SuppressLint("UnspecifiedRegisterReceiverFlag") @SuppressLint("UnspecifiedRegisterReceiverFlag")
fun showNewAppUpdateDialog(v: GithubRelease, context: Activity, preferences: SharedPreferences) { fun showNewAppUpdateDialog(v: GithubRelease, context: Activity, preferences: SharedPreferences) {
if (context.isFinishing || context.isDestroyed) return
val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val skippedVersions = preferences.getString("skip_updates", "")?.split(",")?.distinct()?.toMutableList() ?: mutableListOf() val skippedVersions = preferences.getString("skip_updates", "")?.split(",")?.distinct()?.toMutableList() ?: mutableListOf()

View file

@ -214,7 +214,7 @@ class NewPipeUtil(context: Context) {
} }
} }
suspend fun getPlaylistData(playlistURL: String, progress: (pagedResults: MutableList<ResultItem>) -> Unit) : Result<List<ResultItem>> { fun getPlaylistData(playlistURL: String, progress: (pagedResults: MutableList<ResultItem>) -> Unit) : Result<List<ResultItem>> {
try { try {
val totalItems = mutableListOf<ResultItem>() val totalItems = mutableListOf<ResultItem>()
var nextPage : Page? = null var nextPage : Page? = null
@ -235,8 +235,6 @@ class NewPipeUtil(context: Context) {
tmp.items.toList() tmp.items.toList()
} }
if (req.isEmpty()) return Result.failure(Throwable())
for (element in req) { for (element in req) {
if (element is StreamInfoItem) { if (element is StreamInfoItem) {
if (element.duration <= 0) continue if (element.duration <= 0) continue