Skip to content

Commit c6425b8

Browse files
committed
fix: don't refetch channel metadata of already subscribed channel when importing subscriptions
1 parent 85967d4 commit c6425b8

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

app/src/main/java/com/github/libretube/repo/LocalSubscriptionsRepository.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ class LocalSubscriptionsRepository : SubscriptionsRepository {
3030
}
3131

3232
override suspend fun importSubscriptions(newChannels: List<String>) {
33-
for (chunk in newChannels.chunked(CHANNEL_CHUNK_SIZE)) {
33+
val subscribedChannels = getSubscriptionChannelIds()
34+
35+
val newFiltered = newChannels.filter { !subscribedChannels.contains(it) }
36+
for (chunk in newFiltered.chunked(CHANNEL_CHUNK_SIZE)) {
3437
chunk.parallelMap { channelId ->
3538
val channelUrl = "$YOUTUBE_FRONTEND_URL/channel/${channelId}"
3639
val channelInfo = ChannelInfo.getInfo(channelUrl)
3740

38-
runCatching { subscribe(channelId, channelInfo.name, channelInfo.avatars.maxByOrNull { it.height }?.url, channelInfo.isVerified) }
41+
val avatarUrl = channelInfo.avatars.maxByOrNull { it.height }?.url
42+
subscribe(channelId, channelInfo.name, avatarUrl, channelInfo.isVerified)
3943
}
4044
}
4145
}

app/src/main/java/com/github/libretube/ui/preferences/BackupRestoreSettings.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class BackupRestoreSettings : BasePreferenceFragment() {
4747
}
4848
private val createBackupFile = registerForActivityResult(CreateDocument(FILETYPE_ANY)) { uri ->
4949
if (uri == null) return@registerForActivityResult
50-
CoroutineScope(Dispatchers.IO).launch {
50+
lifecycleScope.launch(Dispatchers.IO) {
5151
BackupHelper.createAdvancedBackup(requireContext(), uri, backupFile)
5252
}
5353
}
@@ -59,7 +59,7 @@ class BackupRestoreSettings : BasePreferenceFragment() {
5959
ActivityResultContracts.GetContent()
6060
) { uri ->
6161
if (uri == null) return@registerForActivityResult
62-
lifecycleScope.launch(Dispatchers.IO) {
62+
CoroutineScope(Dispatchers.IO).launch {
6363
ImportHelper.importSubscriptions(requireActivity(), uri, importFormat)
6464
}
6565
}

0 commit comments

Comments
 (0)