Port subscriptions related changes from refactor#13347
Port subscriptions related changes from refactor#13347theimpulson merged 2 commits intoTeamNewPipe:devfrom
Conversation
Please see TeamNewPipe#11759 for the original change Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
…iptions * create SubscriptionsImportExportHelper to share common code used in SubscriptionFragment and BackupRestoreSettingsFragment * Add UI options for import/export in BackupRestoreSettingsFragment
|
I don't think the functionality actually needs a dependency upon the rx3 library. I will do a separate PR to address that and then we can merge that in refactor as well. |
|
These changes broke importing subscriptions on Android, also pinging @Isira-Seneviratne as the original author of the changes in #11759. The previous code used The current code uses I would propose restoring the previous file-handling code both on To test this, just create a Error while loading subscriptions from path
org.schabi.newpipe.extractor.subscription.SubscriptionExtractor$InvalidSourceException: Not a valid source (Unsupported content type: application/octet-stream)
at org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSubscriptionExtractor.fromInputStream(YoutubeSubscriptionExtractor.java:67)
at org.schabi.newpipe.local.subscription.workers.SubscriptionImportWorker$loadSubscriptionsFromInput$2.invokeSuspend(SubscriptionImportWorker.kt:127)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34) |
|
Other issues I've found:
So maybe it's better to revert this PR altogether. And to keep things much simpler in general. I don't see a need to fetch I quickly hacked together something that allowed me to load 340 subscriptions for a friend:diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt
index 5cf378cc3..8d1650259 100644
--- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt
+++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt
@@ -50,13 +50,13 @@ class SubscriptionManager(context: Context) {
}
}
- fun upsertAll(infoList: List<Pair<ChannelInfo, ChannelTabInfo>>) {
+ fun upsertAll(infoList: List<Pair<ChannelInfo, ChannelTabInfo?>>) {
val listEntities = infoList.map { SubscriptionEntity.from(it.first) }
subscriptionTable.upsertAll(listEntities)
database.runInTransaction {
infoList.forEachIndexed { index, info ->
- val streams = info.second.relatedItems.filterIsInstance<StreamInfoItem>()
+ val streams = info.second?.relatedItems?.filterIsInstance<StreamInfoItem>() ?: listOf()
feedDatabaseManager.upsertAll(listEntities[index].uid, streams)
}
}
diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/workers/SubscriptionImportWorker.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/workers/SubscriptionImportWorker.kt
index cc8cf6f24..e33262429 100644
--- a/app/src/main/java/org/schabi/newpipe/local/subscription/workers/SubscriptionImportWorker.kt
+++ b/app/src/main/java/org/schabi/newpipe/local/subscription/workers/SubscriptionImportWorker.kt
@@ -2,6 +2,7 @@ package org.schabi.newpipe.local.subscription.workers
import android.content.Context
import android.content.pm.ServiceInfo
+import android.net.Uri
import android.os.Build
import android.os.Parcelable
import android.util.Log
@@ -26,7 +27,10 @@ import kotlinx.parcelize.Parcelize
import org.schabi.newpipe.BuildConfig
import org.schabi.newpipe.R
import org.schabi.newpipe.extractor.NewPipe
+import org.schabi.newpipe.extractor.channel.ChannelInfo
+import org.schabi.newpipe.extractor.channel.tabs.ChannelTabInfo
import org.schabi.newpipe.local.subscription.SubscriptionManager
+import org.schabi.newpipe.streams.io.StoredFileHelper
import org.schabi.newpipe.util.ExtractorHelper
class SubscriptionImportWorker(
@@ -59,25 +63,39 @@ class SubscriptionImportWorker(
val qty = subscriptions.size
var title =
applicationContext.resources.getQuantityString(R.plurals.load_subscriptions, qty, qty)
+ val subscriptionManager = SubscriptionManager(applicationContext)
val channelInfoList =
try {
- withContext(Dispatchers.IO.limitedParallelism(PARALLEL_EXTRACTIONS)) {
- subscriptions
- .map {
- async {
- val channelInfo =
- ExtractorHelper.getChannelInfo(it.serviceId, it.url, true).await()
+ withContext(Dispatchers.IO) {
+ subscriptions.forEach {
+ var currentName = ""
+ val res = try {
+ val channelInfo =
+ ExtractorHelper.getChannelInfo(it.serviceId, it.url, true).await()
+ currentName = channelInfo.name
+// if (channelInfo.tabs.isEmpty()) null else (channelInfo to null)
+ try {
val channelTab =
ExtractorHelper.getChannelTab(it.serviceId, channelInfo.tabs[0], true).await()
- val currentIndex = mutex.withLock { index++ }
- setForeground(createForegroundInfo(title, channelInfo.name, currentIndex, qty))
-
channelInfo to channelTab
+ } catch (e: Exception) {
+ Log.e(TAG, "Error while loading subscription data", e)
+ channelInfo to null
}
- }.awaitAll()
+ } catch (e: Exception) {
+ Log.e(TAG, "Error while loading subscription data", e)
+ null
+ }
+
+ val currentIndex = mutex.withLock { index++ }
+ setForeground(createForegroundInfo(title, currentName, currentIndex, qty))
+
+ res?.let { subscriptionManager.upsertAll(listOf(res)) }
+ }
}
+ listOf<Pair<ChannelInfo, ChannelTabInfo?>>()
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
Log.e(TAG, "Error while loading subscription data", e)
@@ -93,7 +111,6 @@ class SubscriptionImportWorker(
setForeground(createForegroundInfo(title, null, 0, 0))
index = 0
- val subscriptionManager = SubscriptionManager(applicationContext)
for (chunk in channelInfoList.chunked(BUFFER_COUNT_BEFORE_INSERT)) {
withContext(Dispatchers.IO) {
subscriptionManager.upsertAll(chunk)
@@ -123,7 +140,7 @@ class SubscriptionImportWorker(
val contentType =
MimeTypeMap.getFileExtensionFromUrl(input.url).ifEmpty { DEFAULT_MIME }
NewPipe.getService(input.serviceId).subscriptionExtractor
- .fromInputStream(it, contentType)
+ .fromInputStream(it, "text/csv")
.map { SubscriptionItem(it.serviceId, it.url, it.name) }
}
|
What is it?
refactorbranchDescription of the changes in your PR
APK testing
The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR. You can find more info and a video demonstration on this wiki page.
Due diligence