1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-01-08 16:30:34 +00:00

Only get subscription extractor when needed

This commit is contained in:
Isira Seneviratne 2024-12-01 06:24:26 +05:30
parent 673993272b
commit bcfe6285a4

View File

@ -37,20 +37,19 @@ class SubscriptionImportWorker(
override suspend fun doWork(): Result {
val mode = inputData.getInt(KEY_MODE, CHANNEL_URL_MODE)
val extractor = NewPipe.getService(inputData.getInt(KEY_SERVICE_ID, NO_SERVICE_ID))
.subscriptionExtractor
val value = inputData.getString(KEY_VALUE) ?: ""
val serviceId = inputData.getInt(KEY_SERVICE_ID, NO_SERVICE_ID)
val value = inputData.getString(KEY_VALUE)!!
val subscriptions = withContext(Dispatchers.IO) {
if (mode == CHANNEL_URL_MODE) {
extractor
NewPipe.getService(serviceId).subscriptionExtractor
.fromChannelUrl(value)
.map { SubscriptionItem(it.serviceId, it.url, it.name) }
} else {
applicationContext.contentResolver.openInputStream(value.toUri())?.use {
if (mode == INPUT_STREAM_MODE) {
val contentType = MimeTypeMap.getFileExtensionFromUrl(value).ifEmpty { DEFAULT_MIME }
extractor
NewPipe.getService(serviceId).subscriptionExtractor
.fromInputStream(it, contentType)
.map { SubscriptionItem(it.serviceId, it.url, it.name) }
} else {