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:
parent
673993272b
commit
bcfe6285a4
@ -37,20 +37,19 @@ class SubscriptionImportWorker(
|
|||||||
|
|
||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
val mode = inputData.getInt(KEY_MODE, CHANNEL_URL_MODE)
|
val mode = inputData.getInt(KEY_MODE, CHANNEL_URL_MODE)
|
||||||
val extractor = NewPipe.getService(inputData.getInt(KEY_SERVICE_ID, NO_SERVICE_ID))
|
val serviceId = inputData.getInt(KEY_SERVICE_ID, NO_SERVICE_ID)
|
||||||
.subscriptionExtractor
|
val value = inputData.getString(KEY_VALUE)!!
|
||||||
val value = inputData.getString(KEY_VALUE) ?: ""
|
|
||||||
|
|
||||||
val subscriptions = withContext(Dispatchers.IO) {
|
val subscriptions = withContext(Dispatchers.IO) {
|
||||||
if (mode == CHANNEL_URL_MODE) {
|
if (mode == CHANNEL_URL_MODE) {
|
||||||
extractor
|
NewPipe.getService(serviceId).subscriptionExtractor
|
||||||
.fromChannelUrl(value)
|
.fromChannelUrl(value)
|
||||||
.map { SubscriptionItem(it.serviceId, it.url, it.name) }
|
.map { SubscriptionItem(it.serviceId, it.url, it.name) }
|
||||||
} else {
|
} else {
|
||||||
applicationContext.contentResolver.openInputStream(value.toUri())?.use {
|
applicationContext.contentResolver.openInputStream(value.toUri())?.use {
|
||||||
if (mode == INPUT_STREAM_MODE) {
|
if (mode == INPUT_STREAM_MODE) {
|
||||||
val contentType = MimeTypeMap.getFileExtensionFromUrl(value).ifEmpty { DEFAULT_MIME }
|
val contentType = MimeTypeMap.getFileExtensionFromUrl(value).ifEmpty { DEFAULT_MIME }
|
||||||
extractor
|
NewPipe.getService(serviceId).subscriptionExtractor
|
||||||
.fromInputStream(it, contentType)
|
.fromInputStream(it, contentType)
|
||||||
.map { SubscriptionItem(it.serviceId, it.url, it.name) }
|
.map { SubscriptionItem(it.serviceId, it.url, it.name) }
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user