Skip to content

Rework subscription import worker - #13608

Merged
theimpulson merged 4 commits into
devfrom
subscriptions
Jul 11, 2026
Merged

theimpulson merged 4 commits into
devfrom
subscriptions

Conversation

@theimpulson

@theimpulson theimpulson commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

  • Fixes OOM error when importing a large number of subscriptions as seen here
  • Fixes error when no video is found on channel as seen here
  • Fixes error due to service not going foreground in allowed time of 10s
  • Avoids crashing whole import if a channel is not found (banned for example noticed in the OOM import)

Fixes the following issue(s)

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

@github-actions github-actions Bot added the size/medium PRs with less than 250 changed lines label Jun 15, 2026
@theimpulson

Copy link
Copy Markdown
Member Author

This should fix most of the issues raised by @Stypox in #13347 (comment)

@theimpulson

Copy link
Copy Markdown
Member Author

I am not super happy with the notification being shown before channels are inserted into database but I assume there shouldn't a failure to insert the subscriptions into database in any case.

@AudricV AudricV added bug Issue is related to a bug ASAP Issue/PR needs to be adressed as soon as possible import/export Anything related to import/export of data and subscriptions regression A bug that didn't exist in prior versions but appeared after a certain change labels Jun 15, 2026

@Idadelveloper Idadelveloper left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if i missed it but is it deliberate that the user is not notified once import begins? Tried importing a csv and for a second i thought i did not work or my phone froze especially as there were so many items in the file. Will be nice if once the user uploads the file for youtube/soundcloud it leaves that import screen and return back to the subscriptions tab while the import happens. Remaining in the import screen plus the fact that there's no notification to tell the user the import is in progress does not do justice for the UX... or let me know what you think.

@theimpulson

Copy link
Copy Markdown
Member Author

Not sure if i missed it but is it deliberate that the user is not notified once import begins? Tried importing a csv and for a second i thought i did not work or my phone froze especially as there were so many items in the file. Will be nice if once the user uploads the file for youtube/soundcloud it leaves that import screen and return back to the subscriptions tab while the import happens. Remaining in the import screen plus the fact that there's no notification to tell the user the import is in progress does not do justice for the UX... or let me know what you think.

The UI part is indeed handled poorly overall in general. For example, we have a worker trying to update UI by toast, which in my opinion should be done by a notification instead. I will do another PR for changing UI behavior and would like this one to be focused on fixing bugs.

@Isira-Seneviratne Isira-Seneviratne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

@Stypox

Stypox commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

Thank you! I tested the APK from CI using the same data as in #13347 (comment).

I still got the following after importing a .csv file as a YouTube export:

21:13:35.512 26202-26317 SubscriptionImport      org...ous.subscriptions  E  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(r8-map-id-1f32333c5f9fccc65df0ec96b41e3917e6af81f7281dcd0c469e8838186c1f83:103)
                                                                             	at org.schabi.newpipe.local.subscription.workers.SubscriptionImportWorker$loadSubscriptionsFromInput$2.invokeSuspend(r8-map-id-1f32333c5f9fccc65df0ec96b41e3917e6af81f7281dcd0c469e8838186c1f83:156)
                                                                             	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(r8-map-id-1f32333c5f9fccc65df0ec96b41e3917e6af81f7281dcd0c469e8838186c1f83:8)
                                                                             	at kotlinx.coroutines.DispatchedTask.run(r8-map-id-1f32333c5f9fccc65df0ec96b41e3917e6af81f7281dcd0c469e8838186c1f83:114)
                                                                             	at androidx.core.app.ActivityRecreator$1.run(r8-map-id-1f32333c5f9fccc65df0ec96b41e3917e6af81f7281dcd0c469e8838186c1f83:13)
                                                                             	at kotlinx.coroutines.scheduling.TaskImpl.run(r8-map-id-1f32333c5f9fccc65df0ec96b41e3917e6af81f7281dcd0c469e8838186c1f83:3)
                                                                             	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(r8-map-id-1f32333c5f9fccc65df0ec96b41e3917e6af81f7281dcd0c469e8838186c1f83:88)

The same happens also with importing a .zip takeout file, although I did not really have a takeout file at my fingertips to test, so what I did was just zip the csv (which might not be representative). I guess you could switch back to StoredFileHelper to fix these issues as mentioned in #13347 (comment).

Importing a huge "previously exported" JSON works though (which is one of the big things that wasn't working before), so the memory issues seems fixed indeed.

Do you think it would be possible to write some Android tests to ensure we don't introduce regressions again in the future?

@github-actions github-actions Bot added size/large PRs with less than 750 changed lines and removed size/medium PRs with less than 250 changed lines labels Jun 29, 2026
@theimpulson

Copy link
Copy Markdown
Member Author

Zip part should be fixed now thanks to @djchittoor's commit. I will take a look at tests this week.

@sanket143

Copy link
Copy Markdown

It imports subscriptions, but not the channel groups. Is this expected?

theimpulson and others added 4 commits July 7, 2026 19:13
Signed-off-by: Aayush Gupta <contact@aayush.io>
After subscription import was moved from the Java service to the worker,
picked files were classified using only the URI string. Files selected
through Android's document picker may use opaque content URIs, so a
subscriptions.csv file from Downloads could be treated as
application/octet-stream and rejected before parsing.

The previous StoredFileHelper path has been restored. The document
provider is asked for the type first, with the picked file name used as
a fallback. This matches the behavior used before the worker refactor.
The resolver tests cover the octet-stream, missing-type, and
unknown-extension fallbacks. The extractor tests confirm that CSV and
Takeout zip inputs parse through the YouTube extractor once the
content type is resolved.

This keeps the regression coverage tied to the parser path that
rejected the Downloads import.
Import requests queued by older code can omit the explicit mode field.
That path must still be decoded as the previous export format while the
new channel URL and input stream modes keep their WorkManager payloads
stable.

The pure data tests cover those round trips and the invalid mode cases
without requiring the worker to be started.
@theimpulson

Copy link
Copy Markdown
Member Author

It imports subscriptions, but not the channel groups. Is this expected?

Was that working before?

@sanket143

Copy link
Copy Markdown

I don't know, but that was my expectation while importing.
This was the first time I used import, because of circumstances. Import failed in the released version, but I was able to import using this PR.

Added commented just in case it is a miss, because I was expecting it to import groups too but it's fine if it was there from the beginning.

Thanks.

@Stypox Stypox left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I tested again with the previously mentioned .csv, .json and .zip of 342 subscriptions, and it worked well even under averse network conditions. I did not test whether everything still works well with non-SAF, so someone could test that.

@theimpulson
theimpulson merged commit 96226a8 into dev Jul 11, 2026
5 checks passed
@theimpulson
theimpulson deleted the subscriptions branch July 11, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ASAP Issue/PR needs to be adressed as soon as possible bug Issue is related to a bug import/export Anything related to import/export of data and subscriptions regression A bug that didn't exist in prior versions but appeared after a certain change size/large PRs with less than 750 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[YouTube] Subscriptions import fails under certain scenarios

7 participants