package com.strmr.ps.data.subtitle;

import android.util.Log;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.n89;
import defpackage.q38;
import defpackage.s38;
import defpackage.sb9;
import java.io.File;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
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;", "Ljava/io/File;", "<anonymous>", "(Lak1;)Lq38;"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.data.subtitle.OpenSubtitlesProvider$download$2", f = "OpenSubtitlesProvider.kt", i = {1}, l = {148, 153, 156}, m = "invokeSuspend", n = {"cacheFile"}, s = {"L$1"})
final class b extends SuspendLambda implements gr3<ak1, Continuation<? super q38<? extends File>>, Object> {
    public File a;
    public int b;
    public /* synthetic */ Object c;
    public final /* synthetic */ OpenSubtitlesProvider d;
    public final /* synthetic */ sb9 e;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public b(OpenSubtitlesProvider openSubtitlesProvider, sb9 sb9Var, Continuation continuation) {
        super(2, continuation);
        this.d = openSubtitlesProvider;
        this.e = sb9Var;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        b bVar = new b(this.d, this.e, continuation);
        bVar.c = obj;
        return bVar;
    }

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

    /* JADX WARN: Code restructure failed: missing block: B:35:0x00b3, code lost:
    
        if (r12 != r0) goto L37;
     */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        Object objA;
        OpenSubtitlesProvider openSubtitlesProvider;
        File file;
        ck1 ck1Var = ck1.a;
        int i = this.b;
        try {
            if (i == 0) {
                s38.b(obj);
                OpenSubtitlesProvider openSubtitlesProvider2 = this.d;
                sb9 sb9Var = this.e;
                File file2 = new File((File) openSubtitlesProvider2.d.getValue(), sb9Var.a + "." + sb9Var.k);
                if (file2.exists()) {
                    if (OpenSubtitlesProvider.f(file2)) {
                        file2.getAbsolutePath();
                        objA = file2;
                    } else {
                        Log.w("OpenSubtitlesProvider", "Cached subtitle file invalid, re-downloading");
                        file2.delete();
                    }
                }
                Integer numBe = n89.be(sb9Var.a);
                if (numBe == null) {
                    String str = sb9Var.e;
                    this.b = 1;
                    obj = openSubtitlesProvider2.d(str, file2, 3, this);
                    if (obj == ck1Var) {
                    }
                    objA = (File) obj;
                } else {
                    int iIntValue = numBe.intValue();
                    this.c = openSubtitlesProvider2;
                    this.a = file2;
                    this.b = 2;
                    Object objA2 = OpenSubtitlesProvider.a(openSubtitlesProvider2, iIntValue, 5, this);
                    if (objA2 != ck1Var) {
                        openSubtitlesProvider = openSubtitlesProvider2;
                        obj = objA2;
                        file = file2;
                        this.c = null;
                        this.a = null;
                        this.b = 3;
                        Object obj2 = OpenSubtitlesProvider.e;
                        obj = openSubtitlesProvider.d((String) obj, file, 3, this);
                    }
                }
                return ck1Var;
            }
            if (i == 1) {
                s38.b(obj);
                objA = (File) obj;
            } else if (i == 2) {
                File file3 = this.a;
                OpenSubtitlesProvider openSubtitlesProvider3 = (OpenSubtitlesProvider) this.c;
                s38.b(obj);
                file = file3;
                openSubtitlesProvider = openSubtitlesProvider3;
                this.c = null;
                this.a = null;
                this.b = 3;
                Object obj22 = OpenSubtitlesProvider.e;
                obj = openSubtitlesProvider.d((String) obj, file, 3, this);
            } else {
                if (i != 3) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
                objA = (File) obj;
            }
        } catch (Throwable th) {
            objA = s38.a(th);
        }
        Throwable thA = q38.a(objA);
        if (thA != null) {
            Log.e("OpenSubtitlesProvider", "Subtitle download failed", thA);
        }
        return new q38(objA);
    }
}
