package com.strmr.ps.data.service;

import androidx.media3.exoplayer.rtsp.RtspMessageChannel;
import com.strmr.ps.data.model.EpisodeFilter;
import com.strmr.ps.data.model.addon.InstalledAddon;
import com.strmr.ps.data.repository.AddonRepository;
import com.strmr.ps.data.repository.ScreenConfigRepository;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.ik2;
import defpackage.kc8;
import defpackage.km8;
import defpackage.kq;
import defpackage.n41;
import defpackage.n89;
import defpackage.oz2;
import defpackage.pk2;
import defpackage.q07;
import defpackage.s38;
import defpackage.vx8;
import defpackage.y41;
import defpackage.yi7;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CancellationException;
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\u00020\u0002*\b\u0012\u0004\u0012\u00020\u00010\u0000H\n¢\u0006\u0004\b\u0003\u0010\u0004"}, d2 = {"Lyi7;", "Lkc8;", "Le6a;", "<anonymous>", "(Lyi7;)V"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.data.service.AddonResolutionService$scrapeWithStremioId$1", f = "AddonResolutionService.kt", i = {0, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9}, l = {523, 535, 547, RtspMessageChannel.DEFAULT_RTSP_PORT, 566, 571, 592, 598, ScreenConfigRepository.MAX_TOTAL_ROWS, 607, 618}, m = "invokeSuspend", n = {"$this$channelFlow", "$this$channelFlow", "sourceAddon", "allRawStreams", "$this$channelFlow", "sourceAddon", "allRawStreams", "label", "$this$channelFlow", "sourceAddon", "allRawStreams", "$this$channelFlow", "sourceAddon", "$this$channelFlow", "sourceAddon", "customAddonIds", "$this$channelFlow", "sourceAddon", "customAddonIds", "filterResult", "$this$channelFlow", "sourceAddon", "$this$channelFlow", "sourceAddon"}, s = {"L$0", "L$0", "L$1", "L$2", "L$0", "L$1", "L$2", "L$4", "L$0", "L$1", "L$2", "L$0", "L$1", "L$0", "L$1", "L$2", "L$0", "L$1", "L$2", "L$3", "L$0", "L$1", "L$0", "L$1"})
@vx8
final class n extends SuspendLambda implements gr3<yi7<? super kc8>, Continuation<? super e6a>, Object> {
    public InstalledAddon a;
    public Collection b;
    public Object c;
    public String d;
    public int e;
    public /* synthetic */ Object f;
    public final /* synthetic */ String i;
    public final /* synthetic */ String j;
    public final /* synthetic */ AddonResolutionService k;
    public final /* synthetic */ String l;
    public final /* synthetic */ Integer m;
    public final /* synthetic */ Integer n;
    public final /* synthetic */ Integer o;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public n(String str, String str2, AddonResolutionService addonResolutionService, String str3, Integer num, Integer num2, Integer num3, Continuation continuation) {
        super(2, continuation);
        this.i = str;
        this.j = str2;
        this.k = addonResolutionService;
        this.l = str3;
        this.m = num;
        this.n = num2;
        this.o = num3;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        n nVar = new n(this.i, this.j, this.k, this.l, this.m, this.n, this.o, continuation);
        nVar.f = obj;
        return nVar;
    }

    @Override // defpackage.gr3
    public final Object invoke(Object obj, Object obj2) {
        return ((n) create((yi7) obj, (Continuation) obj2)).invokeSuspend(e6a.a);
    }

