package com.strmr.ps.data.repository;

import androidx.credentials.exceptions.publickeycredential.DomExceptionUtils;
import com.google.android.gms.measurement.api.AppMeasurementSdk;
import com.strmr.ps.data.local.dao.InstalledAddonDao;
import com.strmr.ps.data.local.entity.InstalledAddonEntity;
import com.strmr.ps.data.model.addon.BundleAddonDef;
import com.strmr.ps.data.model.addon.DebridInjectionDef;
import com.strmr.ps.data.model.addon.StremioCatalog;
import com.strmr.ps.data.model.addon.StremioManifest;
import com.strmr.ps.data.model.addon.StrmrBundle;
import com.strmr.ps.data.repository.AddonRepository;
import com.strmr.ps.data.service.StremioAddonService;
import defpackage.ak1;
import defpackage.bz0;
import defpackage.ck1;
import defpackage.cp4;
import defpackage.cr4;
import defpackage.dp4;
import defpackage.dy4;
import defpackage.e6a;
import defpackage.f21;
import defpackage.fi7;
import defpackage.gr3;
import defpackage.io6;
import defpackage.iy4;
import defpackage.kq;
import defpackage.n89;
import defpackage.q38;
import defpackage.rz4;
import defpackage.s38;
import defpackage.to4;
import defpackage.vo0;
import defpackage.vx8;
import defpackage.y41;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.ExecutorService;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0003\u001a\b\u0012\u0004\u0012\u00020\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0003\u0010\u0004"}, d2 = {"Lak1;", "Lq38;", "Lcom/strmr/ps/data/repository/AddonRepository$BundleUpdateResult;", "<anonymous>", "(Lak1;)Lq38;"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.data.repository.AddonRepository$updateBundle$2", f = "AddonRepository.kt", i = {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5}, l = {445, 469, 524, 529, 535, 556}, m = "invokeSuspend", n = {"existingAddons", "bundleUrl", "jsonParser", "bundle", "addonDef", "oldVersion", "updatedCount", "newCount", "existingAddons", "bundleUrl", "jsonParser", "bundle", "addonDef", "oldVersion", "updatedCount", "newCount", "existingAddons", "bundleUrl", "jsonParser", "bundle", "addonDef", "manifest", "resolvedAddonId", "oldVersion", "updatedCount", "newCount", "existingAddons", "bundleUrl", "jsonParser", "bundle", "addonDef", "manifest", "resolvedAddonId", "oldVersion", "updatedCount", "newCount", "existingAddons", "bundleUrl", "jsonParser", "bundle", "addonDef", "instanceId", "oldVersion", "updatedCount", "newCount"}, s = {"L$0", "L$1", "L$2", "L$3", "L$5", "I$0", "I$1", "I$2", "L$0", "L$1", "L$2", "L$3", "L$5", "I$0", "I$1", "I$2", "L$0", "L$1", "L$2", "L$3", "L$5", "L$6", "L$7", "I$0", "I$1", "I$2", "L$0", "L$1", "L$2", "L$3", "L$5", "L$6", "L$7", "I$0", "I$1", "I$2", "L$0", "L$1", "L$2", "L$3", "L$5", "L$6", "I$0", "I$1", "I$2"})
@vx8
public final class AddonRepository$updateBundle$2 extends SuspendLambda implements gr3<ak1, Continuation<? super q38<? extends AddonRepository.BundleUpdateResult>>, Object> {
    final /* synthetic */ String $bundleId;
    int I$0;
    int I$1;
    int I$2;
    Object L$0;
    Object L$1;
    Object L$2;
    Object L$3;
    Object L$4;
    Object L$5;
    Object L$6;
    Object L$7;
    int label;
    final /* synthetic */ AddonRepository this$0;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public AddonRepository$updateBundle$2(String str, AddonRepository addonRepository, Continuation<? super AddonRepository$updateBundle$2> continuation) {
        super(2, continuation);
        this.$bundleId = str;
        this.this$0 = addonRepository;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final e6a invokeSuspend$lambda$0(iy4 iy4Var) {
        iy4Var.b = true;
        return e6a.a;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
        return new AddonRepository$updateBundle$2(this.$bundleId, this.this$0, continuation);
    }

    @Override // defpackage.gr3
    public final Object invoke(ak1 ak1Var, Continuation<? super q38<AddonRepository.BundleUpdateResult>> continuation) {
        return ((AddonRepository$updateBundle$2) create(ak1Var, continuation)).invokeSuspend(e6a.a);
    }

    /* JADX WARN: Can't wrap try/catch for region: R(11:195|196|197|410|198|(5:382|200|(0)|213|(15:216|17|447|217|218|435|219|408|220|(4:223|(1:307)(32:456|225|(31:415|227|(0)|229|429|234|(6:380|236|237|400|238|239)(1:245)|378|246|(2:248|249)(1:250)|251|252|374|253|254|396|255|256|417|257|(1:259)(1:260)|261|(3:439|263|264)(1:267)|268|269|425|270|271|445|272|(13:275|9|276|449|277|278|431|279|280|212|180|57|(0)(0)))|233|229|429|234|(0)(0)|378|246|(0)(0)|251|252|374|253|254|396|255|256|417|257|(0)(0)|261|(0)(0)|268|269|425|270|271|445|272|(0))|372|221)|457|310|402|311|312))|205|(3:208|(7:453|210|211|212|180|57|(0)(0))(1:455)|206)|454|213|(0)) */
    /* JADX WARN: Can't wrap try/catch for region: R(12:174|26|175|404|176|177|386|178|179|180|57|(6:352|(1:355)|356|357|366|367)(0)) */
    /* JADX WARN: Can't wrap try/catch for region: R(13:275|9|276|449|277|278|431|279|280|212|180|57|(0)(0)) */
    /* JADX WARN: Can't wrap try/catch for region: R(15:216|17|447|217|218|435|219|408|220|(4:223|(1:307)(32:456|225|(31:415|227|(0)|229|429|234|(6:380|236|237|400|238|239)(1:245)|378|246|(2:248|249)(1:250)|251|252|374|253|254|396|255|256|417|257|(1:259)(1:260)|261|(3:439|263|264)(1:267)|268|269|425|270|271|445|272|(13:275|9|276|449|277|278|431|279|280|212|180|57|(0)(0)))|233|229|429|234|(0)(0)|378|246|(0)(0)|251|252|374|253|254|396|255|256|417|257|(0)(0)|261|(0)(0)|268|269|425|270|271|445|272|(0))|372|221)|457|310|402|311|312) */
    /* JADX WARN: Can't wrap try/catch for region: R(32:456|225|(31:415|227|(0)|229|429|234|(6:380|236|237|400|238|239)(1:245)|378|246|(2:248|249)(1:250)|251|252|374|253|254|396|255|256|417|257|(1:259)(1:260)|261|(3:439|263|264)(1:267)|268|269|425|270|271|445|272|(13:275|9|276|449|277|278|431|279|280|212|180|57|(0)(0)))|233|229|429|234|(0)(0)|378|246|(0)(0)|251|252|374|253|254|396|255|256|417|257|(0)(0)|261|(0)(0)|268|269|425|270|271|445|272|(0)) */
    /* JADX WARN: Can't wrap try/catch for region: R(34:(1:384)|92|(2:94|95)(1:96)|97|(5:394|99|100|423|101)(1:107)|376|108|(30:110|(5:113|(1:115)(2:116|(2:118|(1:120)(1:121))(0))|(2:123|459)(1:460)|124|111)|458|125|(0)|128|388|132|(1:134)(1:136)|433|137|(1:139)(1:141)|142|(1:144)|145|146|(1:148)|149|(1:151)|152|(1:154)|155|156|(2:158|159)(1:160)|161|(1:163)(1:164)|165|(1:170)(1:(1:168)(1:169))|171|(12:174|26|175|404|176|177|386|178|179|180|57|(6:352|(1:355)|356|357|366|367)(0)))(1:129)|130|128|388|132|(0)(0)|433|137|(0)(0)|142|(0)|145|146|(0)|149|(0)|152|(0)|155|156|(0)(0)|161|(0)(0)|165|(0)(0)|171|(0)) */
    /* JADX WARN: Can't wrap try/catch for region: R(34:384|92|(2:94|95)(1:96)|97|(5:394|99|100|423|101)(1:107)|376|108|(30:110|(5:113|(1:115)(2:116|(2:118|(1:120)(1:121))(0))|(2:123|459)(1:460)|124|111)|458|125|(0)|128|388|132|(1:134)(1:136)|433|137|(1:139)(1:141)|142|(1:144)|145|146|(1:148)|149|(1:151)|152|(1:154)|155|156|(2:158|159)(1:160)|161|(1:163)(1:164)|165|(1:170)(1:(1:168)(1:169))|171|(12:174|26|175|404|176|177|386|178|179|180|57|(6:352|(1:355)|356|357|366|367)(0)))(1:129)|130|128|388|132|(0)(0)|433|137|(0)(0)|142|(0)|145|146|(0)|149|(0)|152|(0)|155|156|(0)(0)|161|(0)(0)|165|(0)(0)|171|(0)) */
    /* JADX WARN: Can't wrap try/catch for region: R(4:223|(1:307)(32:456|225|(31:415|227|(0)|229|429|234|(6:380|236|237|400|238|239)(1:245)|378|246|(2:248|249)(1:250)|251|252|374|253|254|396|255|256|417|257|(1:259)(1:260)|261|(3:439|263|264)(1:267)|268|269|425|270|271|445|272|(13:275|9|276|449|277|278|431|279|280|212|180|57|(0)(0)))|233|229|429|234|(0)(0)|378|246|(0)(0)|251|252|374|253|254|396|255|256|417|257|(0)(0)|261|(0)(0)|268|269|425|270|271|445|272|(0))|372|221) */
    /* JADX WARN: Can't wrap try/catch for region: R(5:394|99|100|423|101) */
    /* JADX WARN: Can't wrap try/catch for region: R(6:(1:441)|77|78|427|79|(1:82)) */
    /* JADX WARN: Can't wrap try/catch for region: R(6:380|236|237|400|238|239) */
    /* JADX WARN: Can't wrap try/catch for region: R(7:333|334|390|335|336|57|(0)(0)) */
    /* JADX WARN: Can't wrap try/catch for region: R(8:392|68|(1:70)|74|(2:75|(6:441|77|78|427|79|(1:82))(2:452|89))|398|90|(34:384|92|(2:94|95)(1:96)|97|(5:394|99|100|423|101)(1:107)|376|108|(30:110|(5:113|(1:115)(2:116|(2:118|(1:120)(1:121))(0))|(2:123|459)(1:460)|124|111)|458|125|(0)|128|388|132|(1:134)(1:136)|433|137|(1:139)(1:141)|142|(1:144)|145|146|(1:148)|149|(1:151)|152|(1:154)|155|156|(2:158|159)(1:160)|161|(1:163)(1:164)|165|(1:170)(1:(1:168)(1:169))|171|(12:174|26|175|404|176|177|386|178|179|180|57|(6:352|(1:355)|356|357|366|367)(0)))(1:129)|130|128|388|132|(0)(0)|433|137|(0)(0)|142|(0)|145|146|(0)|149|(0)|152|(0)|155|156|(0)(0)|161|(0)(0)|165|(0)(0)|171|(0))(4:191|419|192|(1:194)(11:195|196|197|410|198|(5:382|200|(0)|213|(15:216|17|447|217|218|435|219|408|220|(4:223|(1:307)(32:456|225|(31:415|227|(0)|229|429|234|(6:380|236|237|400|238|239)(1:245)|378|246|(2:248|249)(1:250)|251|252|374|253|254|396|255|256|417|257|(1:259)(1:260)|261|(3:439|263|264)(1:267)|268|269|425|270|271|445|272|(13:275|9|276|449|277|278|431|279|280|212|180|57|(0)(0)))|233|229|429|234|(0)(0)|378|246|(0)(0)|251|252|374|253|254|396|255|256|417|257|(0)(0)|261|(0)(0)|268|269|425|270|271|445|272|(0))|372|221)|457|310|402|311|312))|205|(3:208|(7:453|210|211|212|180|57|(0)(0))(1:455)|206)|454|213|(0)))) */
    /* JADX WARN: Can't wrap try/catch for region: R(8:59|(1:443)|60|61|437|62|(4:65|370|66|(8:392|68|(1:70)|74|(2:75|(6:441|77|78|427|79|(1:82))(2:452|89))|398|90|(34:384|92|(2:94|95)(1:96)|97|(5:394|99|100|423|101)(1:107)|376|108|(30:110|(5:113|(1:115)(2:116|(2:118|(1:120)(1:121))(0))|(2:123|459)(1:460)|124|111)|458|125|(0)|128|388|132|(1:134)(1:136)|433|137|(1:139)(1:141)|142|(1:144)|145|146|(1:148)|149|(1:151)|152|(1:154)|155|156|(2:158|159)(1:160)|161|(1:163)(1:164)|165|(1:170)(1:(1:168)(1:169))|171|(12:174|26|175|404|176|177|386|178|179|180|57|(6:352|(1:355)|356|357|366|367)(0)))(1:129)|130|128|388|132|(0)(0)|433|137|(0)(0)|142|(0)|145|146|(0)|149|(0)|152|(0)|155|156|(0)(0)|161|(0)(0)|165|(0)(0)|171|(0))(4:191|419|192|(1:194)(11:195|196|197|410|198|(5:382|200|(0)|213|(15:216|17|447|217|218|435|219|408|220|(4:223|(1:307)(32:456|225|(31:415|227|(0)|229|429|234|(6:380|236|237|400|238|239)(1:245)|378|246|(2:248|249)(1:250)|251|252|374|253|254|396|255|256|417|257|(1:259)(1:260)|261|(3:439|263|264)(1:267)|268|269|425|270|271|445|272|(13:275|9|276|449|277|278|431|279|280|212|180|57|(0)(0)))|233|229|429|234|(0)(0)|378|246|(0)(0)|251|252|374|253|254|396|255|256|417|257|(0)(0)|261|(0)(0)|268|269|425|270|271|445|272|(0))|372|221)|457|310|402|311|312))|205|(3:208|(7:453|210|211|212|180|57|(0)(0))(1:455)|206)|454|213|(0))))(10:330|406|331|(7:333|334|390|335|336|57|(0)(0))(2:341|342)|337|338|349|451|57|(0)(0)))|274) */
    /* JADX WARN: Code restructure failed: missing block: B:103:0x0312, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:104:0x0313, code lost:
    
        r18 = r6;
        r5 = r8;
        r8 = r10;
        r9 = r23;
        r7 = r56;
        r2 = r2;
     */
    /* JADX WARN: Code restructure failed: missing block: B:181:0x04a0, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:182:0x04a1, code lost:
    
        r18 = r6;
        r2 = r2;
     */
    /* JADX WARN: Code restructure failed: missing block: B:183:0x04a5, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:184:0x04a6, code lost:
    
        r7 = r56;
     */
    /* JADX WARN: Code restructure failed: missing block: B:185:0x04a9, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:186:0x04aa, code lost:
    
        r7 = r56;
     */
    /* JADX WARN: Code restructure failed: missing block: B:187:0x04ac, code lost:
    
        r18 = r6;
     */
    /* JADX WARN: Code restructure failed: missing block: B:240:0x05e7, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:241:0x05e8, code lost:
    
        r5 = r6;
        r18 = r7;
     */
    /* JADX WARN: Code restructure failed: missing block: B:242:0x05eb, code lost:
    
        r8 = r14;
        r12 = r15;
        r9 = r23;
        r11 = r52;
        r7 = r56;
     */
    /* JADX WARN: Code restructure failed: missing block: B:281:0x06fb, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:284:0x0701, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:285:0x0702, code lost:
    
        r10 = r56;
     */
    /* JADX WARN: Code restructure failed: missing block: B:286:0x0705, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:287:0x0706, code lost:
    
        r10 = r56;
     */
    /* JADX WARN: Code restructure failed: missing block: B:288:0x070a, code lost:
    
        r13 = r5;
     */
    /* JADX WARN: Code restructure failed: missing block: B:289:0x070b, code lost:
    
        r5 = r6;
        r8 = r14;
        r12 = r15;
     */
    /* JADX WARN: Code restructure failed: missing block: B:291:0x0711, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:292:0x0712, code lost:
    
        r9 = r5;
     */
    /* JADX WARN: Code restructure failed: missing block: B:293:0x0715, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:294:0x0716, code lost:
    
        r9 = r5;
        r11 = r52;
     */
    /* JADX WARN: Code restructure failed: missing block: B:295:0x071b, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:296:0x071c, code lost:
    
        r9 = r5;
        r18 = r7;
        r5 = r17;
        r11 = r52;
        r10 = r56;
        r7 = r59;
     */
    /* JADX WARN: Code restructure failed: missing block: B:297:0x072a, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:298:0x072b, code lost:
    
        r9 = r5;
        r18 = r7;
     */
    /* JADX WARN: Code restructure failed: missing block: B:299:0x072e, code lost:
    
        r11 = r52;
        r10 = r56;
     */
    /* JADX WARN: Code restructure failed: missing block: B:300:0x0735, code lost:
    
        r7 = r59;
     */
    /* JADX WARN: Code restructure failed: missing block: B:301:0x0738, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:302:0x0739, code lost:
    
        r18 = r7;
        r9 = r10;
     */
    /* JADX WARN: Code restructure failed: missing block: B:303:0x073d, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:304:0x073e, code lost:
    
        r9 = r10;
     */
    /* JADX WARN: Code restructure failed: missing block: B:305:0x0740, code lost:
    
        r11 = r52;
     */
    /* JADX WARN: Code restructure failed: missing block: B:306:0x0744, code lost:
    
        r10 = r7;
     */
    /* JADX WARN: Code restructure failed: missing block: B:308:0x074f, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:309:0x0750, code lost:
    
        r9 = r10;
     */
    /* JADX WARN: Code restructure failed: missing block: B:315:0x076d, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:316:0x076e, code lost:
    
        r9 = r10;
        r17 = r13;
        r11 = r52;
        r10 = r7;
        r7 = r59;
     */
    /* JADX WARN: Code restructure failed: missing block: B:317:0x0779, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:318:0x077a, code lost:
    
        r9 = r10;
        r11 = r52;
     */
    /* JADX WARN: Code restructure failed: missing block: B:319:0x0782, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:320:0x0783, code lost:
    
        r9 = r10;
        r11 = r52;
        r10 = r7;
        r7 = r8;
     */
    /* JADX WARN: Code restructure failed: missing block: B:321:0x078e, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:325:0x0799, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:326:0x079a, code lost:
    
        r18 = r6;
     */
    /* JADX WARN: Code restructure failed: missing block: B:327:0x079c, code lost:
    
        r7 = r9;
     */
    /* JADX WARN: Code restructure failed: missing block: B:345:0x07f9, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:346:0x07fa, code lost:
    
        r16 = r9;
        r9 = r7;
        r7 = r16;
        r18 = r6;
        r5 = r17;
        r2 = r2;
     */
    /* JADX WARN: Code restructure failed: missing block: B:83:0x02be, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:84:0x02bf, code lost:
    
        r18 = r6;
        r5 = r8;
        r7 = r9;
        r2 = r2;
     */
    /* JADX WARN: Finally extract failed */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Not initialized variable reg: 10, insn: 0x009d: MOVE (r5 I:??[OBJECT, ARRAY]) = (r10 I:??[OBJECT, ARRAY]), block:B:19:0x0098 */
    /* JADX WARN: Path cross not found for [B:205:0x04f6, B:382:0x04ea], limit reached: 447 */
    /* JADX WARN: Path cross not found for [B:382:0x04ea, B:205:0x04f6], limit reached: 447 */
    /* JADX WARN: Path cross not found for [B:415:0x058c, B:233:0x05a7], limit reached: 447 */
    /* JADX WARN: Removed duplicated region for block: B:121:0x035d  */
    /* JADX WARN: Removed duplicated region for block: B:134:0x0394 A[Catch: Exception -> 0x039f, TRY_LEAVE, TryCatch #9 {Exception -> 0x039f, blocks: (B:132:0x0387, B:134:0x0394), top: B:388:0x0387 }] */
    /* JADX WARN: Removed duplicated region for block: B:136:0x039f  */
    /* JADX WARN: Removed duplicated region for block: B:139:0x03af A[Catch: Exception -> 0x03ba, TRY_LEAVE, TryCatch #34 {Exception -> 0x03ba, blocks: (B:137:0x03a0, B:139:0x03af), top: B:433:0x03a0 }] */
    /* JADX WARN: Removed duplicated region for block: B:141:0x03ba  */
    /* JADX WARN: Removed duplicated region for block: B:144:0x03c9 A[Catch: Exception -> 0x0312, TRY_ENTER, TRY_LEAVE, TryCatch #28 {Exception -> 0x0312, blocks: (B:101:0x02ff, B:110:0x032a, B:111:0x0335, B:113:0x033b, B:115:0x0347, B:123:0x0360, B:116:0x034a, B:118:0x034e, B:120:0x035a, B:125:0x0368, B:144:0x03c9, B:148:0x03d5, B:151:0x03dd, B:154:0x03e5, B:158:0x03f1), top: B:423:0x02ff }] */
    /* JADX WARN: Removed duplicated region for block: B:148:0x03d5 A[Catch: Exception -> 0x0312, TRY_ENTER, TryCatch #28 {Exception -> 0x0312, blocks: (B:101:0x02ff, B:110:0x032a, B:111:0x0335, B:113:0x033b, B:115:0x0347, B:123:0x0360, B:116:0x034a, B:118:0x034e, B:120:0x035a, B:125:0x0368, B:144:0x03c9, B:148:0x03d5, B:151:0x03dd, B:154:0x03e5, B:158:0x03f1), top: B:423:0x02ff }] */
    /* JADX WARN: Removed duplicated region for block: B:151:0x03dd A[Catch: Exception -> 0x0312, TryCatch #28 {Exception -> 0x0312, blocks: (B:101:0x02ff, B:110:0x032a, B:111:0x0335, B:113:0x033b, B:115:0x0347, B:123:0x0360, B:116:0x034a, B:118:0x034e, B:120:0x035a, B:125:0x0368, B:144:0x03c9, B:148:0x03d5, B:151:0x03dd, B:154:0x03e5, B:158:0x03f1), top: B:423:0x02ff }] */
    /* JADX WARN: Removed duplicated region for block: B:154:0x03e5 A[Catch: Exception -> 0x0312, TRY_LEAVE, TryCatch #28 {Exception -> 0x0312, blocks: (B:101:0x02ff, B:110:0x032a, B:111:0x0335, B:113:0x033b, B:115:0x0347, B:123:0x0360, B:116:0x034a, B:118:0x034e, B:120:0x035a, B:125:0x0368, B:144:0x03c9, B:148:0x03d5, B:151:0x03dd, B:154:0x03e5, B:158:0x03f1), top: B:423:0x02ff }] */
    /* JADX WARN: Removed duplicated region for block: B:158:0x03f1 A[Catch: Exception -> 0x0312, TRY_ENTER, TRY_LEAVE, TryCatch #28 {Exception -> 0x0312, blocks: (B:101:0x02ff, B:110:0x032a, B:111:0x0335, B:113:0x033b, B:115:0x0347, B:123:0x0360, B:116:0x034a, B:118:0x034e, B:120:0x035a, B:125:0x0368, B:144:0x03c9, B:148:0x03d5, B:151:0x03dd, B:154:0x03e5, B:158:0x03f1), top: B:423:0x02ff }] */
    /* JADX WARN: Removed duplicated region for block: B:160:0x03f8  */
    /* JADX WARN: Removed duplicated region for block: B:163:0x0408  */
    /* JADX WARN: Removed duplicated region for block: B:164:0x040b A[Catch: Exception -> 0x04a9, TryCatch #3 {Exception -> 0x04a9, blocks: (B:108:0x0324, B:142:0x03bb, B:146:0x03cf, B:156:0x03eb, B:161:0x03fa, B:165:0x0411, B:171:0x0429, B:170:0x0423, B:164:0x040b, B:130:0x0382), top: B:376:0x0324 }] */
    /* JADX WARN: Removed duplicated region for block: B:167:0x041b  */
    /* JADX WARN: Removed duplicated region for block: B:170:0x0423 A[Catch: Exception -> 0x04a9, TryCatch #3 {Exception -> 0x04a9, blocks: (B:108:0x0324, B:142:0x03bb, B:146:0x03cf, B:156:0x03eb, B:161:0x03fa, B:165:0x0411, B:171:0x0429, B:170:0x0423, B:164:0x040b, B:130:0x0382), top: B:376:0x0324 }] */
    /* JADX WARN: Removed duplicated region for block: B:174:0x0479  */
    /* JADX WARN: Removed duplicated region for block: B:208:0x0500 A[Catch: Exception -> 0x04f4, TRY_ENTER, TryCatch #6 {Exception -> 0x04f4, blocks: (B:200:0x04ea, B:208:0x0500, B:210:0x050c), top: B:382:0x04ea }] */
    /* JADX WARN: Removed duplicated region for block: B:216:0x0559  */
    /* JADX WARN: Removed duplicated region for block: B:223:0x0578 A[Catch: Exception -> 0x074f, TRY_ENTER, TRY_LEAVE, TryCatch #19 {Exception -> 0x074f, blocks: (B:220:0x056d, B:223:0x0578), top: B:408:0x056d }] */
    /* JADX WARN: Removed duplicated region for block: B:245:0x05fb  */
    /* JADX WARN: Removed duplicated region for block: B:248:0x0607 A[Catch: Exception -> 0x05e7, TRY_ENTER, TRY_LEAVE, TryCatch #15 {Exception -> 0x05e7, blocks: (B:238:0x05da, B:248:0x0607), top: B:400:0x05da }] */
    /* JADX WARN: Removed duplicated region for block: B:250:0x0614  */
    /* JADX WARN: Removed duplicated region for block: B:259:0x0636  */
    /* JADX WARN: Removed duplicated region for block: B:260:0x0639  */
    /* JADX WARN: Removed duplicated region for block: B:267:0x065a  */
    /* JADX WARN: Removed duplicated region for block: B:275:0x06c4  */
    /* JADX WARN: Removed duplicated region for block: B:330:0x07a4  */
    /* JADX WARN: Removed duplicated region for block: B:352:0x083b  */
    /* JADX WARN: Removed duplicated region for block: B:380:0x05c6 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:382:0x04ea A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:392:0x0281 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:40:0x0178 A[Catch: Exception -> 0x013d, TryCatch #32 {Exception -> 0x013d, blocks: (B:57:0x023d, B:59:0x0243, B:30:0x0137, B:38:0x0170, B:40:0x0178, B:42:0x0195, B:44:0x01a1, B:46:0x01be, B:48:0x01ca, B:50:0x01d0, B:52:0x01f9, B:54:0x021d, B:56:0x022e, B:35:0x015d), top: B:414:0x0010 }] */
    /* JADX WARN: Removed duplicated region for block: B:42:0x0195 A[Catch: Exception -> 0x013d, TryCatch #32 {Exception -> 0x013d, blocks: (B:57:0x023d, B:59:0x0243, B:30:0x0137, B:38:0x0170, B:40:0x0178, B:42:0x0195, B:44:0x01a1, B:46:0x01be, B:48:0x01ca, B:50:0x01d0, B:52:0x01f9, B:54:0x021d, B:56:0x022e, B:35:0x015d), top: B:414:0x0010 }] */
    /* JADX WARN: Removed duplicated region for block: B:439:0x0641 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:59:0x0243 A[Catch: Exception -> 0x013d, TRY_LEAVE, TryCatch #32 {Exception -> 0x013d, blocks: (B:57:0x023d, B:59:0x0243, B:30:0x0137, B:38:0x0170, B:40:0x0178, B:42:0x0195, B:44:0x01a1, B:46:0x01be, B:48:0x01ca, B:50:0x01d0, B:52:0x01f9, B:54:0x021d, B:56:0x022e, B:35:0x015d), top: B:414:0x0010 }] */
    /* JADX WARN: Type inference failed for: r0v118, types: [java.lang.StringBuilder] */
    /* JADX WARN: Type inference failed for: r22v1 */
    /* JADX WARN: Type inference failed for: r2v10 */
    /* JADX WARN: Type inference failed for: r2v11 */
    /* JADX WARN: Type inference failed for: r2v12 */
    /* JADX WARN: Type inference failed for: r2v13 */
    /* JADX WARN: Type inference failed for: r2v14, types: [int] */
    /* JADX WARN: Type inference failed for: r2v15, types: [int] */
    /* JADX WARN: Type inference failed for: r2v16 */
    /* JADX WARN: Type inference failed for: r2v17, types: [int] */
    /* JADX WARN: Type inference failed for: r2v18, types: [int] */
    /* JADX WARN: Type inference failed for: r2v19 */
    /* JADX WARN: Type inference failed for: r2v20 */
    /* JADX WARN: Type inference failed for: r2v21, types: [int] */
    /* JADX WARN: Type inference failed for: r2v22, types: [int] */
    /* JADX WARN: Type inference failed for: r2v27 */
    /* JADX WARN: Type inference failed for: r2v39 */
    /* JADX WARN: Type inference failed for: r2v40 */
    /* JADX WARN: Type inference failed for: r2v41 */
    /* JADX WARN: Type inference failed for: r2v42 */
    /* JADX WARN: Type inference failed for: r2v43 */
    /* JADX WARN: Type inference failed for: r2v44 */
    /* JADX WARN: Type inference failed for: r2v45 */
    /* JADX WARN: Type inference failed for: r2v46 */
    /* JADX WARN: Type inference failed for: r2v47 */
    /* JADX WARN: Type inference failed for: r2v48 */
    /* JADX WARN: Type inference failed for: r2v49 */
    /* JADX WARN: Type inference failed for: r2v5 */
    /* JADX WARN: Type inference failed for: r2v50 */
    /* JADX WARN: Type inference failed for: r2v51 */
    /* JADX WARN: Type inference failed for: r2v52 */
    /* JADX WARN: Type inference failed for: r2v53 */
    /* JADX WARN: Type inference failed for: r2v54 */
    /* JADX WARN: Type inference failed for: r2v55 */
    /* JADX WARN: Type inference failed for: r2v56 */
    /* JADX WARN: Type inference failed for: r2v57 */
    /* JADX WARN: Type inference failed for: r2v58 */
    /* JADX WARN: Type inference failed for: r2v59 */
    /* JADX WARN: Type inference failed for: r2v6 */
    /* JADX WARN: Type inference failed for: r2v60 */
    /* JADX WARN: Type inference failed for: r2v61 */
    /* JADX WARN: Type inference failed for: r2v62 */
    /* JADX WARN: Type inference failed for: r2v63 */
    /* JADX WARN: Type inference failed for: r2v64 */
    /* JADX WARN: Type inference failed for: r2v65 */
    /* JADX WARN: Type inference failed for: r2v66 */
    /* JADX WARN: Type inference failed for: r2v67 */
    /* JADX WARN: Type inference failed for: r2v68 */
    /* JADX WARN: Type inference failed for: r2v69 */
    /* JADX WARN: Type inference failed for: r2v7 */
    /* JADX WARN: Type inference failed for: r2v70 */
    /* JADX WARN: Type inference failed for: r2v8 */
    /* JADX WARN: Type inference failed for: r2v9 */
    /* JADX WARN: Unreachable blocks removed: 2, instructions: 7 */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:179:0x049b -> B:180:0x049c). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:211:0x052b -> B:212:0x052e). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:275:0x06c4 -> B:9:0x0046). Please report as a decompilation issue!!! */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        String str;
        String str2;
        String str3;
        List list;
        List list2;
        Object objA;
        ?? r2;
        String str4;
        String str5;
        StrmrBundle strmrBundle;
        Iterator<BundleAddonDef> it;
        BundleAddonDef next;
        int i;
        String str6;
        dy4 dy4VarA;
        ?? r22;
        dy4 dy4Var;
        List list3;
        ?? r23;
        ?? r24;
        ?? r25;
        String str7;
        ?? r26;
        dy4 dy4Var2;
        StremioManifest stremioManifest;
        Iterator<BundleAddonDef> it2;
        List list4;
        String id;
        Object usedInstanceNumbers;
        StrmrBundle strmrBundle2;
        Iterator<BundleAddonDef> it3;
        Iterator<Integer> it4;
        String str8;
        String str9;
        String string;
        DebridInjectionDef debridInjection;
        String type;
        InstalledAddonEntity installedAddonEntityCopy$default;
        InstalledAddonDao installedAddonDao;
        String str10;
        Object addonsByAddonId;
        List list5;
        Iterator it5;
        Object objB;
        StremioAddonService.c cVar;
        Object next2;
        String str11;
        String str12;
        String capabilities;
        String json;
        String json2;
        String version;
        String description;
        InstalledAddonEntity installedAddonEntityCopy$default2;
        InstalledAddonDao installedAddonDao2;
        String str13;
        ?? r27;
        ?? r28;
        Object addonsByBundleId;
        List list6;
        StrmrBundle strmrBundle3;
        String str14 = "No addons found for bundle: ";
        ck1 ck1Var = ck1.a;
        int i2 = this.label;
        String str15 = DomExceptionUtils.SEPARATOR;
        String str16 = ": ";
        String str17 = "AddonRepository";
        try {
            try {
                try {
                } catch (Exception e) {
                    e = e;
                    str = ": ";
                    str2 = "AddonRepository";
                    r2 = str14;
                    str3 = str15;
                    r24 = r2;
                    r23 = r24;
                    ExecutorService executorService = kq.a;
                    kq.a(str2, "Bundle update: failed for " + next.getName() + str + e.getMessage(), null);
                    String str18 = str;
                    str17 = str2;
                    str16 = str18;
                    str15 = str3;
                    if (!it.hasNext()) {
                    }
                }
            } catch (Exception e2) {
                e = e2;
                str = ": ";
                str2 = "AddonRepository";
                str3 = DomExceptionUtils.SEPARATOR;
                list2 = list;
                r24 = str14;
                r23 = r24;
                ExecutorService executorService2 = kq.a;
                kq.a(str2, "Bundle update: failed for " + next.getName() + str + e.getMessage(), null);
                String str182 = str;
                str17 = str2;
                str16 = str182;
                str15 = str3;
                if (!it.hasNext()) {
                }
            }
        } catch (Exception e3) {
            e = e3;
            str17 = ": ";
            str16 = "AddonRepository";
        }
        switch (i2) {
            case 0:
                s38.b(obj);
                ExecutorService executorService3 = kq.a;
                kq.h("AddonRepository", "Updating bundle: " + this.$bundleId);
                InstalledAddonDao installedAddonDao3 = this.this$0.addonDao;
                String str19 = this.$bundleId;
                this.label = 1;
                addonsByBundleId = installedAddonDao3.getAddonsByBundleId(str19, this);
                if (addonsByBundleId == ck1Var) {
                    return ck1Var;
                }
                list6 = (List) addonsByBundleId;
                if (!list6.isEmpty()) {
                    return new q38(s38.a(new IllegalStateException("No addons found for bundle: " + this.$bundleId)));
                }
                String bundleUrl = ((InstalledAddonEntity) y41.z(list6)).getBundleUrl();
                if (bundleUrl == null) {
                    return new q38(s38.a(new IllegalStateException("No bundle URL stored for: " + this.$bundleId)));
                }
                Integer bundleVersion = ((InstalledAddonEntity) y41.z(list6)).getBundleVersion();
                int iIntValue = bundleVersion != null ? bundleVersion.intValue() : 0;
                URL url = new URL(bundleUrl);
                Charset charset = bz0.a;
                InputStream inputStreamOpenStream = url.openStream();
                try {
                    try {
                        cr4.d(inputStreamOpenStream);
                        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(Math.max(8192, inputStreamOpenStream.available()));
                        vo0.a(inputStreamOpenStream, byteArrayOutputStream);
                        byte[] byteArray = byteArrayOutputStream.toByteArray();
                        cr4.f(byteArray, "toByteArray(...)");
                        inputStreamOpenStream.close();
                        String str20 = new String(byteArray, charset);
                        dy4VarA = rz4.a(new a(2));
                        strmrBundle3 = (StrmrBundle) dy4VarA.c(StrmrBundle.INSTANCE.serializer(), str20);
                    } catch (Throwable th) {
                        str17 = ": ";
                        str16 = "AddonRepository";
                        try {
                            throw th;
                        } catch (Throwable th2) {
                            f21.a(inputStreamOpenStream, th);
                            throw th2;
                        }
                    }
                } catch (Exception e4) {
                    e = e4;
                    ExecutorService executorService4 = kq.a;
                    kq.a(str16, fi7.h("Failed to update bundle ", this.$bundleId, str17, e.getMessage()), null);
                    objA = s38.a(e);
                }
                if (!strmrBundle3.getStrmrBundle()) {
                    return new q38(s38.a(new IllegalArgumentException("Not a valid strmr bundle")));
                }
                i = iIntValue;
                str6 = bundleUrl;
                strmrBundle = strmrBundle3;
                it = strmrBundle3.getAddons().iterator();
                r23 = 0;
                list2 = list6;
                i2 = 0;
                if (!it.hasNext()) {
                    next = it.next();
                    try {
                    } catch (Exception e5) {
                        e = e5;
                        String str21 = str17;
                        str = str16;
                        str2 = str21;
                        r2 = r23;
                        str3 = str15;
                        r24 = r2;
                        r23 = r24;
                        ExecutorService executorService22 = kq.a;
                        kq.a(str2, "Bundle update: failed for " + next.getName() + str + e.getMessage(), null);
                        String str1822 = str;
                        str17 = str2;
                        str16 = str1822;
                        str15 = str3;
                        if (!it.hasNext()) {
                        }
                    }
                    StremioAddonService stremioAddonService = this.this$0.stremioAddonService;
                    String manifestUrl = next.getManifestUrl();
                    this.L$0 = list2;
                    this.L$1 = str6;
                    this.L$2 = dy4VarA;
                    this.L$3 = strmrBundle;
                    this.L$4 = it;
                    this.L$5 = next;
                    List list7 = list2;
                    this.L$6 = null;
                    this.L$7 = null;
                    this.I$0 = i;
                    this.I$1 = i2;
                    this.I$2 = r23;
                    this.label = 2;
                    objB = stremioAddonService.b(manifestUrl, this);
                    if (objB != ck1Var) {
                        dy4Var = dy4VarA;
                        list3 = list7;
                        r23 = r23;
                        try {
                        } catch (Exception e6) {
                            e = e6;
                            String str22 = str17;
                            str = str16;
                            str2 = str22;
                            str3 = str15;
                        }
                        cVar = (StremioAddonService.c) objB;
                        if (cVar instanceof StremioAddonService.c.b) {
                            str3 = str15;
                            String str23 = str16;
                            str2 = str17;
                            try {
                            } catch (Exception e7) {
                                e = e7;
                                str = str23;
                            }
                            if (!(cVar instanceof StremioAddonService.c.a)) {
                                str = str23;
                                throw new io6();
                            }
                            ExecutorService executorService5 = kq.a;
                            String name = next.getName();
                            String str24 = ((StremioAddonService.c.a) cVar).a;
                            StringBuilder sb = new StringBuilder();
                            sb.append("Bundle update: skipped ");
                            sb.append(name);
                            str = str23;
                            sb.append(str);
                            sb.append(str24);
                            kq.h(str2, sb.toString());
                            str17 = str2;
                            str16 = str;
                            list2 = list3;
                            dy4VarA = dy4Var;
                            str15 = str3;
                            if (!it.hasNext()) {
                            }
                            e = e;
                            list2 = list3;
                            dy4VarA = dy4Var;
                            r23 = r23;
                            ExecutorService executorService222 = kq.a;
                            kq.a(str2, "Bundle update: failed for " + next.getName() + str + e.getMessage(), null);
                            String str18222 = str;
                            str17 = str2;
                            str16 = str18222;
                            str15 = str3;
                            if (!it.hasNext()) {
                            }
                        } else {
                            try {
                            } catch (Exception e8) {
                                e = e8;
                                str3 = str15;
                                str5 = str16;
                                break;
                            }
                            StremioManifest stremioManifest2 = ((StremioAddonService.c.b) cVar).a;
                            id = stremioManifest2.getId();
                            if (id == null) {
                                id = "";
                            }
                            Iterator it6 = list3.iterator();
                            while (true) {
                                if (it6.hasNext()) {
                                    try {
                                    } catch (Exception e9) {
                                        e = e9;
                                        str5 = str16;
                                        break;
                                    }
                                    next2 = it6.next();
                                    str5 = str16;
                                    if (!cr4.b(((InstalledAddonEntity) next2).getAddonId(), id)) {
                                        str16 = str5;
                                    }
                                } else {
                                    str5 = str16;
                                    next2 = null;
                                }
                            }
                            InstalledAddonEntity installedAddonEntity = (InstalledAddonEntity) next2;
                            if (installedAddonEntity != null) {
                                try {
                                } catch (Exception e10) {
                                    e = e10;
                                    str2 = str17;
                                    break;
                                }
                                DebridInjectionDef debridInjection2 = next.getDebridInjection();
                                String strB = debridInjection2 != null ? dy4Var.b(DebridInjectionDef.INSTANCE.serializer(), debridInjection2) : null;
                                if (!n89.ab(next.getBaseConfig())) {
                                    try {
                                    } catch (Exception e11) {
                                        e = e11;
                                        str4 = str17;
                                        break;
                                    }
                                    str4 = str17;
                                    str11 = next.getBaseUrl() + str15 + next.getBaseConfig();
                                } else {
                                    str4 = str17;
                                    str11 = null;
                                }
                                List<Object> resources = stremioManifest2.getResources();
                                if (resources != null) {
                                    ArrayList arrayList = new ArrayList();
                                    Iterator it7 = resources.iterator();
                                    while (it7.hasNext()) {
                                        String str25 = str11;
                                        Object next3 = it7.next();
                                        Iterator it8 = it7;
                                        if (next3 instanceof String) {
                                            str13 = (String) next3;
                                        } else if (next3 instanceof Map) {
                                            Object obj2 = ((Map) next3).get(AppMeasurementSdk.ConditionalUserProperty.NAME);
                                            str13 = obj2 instanceof String ? (String) obj2 : null;
                                        }
                                        if (str13 != null) {
                                            arrayList.add(str13);
                                        }
                                        str11 = str25;
                                        it7 = it8;
                                    }
                                    str12 = str11;
                                    capabilities = y41.ai(arrayList, ",", null, null, null, 62);
                                    if (capabilities == null) {
                                    }
                                    String str26 = capabilities;
                                    List<StremioCatalog> parsedCatalogs = stremioManifest2.getParsedCatalogs();
                                    json = parsedCatalogs.isEmpty() ? this.this$0.gson.toJson(parsedCatalogs) : null;
                                    List resources2 = this.this$0.parseResources(stremioManifest2);
                                    json2 = resources2.isEmpty() ? this.this$0.gson.toJson(resources2) : null;
                                    String baseUrl = next.getBaseUrl();
                                    String manifestUrl2 = next.getManifestUrl();
                                    version = stremioManifest2.getVersion();
                                    if (version == null) {
                                        version = installedAddonEntity.getVersion();
                                    }
                                    String str27 = version;
                                    description = stremioManifest2.getDescription();
                                    if (description == null) {
                                        description = installedAddonEntity.getDescription();
                                    }
                                    String str28 = description;
                                    if (json == null) {
                                        json = installedAddonEntity.getCatalogsJson();
                                    }
                                    String str29 = json;
                                    if (json2 == null) {
                                        json2 = installedAddonEntity.getResourcesJson();
                                    }
                                    String str30 = json2;
                                    DebridInjectionDef debridInjection3 = next.getDebridInjection();
                                    installedAddonEntityCopy$default2 = InstalledAddonEntity.copy$default(installedAddonEntity, null, null, 0, null, str27, str28, baseUrl, manifestUrl2, n89.ab(next.getBaseConfig()) ? str12 : installedAddonEntity.getConfiguredUrl(), n89.ab(next.getBaseConfig()) ? installedAddonEntity.isConfigured() : str12 != null, null, str26, null, null, 0, false, false, null, 0L, null, str29, str30, false, debridInjection3 == null ? debridInjection3.getType() : null, strB, null, null, Boxing.boxInt(strmrBundle.getVersion()), 105903119, null);
                                    installedAddonDao2 = this.this$0.addonDao;
                                    this.L$0 = list3;
                                    this.L$1 = str6;
                                    this.L$2 = dy4Var;
                                    this.L$3 = strmrBundle;
                                    this.L$4 = it;
                                    this.L$5 = next;
                                    this.I$0 = i;
                                    this.I$1 = i2;
                                    this.I$2 = r23;
                                    this.label = 3;
                                    if (installedAddonDao2.upsertAddon(installedAddonEntityCopy$default2, this) != ck1Var) {
                                        list2 = list3;
                                        dy4VarA = dy4Var;
                                        r22 = r23;
                                        i2++;
                                        ExecutorService executorService6 = kq.a;
                                        str2 = str4;
                                        kq.h(str2, "Bundle update: updated " + next.getName());
                                        str17 = str2;
                                        r23 = r22;
                                        str16 = str5;
                                        if (!it.hasNext()) {
                                            String str31 = str17;
                                            if (i2 > 0 || r23 > 0) {
                                                this.this$0.triggerCloudSync();
                                            }
                                            ExecutorService executorService7 = kq.a;
                                            kq.h(str31, "Bundle update complete: " + i2 + " updated, " + r23 + " new");
                                            objA = new AddonRepository.BundleUpdateResult(this.$bundleId, i, strmrBundle.getVersion(), i2, r23 == true ? 1 : 0);
                                            return new q38(objA);
                                        }
                                    }
                                } else {
                                    str12 = str11;
                                }
                                capabilities = installedAddonEntity.getCapabilities();
                                String str262 = capabilities;
                                List<StremioCatalog> parsedCatalogs2 = stremioManifest2.getParsedCatalogs();
                                if (parsedCatalogs2.isEmpty()) {
                                }
                                List resources22 = this.this$0.parseResources(stremioManifest2);
                                if (resources22.isEmpty()) {
                                }
                                String baseUrl2 = next.getBaseUrl();
                                String manifestUrl22 = next.getManifestUrl();
                                version = stremioManifest2.getVersion();
                                if (version == null) {
                                }
                                String str272 = version;
                                description = stremioManifest2.getDescription();
                                if (description == null) {
                                }
                                String str282 = description;
                                if (json == null) {
                                }
                                String str292 = json;
                                if (json2 == null) {
                                }
                                String str302 = json2;
                                DebridInjectionDef debridInjection32 = next.getDebridInjection();
                                if (debridInjection32 == null) {
                                }
                                installedAddonEntityCopy$default2 = InstalledAddonEntity.copy$default(installedAddonEntity, null, null, 0, null, str272, str282, baseUrl2, manifestUrl22, n89.ab(next.getBaseConfig()) ? str12 : installedAddonEntity.getConfiguredUrl(), n89.ab(next.getBaseConfig()) ? installedAddonEntity.isConfigured() : str12 != null, null, str262, null, null, 0, false, false, null, 0L, null, str292, str302, false, debridInjection32 == null ? debridInjection32.getType() : null, strB, null, null, Boxing.boxInt(strmrBundle.getVersion()), 105903119, null);
                                installedAddonDao2 = this.this$0.addonDao;
                                this.L$0 = list3;
                                this.L$1 = str6;
                                this.L$2 = dy4Var;
                                this.L$3 = strmrBundle;
                                this.L$4 = it;
                                this.L$5 = next;
                                this.I$0 = i;
                                this.I$1 = i2;
                                this.I$2 = r23;
                                this.label = 3;
                                if (installedAddonDao2.upsertAddon(installedAddonEntityCopy$default2, this) != ck1Var) {
                                }
                                break;
                            } else {
                                str2 = str17;
                                try {
                                } catch (Exception e12) {
                                    e = e12;
                                    str3 = str15;
                                    list2 = list3;
                                    dy4VarA = dy4Var;
                                    r25 = r23;
                                    str = str5;
                                    r23 = r25;
                                    ExecutorService executorService2222 = kq.a;
                                    kq.a(str2, "Bundle update: failed for " + next.getName() + str + e.getMessage(), null);
                                    String str182222 = str;
                                    str17 = str2;
                                    str16 = str182222;
                                    str15 = str3;
                                    if (!it.hasNext()) {
                                    }
                                }
                                InstalledAddonDao installedAddonDao4 = this.this$0.addonDao;
                                this.L$0 = list3;
                                this.L$1 = str6;
                                this.L$2 = dy4Var;
                                this.L$3 = strmrBundle;
                                this.L$4 = it;
                                this.L$5 = next;
                                this.L$6 = stremioManifest2;
                                this.L$7 = id;
                                this.I$0 = i;
                                this.I$1 = i2;
                                this.I$2 = r23;
                                this.label = 4;
                                addonsByAddonId = installedAddonDao4.getAddonsByAddonId(id, this);
                                if (addonsByAddonId != ck1Var) {
                                    stremioManifest = stremioManifest2;
                                    r23 = r23;
                                    list5 = (List) addonsByAddonId;
                                    str3 = str15;
                                    if (list5 instanceof Collection) {
                                        try {
                                        } catch (Exception e13) {
                                            e = e13;
                                            list2 = list3;
                                            ?? r29 = r23;
                                            dy4VarA = dy4Var;
                                            ?? r210 = r29;
                                            str = str5;
                                            r24 = r210;
                                            r23 = r24;
                                            ExecutorService executorService22222 = kq.a;
                                            kq.a(str2, "Bundle update: failed for " + next.getName() + str + e.getMessage(), null);
                                            String str1822222 = str;
                                            str17 = str2;
                                            str16 = str1822222;
                                            str15 = str3;
                                            if (!it.hasNext()) {
                                            }
                                        }
                                        if (!list5.isEmpty()) {
                                        }
                                        InstalledAddonDao installedAddonDao5 = this.this$0.addonDao;
                                        this.L$0 = list3;
                                        this.L$1 = str6;
                                        this.L$2 = dy4Var;
                                        this.L$3 = strmrBundle;
                                        this.L$4 = it;
                                        this.L$5 = next;
                                        this.L$6 = stremioManifest;
                                        this.L$7 = id;
                                        this.I$0 = i;
                                        this.I$1 = i2;
                                        this.I$2 = r23;
                                        this.label = 5;
                                        usedInstanceNumbers = installedAddonDao5.getUsedInstanceNumbers(id, this);
                                        if (usedInstanceNumbers != ck1Var) {
                                            list4 = list3;
                                            it2 = it;
                                            dy4Var2 = dy4Var;
                                            r26 = r23;
                                            String str32 = str6;
                                            StrmrBundle strmrBundle4 = strmrBundle;
                                            int i3 = i;
                                            List list8 = (List) usedInstanceNumbers;
                                            Iterator<BundleAddonDef> it9 = it2;
                                            it4 = new dp4(1, list8.size() + 1, 1).iterator();
                                            while (((cp4) it4).c) {
                                                int iNextInt = ((to4) it4).nextInt();
                                                if (list8.contains(Boxing.boxInt(iNextInt))) {
                                                    strmrBundle4 = strmrBundle4;
                                                    stremioManifest = stremioManifest;
                                                } else {
                                                    if (iNextInt == 1) {
                                                        try {
                                                        } catch (Exception e14) {
                                                            e = e14;
                                                            list2 = list4;
                                                            dy4VarA = dy4Var2;
                                                            i = i3;
                                                            str = str5;
                                                            str6 = str32;
                                                            it = it9;
                                                            strmrBundle = strmrBundle4;
                                                            r23 = r26;
                                                            ExecutorService executorService222222 = kq.a;
                                                            kq.a(str2, "Bundle update: failed for " + next.getName() + str + e.getMessage(), null);
                                                            String str18222222 = str;
                                                            str17 = str2;
                                                            str16 = str18222222;
                                                            str15 = str3;
                                                            if (!it.hasNext()) {
                                                            }
                                                        }
                                                        if (list8.contains(Boxing.boxInt(1))) {
                                                        }
                                                        String str33 = id;
                                                        if (n89.ab(next.getBaseConfig())) {
                                                            try {
                                                            } catch (Exception e15) {
                                                                e = e15;
                                                                str8 = str2;
                                                                list2 = list4;
                                                                break;
                                                            }
                                                            String baseUrl3 = next.getBaseUrl();
                                                            String baseConfig = next.getBaseConfig();
                                                            StringBuilder sb2 = new StringBuilder();
                                                            sb2.append(baseUrl3);
                                                            str8 = str2;
                                                            str9 = str3;
                                                            sb2.append(str9);
                                                            sb2.append(baseConfig);
                                                            string = sb2.toString();
                                                        } else {
                                                            str8 = str2;
                                                            str9 = str3;
                                                            string = null;
                                                        }
                                                        DebridInjectionDef debridInjection4 = next.getDebridInjection();
                                                        String strB2 = debridInjection4 == null ? dy4Var2.b(DebridInjectionDef.INSTANCE.serializer(), debridInjection4) : null;
                                                        StrmrBundle strmrBundle5 = strmrBundle4;
                                                        BundleAddonDef bundleAddonDef = next;
                                                        str3 = str9;
                                                        it3 = it9;
                                                        BundleAddonDef bundleAddonDef2 = bundleAddonDef;
                                                        InstalledAddonEntity installedAddonEntityCreateAddonEntity = this.this$0.createAddonEntity(stremioManifest, next.getBaseUrl(), bundleAddonDef.getManifestUrl(), str33, iNextInt);
                                                        String baseUrl4 = bundleAddonDef2.getBaseUrl();
                                                        boolean z = string == null;
                                                        debridInjection = bundleAddonDef2.getDebridInjection();
                                                        if (debridInjection == null) {
                                                            try {
                                                            } catch (Exception e16) {
                                                                e = e16;
                                                                next = bundleAddonDef2;
                                                                list2 = list4;
                                                                dy4VarA = dy4Var2;
                                                                i = i3;
                                                                str = str5;
                                                                str6 = str32;
                                                                strmrBundle = strmrBundle5;
                                                                it = it3;
                                                                str2 = str8;
                                                                r23 = r26;
                                                            }
                                                            type = debridInjection.getType();
                                                        } else {
                                                            type = null;
                                                        }
                                                        installedAddonEntityCopy$default = InstalledAddonEntity.copy$default(installedAddonEntityCreateAddonEntity, null, null, 0, null, null, null, baseUrl4, null, string, z, null, null, null, null, 0, false, false, null, 0L, null, null, null, true, type, strB2, strmrBundle5.getBundleId(), str32, Boxing.boxInt(strmrBundle5.getVersion()), 4193471, null);
                                                        str6 = str32;
                                                        installedAddonDao = this.this$0.addonDao;
                                                        this.L$0 = list4;
                                                        this.L$1 = str6;
                                                        this.L$2 = dy4Var2;
                                                        strmrBundle2 = strmrBundle5;
                                                        this.L$3 = strmrBundle2;
                                                        this.L$4 = it3;
                                                        this.L$5 = bundleAddonDef2;
                                                        this.L$6 = str33;
                                                        this.L$7 = null;
                                                        this.I$0 = i3;
                                                        this.I$1 = i2;
                                                        this.I$2 = r26;
                                                        this.label = 6;
                                                        if (installedAddonDao.upsertAddon(installedAddonEntityCopy$default, this) != ck1Var) {
                                                            next = bundleAddonDef2;
                                                            list2 = list4;
                                                            str10 = str33;
                                                            dy4VarA = dy4Var2;
                                                            i = i3;
                                                            it = it3;
                                                            strmrBundle = strmrBundle2;
                                                            r28 = r26;
                                                            r26 = r28 + 1;
                                                            ExecutorService executorService8 = kq.a;
                                                            str7 = str8;
                                                            kq.h(str7, "Bundle update: installed new " + next.getName() + " (instance: " + str10 + ")");
                                                            str17 = str7;
                                                            r27 = r26;
                                                            str15 = str3;
                                                            r23 = r27;
                                                            str16 = str5;
                                                            if (!it.hasNext()) {
                                                            }
                                                        }
                                                    }
                                                    id = id + "_" + iNextInt;
                                                    String str332 = id;
                                                    if (n89.ab(next.getBaseConfig())) {
                                                    }
                                                    DebridInjectionDef debridInjection42 = next.getDebridInjection();
                                                    if (debridInjection42 == null) {
                                                    }
                                                    StrmrBundle strmrBundle52 = strmrBundle4;
                                                    BundleAddonDef bundleAddonDef3 = next;
                                                    str3 = str9;
                                                    it3 = it9;
                                                    BundleAddonDef bundleAddonDef22 = bundleAddonDef3;
                                                    InstalledAddonEntity installedAddonEntityCreateAddonEntity2 = this.this$0.createAddonEntity(stremioManifest, next.getBaseUrl(), bundleAddonDef3.getManifestUrl(), str332, iNextInt);
                                                    String baseUrl42 = bundleAddonDef22.getBaseUrl();
                                                    if (string == null) {
                                                    }
                                                    debridInjection = bundleAddonDef22.getDebridInjection();
                                                    if (debridInjection == null) {
                                                    }
                                                    installedAddonEntityCopy$default = InstalledAddonEntity.copy$default(installedAddonEntityCreateAddonEntity2, null, null, 0, null, null, null, baseUrl42, null, string, z, null, null, null, null, 0, false, false, null, 0L, null, null, null, true, type, strB2, strmrBundle52.getBundleId(), str32, Boxing.boxInt(strmrBundle52.getVersion()), 4193471, null);
                                                    str6 = str32;
                                                    installedAddonDao = this.this$0.addonDao;
                                                    this.L$0 = list4;
                                                    this.L$1 = str6;
                                                    this.L$2 = dy4Var2;
                                                    strmrBundle2 = strmrBundle52;
                                                    this.L$3 = strmrBundle2;
                                                    this.L$4 = it3;
                                                    this.L$5 = bundleAddonDef22;
                                                    this.L$6 = str332;
                                                    this.L$7 = null;
                                                    this.I$0 = i3;
                                                    this.I$1 = i2;
                                                    this.I$2 = r26;
                                                    this.label = 6;
                                                    if (installedAddonDao.upsertAddon(installedAddonEntityCopy$default, this) != ck1Var) {
                                                    }
                                                }
                                                break;
                                            }
                                            strmrBundle2 = strmrBundle4;
                                            BundleAddonDef bundleAddonDef4 = next;
                                            str6 = str32;
                                            str7 = str2;
                                            it3 = it9;
                                            try {
                                            } catch (Exception e17) {
                                                e = e17;
                                                list2 = list4;
                                                dy4VarA = dy4Var2;
                                                i = i3;
                                                next = bundleAddonDef4;
                                                it = it3;
                                                strmrBundle = strmrBundle2;
                                                str2 = str7;
                                                r25 = r26;
                                                str = str5;
                                                r23 = r25;
                                                ExecutorService executorService2222222 = kq.a;
                                                kq.a(str2, "Bundle update: failed for " + next.getName() + str + e.getMessage(), null);
                                                String str182222222 = str;
                                                str17 = str2;
                                                str16 = str182222222;
                                                str15 = str3;
                                                if (!it.hasNext()) {
                                                }
                                            }
                                            throw new NoSuchElementException("Collection contains no element matching the predicate.");
                                        }
                                    }
                                    it5 = list5.iterator();
                                    while (it5.hasNext()) {
                                        if (((InstalledAddonEntity) it5.next()).isQuickAdd()) {
                                            ExecutorService executorService9 = kq.a;
                                            kq.h(str2, "Bundle update: " + next.getName() + " already quick-added outside bundle, skipping");
                                            str17 = str2;
                                            list2 = list3;
                                            dy4VarA = dy4Var;
                                            r27 = r23;
                                            str15 = str3;
                                            r23 = r27;
                                            str16 = str5;
                                            if (!it.hasNext()) {
                                            }
                                        }
                                    }
                                    InstalledAddonDao installedAddonDao52 = this.this$0.addonDao;
                                    this.L$0 = list3;
                                    this.L$1 = str6;
                                    this.L$2 = dy4Var;
                                    this.L$3 = strmrBundle;
                                    this.L$4 = it;
                                    this.L$5 = next;
                                    this.L$6 = stremioManifest;
                                    this.L$7 = id;
                                    this.I$0 = i;
                                    this.I$1 = i2;
                                    this.I$2 = r23;
                                    this.label = 5;
                                    usedInstanceNumbers = installedAddonDao52.getUsedInstanceNumbers(id, this);
                                    if (usedInstanceNumbers != ck1Var) {
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    return ck1Var;
                }
                break;
            case 1:
                s38.b(obj);
                addonsByBundleId = obj;
                list6 = (List) addonsByBundleId;
                if (!list6.isEmpty()) {
                }
                break;
            case 2:
                int i4 = this.I$2;
                i2 = this.I$1;
                i = this.I$0;
                next = (BundleAddonDef) this.L$5;
                it = (Iterator) this.L$4;
                strmrBundle = (StrmrBundle) this.L$3;
                dy4 dy4Var3 = (dy4) this.L$2;
                str6 = (String) this.L$1;
                List list9 = (List) this.L$0;
                s38.b(obj);
                objB = obj;
                dy4Var = dy4Var3;
                list3 = list9;
                r23 = i4;
                cVar = (StremioAddonService.c) objB;
                if (cVar instanceof StremioAddonService.c.b) {
                }
                break;
            case 3:
                int i5 = this.I$2;
                i2 = this.I$1;
                i = this.I$0;
                next = (BundleAddonDef) this.L$5;
                it = (Iterator) this.L$4;
                strmrBundle = (StrmrBundle) this.L$3;
                dy4VarA = (dy4) this.L$2;
                str6 = (String) this.L$1;
                list2 = (List) this.L$0;
                s38.b(obj);
                str5 = ": ";
                str4 = "AddonRepository";
                r22 = i5;
                i2++;
                ExecutorService executorService62 = kq.a;
                str2 = str4;
                kq.h(str2, "Bundle update: updated " + next.getName());
                str17 = str2;
                r23 = r22;
                str16 = str5;
                if (!it.hasNext()) {
                }
                break;
            case 4:
                int i6 = this.I$2;
                i2 = this.I$1;
                i = this.I$0;
                String str34 = (String) this.L$7;
                StremioManifest stremioManifest3 = (StremioManifest) this.L$6;
                next = (BundleAddonDef) this.L$5;
                it = (Iterator) this.L$4;
                strmrBundle = (StrmrBundle) this.L$3;
                dy4 dy4Var4 = (dy4) this.L$2;
                str6 = (String) this.L$1;
                List list10 = (List) this.L$0;
                s38.b(obj);
                dy4Var = dy4Var4;
                list3 = list10;
                str5 = ": ";
                str2 = "AddonRepository";
                stremioManifest = stremioManifest3;
                id = str34;
                addonsByAddonId = obj;
                r23 = i6;
                list5 = (List) addonsByAddonId;
                str3 = str15;
                if (list5 instanceof Collection) {
                }
                it5 = list5.iterator();
                while (it5.hasNext()) {
                }
                InstalledAddonDao installedAddonDao522 = this.this$0.addonDao;
                this.L$0 = list3;
                this.L$1 = str6;
                this.L$2 = dy4Var;
                this.L$3 = strmrBundle;
                this.L$4 = it;
                this.L$5 = next;
                this.L$6 = stremioManifest;
                this.L$7 = id;
                this.I$0 = i;
                this.I$1 = i2;
                this.I$2 = r23;
                this.label = 5;
                usedInstanceNumbers = installedAddonDao522.getUsedInstanceNumbers(id, this);
                if (usedInstanceNumbers != ck1Var) {
                }
                return ck1Var;
            case 5:
                int i7 = this.I$2;
                i2 = this.I$1;
                i = this.I$0;
                String str35 = (String) this.L$7;
                StremioManifest stremioManifest4 = (StremioManifest) this.L$6;
                next = (BundleAddonDef) this.L$5;
                Iterator<BundleAddonDef> it10 = (Iterator) this.L$4;
                strmrBundle = (StrmrBundle) this.L$3;
                dy4 dy4Var5 = (dy4) this.L$2;
                str6 = (String) this.L$1;
                List list11 = (List) this.L$0;
                s38.b(obj);
                dy4Var2 = dy4Var5;
                it2 = it10;
                str3 = DomExceptionUtils.SEPARATOR;
                str5 = ": ";
                str2 = "AddonRepository";
                list4 = list11;
                stremioManifest = stremioManifest4;
                id = str35;
                usedInstanceNumbers = obj;
                r26 = i7;
                String str322 = str6;
                StrmrBundle strmrBundle42 = strmrBundle;
                int i32 = i;
                List list82 = (List) usedInstanceNumbers;
                Iterator<BundleAddonDef> it92 = it2;
                it4 = new dp4(1, list82.size() + 1, 1).iterator();
                while (((cp4) it4).c) {
                    break;
                }
                strmrBundle2 = strmrBundle42;
                BundleAddonDef bundleAddonDef42 = next;
                str6 = str322;
                str7 = str2;
                it3 = it92;
                throw new NoSuchElementException("Collection contains no element matching the predicate.");
            case 6:
                int i8 = this.I$2;
                i2 = this.I$1;
                i = this.I$0;
                str10 = (String) this.L$6;
                next = (BundleAddonDef) this.L$5;
                it = (Iterator) this.L$4;
                strmrBundle = (StrmrBundle) this.L$3;
                dy4VarA = (dy4) this.L$2;
                str6 = (String) this.L$1;
                list2 = (List) this.L$0;
                s38.b(obj);
                str3 = DomExceptionUtils.SEPARATOR;
                str5 = ": ";
                str8 = "AddonRepository";
                r28 = i8;
                r26 = r28 + 1;
                ExecutorService executorService82 = kq.a;
                str7 = str8;
                kq.h(str7, "Bundle update: installed new " + next.getName() + " (instance: " + str10 + ")");
                str17 = str7;
                r27 = r26;
                str15 = str3;
                r23 = r27;
                str16 = str5;
                if (!it.hasNext()) {
                }
                break;
            default:
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
    }
}
