@@ -17,6 +17,7 @@ import org.schabi.newpipe.database.subscription.NotificationMode
1717import org.schabi.newpipe.database.subscription.SubscriptionEntity
1818import org.schabi.newpipe.extractor.Info
1919import org.schabi.newpipe.extractor.NewPipe
20+ import org.schabi.newpipe.extractor.ServiceList
2021import org.schabi.newpipe.extractor.feed.FeedInfo
2122import org.schabi.newpipe.extractor.stream.StreamInfoItem
2223import org.schabi.newpipe.ktx.getStringSafe
@@ -90,9 +91,9 @@ class FeedLoadManager(private val context: Context) {
9091 else -> feedDatabaseManager.outdatedSubscriptionsForGroup(groupId, outdatedThreshold)
9192 }
9293
93- // like `currentProgress`, but counts the number of extractions that have begun, so they
94- // can be properly throttled every once in a while (see doOnNext below)
95- val extractionCount = AtomicInteger ()
94+ // like `currentProgress`, but counts the number of YouTube extractions that have begun, so
95+ // they can be properly throttled every once in a while (see doOnNext below)
96+ val youtubeExtractionCount = AtomicInteger ()
9697
9798 return outdatedSubscriptions
9899 .take(1 )
@@ -109,11 +110,13 @@ class FeedLoadManager(private val context: Context) {
109110 .observeOn(Schedulers .io())
110111 .flatMap { Flowable .fromIterable(it) }
111112 .takeWhile { ! cancelSignal.get() }
112- .doOnNext {
113- // throttle extractions once every BATCH_SIZE to avoid being throttled
114- val previousCount = extractionCount.getAndIncrement()
115- if (previousCount != 0 && previousCount % BATCH_SIZE == 0 ) {
116- Thread .sleep(DELAY_BETWEEN_BATCHES_MILLIS .random())
113+ .doOnNext { subscriptionEntity ->
114+ // throttle YouTube extractions once every BATCH_SIZE to avoid being rate limited
115+ if (subscriptionEntity.serviceId == ServiceList .YouTube .serviceId) {
116+ val previousCount = youtubeExtractionCount.getAndIncrement()
117+ if (previousCount != 0 && previousCount % BATCH_SIZE == 0 ) {
118+ Thread .sleep(DELAY_BETWEEN_BATCHES_MILLIS .random())
119+ }
117120 }
118121 }
119122 .parallel(PARALLEL_EXTRACTIONS , PARALLEL_EXTRACTIONS * 2 )
@@ -342,14 +345,14 @@ class FeedLoadManager(private val context: Context) {
342345 private const val PARALLEL_EXTRACTIONS = 3
343346
344347 /* *
345- * How many extractions to perform before waiting [DELAY_BETWEEN_BATCHES_MILLIS] to avoid
346- * being rate limited
348+ * How many YouTube extractions to perform before waiting [DELAY_BETWEEN_BATCHES_MILLIS]
349+ * to avoid being rate limited
347350 */
348351 private const val BATCH_SIZE = 50
349352
350353 /* *
351- * Wait a random delay in this range once every [BATCH_SIZE] extractions to avoid being
352- * rate limited
354+ * Wait a random delay in this range once every [BATCH_SIZE] YouTube extractions to avoid
355+ * being rate limited
353356 */
354357 private val DELAY_BETWEEN_BATCHES_MILLIS = (6000L .. 12000L )
355358
0 commit comments