    /* JADX INFO: Infinite loop detected, blocks: 7, insns: 0 */
    /* JADX WARN: Can't wrap try/catch for region: R(10:(1:242)|122|123|234|124|125|126|230|89|(4:152|166|167|(5:169|170|171|(1:173)|215)(6:176|(1:178)(1:179)|(4:184|(1:186)|188|(2:190|(5:193|23|232|194|(4:197|198|(1:200)|215)))(2:203|(0)(0)))|187|188|(0)(0)))(0)) */
    /* JADX WARN: Can't wrap try/catch for region: R(15:91|92|224|93|(2:222|95)(1:100)|(4:102|248|103|104)(1:108)|105|252|109|(1:111)(1:116)|112|117|258|118|(11:121|242|122|123|234|124|125|126|230|89|(4:152|166|167|(5:169|170|171|(1:173)|215)(6:176|(1:178)(1:179)|(4:184|(1:186)|188|(2:190|(5:193|23|232|194|(4:197|198|(1:200)|215)))(2:203|(0)(0)))|187|188|(0)(0)))(0))) */
    /* JADX WARN: Can't wrap try/catch for region: R(7:240|72|(3:256|74|(2:76|(9:79|250|80|(3:82|254|83)|87|88|230|89|(15:91|92|224|93|(2:222|95)(1:100)|(4:102|248|103|104)(1:108)|105|252|109|(1:111)(1:116)|112|117|258|118|(11:121|242|122|123|234|124|125|126|230|89|(4:152|166|167|(5:169|170|171|(1:173)|215)(6:176|(1:178)(1:179)|(4:184|(1:186)|188|(2:190|(5:193|23|232|194|(4:197|198|(1:200)|215)))(2:203|(0)(0)))|187|188|(0)(0)))(0)))(0))))|159|244|160|(7:163|236|164|165|166|167|(0)(0))) */
    /* JADX WARN: Code restructure failed: missing block: B:127:0x034b, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:128:0x034c, code lost:
    
        r21 = r12;
        r22 = r22;
     */
    /* JADX WARN: Code restructure failed: missing block: B:133:0x0357, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:134:0x0358, code lost:
    
        r14 = r17;
        r28 = r9;
        r9 = r6;
        r6 = r11;
        r11 = r28;
        r22 = r22;
     */
    /* JADX WARN: Code restructure failed: missing block: B:135:0x0361, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:208:0x0551, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:209:0x0552, code lost:
    
        r12 = r27;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Path cross not found for [B:64:0x01d0, B:67:0x01ee], limit reached: 249 */
    /* JADX WARN: Removed duplicated region for block: B:152:0x03ad  */
    /* JADX WARN: Removed duplicated region for block: B:169:0x0444 A[Catch: CancellationException -> 0x0041, Exception -> 0x039c, TRY_ENTER, TRY_LEAVE, TryCatch #6 {Exception -> 0x039c, blocks: (B:166:0x043c, B:169:0x0444, B:145:0x039b), top: B:219:0x0021 }] */
    /* JADX WARN: Removed duplicated region for block: B:176:0x046c A[Catch: CancellationException -> 0x0041, Exception -> 0x0469, TryCatch #2 {Exception -> 0x0469, blocks: (B:198:0x04fb, B:171:0x0450, B:176:0x046c, B:178:0x047a, B:182:0x0489, B:184:0x048f, B:188:0x04b3, B:190:0x04bc, B:203:0x0528, B:179:0x0483), top: B:219:0x0021 }] */
    /* JADX WARN: Removed duplicated region for block: B:190:0x04bc A[Catch: CancellationException -> 0x0041, Exception -> 0x0469, TRY_LEAVE, TryCatch #2 {Exception -> 0x0469, blocks: (B:198:0x04fb, B:171:0x0450, B:176:0x046c, B:178:0x047a, B:182:0x0489, B:184:0x048f, B:188:0x04b3, B:190:0x04bc, B:203:0x0528, B:179:0x0483), top: B:219:0x0021 }] */
    /* JADX WARN: Removed duplicated region for block: B:197:0x04f9  */
    /* JADX WARN: Removed duplicated region for block: B:200:0x0523  */
    /* JADX WARN: Removed duplicated region for block: B:203:0x0528 A[Catch: CancellationException -> 0x0041, Exception -> 0x0469, TRY_LEAVE, TryCatch #2 {Exception -> 0x0469, blocks: (B:198:0x04fb, B:171:0x0450, B:176:0x046c, B:178:0x047a, B:182:0x0489, B:184:0x048f, B:188:0x04b3, B:190:0x04bc, B:203:0x0528, B:179:0x0483), top: B:219:0x0021 }] */
    /* JADX WARN: Removed duplicated region for block: B:214:0x059c A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:215:0x059d A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:240:0x0212 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:262:0x01c2 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:57:0x0199  */
    /* JADX WARN: Removed duplicated region for block: B:69:0x01f2  */
    /* JADX WARN: Removed duplicated region for block: B:82:0x023f  */
    /* JADX WARN: Removed duplicated region for block: B:91:0x025f A[Catch: CancellationException -> 0x0041, Exception -> 0x03a5, TRY_LEAVE, TryCatch #9 {Exception -> 0x03a5, blocks: (B:89:0x0259, B:91:0x025f), top: B:230:0x0259 }] */
    /* JADX WARN: Type inference failed for: r10v12, types: [com.strmr.ps.data.service.AddonResolutionService] */
    /* JADX WARN: Type inference failed for: r10v16, types: [com.strmr.ps.data.service.AddonResolutionService] */
    /* JADX WARN: Type inference failed for: r10v17 */
    /* JADX WARN: Type inference failed for: r10v18, types: [com.strmr.ps.data.service.AddonResolutionService] */
    /* JADX WARN: Type inference failed for: r10v19 */
    /* JADX WARN: Type inference failed for: r10v20 */
    /* JADX WARN: Type inference failed for: r10v21 */
    /* JADX WARN: Type inference failed for: r22v10 */
    /* JADX WARN: Type inference failed for: r22v11 */
    /* JADX WARN: Type inference failed for: r22v12 */
    /* JADX WARN: Type inference failed for: r22v13 */
    /* JADX WARN: Type inference failed for: r22v15 */
    /* JADX WARN: Type inference failed for: r22v16 */
    /* JADX WARN: Type inference failed for: r22v17 */
    /* JADX WARN: Type inference failed for: r22v18 */
    /* JADX WARN: Type inference failed for: r22v19 */
    /* JADX WARN: Type inference failed for: r22v20 */
    /* JADX WARN: Type inference failed for: r22v21 */
    /* JADX WARN: Type inference failed for: r22v22 */
    /* JADX WARN: Type inference failed for: r22v3 */
    /* JADX WARN: Type inference failed for: r22v4 */
    /* JADX WARN: Type inference failed for: r22v5 */
    /* JADX WARN: Type inference failed for: r22v6 */
    /* JADX WARN: Type inference failed for: r22v7 */
    /* JADX WARN: Type inference failed for: r22v8 */
    /* JADX WARN: Type inference failed for: r22v9 */
    /* JADX WARN: Type inference failed for: r2v0, types: [com.strmr.ps.data.service.AddonResolutionService] */
    /* JADX WARN: Type inference failed for: r2v1 */
    /* JADX WARN: Type inference failed for: r2v12 */
    /* JADX WARN: Type inference failed for: r2v13 */
    /* JADX WARN: Type inference failed for: r2v14 */
    /* JADX WARN: Type inference failed for: r2v16 */
    /* JADX WARN: Type inference failed for: r2v17 */
    /* JADX WARN: Type inference failed for: r2v18 */
    /* JADX WARN: Type inference failed for: r2v2, types: [com.strmr.ps.data.model.addon.InstalledAddon] */
    /* JADX WARN: Type inference failed for: r2v20 */
    /* JADX WARN: Type inference failed for: r2v21 */
    /* JADX WARN: Type inference failed for: r2v22 */
    /* JADX WARN: Type inference failed for: r2v26 */
    /* JADX WARN: Type inference failed for: r2v28 */
    /* JADX WARN: Type inference failed for: r2v36 */
    /* JADX WARN: Type inference failed for: r2v38 */
    /* JADX WARN: Type inference failed for: r2v42 */
    /* JADX WARN: Type inference failed for: r2v44 */
    /* JADX WARN: Type inference failed for: r2v46 */
    /* 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: r2v55 */
    /* JADX WARN: Type inference failed for: r2v6 */
    /* JADX WARN: Type inference failed for: r2v7 */
    /* JADX WARN: Type inference failed for: r3v0, types: [com.strmr.ps.data.remote.AddonStreamClient] */
    /* JADX WARN: Type inference failed for: r3v1 */
    /* JADX WARN: Type inference failed for: r3v10 */
    /* JADX WARN: Type inference failed for: r3v12 */
    /* JADX WARN: Type inference failed for: r3v13 */
    /* JADX WARN: Type inference failed for: r3v14 */
    /* JADX WARN: Type inference failed for: r3v16 */
    /* JADX WARN: Type inference failed for: r3v2, types: [hg8] */
    /* JADX WARN: Type inference failed for: r3v21 */
    /* JADX WARN: Type inference failed for: r3v27 */
    /* JADX WARN: Type inference failed for: r3v3 */
    /* JADX WARN: Type inference failed for: r3v32 */
    /* JADX WARN: Type inference failed for: r3v35 */
    /* JADX WARN: Type inference failed for: r3v4 */
    /* JADX WARN: Type inference failed for: r3v42 */
    /* JADX WARN: Type inference failed for: r3v43 */
    /* JADX WARN: Type inference failed for: r3v44 */
    /* JADX WARN: Type inference failed for: r3v6 */
    /* JADX WARN: Type inference failed for: r3v7 */
    /* JADX WARN: Type inference failed for: r3v8 */
    /* JADX WARN: Type inference failed for: r3v9 */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:121:0x0307 -> B:242:0x030d). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:140:0x0387 -> B:126:0x0341). 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) {
        ik2 ik2Var;
        ?? r3;
        ?? r2;
        kc8 kc8Var;
        yi7 yi7Var;
        Integer num;
        int i;
        yi7 yi7Var2;
        Iterator it;
        String str;
        Integer num2;
        String str2;
        Object next;
        InstalledAddon installedAddon;
        AddonRepository addonRepository;
        List arrayList;
        Object objC;
        InstalledAddon installedAddon2;
        ?? r22;
        String str3;
        ik2 ik2Var2;
        String str4;
        Integer num3;
        Integer num4;
        Object objA;
        yi7 yi7Var3;
        InstalledAddon installedAddon3;
        List list;
        List listAm;
        Iterator it2;
        yi7 yi7Var4;
        InstalledAddon installedAddon4;
        List list2;
        Integer num5;
        String str5;
        String str6;
        InstalledAddon installedAddon5;
        String str7;
        Iterator it3;
        String str8;
        String str9;
        Exception e;
        yi7 yi7Var5;
        String message;
        StringBuilder sb;
        CancellationException e2;
        ?? r23;
        ?? r222;
        yi7 yi7Var6;
        InstalledAddon installedAddon6;
        ik2 ik2Var3;
        String str10;
        ?? r223;
        String str11;
        String str12;
        String str13;
        String name;
        Object objA2;
        List list3;
        ?? r224;
        ?? r225;
        Set setH;
        List list4;
        Object objA3;
        yi7 yi7Var7;
        ?? r10;
        InstalledAddon installedAddon7;
        Set set;
        oz2 oz2VarB;
        String instanceId;
        Set set2;
        yi7 yi7Var8;
        yi7 yi7Var9;
        ?? r102;
        InstalledAddon installedAddon8;
        kc8 kc8Var2;
        ?? r24 = this.k;
        ?? r32 = r24.b;
        AddonRepository addonRepository2 = r24.a;
        ck1 ck1Var = ck1.a;
        int i2 = this.e;
        String str14 = " raw streams";
        String str15 = this.j;
        Integer num6 = this.n;
        Integer num7 = this.m;
        e6a e6aVar = e6a.a;
        ik2 ik2Var4 = ik2.a;
        Integer num8 = num7;
        String str16 = this.i;
        String str17 = ": ";
        String str18 = "AddonResolutionService";
        try {
            try {
                try {
                    try {
                    } catch (Exception e3) {
                        e = e3;
                        r2 = r24;
                        r3 = r32;
                    }
                } catch (Exception e4) {
                    e = e4;
                }
            } catch (CancellationException e5) {
                throw e5;
            }
        } catch (Exception e6) {
            e = e6;
        }
        switch (i2) {
            case 0:
                s38.b(obj);
                yi7Var = (yi7) this.f;
                ExecutorService executorService = kq.a;
                num = num6;
                kq.h("AddonResolutionService", "Starting stremioId scrape: type=" + str16 + ", id=" + str15);
                this.f = yi7Var;
                i = 1;
                this.e = 1;
                Object enabledAddons = addonRepository2.getEnabledAddons(this);
                if (enabledAddons != ck1Var) {
                    obj = enabledAddons;
                    yi7Var2 = yi7Var;
                    char[] cArr = new char[i];
                    cArr[0] = '/';
                    String str19 = this.l;
                    String strBh = n89.bh(str19, cArr);
                    it = ((List) obj).iterator();
                    while (true) {
                        if (it.hasNext()) {
                            str = str15;
                            num2 = num8;
                            str2 = str17;
                            next = null;
                        } else {
                            next = it.next();
                            str = str15;
                            num2 = num8;
                            str2 = str17;
                            if (!cr4.b(n89.bh(((InstalledAddon) next).getEffectiveBaseUrl(), '/'), strBh)) {
                                str17 = str2;
                                num8 = num2;
                                str15 = str;
                            }
                        }
                    }
                    installedAddon = (InstalledAddon) next;
                    if (installedAddon != null || installedAddon.supportsResourceForType("stream", str16)) {
                        addonRepository = addonRepository2;
                    } else {
                        ExecutorService executorService2 = kq.a;
                        addonRepository = addonRepository2;
                        kq.h("AddonResolutionService", n41.o("Addon ", installedAddon.getName(), " does not declare stream support for type '", str16, "' — trying anyway"));
                    }
                    if (installedAddon != null) {
                        ExecutorService executorService3 = kq.a;
                        kq.h("AddonResolutionService", "Source addon not found for URL: ".concat(str19));
                        kc8 kc8Var3 = new kc8("Source addon not found", ik2Var4, ik2Var4, ik2Var4);
                        this.f = null;
                        this.e = 2;
                        if (yi7Var2.s(kc8Var3, this) != ck1Var) {
                            return e6aVar;
                        }
                    } else {
                        try {
                            arrayList = new ArrayList();
                        } catch (Exception e7) {
                            e = e7;
                        }
                        if (installedAddon.isQuickAdd()) {
                            try {
                            } catch (Exception e8) {
                                e = e8;
                                str14 = "AddonResolutionService";
                                r3 = yi7Var2;
                                r2 = installedAddon;
                                ExecutorService executorService4 = kq.a;
                                kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                                kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                                this.f = null;
                                this.a = null;
                                this.b = null;
                                this.c = null;
                                this.d = null;
                                this.e = 11;
                                if (r3.s(kc8Var, this) == ck1Var) {
                                }
                            }
                            if (installedAddon.getDebridInjectionType() != null) {
                                this.f = yi7Var2;
                                this.a = installedAddon;
                                this.b = arrayList;
                                this.e = 3;
                                objC = AddonResolutionService.c(r24, this);
                                if (objC != ck1Var) {
                                    installedAddon2 = installedAddon;
                                    try {
                                        listAm = (List) objC;
                                        if (listAm.isEmpty()) {
                                            try {
                                                listAm = y41.am(null);
                                                break;
                                            } catch (Exception e9) {
                                                e = e9;
                                                r24 = installedAddon2;
                                                r32 = yi7Var2;
                                                str14 = str18;
                                                r2 = r24;
                                                r3 = r32;
                                                ExecutorService executorService42 = kq.a;
                                                kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                                                kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                                                this.f = null;
                                                this.a = null;
                                                this.b = null;
                                                this.c = null;
                                                this.d = null;
                                                this.e = 11;
                                                if (r3.s(kc8Var, this) == ck1Var) {
                                                }
                                            }
                                        }
                                        InstalledAddon installedAddon9 = installedAddon2;
                                        it2 = listAm.iterator();
                                        yi7Var4 = yi7Var2;
                                        installedAddon4 = installedAddon9;
                                        list2 = arrayList;
                                        r23 = r24;
                                        try {
                                            break;
                                        } catch (Exception e10) {
                                            e = e10;
                                            str14 = str18;
                                            r3 = yi7Var4;
                                            r2 = installedAddon4;
                                            ExecutorService executorService422 = kq.a;
                                            kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                                            kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                                            this.f = null;
                                            this.a = null;
                                            this.b = null;
                                            this.c = null;
                                            this.d = null;
                                            this.e = 11;
                                            if (r3.s(kc8Var, this) == ck1Var) {
                                            }
                                        }
                                    } catch (Exception e11) {
                                        e = e11;
                                        str14 = "AddonResolutionService";
                                        r2 = installedAddon2;
                                        r3 = yi7Var2;
                                        ExecutorService executorService4222 = kq.a;
                                        kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                                        kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                                        this.f = null;
                                        this.a = null;
                                        this.b = null;
                                        this.c = null;
                                        this.d = null;
                                        this.e = 11;
                                        if (r3.s(kc8Var, this) == ck1Var) {
                                        }
                                    }
                                    if (it2.hasNext()) {
                                        try {
                                            try {
                                                q07 q07Var = (q07) it2.next();
                                                Integer num9 = this.m;
                                                Integer num10 = this.n;
                                                if (q07Var != null) {
                                                    try {
                                                        str10 = (String) q07Var.a;
                                                        break;
                                                    } catch (Exception e12) {
                                                        e = e12;
                                                        r32 = yi7Var4;
                                                        r24 = installedAddon4;
                                                        ik2Var4 = ik2Var3;
                                                        str14 = str18;
                                                        r2 = r24;
                                                        r3 = r32;
                                                        ExecutorService executorService42222 = kq.a;
                                                        kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                                                        kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                                                        this.f = null;
                                                        this.a = null;
                                                        this.b = null;
                                                        this.c = null;
                                                        this.d = null;
                                                        this.e = 11;
                                                        if (r3.s(kc8Var, this) == ck1Var) {
                                                        }
                                                    }
                                                } else {
                                                    str10 = null;
                                                }
                                                if (q07Var != null) {
                                                    InstalledAddon installedAddon10 = installedAddon4;
                                                    try {
                                                        r223 = r23;
                                                        str9 = str2;
                                                        str11 = str14;
                                                        str14 = str18;
                                                        str12 = (String) q07Var.b;
                                                        installedAddon4 = installedAddon10;
                                                    } catch (Exception e13) {
                                                        e = e13;
                                                        r24 = installedAddon10;
                                                        r32 = yi7Var4;
                                                        ik2Var4 = ik2Var3;
                                                        str14 = str18;
                                                        r2 = r24;
                                                        r3 = r32;
                                                        ExecutorService executorService422222 = kq.a;
                                                        kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                                                        kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                                                        this.f = null;
                                                        this.a = null;
                                                        this.b = null;
                                                        this.c = null;
                                                        this.d = null;
                                                        this.e = 11;
                                                        if (r3.s(kc8Var, this) == ck1Var) {
                                                        }
                                                    }
                                                } else {
                                                    r223 = r23;
                                                    str9 = str2;
                                                    str11 = str14;
                                                    str14 = str18;
                                                    str12 = null;
                                                }
                                                String strBuildUrlWithDebrid = installedAddon4.buildUrlWithDebrid(str16, str13, num9, num10, str10, str12);
                                                str6 = str16;
                                                str7 = str13;
                                                name = q07Var != null ? installedAddon4.getName() + "[" + q07Var.a + "]" : installedAddon4.getName();
                                                ExecutorService executorService5 = kq.a;
                                                kq.h(str14, "Fetching from " + name + str9 + strBuildUrlWithDebrid);
                                                this.f = yi7Var4;
                                                this.a = installedAddon4;
                                                this.b = list2;
                                                this.c = it2;
                                                this.d = name;
                                                this.e = 4;
                                                objA2 = r32.a(strBuildUrlWithDebrid, this);
                                            } catch (Exception e14) {
                                                e = e14;
                                                ik2Var = ik2Var3;
                                                str14 = str18;
                                            }
                                            ik2Var3 = ik2Var4;
                                            break;
                                        } catch (Exception e15) {
                                            e = e15;
                                            r32 = yi7Var4;
                                            r24 = installedAddon4;
                                            ik2Var4 = ik2Var;
                                            r2 = r24;
                                            r3 = r32;
                                            ExecutorService executorService4222222 = kq.a;
                                            kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                                            kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                                            this.f = null;
                                            this.a = null;
                                            this.b = null;
                                            this.c = null;
                                            this.d = null;
                                            this.e = 11;
                                            if (r3.s(kc8Var, this) == ck1Var) {
                                            }
                                        }
                                        ik2Var = ik2Var3;
                                        num5 = num2;
                                        str13 = str;
                                        if (objA2 != ck1Var) {
                                            InstalledAddon installedAddon11 = installedAddon4;
                                            it3 = it2;
                                            str8 = name;
                                            installedAddon5 = installedAddon11;
                                            list3 = list2;
                                            r225 = r223;
                                            try {
                                                try {
                                                } catch (Exception e16) {
                                                    e = e16;
                                                    str5 = str11;
                                                    break;
                                                }
                                                List list5 = (List) objA2;
                                                ExecutorService executorService6 = kq.a;
                                                int size = list5.size();
                                                StringBuilder sb2 = new StringBuilder();
                                                sb2.append(str8);
                                                sb2.append(str9);
                                                sb2.append(size);
                                                str5 = str11;
                                                sb2.append(str5);
                                                kq.h(str14, sb2.toString());
                                                Boxing.boxBoolean(list3.addAll(list5));
                                                str2 = str9;
                                                str18 = str14;
                                                it2 = it3;
                                                str = str7;
                                                installedAddon4 = installedAddon5;
                                                list2 = list3;
                                                r224 = r225;
                                                str16 = str6;
                                                str14 = str5;
                                                r23 = r224;
                                                num2 = num5;
                                                ik2Var4 = ik2Var;
                                                if (it2.hasNext()) {
                                                    r222 = r23;
                                                    ik2Var2 = ik2Var4;
                                                    str14 = str18;
                                                    yi7Var6 = yi7Var4;
                                                    installedAddon6 = installedAddon4;
                                                    num3 = num;
                                                    list = list2;
                                                    num4 = num2;
                                                    if (list.isEmpty()) {
                                                        ik2 ik2Var5 = ik2Var2;
                                                        kc8 kc8Var4 = new kc8("No streams found", ik2Var5, ik2Var5, y41.am(installedAddon6.getName()));
                                                        this.f = yi7Var6;
                                                        this.a = installedAddon6;
                                                        this.b = null;
                                                        this.c = null;
                                                        this.d = null;
                                                        this.e = 6;
                                                        if (yi7Var6.s(kc8Var4, this) == ck1Var) {
                                                        }
                                                        return e6aVar;
                                                    }
                                                    ?? r103 = r222;
                                                    ik2Var4 = ik2Var2;
                                                    ArrayList arrayListB = AddonResolutionService.b(r103, list, installedAddon6);
                                                    setH = installedAddon6.isCustom() ? km8.h(installedAddon6.getAddonId()) : pk2.a;
                                                    if (num4 != null && num3 != null && !arrayListB.isEmpty()) {
                                                        list4 = (List) EpisodeFilter.filterStreams$default(EpisodeFilter.INSTANCE, arrayListB, num4.intValue(), num3.intValue(), null, 8, null).a;
                                                        if (!list4.isEmpty()) {
                                                        }
                                                        if (list4.isEmpty()) {
                                                            this.f = yi7Var6;
                                                            this.a = installedAddon6;
                                                            this.b = setH;
                                                            this.c = null;
                                                            this.d = null;
                                                            this.e = 7;
                                                            objA3 = AddonResolutionService.a(r103, list4, this);
                                                            if (objA3 != ck1Var) {
                                                                yi7Var7 = yi7Var6;
                                                                installedAddon7 = installedAddon6;
                                                                r10 = r103;
                                                                set = setH;
                                                                try {
                                                                    oz2VarB = r10.c.b((List) objA3, this.o, set);
                                                                    instanceId = installedAddon7.getInstanceId();
                                                                    this.f = yi7Var7;
                                                                    this.a = installedAddon7;
                                                                    this.b = set;
                                                                    this.c = oz2VarB;
                                                                    this.e = 8;
                                                                    break;
                                                                } catch (Exception e17) {
                                                                    e = e17;
                                                                    r3 = yi7Var7;
                                                                    r2 = installedAddon7;
                                                                    ExecutorService executorService42222222 = kq.a;
                                                                    kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                                                                    kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                                                                    this.f = null;
                                                                    this.a = null;
                                                                    this.b = null;
                                                                    this.c = null;
                                                                    this.d = null;
                                                                    this.e = 11;
                                                                    if (r3.s(kc8Var, this) == ck1Var) {
                                                                    }
                                                                }
                                                                if (addonRepository.updateLastUsed(instanceId, this) != ck1Var) {
                                                                    set2 = set;
                                                                    yi7Var8 = yi7Var7;
                                                                    installedAddon8 = installedAddon7;
                                                                    r102 = r10;
                                                                    kc8Var2 = new kc8(null, AddonResolutionService.e(r102, oz2VarB.a, set2), oz2VarB.b, y41.am(installedAddon8.getName()));
                                                                    this.f = yi7Var8;
                                                                    this.a = installedAddon8;
                                                                    this.b = null;
                                                                    this.c = null;
                                                                    this.e = 9;
                                                                    if (yi7Var8.s(kc8Var2, this) == ck1Var) {
                                                                    }
                                                                    return e6aVar;
                                                                }
                                                            }
                                                        } else {
                                                            kc8 kc8Var5 = new kc8("No streams found", ik2Var4, ik2Var4, y41.am(installedAddon6.getName()));
                                                            this.f = yi7Var6;
                                                            this.a = installedAddon6;
                                                            this.b = null;
                                                            this.c = null;
                                                            this.d = null;
                                                            this.e = 10;
                                                            if (yi7Var6.s(kc8Var5, this) == ck1Var) {
                                                            }
                                                        }
                                                    }
                                                    list4 = arrayListB;
                                                    if (list4.isEmpty()) {
                                                    }
                                                }
                                            } catch (CancellationException e18) {
                                                e2 = e18;
                                                throw e2;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        r22 = r24;
                        str3 = " raw streams";
                        ik2Var2 = ik2Var4;
                        str14 = "AddonResolutionService";
                        str4 = str2;
                        num3 = num;
                        num4 = num2;
                        String strBuildStreamUrl = installedAddon.buildStreamUrl(str16, str, num4, num3);
                        ExecutorService executorService7 = kq.a;
                        kq.h(str14, "Fetching from " + installedAddon.getName() + str4 + strBuildStreamUrl);
                        this.f = yi7Var2;
                        this.a = installedAddon;
                        this.b = arrayList;
                        this.c = arrayList;
                        this.e = 5;
                        objA = r32.a(strBuildStreamUrl, this);
                        if (objA != ck1Var) {
                            yi7Var3 = yi7Var2;
                            installedAddon3 = installedAddon;
                            list = arrayList;
                            try {
                                arrayList.addAll((Collection) objA);
                                ExecutorService executorService8 = kq.a;
                                kq.h(str14, installedAddon3.getName() + str4 + list.size() + str3);
                                installedAddon6 = installedAddon3;
                                yi7Var6 = yi7Var3;
                                r222 = r22;
                                if (list.isEmpty()) {
                                }
                            } catch (Exception e19) {
                                e = e19;
                                ik2Var4 = ik2Var2;
                                r2 = installedAddon3;
                                r3 = yi7Var3;
                                ExecutorService executorService422222222 = kq.a;
                                kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                                kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                                this.f = null;
                                this.a = null;
                                this.b = null;
                                this.c = null;
                                this.d = null;
                                this.e = 11;
                                if (r3.s(kc8Var, this) == ck1Var) {
                                }
                            }
                        }
                    }
                    break;
                }
                return ck1Var;
            case 1:
                yi7Var = (yi7) this.f;
                s38.b(obj);
                num = num6;
                i = 1;
                yi7Var2 = yi7Var;
                char[] cArr2 = new char[i];
                cArr2[0] = '/';
                String str192 = this.l;
                String strBh2 = n89.bh(str192, cArr2);
                it = ((List) obj).iterator();
                while (true) {
                    if (it.hasNext()) {
                    }
                    str17 = str2;
                    num8 = num2;
                    str15 = str;
                }
                installedAddon = (InstalledAddon) next;
                if (installedAddon != null) {
                    break;
                }
                addonRepository = addonRepository2;
                if (installedAddon != null) {
                }
                return ck1Var;
            case 2:
                s38.b(obj);
                return e6aVar;
            case 3:
                List list6 = (List) this.b;
                installedAddon2 = this.a;
                yi7 yi7Var10 = (yi7) this.f;
                try {
                    s38.b(obj);
                    num = num6;
                    yi7Var2 = yi7Var10;
                    addonRepository = addonRepository2;
                    str = str15;
                    num2 = num8;
                    arrayList = list6;
                    objC = obj;
                    str2 = ": ";
                    listAm = (List) objC;
                    if (listAm.isEmpty()) {
                    }
                    InstalledAddon installedAddon92 = installedAddon2;
                    it2 = listAm.iterator();
                    yi7Var4 = yi7Var2;
                    installedAddon4 = installedAddon92;
                    list2 = arrayList;
                    r23 = r24;
                    if (it2.hasNext()) {
                    }
                } catch (Exception e20) {
                    e = e20;
                    r2 = installedAddon2;
                    str14 = "AddonResolutionService";
                    r3 = yi7Var10;
                    ExecutorService executorService4222222222 = kq.a;
                    kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                    kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                    this.f = null;
                    this.a = null;
                    this.b = null;
                    this.c = null;
                    this.d = null;
                    this.e = 11;
                    if (r3.s(kc8Var, this) == ck1Var) {
                        return ck1Var;
                    }
                }
                break;
            case 4:
                String str20 = this.d;
                Iterator it4 = (Iterator) this.c;
                List list7 = (List) this.b;
                InstalledAddon installedAddon12 = this.a;
                yi7 yi7Var11 = (yi7) this.f;
                try {
                    s38.b(obj);
                    objA2 = obj;
                    r225 = r24;
                    ik2Var = ik2Var4;
                    num5 = num8;
                    str9 = ": ";
                    list3 = list7;
                    num = num6;
                    str6 = str16;
                    str7 = str15;
                    it3 = it4;
                    installedAddon5 = installedAddon12;
                    str11 = " raw streams";
                    str14 = "AddonResolutionService";
                    str8 = str20;
                    addonRepository = addonRepository2;
                    yi7Var4 = yi7Var11;
                } catch (CancellationException e21) {
                    e2 = e21;
                    throw e2;
                } catch (Exception e22) {
                    e = e22;
                    ?? r226 = r24;
                    ik2Var = ik2Var4;
                    num5 = num8;
                    str9 = ": ";
                    str5 = " raw streams";
                    str6 = str16;
                    str7 = str15;
                    str14 = "AddonResolutionService";
                    installedAddon5 = installedAddon12;
                    str8 = str20;
                    addonRepository = addonRepository2;
                    yi7Var4 = yi7Var11;
                    list2 = list7;
                    num = num6;
                    it3 = it4;
                    try {
                        ExecutorService executorService9 = kq.a;
                        message = e.getMessage();
                        sb = new StringBuilder();
                        yi7Var5 = yi7Var4;
                    } catch (Exception e23) {
                        e = e23;
                        yi7Var5 = yi7Var4;
                    }
                    try {
                        sb.append("Error fetching from ");
                        sb.append(str8);
                        sb.append(str9);
                        sb.append(message);
                        kq.a(str14, sb.toString(), e);
                        yi7Var4 = yi7Var5;
                        str2 = str9;
                        str18 = str14;
                        it2 = it3;
                        str = str7;
                        installedAddon4 = installedAddon5;
                        r224 = r226;
                        str16 = str6;
                        str14 = str5;
                        r23 = r224;
                        num2 = num5;
                        ik2Var4 = ik2Var;
                        if (it2.hasNext()) {
                        }
                    } catch (Exception e24) {
                        e = e24;
                        r32 = yi7Var5;
                        r24 = installedAddon5;
                        ik2Var4 = ik2Var;
                        r2 = r24;
                        r3 = r32;
                        ExecutorService executorService42222222222 = kq.a;
                        kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                        kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                        this.f = null;
                        this.a = null;
                        this.b = null;
                        this.c = null;
                        this.d = null;
                        this.e = 11;
                        if (r3.s(kc8Var, this) == ck1Var) {
                        }
                    }
                }
                List list52 = (List) objA2;
                ExecutorService executorService62 = kq.a;
                int size2 = list52.size();
                StringBuilder sb22 = new StringBuilder();
                sb22.append(str8);
                sb22.append(str9);
                sb22.append(size2);
                str5 = str11;
                sb22.append(str5);
                kq.h(str14, sb22.toString());
                Boxing.boxBoolean(list3.addAll(list52));
                str2 = str9;
                str18 = str14;
                it2 = it3;
                str = str7;
                installedAddon4 = installedAddon5;
                list2 = list3;
                r224 = r225;
                str16 = str6;
                str14 = str5;
                r23 = r224;
                num2 = num5;
                ik2Var4 = ik2Var;
                if (it2.hasNext()) {
                }
                break;
            case 5:
                arrayList = (List) this.c;
                List list8 = (List) this.b;
                installedAddon3 = this.a;
                yi7Var3 = (yi7) this.f;
                try {
                    s38.b(obj);
                    r22 = r24;
                    addonRepository = addonRepository2;
                    num3 = num6;
                    ik2Var2 = ik2Var4;
                    num4 = num8;
                    str4 = ": ";
                    list = list8;
                    str3 = " raw streams";
                    str14 = "AddonResolutionService";
                    objA = obj;
                    arrayList.addAll((Collection) objA);
                    ExecutorService executorService82 = kq.a;
                    kq.h(str14, installedAddon3.getName() + str4 + list.size() + str3);
                    installedAddon6 = installedAddon3;
                    yi7Var6 = yi7Var3;
                    r222 = r22;
                    if (list.isEmpty()) {
                    }
                } catch (Exception e25) {
                    e = e25;
                    r24 = installedAddon3;
                    r32 = yi7Var3;
                    str14 = str18;
                    r2 = r24;
                    r3 = r32;
                    ExecutorService executorService422222222222 = kq.a;
                    kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                    kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                    this.f = null;
                    this.a = null;
                    this.b = null;
                    this.c = null;
                    this.d = null;
                    this.e = 11;
                    if (r3.s(kc8Var, this) == ck1Var) {
                    }
                }
                break;
            case 6:
                InstalledAddon installedAddon13 = this.a;
                s38.b(obj);
                return e6aVar;
            case 7:
                setH = (Set) this.b;
                InstalledAddon installedAddon14 = this.a;
                yi7Var9 = (yi7) this.f;
                try {
                    s38.b(obj);
                    r10 = r24;
                    installedAddon7 = installedAddon14;
                    addonRepository = addonRepository2;
                    yi7Var7 = yi7Var9;
                    str14 = "AddonResolutionService";
                    objA3 = obj;
                    set = setH;
                    oz2VarB = r10.c.b((List) objA3, this.o, set);
                    instanceId = installedAddon7.getInstanceId();
                    this.f = yi7Var7;
                    this.a = installedAddon7;
                    this.b = set;
                    this.c = oz2VarB;
                    this.e = 8;
                    if (addonRepository.updateLastUsed(instanceId, this) != ck1Var) {
                    }
                } catch (Exception e26) {
                    e = e26;
                    r24 = installedAddon14;
                    r32 = yi7Var9;
                    str14 = str18;
                    r2 = r24;
                    r3 = r32;
                    ExecutorService executorService4222222222222 = kq.a;
                    kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                    kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                    this.f = null;
                    this.a = null;
                    this.b = null;
                    this.c = null;
                    this.d = null;
                    this.e = 11;
                    if (r3.s(kc8Var, this) == ck1Var) {
                    }
                }
                return ck1Var;
            case 8:
                oz2VarB = (oz2) this.c;
                Set set3 = (Set) this.b;
                InstalledAddon installedAddon15 = this.a;
                yi7Var9 = (yi7) this.f;
                try {
                    s38.b(obj);
                    r102 = r24;
                    installedAddon8 = installedAddon15;
                    set2 = set3;
                    yi7Var8 = yi7Var9;
                    kc8Var2 = new kc8(null, AddonResolutionService.e(r102, oz2VarB.a, set2), oz2VarB.b, y41.am(installedAddon8.getName()));
                    this.f = yi7Var8;
                    this.a = installedAddon8;
                    this.b = null;
                    this.c = null;
                    this.e = 9;
                    if (yi7Var8.s(kc8Var2, this) == ck1Var) {
                    }
                } catch (Exception e27) {
                    e = e27;
                    r24 = installedAddon15;
                    r32 = yi7Var9;
                    str14 = str18;
                    r2 = r24;
                    r3 = r32;
                    ExecutorService executorService42222222222222 = kq.a;
                    kq.a(str14, "Error scraping with stremioId: " + e.getMessage(), e);
                    kc8Var = new kc8(n41.n("Failed to fetch streams: ", e.getMessage()), ik2Var4, ik2Var4, y41.am(r2.getName()));
                    this.f = null;
                    this.a = null;
                    this.b = null;
                    this.c = null;
                    this.d = null;
                    this.e = 11;
                    if (r3.s(kc8Var, this) == ck1Var) {
                    }
                }
                return e6aVar;
            case 9:
            case 10:
                InstalledAddon installedAddon16 = this.a;
                s38.b(obj);
                return e6aVar;
            case 11:
                s38.b(obj);
                return e6aVar;
            default:
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
    }
}
