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.StremioSubtitleProvider$download$2", f = "StremioSubtitleProvider.kt", i = {}, l = {108}, m = "invokeSuspend", n = {}, s = {})
final class h extends SuspendLambda implements gr3<ak1, Continuation<? super q38<? extends File>>, Object> {
    public int a;
    public /* synthetic */ Object b;
    public final /* synthetic */ StremioSubtitleProvider c;
    public final /* synthetic */ sb9 d;

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

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

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

    /* JADX WARN: Removed duplicated region for block: B:29:0x0089  */
    /* 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;
        Throwable thA;
        ck1 ck1Var = ck1.a;
        int i = this.a;
        try {
        } catch (Throwable th) {
            objA = s38.a(th);
        }
        if (i == 0) {
            s38.b(obj);
            StremioSubtitleProvider stremioSubtitleProvider = this.c;
            sb9 sb9Var = this.d;
            File file = new File((File) stremioSubtitleProvider.d.getValue(), sb9Var.a + "." + sb9Var.k);
            if (file.exists()) {
                if (StremioSubtitleProvider.e(file)) {
                    file.getAbsolutePath();
                    objA = file;
                    thA = q38.a(objA);
                    if (thA != null) {
                        Log.e("StremioSubtitleProvider", "Stremio subtitle download failed", thA);
                    }
                    return new q38(objA);
                }
                Log.w("StremioSubtitleProvider", "Cached subtitle file invalid, re-downloading");
                file.delete();
            }
            String str = sb9Var.e;
            if (n89.ab(str)) {
                throw new IllegalStateException("No download URL for subtitle");
            }
            this.a = 1;
            obj = stremioSubtitleProvider.c(str, file, 3, this);
            if (obj == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(obj);
        }
        objA = (File) obj;
        thA = q38.a(objA);
        if (thA != null) {
        }
        return new q38(objA);
    }
}
