Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.libretube.repo

import android.util.Log
import com.github.libretube.api.obj.Subscription
import com.github.libretube.db.DatabaseHolder.Database
import com.github.libretube.db.obj.LocalSubscription
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.parallelMap
import com.github.libretube.ui.dialogs.ShareDialog.Companion.YOUTUBE_FRONTEND_URL
import org.schabi.newpipe.extractor.channel.ChannelInfo
Expand Down Expand Up @@ -33,15 +35,26 @@ class LocalSubscriptionsRepository : SubscriptionsRepository {
val subscribedChannels = getSubscriptionChannelIds()

val newFiltered = newChannels.filter { !subscribedChannels.contains(it) }

val failedChannels = mutableListOf<String>()
for (chunk in newFiltered.chunked(CHANNEL_CHUNK_SIZE)) {
chunk.parallelMap { channelId ->
val channelUrl = "$YOUTUBE_FRONTEND_URL/channel/${channelId}"
val channelInfo = ChannelInfo.getInfo(channelUrl)
try {
val channelUrl = "$YOUTUBE_FRONTEND_URL/channel/${channelId}"
val channelInfo = ChannelInfo.getInfo(channelUrl)

val avatarUrl = channelInfo.avatars.maxByOrNull { it.height }?.url
subscribe(channelId, channelInfo.name, avatarUrl, channelInfo.isVerified)
val avatarUrl = channelInfo.avatars.maxByOrNull { it.height }?.url
subscribe(channelId, channelInfo.name, avatarUrl, channelInfo.isVerified)
} catch (e: Exception) {
Log.e(TAG(), e.toString())
failedChannels.add(channelId)
}
}
}

if (!failedChannels.isEmpty()) {
throw Exception("Failed to import ${failedChannels.joinToString(", ")}")
}
}

override suspend fun getSubscriptions(): List<Subscription> {
Expand Down
Loading