package com.strmr.ps.data.subtitle;

import android.util.Log;
import defpackage.ak1;
import defpackage.bz0;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.ez2;
import defpackage.gr3;
import defpackage.n89;
import defpackage.pw7;
import defpackage.r2;
import defpackage.s38;
import java.io.File;
import java.nio.charset.Charset;
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\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Ljava/io/File;", "<anonymous>", "(Lak1;)Ljava/io/File;"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.data.subtitle.SubtitleManager$applySubtitleOffset$2", f = "SubtitleManager.kt", i = {}, l = {}, m = "invokeSuspend", n = {}, s = {})
final class l extends SuspendLambda implements gr3<ak1, Continuation<? super File>, Object> {
    public final /* synthetic */ long a;
    public final /* synthetic */ File b;
    public final /* synthetic */ SubtitleManager c;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public l(long j, File file, SubtitleManager subtitleManager, Continuation continuation) {
        super(2, continuation);
        this.a = j;
        this.b = file;
        this.c = subtitleManager;
    }

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

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

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Object invokeSuspend(Object obj) {
        String strE;
        ck1 ck1Var = ck1.a;
        s38.b(obj);
        long j = this.a;
        File file = this.b;
        if (j == 0) {
            return file;
        }
        try {
            Charset charset = bz0.a;
            String strB = ez2.b(file, charset);
            String name = file.getName();
            cr4.f(name, "getName(...)");
            boolean zR = n89.r(name, ".srt", true);
            SubtitleManager subtitleManager = this.c;
            if (zR) {
                Object obj2 = SubtitleManager.g;
                strE = new pw7("(\\d{2}):(\\d{2}):(\\d{2}),(\\d{3})\\s*-->\\s*(\\d{2}):(\\d{2}):(\\d{2}),(\\d{3})").e(strB, new r2(j, subtitleManager, 4));
            } else {
                String name2 = file.getName();
                cr4.f(name2, "getName(...)");
                if (!n89.r(name2, ".vtt", true)) {
                    Log.w("SubtitleManager", "Subtitle offset not supported for format: " + file.getName());
                    return file;
                }
                Object obj3 = SubtitleManager.g;
                strE = new pw7("(\\d{2}):(\\d{2})\\.(\\d{3})\\s*-->\\s*(\\d{2}):(\\d{2})\\.(\\d{3})").e(new pw7("(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{3})\\s*-->\\s*(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{3})").e(strB, new r2(j, subtitleManager, 2)), new r2(j, subtitleManager, 3));
            }
            File file2 = new File(subtitleManager.f.getCacheDir(), "subtitle_offset");
            file2.mkdirs();
            File file3 = new File(file2, "offset_" + j + "_" + file.getName());
            ez2.c(file3, strE, charset);
            file3.getName();
            return file3;
        } catch (Exception e) {
            Log.e("SubtitleManager", "Error applying subtitle offset", e);
            return file;
        }
    }
}
