package com.strmr.ps.data.repository;

import android.util.Log;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.session.MediaSessionService;
import com.google.android.gms.measurement.api.AppMeasurementSdk;
import com.strmr.ps.data.local.dao.TorBoxAccountDao;
import com.strmr.ps.data.local.entity.PlaybackProgress;
import com.strmr.ps.data.local.entity.TorBoxAccount;
import com.strmr.ps.data.model.DebridError;
import com.strmr.ps.data.model.DebridProvider;
import com.strmr.ps.data.model.debrid.DebridFileItem;
import com.strmr.ps.data.model.debrid.DebridService;
import com.strmr.ps.data.model.debrid.VideoExtensions;
import com.strmr.ps.data.remote.api.TorBoxApiService;
import com.strmr.ps.data.remote.model.torbox.TorBoxCacheResult;
import com.strmr.ps.data.remote.model.torbox.TorBoxDeviceCodeData;
import com.strmr.ps.data.remote.model.torbox.TorBoxDeviceTokenData;
import com.strmr.ps.data.remote.model.torbox.TorBoxDeviceTokenRequest;
import com.strmr.ps.data.remote.model.torbox.TorBoxFile;
import com.strmr.ps.data.remote.model.torbox.TorBoxResponse;
import com.strmr.ps.data.remote.model.torbox.TorBoxTorrentData;
import com.strmr.ps.data.remote.model.torbox.TorBoxTorrentInfo;
import com.strmr.ps.data.remote.model.torbox.TorBoxUserData;
import com.strmr.ps.data.supabase.DeviceManager;
import com.strmr.ps.data.supabase.SettingsSyncManager;
import dagger.Lazy;
import defpackage.ak1;
import defpackage.bk1;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.dr4;
import defpackage.e6a;
import defpackage.h32;
import defpackage.ik2;
import defpackage.kp6;
import defpackage.kq;
import defpackage.m02;
import defpackage.m12;
import defpackage.n41;
import defpackage.n89;
import defpackage.pq6;
import defpackage.pw7;
import defpackage.q38;
import defpackage.qo9;
import defpackage.s38;
import defpackage.sc2;
import defpackage.vo2;
import defpackage.vw2;
import defpackage.vx8;
import defpackage.wo5;
import defpackage.x71;
import defpackage.y41;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Singleton;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.ContinuationImpl;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import retrofit2.HttpException;

/* JADX INFO: loaded from: classes3.dex */
@Singleton
@Metadata(d1 = {"\u0000\u0096\u0001\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0010 \n\u0000\n\u0002\u0010$\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0010\b\n\u0002\b\u000f\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\t\n\u0002\u0010\t\n\u0002\b\t\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0007\u0018\u0000 f2\u00020\u0001:\u0001fB=\b\u0007\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\u0006\u0010\u0005\u001a\u00020\u0004\u0012\f\u0010\b\u001a\b\u0012\u0004\u0012\u00020\u00070\u0006\u0012\f\u0010\n\u001a\b\u0012\u0004\u0012\u00020\t0\u0006\u0012\u0006\u0010\f\u001a\u00020\u000b¢\u0006\u0004\b\r\u0010\u000eJ\u0017\u0010\u0011\u001a\u00020\u000f2\u0006\u0010\u0010\u001a\u00020\u000fH\u0002¢\u0006\u0004\b\u0011\u0010\u0012J\u0010\u0010\u0014\u001a\u00020\u0013H\u0082@¢\u0006\u0004\b\u0014\u0010\u0015J\u0012\u0010\u0017\u001a\u0004\u0018\u00010\u0016H\u0086@¢\u0006\u0004\b\u0017\u0010\u0015J\u001e\u0010\u001c\u001a\b\u0012\u0004\u0012\u00020\u00160\u00192\u0006\u0010\u0018\u001a\u00020\u000fH\u0086@¢\u0006\u0004\b\u001a\u0010\u001bJ\u0016\u0010\u001e\u001a\b\u0012\u0004\u0012\u00020\u00160\u0019H\u0086@¢\u0006\u0004\b\u001d\u0010\u0015J\u0016\u0010!\u001a\b\u0012\u0004\u0012\u00020\u001f0\u0019H\u0086@¢\u0006\u0004\b \u0010\u0015J \u0010$\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u000f0\u00192\u0006\u0010\"\u001a\u00020\u000fH\u0086@¢\u0006\u0004\b#\u0010\u001bJ\u001e\u0010'\u001a\b\u0012\u0004\u0012\u00020\u00160\u00192\u0006\u0010%\u001a\u00020\u000fH\u0086@¢\u0006\u0004\b&\u0010\u001bJ2\u0010.\u001a\u0016\u0012\u0012\u0012\u0010\u0012\u0004\u0012\u00020\u000f\u0012\u0006\u0012\u0004\u0018\u00010+0*0\u00192\f\u0010)\u001a\b\u0012\u0004\u0012\u00020\u000f0(H\u0096@¢\u0006\u0004\b,\u0010-J\u0012\u00100\u001a\u0004\u0018\u00010/H\u0096@¢\u0006\u0004\b0\u0010\u0015JF\u00108\u001a\b\u0012\u0004\u0012\u00020\u000f0\u00192\u0006\u00101\u001a\u00020\u000f2\b\u00102\u001a\u0004\u0018\u00010/2\b\u00103\u001a\u0004\u0018\u00010/2\b\u00104\u001a\u0004\u0018\u00010/2\b\u00105\u001a\u0004\u0018\u00010\u000fH\u0096@¢\u0006\u0004\b6\u00107J\u0010\u00109\u001a\u00020\u0013H\u0096@¢\u0006\u0004\b9\u0010\u0015J\u0010\u0010:\u001a\u00020+H\u0096@¢\u0006\u0004\b:\u0010\u0015J\u0012\u0010;\u001a\u0004\u0018\u00010\u000fH\u0096@¢\u0006\u0004\b;\u0010\u0015J\u0017\u0010=\u001a\u0004\u0018\u00010/2\u0006\u0010<\u001a\u00020\u0016¢\u0006\u0004\b=\u0010>J\u001c\u0010A\u001a\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u00020?0(0\u0019H\u0096@¢\u0006\u0004\b@\u0010\u0015J$\u0010E\u001a\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u00020?0(0\u00192\u0006\u0010B\u001a\u00020/H\u0086@¢\u0006\u0004\bC\u0010DJ\u001e\u0010J\u001a\b\u0012\u0004\u0012\u00020\u000f0\u00192\u0006\u0010G\u001a\u00020FH\u0096@¢\u0006\u0004\bH\u0010IJ\u001e\u0010L\u001a\b\u0012\u0004\u0012\u00020\u00130\u00192\u0006\u0010B\u001a\u00020/H\u0086@¢\u0006\u0004\bK\u0010DJ\u001e\u0010O\u001a\b\u0012\u0004\u0012\u00020+0\u00192\u0006\u0010M\u001a\u00020\u000fH\u0086@¢\u0006\u0004\bN\u0010\u001bJ*\u0010U\u001a\b\u0012\u0004\u0012\u00020\u00130\u00192\u0006\u0010Q\u001a\u00020P2\n\b\u0002\u0010R\u001a\u0004\u0018\u00010\u000fH\u0086@¢\u0006\u0004\bS\u0010TR\u0014\u0010\u0003\u001a\u00020\u00028\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0003\u0010VR\u0014\u0010\u0005\u001a\u00020\u00048\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0005\u0010WR\u001a\u0010\b\u001a\b\u0012\u0004\u0012\u00020\u00070\u00068\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\b\u0010XR\u001a\u0010\n\u001a\b\u0012\u0004\u0012\u00020\t0\u00068\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\n\u0010XR\u0014\u0010\f\u001a\u00020\u000b8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\f\u0010YR\u001a\u0010[\u001a\u00020Z8\u0016X\u0096\u0004¢\u0006\f\n\u0004\b[\u0010\\\u001a\u0004\b]\u0010^R\u001a\u0010_\u001a\u00020\u000f8\u0016X\u0096D¢\u0006\f\n\u0004\b_\u0010`\u001a\u0004\ba\u0010bR\u0014\u0010d\u001a\u00020c8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\bd\u0010e¨\u0006g"}, d2 = {"Lcom/strmr/ps/data/repository/TorBoxRepository;", "Lcom/strmr/ps/data/repository/IDebridLibraryProvider;", "Lcom/strmr/ps/data/remote/api/TorBoxApiService;", "torBoxApiService", "Lcom/strmr/ps/data/local/dao/TorBoxAccountDao;", "accountDao", "Ldagger/Lazy;", "Lcom/strmr/ps/data/supabase/SettingsSyncManager;", "settingsSyncManager", "Lcom/strmr/ps/data/supabase/DeviceManager;", "deviceManager", "Lcom/strmr/ps/data/repository/LinkFilterPreferences;", "linkFilterPreferences", "<init>", "(Lcom/strmr/ps/data/remote/api/TorBoxApiService;Lcom/strmr/ps/data/local/dao/TorBoxAccountDao;Ldagger/Lazy;Ldagger/Lazy;Lcom/strmr/ps/data/repository/LinkFilterPreferences;)V", "", AppMeasurementSdk.ConditionalUserProperty.NAME, "normalizeForMatch", "(Ljava/lang/String;)Ljava/lang/String;", "Le6a;", "triggerCloudSync", "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "Lcom/strmr/ps/data/local/entity/TorBoxAccount;", "getAccount", "apiKey", "Lq38;", "verifyAndSaveApiKey-gIAlu-s", "(Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "verifyAndSaveApiKey", "refreshAccountInfo-IoAF18A", "refreshAccountInfo", "Lcom/strmr/ps/data/remote/model/torbox/TorBoxDeviceCodeData;", "requestDeviceCode-IoAF18A", "requestDeviceCode", "deviceCode", "pollForDeviceToken-gIAlu-s", "pollForDeviceToken", "apiToken", "saveDeviceToken-gIAlu-s", "saveDeviceToken", "", "hashes", "", "", "checkCacheStatus-gIAlu-s", "(Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "checkCacheStatus", "", "getAccountExpirationStatus", "magnetOrHash", "fileIdx", "season", PlaybackProgress.TYPE_EPISODE, "airDate", "resolveToDirectLink-hUnOzRk", "(Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "resolveToDirectLink", "clearAccount", "hasAccount", "getApiKey", "account", "getDaysRemaining", "(Lcom/strmr/ps/data/local/entity/TorBoxAccount;)Ljava/lang/Integer;", "Lcom/strmr/ps/data/model/debrid/DebridFileItem;", "getLibraryItems-IoAF18A", "getLibraryItems", "torrentId", "getTorrentFilesForLibrary-gIAlu-s", "(ILkotlin/coroutines/Continuation;)Ljava/lang/Object;", "getTorrentFilesForLibrary", "Lcom/strmr/ps/data/model/debrid/DebridFileItem$File;", "file", "resolveLibraryFile-gIAlu-s", "(Lcom/strmr/ps/data/model/debrid/DebridFileItem$File;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "resolveLibraryFile", "deleteTorrent-gIAlu-s", "deleteTorrent", "hash", "deleteByHash-gIAlu-s", "deleteByHash", "", "resolveTimestamp", "fileName", "deleteMostRecent-0E7RQCE", "(JLjava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "deleteMostRecent", "Lcom/strmr/ps/data/remote/api/TorBoxApiService;", "Lcom/strmr/ps/data/local/dao/TorBoxAccountDao;", "Ldagger/Lazy;", "Lcom/strmr/ps/data/repository/LinkFilterPreferences;", "Lcom/strmr/ps/data/model/DebridProvider;", "provider", "Lcom/strmr/ps/data/model/DebridProvider;", "getProvider", "()Lcom/strmr/ps/data/model/DebridProvider;", "serviceName", "Ljava/lang/String;", "getServiceName", "()Ljava/lang/String;", "Lak1;", "syncScope", "Lak1;", "Companion", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class TorBoxRepository implements IDebridLibraryProvider {

    @kp6
    private static final String PROVIDER_ID = "torbox";

    @kp6
    private static final String TAG = "TorBoxRepository";

    @kp6
    private final TorBoxAccountDao accountDao;

    @kp6
    private final Lazy<DeviceManager> deviceManager;

    @kp6
    private final LinkFilterPreferences linkFilterPreferences;

    @kp6
    private final DebridProvider provider;

    @kp6
    private final String serviceName;

    @kp6
    private final Lazy<SettingsSyncManager> settingsSyncManager;

    @kp6
    private final ak1 syncScope;

    @kp6
    private final TorBoxApiService torBoxApiService;

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.TorBoxRepository$clearAccount$1, reason: invalid class name */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.TorBoxRepository", f = "TorBoxRepository.kt", i = {0}, l = {463, 466}, m = "clearAccount", n = {"this"}, s = {"L$0"})
    public static final class AnonymousClass1 extends ContinuationImpl {
        Object L$0;
        int label;
        /* synthetic */ Object result;

        public AnonymousClass1(Continuation<? super AnonymousClass1> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return TorBoxRepository.this.clearAccount(this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.TorBoxRepository$getAccountExpirationStatus$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.TorBoxRepository", f = "TorBoxRepository.kt", i = {}, l = {254}, m = "getAccountExpirationStatus", n = {}, s = {})
    public static final class C04181 extends ContinuationImpl {
        int label;
        /* synthetic */ Object result;

        public C04181(Continuation<? super C04181> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return TorBoxRepository.this.getAccountExpirationStatus(this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.TorBoxRepository$getApiKey$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.TorBoxRepository", f = "TorBoxRepository.kt", i = {}, l = {474}, m = "getApiKey", n = {}, s = {})
    public static final class C04191 extends ContinuationImpl {
        int label;
        /* synthetic */ Object result;

        public C04191(Continuation<? super C04191> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return TorBoxRepository.this.getApiKey(this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.TorBoxRepository$hasAccount$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.TorBoxRepository", f = "TorBoxRepository.kt", i = {}, l = {472}, m = "hasAccount", n = {}, s = {})
    public static final class C04201 extends ContinuationImpl {
        int label;
        /* synthetic */ Object result;

        public C04201(Continuation<? super C04201> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return TorBoxRepository.this.hasAccount(this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.TorBoxRepository$triggerCloudSync$1, reason: invalid class name and case insensitive filesystem */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.TorBoxRepository", f = "TorBoxRepository.kt", i = {}, l = {811}, m = "triggerCloudSync", n = {}, s = {})
    public static final class C04211 extends ContinuationImpl {
        int label;
        /* synthetic */ Object result;

        public C04211(Continuation<? super C04211> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return TorBoxRepository.this.triggerCloudSync(this);
        }
    }

    @Inject
    public TorBoxRepository(@kp6 TorBoxApiService torBoxApiService, @kp6 TorBoxAccountDao torBoxAccountDao, @kp6 Lazy<SettingsSyncManager> lazy, @kp6 Lazy<DeviceManager> lazy2, @kp6 LinkFilterPreferences linkFilterPreferences) {
        cr4.g(torBoxApiService, "torBoxApiService");
        cr4.g(torBoxAccountDao, "accountDao");
        cr4.g(lazy, "settingsSyncManager");
        cr4.g(lazy2, "deviceManager");
        cr4.g(linkFilterPreferences, "linkFilterPreferences");
        this.torBoxApiService = torBoxApiService;
        this.accountDao = torBoxAccountDao;
        this.settingsSyncManager = lazy;
        this.deviceManager = lazy2;
        this.linkFilterPreferences = linkFilterPreferences;
        this.provider = DebridProvider.TORBOX;
        this.serviceName = "torbox";
        m12 m12Var = sc2.a;
        this.syncScope = bk1.a(m02.c);
    }

    /* JADX INFO: renamed from: deleteMostRecent-0E7RQCE$default, reason: not valid java name */
    public static /* synthetic */ Object m137deleteMostRecent0E7RQCE$default(TorBoxRepository torBoxRepository, long j, String str, Continuation continuation, int i, Object obj) {
        if ((i & 2) != 0) {
            str = null;
        }
        return torBoxRepository.m139deleteMostRecent0E7RQCE(j, str, continuation);
    }

    private final String normalizeForMatch(String name) {
        String lowerCase = name.toLowerCase(Locale.ROOT);
        cr4.f(lowerCase, "toLowerCase(...)");
        return n89.bg(new pw7("[.\\-_\\s]+").f(" ", n89.ba(lowerCase, lowerCase))).toString();
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object triggerCloudSync(Continuation<? super e6a> continuation) {
        C04211 c04211;
        if (continuation instanceof C04211) {
            c04211 = (C04211) continuation;
            int i = c04211.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c04211.label = i - Integer.MIN_VALUE;
            } else {
                c04211 = new C04211(continuation);
            }
        }
        Object objC = c04211.result;
        ck1 ck1Var = ck1.a;
        int i2 = c04211.label;
        e6a e6aVar = e6a.a;
        try {
            if (i2 == 0) {
                s38.b(objC);
                String strE = this.deviceManager.get().e();
                if (strE == null) {
                    Log.w(TAG, "Skipping cloud sync: device not linked (no access token)");
                    return e6aVar;
                }
                TorBoxRepository$triggerCloudSync$result$1 torBoxRepository$triggerCloudSync$result$1 = new TorBoxRepository$triggerCloudSync$result$1(this, strE, null);
                c04211.label = 1;
                objC = qo9.c(5000L, torBoxRepository$triggerCloudSync$result$1, c04211);
                if (objC == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i2 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(objC);
            }
            if (cr4.b((Boolean) objC, Boxing.boxBoolean(true))) {
                Log.w(TAG, "TorBox cloud sync completed successfully");
            } else {
                Log.w(TAG, "TorBox cloud sync timed out or returned false — pending deletion flag preserved");
            }
        } catch (Exception e) {
            Log.w(TAG, "TorBox cloud sync failed — pending deletion flag preserved", e);
        }
        return e6aVar;
    }

    /* JADX WARN: Removed duplicated region for block: B:67:0x0191  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x0192  */
    /* JADX WARN: Removed duplicated region for block: B:72:0x01a0 A[Catch: Exception -> 0x0038, LOOP:3: B:70:0x019a->B:72:0x01a0, LOOP_END, TryCatch #0 {Exception -> 0x0038, blocks: (B:14:0x0033, B:33:0x00a9, B:35:0x00b5, B:37:0x00bb, B:38:0x00ca, B:41:0x00d2, B:42:0x00ed, B:46:0x00fe, B:47:0x0105, B:49:0x010b, B:51:0x0123, B:53:0x0129, B:54:0x0131, B:63:0x015d, B:57:0x013a, B:58:0x0142, B:60:0x0148, B:62:0x015a, B:65:0x0183, B:69:0x0193, B:70:0x019a, B:72:0x01a0, B:73:0x01af, B:29:0x0079), top: B:77:0x0029 }] */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0018  */
    @Override // com.strmr.ps.data.repository.IDebridProvider
    @pq6
    /* JADX INFO: renamed from: checkCacheStatus-gIAlu-s */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object mo66checkCacheStatusgIAlus(@kp6 List<String> list, @kp6 Continuation<? super q38<? extends Map<String, Boolean>>> continuation) {
        TorBoxRepository$checkCacheStatus$1 torBoxRepository$checkCacheStatus$1;
        Object obj;
        List<String> list2;
        TorBoxRepository torBoxRepository;
        List<String> list3;
        TorBoxResponse torBoxResponse;
        int i;
        int iH;
        if (continuation instanceof TorBoxRepository$checkCacheStatus$1) {
            torBoxRepository$checkCacheStatus$1 = (TorBoxRepository$checkCacheStatus$1) continuation;
            int i2 = torBoxRepository$checkCacheStatus$1.label;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                torBoxRepository$checkCacheStatus$1.label = i2 - Integer.MIN_VALUE;
            } else {
                torBoxRepository$checkCacheStatus$1 = new TorBoxRepository$checkCacheStatus$1(this, continuation);
            }
        }
        TorBoxRepository$checkCacheStatus$1 torBoxRepository$checkCacheStatus$12 = torBoxRepository$checkCacheStatus$1;
        Object obj2 = torBoxRepository$checkCacheStatus$12.result;
        ck1 ck1Var = ck1.a;
        int i3 = torBoxRepository$checkCacheStatus$12.label;
        int i4 = 0;
        try {
            if (i3 == 0) {
                s38.b(obj2);
                TorBoxAccountDao torBoxAccountDao = this.accountDao;
                torBoxRepository$checkCacheStatus$12.L$0 = this;
                torBoxRepository$checkCacheStatus$12.L$1 = list;
                torBoxRepository$checkCacheStatus$12.label = 1;
                Object account = torBoxAccountDao.getAccount("torbox", torBoxRepository$checkCacheStatus$12);
                if (account != ck1Var) {
                    obj = account;
                    list2 = list;
                    torBoxRepository = this;
                }
                return ck1Var;
            }
            if (i3 != 1) {
                if (i3 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                list3 = (List) torBoxRepository$checkCacheStatus$12.L$0;
                s38.b(obj2);
                torBoxResponse = (TorBoxResponse) obj2;
                i = 16;
                if (torBoxResponse.getSuccess() || torBoxResponse.getData() == null) {
                    List<String> list4 = list3;
                    iH = wo5.h(y41.p(list4, 10));
                    if (iH < 16) {
                        i = iH;
                    }
                    LinkedHashMap linkedHashMap = new LinkedHashMap(i);
                    for (Object obj3 : list4) {
                        linkedHashMap.put(obj3, Boxing.boxBoolean(false));
                    }
                    ExecutorService executorService = kq.a;
                    kq.h(TAG, "Cache check returned empty or error, assuming nothing cached");
                    return linkedHashMap;
                }
                LinkedHashMap linkedHashMap2 = new LinkedHashMap();
                Iterator it = ((Iterable) torBoxResponse.getData()).iterator();
                while (it.hasNext()) {
                    String lowerCase = ((TorBoxCacheResult) it.next()).getHash().toLowerCase(Locale.ROOT);
                    cr4.f(lowerCase, "toLowerCase(...)");
                    linkedHashMap2.put(lowerCase, Boxing.boxBoolean(true));
                }
                List<String> list5 = list3;
                int iH2 = wo5.h(y41.p(list5, 10));
                if (iH2 >= 16) {
                    i = iH2;
                }
                LinkedHashMap linkedHashMap3 = new LinkedHashMap(i);
                for (Object obj4 : list5) {
                    String lowerCase2 = ((String) obj4).toLowerCase(Locale.ROOT);
                    cr4.f(lowerCase2, "toLowerCase(...)");
                    Boolean bool = (Boolean) linkedHashMap2.get(lowerCase2);
                    linkedHashMap3.put(obj4, Boxing.boxBoolean(bool != null ? bool.booleanValue() : false));
                }
                ExecutorService executorService2 = kq.a;
                if (!linkedHashMap3.isEmpty()) {
                    Iterator it2 = linkedHashMap3.entrySet().iterator();
                    while (it2.hasNext()) {
                        if (((Boolean) ((Map.Entry) it2.next()).getValue()).booleanValue()) {
                            i4++;
                        }
                    }
                }
                kq.h(TAG, "Cache check: " + i4 + " of " + list3.size() + " cached");
                return linkedHashMap3;
            }
            List<String> list6 = (List) torBoxRepository$checkCacheStatus$12.L$1;
            torBoxRepository = (TorBoxRepository) torBoxRepository$checkCacheStatus$12.L$0;
            s38.b(obj2);
            obj = obj2;
            list2 = list6;
            TorBoxAccount torBoxAccount = (TorBoxAccount) obj;
            if (torBoxAccount == null) {
                return vw2.d("No TorBox account configured");
            }
            String strAi = y41.ai(list2, ",", null, null, null, 62);
            TorBoxApiService torBoxApiService = torBoxRepository.torBoxApiService;
            String authHeader = torBoxAccount.getAuthHeader();
            Boolean boolBoxBoolean = Boxing.boxBoolean(false);
            torBoxRepository$checkCacheStatus$12.L$0 = list2;
            torBoxRepository$checkCacheStatus$12.L$1 = null;
            torBoxRepository$checkCacheStatus$12.label = 2;
            Object objCheckCached = torBoxApiService.checkCached(authHeader, strAi, "list", boolBoxBoolean, torBoxRepository$checkCacheStatus$12);
            if (objCheckCached != ck1Var) {
                list3 = list2;
                obj2 = objCheckCached;
                torBoxResponse = (TorBoxResponse) obj2;
                i = 16;
                if (torBoxResponse.getSuccess()) {
                }
                List<String> list42 = list3;
                iH = wo5.h(y41.p(list42, 10));
                if (iH < 16) {
                }
                LinkedHashMap linkedHashMap4 = new LinkedHashMap(i);
                while (r2.hasNext()) {
                }
                ExecutorService executorService3 = kq.a;
                kq.h(TAG, "Cache check returned empty or error, assuming nothing cached");
                return linkedHashMap4;
            }
            return ck1Var;
        } catch (Exception e) {
            Log.e(TAG, "Failed to check cache status", e);
            return s38.a(e);
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:21:0x006a, code lost:
    
        if (r2.triggerCloudSync(r0) == r1) goto L22;
     */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @Override // com.strmr.ps.data.repository.IDebridProvider
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object clearAccount(@kp6 Continuation<? super e6a> continuation) {
        AnonymousClass1 anonymousClass1;
        TorBoxRepository torBoxRepository;
        if (continuation instanceof AnonymousClass1) {
            anonymousClass1 = (AnonymousClass1) continuation;
            int i = anonymousClass1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                anonymousClass1.label = i - Integer.MIN_VALUE;
            } else {
                anonymousClass1 = new AnonymousClass1(continuation);
            }
        }
        Object obj = anonymousClass1.result;
        ck1 ck1Var = ck1.a;
        int i2 = anonymousClass1.label;
        if (i2 == 0) {
            s38.b(obj);
            TorBoxAccountDao torBoxAccountDao = this.accountDao;
            anonymousClass1.L$0 = this;
            anonymousClass1.label = 1;
            if (torBoxAccountDao.deleteAccount("torbox", anonymousClass1) != ck1Var) {
                torBoxRepository = this;
            }
            return ck1Var;
        }
        if (i2 != 1) {
            if (i2 != 2) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(obj);
            return e6a.a;
        }
        torBoxRepository = (TorBoxRepository) anonymousClass1.L$0;
        s38.b(obj);
        ExecutorService executorService = kq.a;
        kq.h(TAG, "TorBox account cleared");
        torBoxRepository.settingsSyncManager.get().e("torbox");
        anonymousClass1.L$0 = null;
        anonymousClass1.label = 2;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Path cross not found for [B:62:0x01ae, B:64:0x01b4], limit reached: 127 */
    /* JADX WARN: Removed duplicated region for block: B:102:0x0328  */
    /* JADX WARN: Removed duplicated region for block: B:104:0x032e  */
    /* JADX WARN: Removed duplicated region for block: B:105:0x0330 A[Catch: Exception -> 0x005b, CancellationException -> 0x005e, TryCatch #0 {Exception -> 0x005b, blocks: (B:16:0x0053, B:99:0x0318, B:83:0x0267, B:87:0x0297, B:93:0x02ab, B:78:0x022b, B:80:0x0231, B:105:0x0330, B:109:0x033e, B:50:0x0126, B:56:0x0175, B:114:0x039c), top: B:122:0x002b }] */
    /* JADX WARN: Removed duplicated region for block: B:114:0x039c A[Catch: Exception -> 0x005b, CancellationException -> 0x005e, TRY_ENTER, TRY_LEAVE, TryCatch #0 {Exception -> 0x005b, blocks: (B:16:0x0053, B:99:0x0318, B:83:0x0267, B:87:0x0297, B:93:0x02ab, B:78:0x022b, B:80:0x0231, B:105:0x0330, B:109:0x033e, B:50:0x0126, B:56:0x0175, B:114:0x039c), top: B:122:0x002b }] */
    /* JADX WARN: Removed duplicated region for block: B:49:0x0124  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x019f  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0017  */
    /* JADX WARN: Removed duplicated region for block: B:80:0x0231 A[Catch: Exception -> 0x005b, CancellationException -> 0x005e, TryCatch #0 {Exception -> 0x005b, blocks: (B:16:0x0053, B:99:0x0318, B:83:0x0267, B:87:0x0297, B:93:0x02ab, B:78:0x022b, B:80:0x0231, B:105:0x0330, B:109:0x033e, B:50:0x0126, B:56:0x0175, B:114:0x039c), top: B:122:0x002b }] */
    /* JADX WARN: Removed duplicated region for block: B:83:0x0267 A[Catch: Exception -> 0x005b, CancellationException -> 0x005e, TryCatch #0 {Exception -> 0x005b, blocks: (B:16:0x0053, B:99:0x0318, B:83:0x0267, B:87:0x0297, B:93:0x02ab, B:78:0x022b, B:80:0x0231, B:105:0x0330, B:109:0x033e, B:50:0x0126, B:56:0x0175, B:114:0x039c), top: B:122:0x002b }] */
    /* JADX WARN: Removed duplicated region for block: B:89:0x029b  */
    /* JADX WARN: Removed duplicated region for block: B:91:0x02a8  */
    /* JADX WARN: Type inference failed for: r10v5, types: [java.lang.StringBuilder] */
    /* JADX WARN: Type inference failed for: r15v1 */
    /* JADX WARN: Type inference failed for: r15v24 */
    /* JADX WARN: Type inference failed for: r15v3 */
    /* JADX WARN: Type inference failed for: r15v6 */
    /* JADX WARN: Type inference failed for: r15v7 */
    /* JADX WARN: Type inference failed for: r15v8 */
    /* JADX WARN: Type inference failed for: r1v2, types: [java.lang.StringBuilder] */
    /* JADX WARN: Type inference failed for: r4v12, types: [int] */
    /* JADX WARN: Type inference failed for: r4v14 */
    /* JADX WARN: Type inference failed for: r4v15, types: [int] */
    /* JADX WARN: Type inference failed for: r4v18 */
    /* JADX WARN: Type inference failed for: r4v25 */
    /* JADX WARN: Type inference failed for: r4v26 */
    /* JADX WARN: Type inference failed for: r4v27 */
    /* JADX WARN: Type inference failed for: r4v28 */
    /* JADX WARN: Type inference failed for: r4v29 */
    /* JADX WARN: Type inference failed for: r4v3 */
    /* JADX WARN: Type inference failed for: r4v30 */
    /* JADX WARN: Type inference failed for: r4v31 */
    /* JADX WARN: Type inference failed for: r4v32 */
    /* JADX WARN: Type inference failed for: r4v33 */
    /* JADX WARN: Type inference failed for: r4v34 */
    /* JADX WARN: Type inference failed for: r4v35 */
    /* JADX WARN: Type inference failed for: r4v36 */
    /* JADX WARN: Type inference failed for: r4v4, types: [int] */
    /* JADX WARN: Type inference failed for: r4v5 */
    /* JADX WARN: Type inference failed for: r4v6, types: [int] */
    /* JADX WARN: Type inference failed for: r4v7, types: [int] */
    /* JADX WARN: Type inference failed for: r5v13 */
    /* JADX WARN: Type inference failed for: r5v14 */
    /* JADX WARN: Type inference failed for: r5v17 */
    /* JADX WARN: Type inference failed for: r5v18 */
    /* JADX WARN: Type inference failed for: r5v36 */
    /* JADX WARN: Type inference failed for: r5v37 */
    /* JADX WARN: Type inference failed for: r6v0 */
    /* JADX WARN: Type inference failed for: r6v1 */
    /* JADX WARN: Type inference failed for: r6v2, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r6v26 */
    /* JADX WARN: Type inference failed for: r6v3 */
    /* JADX WARN: Type inference failed for: r7v11, types: [int] */
    /* JADX WARN: Type inference failed for: r7v14 */
    /* JADX WARN: Type inference failed for: r7v27 */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:59:0x019f -> B:60:0x01a6). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:80:0x0231 -> B:81:0x0264). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:96:0x0301 -> B:97:0x0303). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:98:0x030c -> B:99:0x0318). Please report as a decompilation issue!!! */
    @pq6
    /* JADX INFO: renamed from: deleteByHash-gIAlu-s, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m138deleteByHashgIAlus(@kp6 String str, @kp6 Continuation<? super q38<Boolean>> continuation) {
        TorBoxRepository$deleteByHash$1 torBoxRepository$deleteByHash$1;
        boolean z;
        String str2;
        TorBoxRepository torBoxRepository;
        String authHeader;
        TorBoxRepository torBoxRepository2;
        long[] jArr;
        int i;
        String str3;
        ?? r4;
        boolean z2;
        ?? r42;
        Object torrentList$default;
        String str4;
        String str5;
        long[] jArr2;
        ?? r43;
        String str6;
        Iterator it;
        String str7;
        ?? r15;
        List list;
        TorBoxTorrentInfo torBoxTorrentInfo;
        int i2;
        Iterator it2;
        int i3;
        TorBoxRepository torBoxRepository3;
        List list2;
        ?? r44;
        Object obj;
        if (continuation instanceof TorBoxRepository$deleteByHash$1) {
            torBoxRepository$deleteByHash$1 = (TorBoxRepository$deleteByHash$1) continuation;
            int i4 = torBoxRepository$deleteByHash$1.label;
            if ((i4 & Integer.MIN_VALUE) != 0) {
                torBoxRepository$deleteByHash$1.label = i4 - Integer.MIN_VALUE;
            } else {
                torBoxRepository$deleteByHash$1 = new TorBoxRepository$deleteByHash$1(this, continuation);
            }
        }
        Object account = torBoxRepository$deleteByHash$1.result;
        ck1 ck1Var = ck1.a;
        int i5 = torBoxRepository$deleteByHash$1.label;
        ?? r6 = 4;
        String str8 = ")";
        int i6 = 3;
        boolean z3 = true;
        try {
            try {
                try {
                } catch (Exception e) {
                    e = e;
                }
            } catch (Exception e2) {
                e = e2;
                r6 = str4;
            }
            if (i5 == 0) {
                z = false;
                s38.b(account);
                TorBoxAccountDao torBoxAccountDao = this.accountDao;
                torBoxRepository$deleteByHash$1.L$0 = this;
                str2 = str;
                torBoxRepository$deleteByHash$1.L$1 = str2;
                torBoxRepository$deleteByHash$1.label = 1;
                account = torBoxAccountDao.getAccount("torbox", torBoxRepository$deleteByHash$1);
                if (account != ck1Var) {
                    torBoxRepository = this;
                }
                return ck1Var;
            }
            if (i5 == 1) {
                z = false;
                str2 = (String) torBoxRepository$deleteByHash$1.L$1;
                torBoxRepository = (TorBoxRepository) torBoxRepository$deleteByHash$1.L$0;
                s38.b(account);
            } else {
                if (i5 == 2) {
                    z = false;
                    int i7 = torBoxRepository$deleteByHash$1.I$1;
                    i = torBoxRepository$deleteByHash$1.I$0;
                    jArr2 = (long[]) torBoxRepository$deleteByHash$1.L$3;
                    authHeader = (String) torBoxRepository$deleteByHash$1.L$2;
                    str5 = (String) torBoxRepository$deleteByHash$1.L$1;
                    torBoxRepository2 = (TorBoxRepository) torBoxRepository$deleteByHash$1.L$0;
                    s38.b(account);
                    z2 = true;
                    r43 = i7;
                    jArr = jArr2;
                    str3 = str5;
                    r42 = r43;
                    TorBoxApiService torBoxApiService = torBoxRepository2.torBoxApiService;
                    Boolean boolBoxBoolean = Boxing.boxBoolean(z2);
                    torBoxRepository$deleteByHash$1.L$0 = torBoxRepository2;
                    torBoxRepository$deleteByHash$1.L$1 = str3;
                    torBoxRepository$deleteByHash$1.L$2 = authHeader;
                    torBoxRepository$deleteByHash$1.L$3 = jArr;
                    torBoxRepository$deleteByHash$1.I$0 = i;
                    torBoxRepository$deleteByHash$1.I$1 = r42;
                    torBoxRepository$deleteByHash$1.label = i6;
                    TorBoxRepository$deleteByHash$1 torBoxRepository$deleteByHash$12 = torBoxRepository$deleteByHash$1;
                    String str9 = authHeader;
                    torrentList$default = TorBoxApiService.DefaultImpls.getTorrentList$default(torBoxApiService, str9, boolBoxBoolean, null, null, torBoxRepository$deleteByHash$12, 12, null);
                    if (torrentList$default != ck1Var) {
                    }
                    return ck1Var;
                }
                if (i5 == 3) {
                    z = false;
                    int i8 = torBoxRepository$deleteByHash$1.I$1;
                    i = torBoxRepository$deleteByHash$1.I$0;
                    long[] jArr3 = (long[]) torBoxRepository$deleteByHash$1.L$3;
                    authHeader = (String) torBoxRepository$deleteByHash$1.L$2;
                    str4 = (String) torBoxRepository$deleteByHash$1.L$1;
                    torBoxRepository2 = (TorBoxRepository) torBoxRepository$deleteByHash$1.L$0;
                    s38.b(account);
                    z2 = true;
                    ?? r45 = i8;
                    TorBoxResponse torBoxResponse = (TorBoxResponse) account;
                    if (!torBoxResponse.getSuccess() && torBoxResponse.getData() != null) {
                        ExecutorService executorService = kq.a;
                        kq.h(TAG, "Cloud sanitization: TB torrent list has " + ((List) torBoxResponse.getData()).size() + " items, searching for hash=" + str4 + " (attempt " + (r45 + 1) + str8);
                        Iterable iterable = (Iterable) torBoxResponse.getData();
                        ArrayList arrayList = new ArrayList();
                        for (Object obj2 : iterable) {
                            String hash = ((TorBoxTorrentInfo) obj2).getHash();
                            if (hash != null && hash.equalsIgnoreCase(str4) == z2) {
                                arrayList.add(obj2);
                            }
                            z2 = true;
                        }
                        if (arrayList.isEmpty()) {
                            str6 = str8;
                            z2 = true;
                        } else {
                            it = arrayList.iterator();
                            str7 = str4;
                            r15 = 1;
                            list = arrayList;
                            if (it.hasNext()) {
                            }
                        }
                        ExecutorService executorService2 = kq.a;
                        kq.a(TAG, "Cloud sanitization TB deleteByHash failed for " + r6, e);
                        return s38.a(e);
                    }
                    str6 = str8;
                    ExecutorService executorService3 = kq.a;
                    kq.h(TAG, "Cloud sanitization: failed to list TB torrents (attempt " + (r45 + 1) + str6);
                    str8 = str6;
                    jArr = jArr3;
                    str3 = str4;
                    z3 = z2;
                    i6 = 3;
                    r4 = r45 + 1;
                    if (r4 >= i) {
                        ExecutorService executorService4 = kq.a;
                        kq.h(TAG, "Cloud sanitization: no TB torrent found for hash " + str3 + " after " + i + " attempts");
                        return Boxing.boxBoolean(z);
                    }
                    if (r4 <= 0) {
                        z2 = z3;
                        r42 = r4;
                        TorBoxApiService torBoxApiService2 = torBoxRepository2.torBoxApiService;
                        Boolean boolBoxBoolean2 = Boxing.boxBoolean(z2);
                        torBoxRepository$deleteByHash$1.L$0 = torBoxRepository2;
                        torBoxRepository$deleteByHash$1.L$1 = str3;
                        torBoxRepository$deleteByHash$1.L$2 = authHeader;
                        torBoxRepository$deleteByHash$1.L$3 = jArr;
                        torBoxRepository$deleteByHash$1.I$0 = i;
                        torBoxRepository$deleteByHash$1.I$1 = r42;
                        torBoxRepository$deleteByHash$1.label = i6;
                        TorBoxRepository$deleteByHash$1 torBoxRepository$deleteByHash$122 = torBoxRepository$deleteByHash$1;
                        String str92 = authHeader;
                        torrentList$default = TorBoxApiService.DefaultImpls.getTorrentList$default(torBoxApiService2, str92, boolBoxBoolean2, null, null, torBoxRepository$deleteByHash$122, 12, null);
                        if (torrentList$default != ck1Var) {
                        }
                        return ck1Var;
                    }
                    ExecutorService executorService5 = kq.a;
                    long j = jArr[r4];
                    ?? sb = new StringBuilder();
                    z2 = z3;
                    sb.append("Cloud sanitization: TB retry ");
                    sb.append(r4);
                    sb.append(" for hash=");
                    sb.append(str3);
                    sb.append(" (waiting ");
                    sb.append(j);
                    sb.append("ms)");
                    kq.h(TAG, sb.toString());
                    long j2 = jArr[r4];
                    torBoxRepository$deleteByHash$1.L$0 = torBoxRepository2;
                    torBoxRepository$deleteByHash$1.L$1 = str3;
                    torBoxRepository$deleteByHash$1.L$2 = authHeader;
                    torBoxRepository$deleteByHash$1.L$3 = jArr;
                    torBoxRepository$deleteByHash$1.I$0 = i;
                    torBoxRepository$deleteByHash$1.I$1 = r4;
                    torBoxRepository$deleteByHash$1.label = 2;
                    if (h32.a(j2, torBoxRepository$deleteByHash$1) == ck1Var) {
                        return ck1Var;
                    }
                    str5 = str3;
                    jArr2 = jArr;
                    r43 = r4;
                    jArr = jArr2;
                    str3 = str5;
                    r42 = r43;
                    TorBoxApiService torBoxApiService22 = torBoxRepository2.torBoxApiService;
                    Boolean boolBoxBoolean22 = Boxing.boxBoolean(z2);
                    torBoxRepository$deleteByHash$1.L$0 = torBoxRepository2;
                    torBoxRepository$deleteByHash$1.L$1 = str3;
                    torBoxRepository$deleteByHash$1.L$2 = authHeader;
                    torBoxRepository$deleteByHash$1.L$3 = jArr;
                    torBoxRepository$deleteByHash$1.I$0 = i;
                    torBoxRepository$deleteByHash$1.I$1 = r42;
                    torBoxRepository$deleteByHash$1.label = i6;
                    TorBoxRepository$deleteByHash$1 torBoxRepository$deleteByHash$1222 = torBoxRepository$deleteByHash$1;
                    String str922 = authHeader;
                    torrentList$default = TorBoxApiService.DefaultImpls.getTorrentList$default(torBoxApiService22, str922, boolBoxBoolean22, null, null, torBoxRepository$deleteByHash$1222, 12, null);
                    if (torrentList$default != ck1Var) {
                        str4 = str3;
                        authHeader = str922;
                        jArr3 = jArr;
                        account = torrentList$default;
                        torBoxRepository$deleteByHash$1 = torBoxRepository$deleteByHash$1222;
                        r45 = r42;
                        TorBoxResponse torBoxResponse2 = (TorBoxResponse) account;
                        if (!torBoxResponse2.getSuccess()) {
                        }
                        str6 = str8;
                        ExecutorService executorService32 = kq.a;
                        kq.h(TAG, "Cloud sanitization: failed to list TB torrents (attempt " + (r45 + 1) + str6);
                        str8 = str6;
                        jArr = jArr3;
                        str3 = str4;
                        z3 = z2;
                        i6 = 3;
                        r4 = r45 + 1;
                        if (r4 >= i) {
                        }
                    }
                    return ck1Var;
                }
                if (i5 == 4) {
                    z = false;
                    int i9 = torBoxRepository$deleteByHash$1.I$2;
                    int i10 = torBoxRepository$deleteByHash$1.I$1;
                    int i11 = torBoxRepository$deleteByHash$1.I$0;
                    TorBoxTorrentInfo torBoxTorrentInfo2 = (TorBoxTorrentInfo) torBoxRepository$deleteByHash$1.L$4;
                    it2 = (Iterator) torBoxRepository$deleteByHash$1.L$3;
                    List list3 = (List) torBoxRepository$deleteByHash$1.L$2;
                    String str10 = (String) torBoxRepository$deleteByHash$1.L$1;
                    TorBoxRepository torBoxRepository4 = (TorBoxRepository) torBoxRepository$deleteByHash$1.L$0;
                    try {
                        s38.b(account);
                        obj = ((q38) account).a;
                        i2 = i10;
                        list2 = list3;
                        torBoxTorrentInfo = torBoxTorrentInfo2;
                        torBoxRepository3 = torBoxRepository4;
                        i3 = i11;
                        str7 = str10;
                        r44 = i9;
                        if (!(obj instanceof q38.b)) {
                        }
                    } catch (Exception e3) {
                        e = e3;
                        r6 = str10;
                    }
                } else {
                    if (i5 != 5) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    int i12 = torBoxRepository$deleteByHash$1.I$2;
                    int i13 = torBoxRepository$deleteByHash$1.I$1;
                    int i14 = torBoxRepository$deleteByHash$1.I$0;
                    torBoxTorrentInfo = (TorBoxTorrentInfo) torBoxRepository$deleteByHash$1.L$4;
                    z = false;
                    it2 = (Iterator) torBoxRepository$deleteByHash$1.L$3;
                    List list4 = (List) torBoxRepository$deleteByHash$1.L$2;
                    str7 = (String) torBoxRepository$deleteByHash$1.L$1;
                    torBoxRepository3 = (TorBoxRepository) torBoxRepository$deleteByHash$1.L$0;
                    s38.b(account);
                    String str11 = ")";
                    ?? r46 = i12;
                    List list5 = list4;
                    int i15 = i13;
                    List list6 = list5;
                    int i16 = i14;
                    torBoxRepository2 = torBoxRepository3;
                    boolean z4 = i15 == true ? 1 : 0;
                    it = it2;
                    ?? r47 = r46;
                    boolean z5 = z4;
                    ?? r7 = r47 + 1;
                    TorBoxTorrentInfo torBoxTorrentInfo3 = torBoxTorrentInfo;
                    boolean z6 = z5 ? 1 : 0;
                    str8 = str11;
                    ?? r5 = i16;
                    List list7 = list6;
                    ?? r52 = r5;
                    List list8 = list7;
                    boolean z7 = z6;
                    if (r7 < 3) {
                        int id = torBoxTorrentInfo3.getId();
                        torBoxRepository$deleteByHash$1.L$0 = torBoxRepository2;
                        torBoxRepository$deleteByHash$1.L$1 = str7;
                        torBoxRepository$deleteByHash$1.L$2 = list7;
                        torBoxRepository$deleteByHash$1.L$3 = it;
                        torBoxRepository$deleteByHash$1.L$4 = torBoxTorrentInfo3;
                        torBoxRepository$deleteByHash$1.I$0 = r5 == true ? 1 : 0;
                        torBoxRepository$deleteByHash$1.I$1 = z6 ? 1 : 0;
                        torBoxRepository$deleteByHash$1.I$2 = r7;
                        torBoxRepository$deleteByHash$1.label = 4;
                        Object objM140deleteTorrentgIAlus = torBoxRepository2.m140deleteTorrentgIAlus(id, torBoxRepository$deleteByHash$1);
                        if (objM140deleteTorrentgIAlus == ck1Var) {
                            return ck1Var;
                        }
                        it2 = it;
                        obj = objM140deleteTorrentgIAlus;
                        boolean z8 = z6 ? 1 : 0;
                        torBoxTorrentInfo = torBoxTorrentInfo3;
                        r44 = r7;
                        torBoxRepository3 = torBoxRepository2;
                        i2 = z8 ? 1 : 0;
                        List list9 = list7;
                        i3 = r5 == true ? 1 : 0;
                        list2 = list9;
                        if (!(obj instanceof q38.b)) {
                            int i17 = i3;
                            list8 = list2;
                            r52 = i17 == true ? 1 : 0;
                            torBoxRepository2 = torBoxRepository3;
                            it = it2;
                            z7 = true;
                        } else {
                            if (r44 < 2) {
                                int i18 = r44 + 1;
                                int i19 = i2;
                                long j3 = ((long) i18) * 5000;
                                ExecutorService executorService6 = kq.a;
                                int id2 = torBoxTorrentInfo.getId();
                                StringBuilder sb2 = new StringBuilder();
                                str11 = str8;
                                sb2.append("Cloud sanitization: TB delete ");
                                sb2.append(id2);
                                sb2.append(" failed (attempt ");
                                sb2.append(i18);
                                sb2.append("), retrying in ");
                                sb2.append(j3);
                                sb2.append("ms");
                                kq.h(TAG, sb2.toString());
                                torBoxRepository$deleteByHash$1.L$0 = torBoxRepository3;
                                torBoxRepository$deleteByHash$1.L$1 = str7;
                                torBoxRepository$deleteByHash$1.L$2 = list2;
                                torBoxRepository$deleteByHash$1.L$3 = it2;
                                torBoxRepository$deleteByHash$1.L$4 = torBoxTorrentInfo;
                                torBoxRepository$deleteByHash$1.I$0 = i3;
                                torBoxRepository$deleteByHash$1.I$1 = i19 == true ? 1 : 0;
                                torBoxRepository$deleteByHash$1.I$2 = r44;
                                torBoxRepository$deleteByHash$1.label = 5;
                                if (h32.a(j3, torBoxRepository$deleteByHash$1) != ck1Var) {
                                    i13 = i19 == true ? 1 : 0;
                                    i14 = i3;
                                    r46 = r44;
                                    list5 = list2;
                                    int i152 = i13;
                                    List list62 = list5;
                                    int i162 = i14;
                                    torBoxRepository2 = torBoxRepository3;
                                    boolean z42 = i152 == true ? 1 : 0;
                                    it = it2;
                                    ?? r472 = r46;
                                    boolean z52 = z42;
                                    ?? r72 = r472 + 1;
                                    TorBoxTorrentInfo torBoxTorrentInfo32 = torBoxTorrentInfo;
                                    boolean z62 = z52 ? 1 : 0;
                                    str8 = str11;
                                    ?? r53 = i162;
                                    List list72 = list62;
                                    ?? r522 = r53;
                                    List list82 = list72;
                                    boolean z72 = z62;
                                    if (r72 < 3) {
                                    }
                                }
                                return ck1Var;
                            }
                            str11 = str8;
                            int i20 = i2;
                            int i21 = i3;
                            list62 = list2;
                            i162 = i21 == true ? 1 : 0;
                            torBoxRepository2 = torBoxRepository3;
                            z42 = i20 == true ? 1 : 0;
                            it = it2;
                            r472 = r44;
                            boolean z522 = z42;
                            ?? r722 = r472 + 1;
                            TorBoxTorrentInfo torBoxTorrentInfo322 = torBoxTorrentInfo;
                            boolean z622 = z522 ? 1 : 0;
                            str8 = str11;
                            ?? r532 = i162;
                            List list722 = list62;
                            ?? r5222 = r532;
                            List list822 = list722;
                            boolean z722 = z622;
                            if (r722 < 3) {
                            }
                        }
                    }
                    str8 = str8;
                    list = list822;
                    r15 = z722 ? z : r5222;
                    if (it.hasNext()) {
                        torBoxTorrentInfo322 = (TorBoxTorrentInfo) it.next();
                        ExecutorService executorService7 = kq.a;
                        kq.h(TAG, "Cloud sanitization: deleting TB torrent " + torBoxTorrentInfo322.getId() + " (" + torBoxTorrentInfo322.getName() + str8);
                        boolean z9 = z;
                        r532 = r15;
                        z622 = z9 ? 1 : 0;
                        r722 = z9;
                        list722 = list;
                        ?? r52222 = r532;
                        List list8222 = list722;
                        boolean z7222 = z622;
                        if (r722 < 3) {
                        }
                        str8 = str8;
                        list = list8222;
                        r15 = z7222 ? z : r52222;
                        if (it.hasNext()) {
                            String str12 = str8;
                            ExecutorService executorService8 = kq.a;
                            kq.h(TAG, "Cloud sanitization: processed " + list.size() + " TB torrent(s) for hash " + str7 + " (allDeleted=" + (r15 != 0 ? true : z) + str12);
                            return Boxing.boxBoolean(true);
                        }
                    }
                }
            }
            TorBoxAccount torBoxAccount = (TorBoxAccount) account;
            if (torBoxAccount == null) {
                return s38.a(new DebridError.NoAccount(DebridProvider.TORBOX));
            }
            try {
                long[] jArr4 = {0, 5000, 10000};
                authHeader = torBoxAccount.getAuthHeader();
                torBoxRepository2 = torBoxRepository;
                jArr = jArr4;
                i = 3;
                str3 = str2;
                r4 = z;
                if (r4 >= i) {
                }
            } catch (Exception e4) {
                e = e4;
                r6 = str2;
            }
        } catch (CancellationException e5) {
            throw e5;
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:133:0x03ec, code lost:
    
        if (defpackage.h32.a(r8, r11) == r5) goto L134;
     */
    /* JADX WARN: Removed duplicated region for block: B:111:0x02dd A[Catch: CancellationException -> 0x0055, Exception -> 0x01ba, TryCatch #1 {Exception -> 0x01ba, blocks: (B:141:0x0418, B:119:0x036b, B:123:0x0383, B:125:0x0387, B:128:0x03a6, B:130:0x03b4, B:132:0x03bb, B:136:0x03f3, B:138:0x03fc, B:140:0x0403, B:45:0x0102, B:47:0x010a, B:50:0x0112, B:51:0x0178, B:54:0x0184, B:64:0x01a7, B:66:0x01b3, B:70:0x01bd, B:71:0x01fc, B:72:0x020f, B:74:0x0218, B:87:0x0245, B:88:0x0249, B:91:0x025b, B:93:0x0280, B:94:0x028f, B:96:0x0295, B:100:0x02a7, B:102:0x02b1, B:104:0x02b7, B:106:0x02bd, B:108:0x02c4, B:109:0x02d4, B:111:0x02dd, B:112:0x0300, B:115:0x0308, B:117:0x032d, B:142:0x041e, B:41:0x00f3), top: B:151:0x00f3 }] */
    /* JADX WARN: Removed duplicated region for block: B:115:0x0308 A[Catch: CancellationException -> 0x0055, Exception -> 0x01ba, TRY_ENTER, TryCatch #1 {Exception -> 0x01ba, blocks: (B:141:0x0418, B:119:0x036b, B:123:0x0383, B:125:0x0387, B:128:0x03a6, B:130:0x03b4, B:132:0x03bb, B:136:0x03f3, B:138:0x03fc, B:140:0x0403, B:45:0x0102, B:47:0x010a, B:50:0x0112, B:51:0x0178, B:54:0x0184, B:64:0x01a7, B:66:0x01b3, B:70:0x01bd, B:71:0x01fc, B:72:0x020f, B:74:0x0218, B:87:0x0245, B:88:0x0249, B:91:0x025b, B:93:0x0280, B:94:0x028f, B:96:0x0295, B:100:0x02a7, B:102:0x02b1, B:104:0x02b7, B:106:0x02bd, B:108:0x02c4, B:109:0x02d4, B:111:0x02dd, B:112:0x0300, B:115:0x0308, B:117:0x032d, B:142:0x041e, B:41:0x00f3), top: B:151:0x00f3 }] */
    /* JADX WARN: Removed duplicated region for block: B:117:0x032d A[Catch: CancellationException -> 0x0055, Exception -> 0x01ba, TryCatch #1 {Exception -> 0x01ba, blocks: (B:141:0x0418, B:119:0x036b, B:123:0x0383, B:125:0x0387, B:128:0x03a6, B:130:0x03b4, B:132:0x03bb, B:136:0x03f3, B:138:0x03fc, B:140:0x0403, B:45:0x0102, B:47:0x010a, B:50:0x0112, B:51:0x0178, B:54:0x0184, B:64:0x01a7, B:66:0x01b3, B:70:0x01bd, B:71:0x01fc, B:72:0x020f, B:74:0x0218, B:87:0x0245, B:88:0x0249, B:91:0x025b, B:93:0x0280, B:94:0x028f, B:96:0x0295, B:100:0x02a7, B:102:0x02b1, B:104:0x02b7, B:106:0x02bd, B:108:0x02c4, B:109:0x02d4, B:111:0x02dd, B:112:0x0300, B:115:0x0308, B:117:0x032d, B:142:0x041e, B:41:0x00f3), top: B:151:0x00f3 }] */
    /* JADX WARN: Removed duplicated region for block: B:119:0x036b A[Catch: CancellationException -> 0x0055, Exception -> 0x01ba, TryCatch #1 {Exception -> 0x01ba, blocks: (B:141:0x0418, B:119:0x036b, B:123:0x0383, B:125:0x0387, B:128:0x03a6, B:130:0x03b4, B:132:0x03bb, B:136:0x03f3, B:138:0x03fc, B:140:0x0403, B:45:0x0102, B:47:0x010a, B:50:0x0112, B:51:0x0178, B:54:0x0184, B:64:0x01a7, B:66:0x01b3, B:70:0x01bd, B:71:0x01fc, B:72:0x020f, B:74:0x0218, B:87:0x0245, B:88:0x0249, B:91:0x025b, B:93:0x0280, B:94:0x028f, B:96:0x0295, B:100:0x02a7, B:102:0x02b1, B:104:0x02b7, B:106:0x02bd, B:108:0x02c4, B:109:0x02d4, B:111:0x02dd, B:112:0x0300, B:115:0x0308, B:117:0x032d, B:142:0x041e, B:41:0x00f3), top: B:151:0x00f3 }] */
    /* JADX WARN: Removed duplicated region for block: B:125:0x0387 A[Catch: CancellationException -> 0x0055, Exception -> 0x01ba, TryCatch #1 {Exception -> 0x01ba, blocks: (B:141:0x0418, B:119:0x036b, B:123:0x0383, B:125:0x0387, B:128:0x03a6, B:130:0x03b4, B:132:0x03bb, B:136:0x03f3, B:138:0x03fc, B:140:0x0403, B:45:0x0102, B:47:0x010a, B:50:0x0112, B:51:0x0178, B:54:0x0184, B:64:0x01a7, B:66:0x01b3, B:70:0x01bd, B:71:0x01fc, B:72:0x020f, B:74:0x0218, B:87:0x0245, B:88:0x0249, B:91:0x025b, B:93:0x0280, B:94:0x028f, B:96:0x0295, B:100:0x02a7, B:102:0x02b1, B:104:0x02b7, B:106:0x02bd, B:108:0x02c4, B:109:0x02d4, B:111:0x02dd, B:112:0x0300, B:115:0x0308, B:117:0x032d, B:142:0x041e, B:41:0x00f3), top: B:151:0x00f3 }] */
    /* JADX WARN: Removed duplicated region for block: B:126:0x03a3  */
    /* JADX WARN: Removed duplicated region for block: B:156:0x01fc A[EDGE_INSN: B:156:0x01fc->B:71:0x01fc BREAK  A[LOOP:0: B:51:0x0178->B:70:0x01bd], SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:172:? A[RETURN, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:54:0x0184 A[Catch: CancellationException -> 0x0055, Exception -> 0x01ba, TRY_ENTER, TRY_LEAVE, TryCatch #1 {Exception -> 0x01ba, blocks: (B:141:0x0418, B:119:0x036b, B:123:0x0383, B:125:0x0387, B:128:0x03a6, B:130:0x03b4, B:132:0x03bb, B:136:0x03f3, B:138:0x03fc, B:140:0x0403, B:45:0x0102, B:47:0x010a, B:50:0x0112, B:51:0x0178, B:54:0x0184, B:64:0x01a7, B:66:0x01b3, B:70:0x01bd, B:71:0x01fc, B:72:0x020f, B:74:0x0218, B:87:0x0245, B:88:0x0249, B:91:0x025b, B:93:0x0280, B:94:0x028f, B:96:0x0295, B:100:0x02a7, B:102:0x02b1, B:104:0x02b7, B:106:0x02bd, B:108:0x02c4, B:109:0x02d4, B:111:0x02dd, B:112:0x0300, B:115:0x0308, B:117:0x032d, B:142:0x041e, B:41:0x00f3), top: B:151:0x00f3 }] */
    /* JADX WARN: Removed duplicated region for block: B:74:0x0218 A[Catch: CancellationException -> 0x0055, Exception -> 0x01ba, TRY_LEAVE, TryCatch #1 {Exception -> 0x01ba, blocks: (B:141:0x0418, B:119:0x036b, B:123:0x0383, B:125:0x0387, B:128:0x03a6, B:130:0x03b4, B:132:0x03bb, B:136:0x03f3, B:138:0x03fc, B:140:0x0403, B:45:0x0102, B:47:0x010a, B:50:0x0112, B:51:0x0178, B:54:0x0184, B:64:0x01a7, B:66:0x01b3, B:70:0x01bd, B:71:0x01fc, B:72:0x020f, B:74:0x0218, B:87:0x0245, B:88:0x0249, B:91:0x025b, B:93:0x0280, B:94:0x028f, B:96:0x0295, B:100:0x02a7, B:102:0x02b1, B:104:0x02b7, B:106:0x02bd, B:108:0x02c4, B:109:0x02d4, B:111:0x02dd, B:112:0x0300, B:115:0x0308, B:117:0x032d, B:142:0x041e, B:41:0x00f3), top: B:151:0x00f3 }] */
    /* JADX WARN: Removed duplicated region for block: B:8:0x001e  */
    /* JADX WARN: Removed duplicated region for block: B:93:0x0280 A[Catch: CancellationException -> 0x0055, Exception -> 0x01ba, TryCatch #1 {Exception -> 0x01ba, blocks: (B:141:0x0418, B:119:0x036b, B:123:0x0383, B:125:0x0387, B:128:0x03a6, B:130:0x03b4, B:132:0x03bb, B:136:0x03f3, B:138:0x03fc, B:140:0x0403, B:45:0x0102, B:47:0x010a, B:50:0x0112, B:51:0x0178, B:54:0x0184, B:64:0x01a7, B:66:0x01b3, B:70:0x01bd, B:71:0x01fc, B:72:0x020f, B:74:0x0218, B:87:0x0245, B:88:0x0249, B:91:0x025b, B:93:0x0280, B:94:0x028f, B:96:0x0295, B:100:0x02a7, B:102:0x02b1, B:104:0x02b7, B:106:0x02bd, B:108:0x02c4, B:109:0x02d4, B:111:0x02dd, B:112:0x0300, B:115:0x0308, B:117:0x032d, B:142:0x041e, B:41:0x00f3), top: B:151:0x00f3 }] */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:133:0x03ec -> B:135:0x03ef). Please report as a decompilation issue!!! */
    @pq6
    /* JADX INFO: renamed from: deleteMostRecent-0E7RQCE, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m139deleteMostRecent0E7RQCE(long j, @pq6 String str, @kp6 Continuation<? super q38<e6a>> continuation) {
        TorBoxRepository$deleteMostRecent$1 torBoxRepository$deleteMostRecent$1;
        String str2;
        Object obj;
        String str3;
        long j2;
        TorBoxRepository torBoxRepository;
        String str4;
        TorBoxRepository torBoxRepository2;
        long j3;
        TorBoxResponse torBoxResponse;
        Iterator it;
        List listBj;
        int i;
        TorBoxTorrentInfo torBoxTorrentInfo;
        int i2;
        String strNormalizeForMatch;
        Date date;
        TorBoxRepository torBoxRepository3;
        TorBoxTorrentInfo torBoxTorrentInfo2;
        int i3;
        Object obj2;
        if (continuation instanceof TorBoxRepository$deleteMostRecent$1) {
            torBoxRepository$deleteMostRecent$1 = (TorBoxRepository$deleteMostRecent$1) continuation;
            int i4 = torBoxRepository$deleteMostRecent$1.label;
            if ((i4 & Integer.MIN_VALUE) != 0) {
                torBoxRepository$deleteMostRecent$1.label = i4 - Integer.MIN_VALUE;
            } else {
                torBoxRepository$deleteMostRecent$1 = new TorBoxRepository$deleteMostRecent$1(this, continuation);
            }
        }
        TorBoxRepository$deleteMostRecent$1 torBoxRepository$deleteMostRecent$12 = torBoxRepository$deleteMostRecent$1;
        Object obj3 = torBoxRepository$deleteMostRecent$12.result;
        ck1 ck1Var = ck1.a;
        int i5 = torBoxRepository$deleteMostRecent$12.label;
        e6a e6aVar = e6a.a;
        try {
            try {
                if (i5 == 0) {
                    s38.b(obj3);
                    TorBoxAccountDao torBoxAccountDao = this.accountDao;
                    torBoxRepository$deleteMostRecent$12.L$0 = this;
                    torBoxRepository$deleteMostRecent$12.L$1 = str;
                    torBoxRepository$deleteMostRecent$12.J$0 = j;
                    torBoxRepository$deleteMostRecent$12.label = 1;
                    Object account = torBoxAccountDao.getAccount("torbox", torBoxRepository$deleteMostRecent$12);
                    if (account != ck1Var) {
                        obj = account;
                        str3 = str;
                        j2 = j;
                        torBoxRepository = this;
                    }
                    return ck1Var;
                }
                if (i5 == 1) {
                    j2 = torBoxRepository$deleteMostRecent$12.J$0;
                    String str5 = (String) torBoxRepository$deleteMostRecent$12.L$1;
                    torBoxRepository = (TorBoxRepository) torBoxRepository$deleteMostRecent$12.L$0;
                    s38.b(obj3);
                    obj = obj3;
                    str3 = str5;
                } else {
                    if (i5 == 2) {
                        j3 = torBoxRepository$deleteMostRecent$12.J$0;
                        str4 = (String) torBoxRepository$deleteMostRecent$12.L$1;
                        torBoxRepository2 = (TorBoxRepository) torBoxRepository$deleteMostRecent$12.L$0;
                        s38.b(obj3);
                        str2 = TAG;
                        torBoxResponse = (TorBoxResponse) obj3;
                        if (torBoxResponse.getSuccess() && torBoxResponse.getData() != null) {
                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
                            simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
                            ExecutorService executorService = kq.a;
                            kq.h(str2, "Cloud sanitization: TB has " + ((List) torBoxResponse.getData()).size() + " torrents, resolveTimestamp=" + j3 + " (" + new Date(j3) + "), fileName=" + str4);
                            it = y41.bk(y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.TorBoxRepository$deleteMostRecent-0E7RQCE$$inlined$sortedByDescending$1
                                /* JADX WARN: Multi-variable type inference failed */
                                @Override // java.util.Comparator
                                public final int compare(T t, T t2) {
                                    String createdAt = ((TorBoxTorrentInfo) t2).getCreatedAt();
                                    if (createdAt == null) {
                                        createdAt = "";
                                    }
                                    String createdAt2 = ((TorBoxTorrentInfo) t).getCreatedAt();
                                    return x71.b(createdAt, createdAt2 != null ? createdAt2 : "");
                                }
                            }, (Iterable) torBoxResponse.getData()), 5).iterator();
                            while (true) {
                                if (it.hasNext()) {
                                    break;
                                }
                                TorBoxTorrentInfo torBoxTorrentInfo3 = (TorBoxTorrentInfo) it.next();
                                Iterator it2 = it;
                                try {
                                    String createdAt = torBoxTorrentInfo3.getCreatedAt();
                                    date = simpleDateFormat.parse(createdAt != null ? n89.az(createdAt, ".") : "");
                                } catch (Exception unused) {
                                }
                                Long lBoxLong = date != null ? Boxing.boxLong(date.getTime()) : null;
                                ExecutorService executorService2 = kq.a;
                                TorBoxRepository$deleteMostRecent$1 torBoxRepository$deleteMostRecent$13 = torBoxRepository$deleteMostRecent$12;
                                kq.h(str2, "Cloud sanitization: TB torrent '" + torBoxTorrentInfo3.getName() + "' createdAt=" + torBoxTorrentInfo3.getCreatedAt() + " parsedMs=" + lBoxLong + " (diff=" + ((lBoxLong != null ? lBoxLong.longValue() : 0L) - j3) + "ms)");
                                it = it2;
                                torBoxRepository$deleteMostRecent$12 = torBoxRepository$deleteMostRecent$13;
                                j3 = j3;
                            }
                            TorBoxRepository$deleteMostRecent$1 torBoxRepository$deleteMostRecent$14 = torBoxRepository$deleteMostRecent$12;
                            long j4 = j3;
                            Iterable iterable = (Iterable) torBoxResponse.getData();
                            ArrayList arrayList = new ArrayList();
                            for (Object obj4 : iterable) {
                                try {
                                    String createdAt2 = ((TorBoxTorrentInfo) obj4).getCreatedAt();
                                    if (createdAt2 != null) {
                                        Date date2 = simpleDateFormat.parse(n89.az(createdAt2, "."));
                                        long time = date2 != null ? date2.getTime() : 0L;
                                        if (time - (j4 - MediaSessionService.DEFAULT_FOREGROUND_SERVICE_TIMEOUT_MS) > 0 && time - j4 < MediaSessionService.DEFAULT_FOREGROUND_SERVICE_TIMEOUT_MS) {
                                            arrayList.add(obj4);
                                        }
                                    }
                                } catch (Exception unused2) {
                                }
                            }
                            listBj = y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.TorBoxRepository$deleteMostRecent-0E7RQCE$$inlined$sortedByDescending$2
                                /* JADX WARN: Multi-variable type inference failed */
                                @Override // java.util.Comparator
                                public final int compare(T t, T t2) {
                                    return x71.b(((TorBoxTorrentInfo) t2).getCreatedAt(), ((TorBoxTorrentInfo) t).getCreatedAt());
                                }
                            }, arrayList);
                            i = 0;
                            if (listBj.isEmpty() && str4 != null) {
                                ExecutorService executorService3 = kq.a;
                                kq.h(str2, "Cloud sanitization: TB timestamp match failed, trying filename match for '" + str4 + "'");
                                strNormalizeForMatch = torBoxRepository2.normalizeForMatch(str4);
                                if (strNormalizeForMatch.length() >= 8) {
                                    Iterable iterable2 = (Iterable) torBoxResponse.getData();
                                    ArrayList arrayList2 = new ArrayList();
                                    for (Object obj5 : iterable2) {
                                        String name = ((TorBoxTorrentInfo) obj5).getName();
                                        String strNormalizeForMatch2 = torBoxRepository2.normalizeForMatch(name == null ? "" : name);
                                        if (strNormalizeForMatch2.length() >= 8 && (n89.l(strNormalizeForMatch2, strNormalizeForMatch, false) || n89.l(strNormalizeForMatch, strNormalizeForMatch2, false))) {
                                            arrayList2.add(obj5);
                                        }
                                    }
                                    listBj = y41.bk(y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.TorBoxRepository$deleteMostRecent-0E7RQCE$$inlined$sortedByDescending$3
                                        /* JADX WARN: Multi-variable type inference failed */
                                        @Override // java.util.Comparator
                                        public final int compare(T t, T t2) {
                                            return x71.b(((TorBoxTorrentInfo) t2).getCreatedAt(), ((TorBoxTorrentInfo) t).getCreatedAt());
                                        }
                                    }, arrayList2), 1);
                                }
                                if (!listBj.isEmpty()) {
                                    ExecutorService executorService4 = kq.a;
                                    kq.h(str2, "Cloud sanitization: TB filename match found: '" + ((TorBoxTorrentInfo) y41.z(listBj)).getName() + "'");
                                }
                            }
                            if (!listBj.isEmpty()) {
                                ExecutorService executorService5 = kq.a;
                                kq.h(str2, "Cloud sanitization: no matching TB torrent found (window=" + MediaSessionService.DEFAULT_FOREGROUND_SERVICE_TIMEOUT_MS + "ms, fileName=" + str4 + ")");
                                return e6aVar;
                            }
                            torBoxTorrentInfo = (TorBoxTorrentInfo) y41.z(listBj);
                            ExecutorService executorService6 = kq.a;
                            kq.h(str2, "Cloud sanitization: deleting TB torrent " + torBoxTorrentInfo.getId() + " (" + torBoxTorrentInfo.getName() + ", createdAt=" + torBoxTorrentInfo.getCreatedAt() + ")");
                            torBoxRepository$deleteMostRecent$12 = torBoxRepository$deleteMostRecent$14;
                            i2 = 3;
                            if (i < i2) {
                            }
                        }
                        ExecutorService executorService7 = kq.a;
                        kq.h(str2, "Cloud sanitization: failed to list TB torrents for recency check");
                        return e6aVar;
                    }
                    if (i5 == 3) {
                        i3 = torBoxRepository$deleteMostRecent$12.I$0;
                        torBoxTorrentInfo2 = (TorBoxTorrentInfo) torBoxRepository$deleteMostRecent$12.L$1;
                        torBoxRepository3 = (TorBoxRepository) torBoxRepository$deleteMostRecent$12.L$0;
                        s38.b(obj3);
                        obj2 = ((q38) obj3).a;
                        i2 = 3;
                        str2 = TAG;
                        if (!(obj2 instanceof q38.b)) {
                        }
                    } else {
                        if (i5 != 4) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        i3 = torBoxRepository$deleteMostRecent$12.I$0;
                        torBoxTorrentInfo2 = (TorBoxTorrentInfo) torBoxRepository$deleteMostRecent$12.L$1;
                        torBoxRepository3 = (TorBoxRepository) torBoxRepository$deleteMostRecent$12.L$0;
                        s38.b(obj3);
                        i2 = 3;
                        str2 = TAG;
                        torBoxTorrentInfo = torBoxTorrentInfo2;
                        torBoxRepository2 = torBoxRepository3;
                        i = i3 + 1;
                        if (i < i2) {
                            int id = torBoxTorrentInfo.getId();
                            torBoxRepository$deleteMostRecent$12.L$0 = torBoxRepository2;
                            torBoxRepository$deleteMostRecent$12.L$1 = torBoxTorrentInfo;
                            torBoxRepository$deleteMostRecent$12.I$0 = i;
                            torBoxRepository$deleteMostRecent$12.label = i2;
                            Object objM140deleteTorrentgIAlus = torBoxRepository2.m140deleteTorrentgIAlus(id, torBoxRepository$deleteMostRecent$12);
                            if (objM140deleteTorrentgIAlus == ck1Var) {
                                return ck1Var;
                            }
                            torBoxTorrentInfo2 = torBoxTorrentInfo;
                            obj2 = objM140deleteTorrentgIAlus;
                            i3 = i;
                            torBoxRepository3 = torBoxRepository2;
                            if (!(obj2 instanceof q38.b)) {
                                ExecutorService executorService8 = kq.a;
                                kq.h(str2, "Cloud sanitization: removed TB torrent " + torBoxTorrentInfo2.getId());
                                return e6aVar;
                            }
                            if (i3 < 2) {
                                int i6 = i3 + 1;
                                long j5 = ((long) i6) * 5000;
                                ExecutorService executorService9 = kq.a;
                                Throwable thA = q38.a(obj2);
                                kq.h(str2, "Cloud sanitization: TB delete failed (attempt " + i6 + "), retrying in " + j5 + "ms: " + (thA != null ? thA.getMessage() : null));
                                torBoxRepository$deleteMostRecent$12.L$0 = torBoxRepository3;
                                torBoxRepository$deleteMostRecent$12.L$1 = torBoxTorrentInfo2;
                                torBoxRepository$deleteMostRecent$12.I$0 = i3;
                                torBoxRepository$deleteMostRecent$12.label = 4;
                            } else {
                                ExecutorService executorService10 = kq.a;
                                Throwable thA2 = q38.a(obj2);
                                if (thA2 != null) {
                                    kq.h(str2, "Cloud sanitization: TB delete failed after 3 attempts: " + thA2.getMessage());
                                } else {
                                    kq.h(str2, "Cloud sanitization: TB delete failed after 3 attempts: " + ((String) null));
                                }
                            }
                            torBoxTorrentInfo = torBoxTorrentInfo2;
                            torBoxRepository2 = torBoxRepository3;
                            i = i3 + 1;
                            if (i < i2) {
                                return e6aVar;
                            }
                        }
                    }
                }
                TorBoxAccount torBoxAccount = (TorBoxAccount) obj;
                if (torBoxAccount == null) {
                    return s38.a(new DebridError.NoAccount(DebridProvider.TORBOX));
                }
                String authHeader = torBoxAccount.getAuthHeader();
                TorBoxApiService torBoxApiService = torBoxRepository.torBoxApiService;
                Boolean boolBoxBoolean = Boxing.boxBoolean(true);
                torBoxRepository$deleteMostRecent$12.L$0 = torBoxRepository;
                torBoxRepository$deleteMostRecent$12.L$1 = str3;
                torBoxRepository$deleteMostRecent$12.J$0 = j2;
                torBoxRepository$deleteMostRecent$12.label = 2;
                long j6 = j2;
                TorBoxRepository torBoxRepository4 = torBoxRepository;
                str2 = TAG;
                try {
                    Object torrentList$default = TorBoxApiService.DefaultImpls.getTorrentList$default(torBoxApiService, authHeader, boolBoxBoolean, null, null, torBoxRepository$deleteMostRecent$12, 12, null);
                    if (torrentList$default == ck1Var) {
                        return ck1Var;
                    }
                    str4 = str3;
                    obj3 = torrentList$default;
                    torBoxRepository2 = torBoxRepository4;
                    j3 = j6;
                    torBoxResponse = (TorBoxResponse) obj3;
                    if (torBoxResponse.getSuccess()) {
                        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
                        simpleDateFormat2.setTimeZone(TimeZone.getTimeZone("UTC"));
                        ExecutorService executorService11 = kq.a;
                        kq.h(str2, "Cloud sanitization: TB has " + ((List) torBoxResponse.getData()).size() + " torrents, resolveTimestamp=" + j3 + " (" + new Date(j3) + "), fileName=" + str4);
                        it = y41.bk(y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.TorBoxRepository$deleteMostRecent-0E7RQCE$$inlined$sortedByDescending$1
                            /* JADX WARN: Multi-variable type inference failed */
                            @Override // java.util.Comparator
                            public final int compare(T t, T t2) {
                                String createdAt3 = ((TorBoxTorrentInfo) t2).getCreatedAt();
                                if (createdAt3 == null) {
                                    createdAt3 = "";
                                }
                                String createdAt22 = ((TorBoxTorrentInfo) t).getCreatedAt();
                                return x71.b(createdAt3, createdAt22 != null ? createdAt22 : "");
                            }
                        }, (Iterable) torBoxResponse.getData()), 5).iterator();
                        while (true) {
                            if (it.hasNext()) {
                            }
                            kq.h(str2, "Cloud sanitization: TB torrent '" + torBoxTorrentInfo3.getName() + "' createdAt=" + torBoxTorrentInfo3.getCreatedAt() + " parsedMs=" + lBoxLong + " (diff=" + ((lBoxLong != null ? lBoxLong.longValue() : 0L) - j3) + "ms)");
                            it = it2;
                            torBoxRepository$deleteMostRecent$12 = torBoxRepository$deleteMostRecent$13;
                            j3 = j3;
                        }
                        TorBoxRepository$deleteMostRecent$1 torBoxRepository$deleteMostRecent$142 = torBoxRepository$deleteMostRecent$12;
                        long j42 = j3;
                        Iterable iterable3 = (Iterable) torBoxResponse.getData();
                        ArrayList arrayList3 = new ArrayList();
                        while (r0.hasNext()) {
                        }
                        listBj = y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.TorBoxRepository$deleteMostRecent-0E7RQCE$$inlined$sortedByDescending$2
                            /* JADX WARN: Multi-variable type inference failed */
                            @Override // java.util.Comparator
                            public final int compare(T t, T t2) {
                                return x71.b(((TorBoxTorrentInfo) t2).getCreatedAt(), ((TorBoxTorrentInfo) t).getCreatedAt());
                            }
                        }, arrayList3);
                        i = 0;
                        if (listBj.isEmpty()) {
                            ExecutorService executorService32 = kq.a;
                            kq.h(str2, "Cloud sanitization: TB timestamp match failed, trying filename match for '" + str4 + "'");
                            strNormalizeForMatch = torBoxRepository2.normalizeForMatch(str4);
                            if (strNormalizeForMatch.length() >= 8) {
                            }
                            if (!listBj.isEmpty()) {
                            }
                        }
                        if (!listBj.isEmpty()) {
                        }
                    }
                    ExecutorService executorService72 = kq.a;
                    kq.h(str2, "Cloud sanitization: failed to list TB torrents for recency check");
                    return e6aVar;
                } catch (Exception e) {
                    e = e;
                    ExecutorService executorService12 = kq.a;
                    kq.a(str2, "Cloud sanitization TB deleteMostRecent failed", e);
                    return s38.a(e);
                }
            } catch (CancellationException e2) {
                throw e2;
            }
        } catch (Exception e3) {
            e = e3;
            str2 = TAG;
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:34:0x008f, code lost:
    
        if (r14 == r1) goto L35;
     */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0016  */
    @pq6
    /* JADX INFO: renamed from: deleteTorrent-gIAlu-s, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m140deleteTorrentgIAlus(int i, @kp6 Continuation<? super q38<e6a>> continuation) {
        TorBoxRepository$deleteTorrent$1 torBoxRepository$deleteTorrent$1;
        TorBoxRepository torBoxRepository;
        if (continuation instanceof TorBoxRepository$deleteTorrent$1) {
            torBoxRepository$deleteTorrent$1 = (TorBoxRepository$deleteTorrent$1) continuation;
            int i2 = torBoxRepository$deleteTorrent$1.label;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                torBoxRepository$deleteTorrent$1.label = i2 - Integer.MIN_VALUE;
            } else {
                torBoxRepository$deleteTorrent$1 = new TorBoxRepository$deleteTorrent$1(this, continuation);
            }
        }
        TorBoxRepository$deleteTorrent$1 torBoxRepository$deleteTorrent$12 = torBoxRepository$deleteTorrent$1;
        Object account = torBoxRepository$deleteTorrent$12.result;
        ck1 ck1Var = ck1.a;
        int i3 = torBoxRepository$deleteTorrent$12.label;
        try {
            if (i3 == 0) {
                s38.b(account);
                TorBoxAccountDao torBoxAccountDao = this.accountDao;
                torBoxRepository$deleteTorrent$12.L$0 = this;
                torBoxRepository$deleteTorrent$12.I$0 = i;
                torBoxRepository$deleteTorrent$12.label = 1;
                account = torBoxAccountDao.getAccount("torbox", torBoxRepository$deleteTorrent$12);
                if (account != ck1Var) {
                    torBoxRepository = this;
                }
                return ck1Var;
            }
            if (i3 != 1) {
                if (i3 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(account);
                TorBoxResponse torBoxResponse = (TorBoxResponse) account;
                if (torBoxResponse.getSuccess()) {
                    return e6a.a;
                }
                String error = torBoxResponse.getError();
                if (error == null && (error = torBoxResponse.getDetail()) == null) {
                    error = "Failed to delete torrent";
                }
                Log.e(TAG, "Failed to delete torrent: ".concat(error));
                return s38.a(new Exception(error));
            }
            i = torBoxRepository$deleteTorrent$12.I$0;
            torBoxRepository = (TorBoxRepository) torBoxRepository$deleteTorrent$12.L$0;
            s38.b(account);
            int i4 = i;
            TorBoxAccount torBoxAccount = (TorBoxAccount) account;
            if (torBoxAccount == null) {
                return s38.a(new DebridError.NoAccount(DebridProvider.TORBOX));
            }
            String authHeader = torBoxAccount.getAuthHeader();
            TorBoxApiService torBoxApiService = torBoxRepository.torBoxApiService;
            torBoxRepository$deleteTorrent$12.L$0 = null;
            torBoxRepository$deleteTorrent$12.I$0 = i4;
            torBoxRepository$deleteTorrent$12.label = 2;
            account = TorBoxApiService.DefaultImpls.controlTorrent$default(torBoxApiService, authHeader, i4, "delete", null, torBoxRepository$deleteTorrent$12, 8, null);
        } catch (CancellationException e) {
            throw e;
        } catch (HttpException e2) {
            Log.e(TAG, "Failed to delete torrent: HTTP " + e2.code(), e2);
            return s38.a(new DebridError.Unknown(DebridProvider.TORBOX, n41.k("HTTP ", e2.code()), e2));
        } catch (Exception e3) {
            Log.e(TAG, "Failed to delete torrent", e3);
            return s38.a(new DebridError.Unknown(DebridProvider.TORBOX, e3.getMessage(), e3));
        }
    }

    @pq6
    public final Object getAccount(@kp6 Continuation<? super TorBoxAccount> continuation) {
        return this.accountDao.getAccount("torbox", continuation);
    }

    /* JADX WARN: Code restructure failed: missing block: B:23:0x004c, code lost:
    
        r5 = r5.getExpiresAt();
     */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @Override // com.strmr.ps.data.repository.IDebridProvider
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object getAccountExpirationStatus(@kp6 Continuation<? super Integer> continuation) {
        C04181 c04181;
        String expiresAt;
        if (continuation instanceof C04181) {
            c04181 = (C04181) continuation;
            int i = c04181.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c04181.label = i - Integer.MIN_VALUE;
            } else {
                c04181 = new C04181(continuation);
            }
        }
        Object account = c04181.result;
        ck1 ck1Var = ck1.a;
        int i2 = c04181.label;
        if (i2 == 0) {
            s38.b(account);
            TorBoxAccountDao torBoxAccountDao = this.accountDao;
            c04181.label = 1;
            account = torBoxAccountDao.getAccount("torbox", c04181);
            if (account == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(account);
        }
        TorBoxAccount torBoxAccount = (TorBoxAccount) account;
        if (torBoxAccount == null || torBoxAccount.getPlan() == 0 || expiresAt == null) {
            return null;
        }
        try {
            Instant instant = Instant.parse(expiresAt);
            Instant instantNow = Instant.now();
            if (instant.isBefore(instantNow)) {
                return Boxing.boxInt((int) ChronoUnit.DAYS.between(instant, instantNow));
            }
            return null;
        } catch (Exception e) {
            Log.w(TAG, "Could not parse expiration date: ".concat(expiresAt), e);
            return null;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @Override // com.strmr.ps.data.repository.IDebridProvider
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object getApiKey(@kp6 Continuation<? super String> continuation) {
        C04191 c04191;
        if (continuation instanceof C04191) {
            c04191 = (C04191) continuation;
            int i = c04191.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c04191.label = i - Integer.MIN_VALUE;
            } else {
                c04191 = new C04191(continuation);
            }
        }
        Object account = c04191.result;
        ck1 ck1Var = ck1.a;
        int i2 = c04191.label;
        if (i2 == 0) {
            s38.b(account);
            TorBoxAccountDao torBoxAccountDao = this.accountDao;
            c04191.label = 1;
            account = torBoxAccountDao.getAccount("torbox", c04191);
            if (account == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(account);
        }
        TorBoxAccount torBoxAccount = (TorBoxAccount) account;
        if (torBoxAccount != null) {
            return torBoxAccount.getApiKey();
        }
        return null;
    }

    @pq6
    public final Integer getDaysRemaining(@kp6 TorBoxAccount account) {
        cr4.g(account, "account");
        return account.getDaysRemaining();
    }

    /* JADX WARN: Code restructure failed: missing block: B:33:0x0087, code lost:
    
        if (r0 == r2) goto L34;
     */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0018  */
    @Override // com.strmr.ps.data.repository.IDebridLibraryProvider
    @pq6
    /* JADX INFO: renamed from: getLibraryItems-IoAF18A */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object mo70getLibraryItemsIoAF18A(@kp6 Continuation<? super q38<? extends List<? extends DebridFileItem>>> continuation) {
        TorBoxRepository$getLibraryItems$1 torBoxRepository$getLibraryItems$1;
        TorBoxRepository torBoxRepository;
        if (continuation instanceof TorBoxRepository$getLibraryItems$1) {
            torBoxRepository$getLibraryItems$1 = (TorBoxRepository$getLibraryItems$1) continuation;
            int i = torBoxRepository$getLibraryItems$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                torBoxRepository$getLibraryItems$1.label = i - Integer.MIN_VALUE;
            } else {
                torBoxRepository$getLibraryItems$1 = new TorBoxRepository$getLibraryItems$1(this, continuation);
            }
        }
        TorBoxRepository$getLibraryItems$1 torBoxRepository$getLibraryItems$12 = torBoxRepository$getLibraryItems$1;
        Object account = torBoxRepository$getLibraryItems$12.result;
        ck1 ck1Var = ck1.a;
        int i2 = torBoxRepository$getLibraryItems$12.label;
        try {
            if (i2 == 0) {
                s38.b(account);
                TorBoxAccountDao torBoxAccountDao = this.accountDao;
                torBoxRepository$getLibraryItems$12.L$0 = this;
                torBoxRepository$getLibraryItems$12.label = 1;
                account = torBoxAccountDao.getAccount("torbox", torBoxRepository$getLibraryItems$12);
                if (account != ck1Var) {
                    torBoxRepository = this;
                }
                return ck1Var;
            }
            if (i2 != 1) {
                if (i2 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(account);
                TorBoxResponse torBoxResponse = (TorBoxResponse) account;
                if (torBoxResponse.getSuccess() && torBoxResponse.getData() != null) {
                    int size = ((List) torBoxResponse.getData()).size();
                    Iterable iterable = (Iterable) torBoxResponse.getData();
                    LinkedHashMap linkedHashMap = new LinkedHashMap();
                    for (Object obj : iterable) {
                        String downloadState = ((TorBoxTorrentInfo) obj).getDownloadState();
                        if (downloadState == null) {
                            downloadState = "null";
                        }
                        Object arrayList = linkedHashMap.get(downloadState);
                        if (arrayList == null) {
                            arrayList = new ArrayList();
                            linkedHashMap.put(downloadState, arrayList);
                        }
                        ((List) arrayList).add(obj);
                    }
                    LinkedHashMap linkedHashMap2 = new LinkedHashMap(wo5.h(linkedHashMap.size()));
                    for (Object obj2 : linkedHashMap.entrySet()) {
                        linkedHashMap2.put(((Map.Entry) obj2).getKey(), Boxing.boxInt(((List) ((Map.Entry) obj2).getValue()).size()));
                    }
                    Iterable iterable2 = (Iterable) torBoxResponse.getData();
                    ArrayList<TorBoxTorrentInfo> arrayList2 = new ArrayList();
                    for (Object obj3 : iterable2) {
                        TorBoxTorrentInfo torBoxTorrentInfo = (TorBoxTorrentInfo) obj3;
                        if (y41.q(y41.an("completed", "cached"), torBoxTorrentInfo.getDownloadState()) || cr4.b(torBoxTorrentInfo.getDownloadPresent(), Boxing.boxBoolean(true))) {
                            arrayList2.add(obj3);
                        }
                    }
                    ArrayList arrayList3 = new ArrayList(y41.p(arrayList2, 10));
                    for (TorBoxTorrentInfo torBoxTorrentInfo2 : arrayList2) {
                        String strValueOf = String.valueOf(torBoxTorrentInfo2.getId());
                        String name = torBoxTorrentInfo2.getName();
                        if (name == null) {
                            name = "Unknown";
                        }
                        String str = name;
                        String displayName = DebridService.INSTANCE.getDisplayName("torbox");
                        List<TorBoxFile> files = torBoxTorrentInfo2.getFiles();
                        arrayList3.add(new DebridFileItem.Folder(strValueOf, str, "torbox", displayName, files != null ? Boxing.boxInt(files.size()) : null, null, String.valueOf(torBoxTorrentInfo2.getId()), 32, null));
                    }
                    ExecutorService executorService = kq.a;
                    kq.h(TAG, "Library: " + arrayList3.size() + " ready of " + size + " total torrents (states: " + linkedHashMap2 + ")");
                    return arrayList3;
                }
                String error = torBoxResponse.getError();
                if (error == null && (error = torBoxResponse.getDetail()) == null) {
                    error = "Failed to get torrents";
                }
                return s38.a(new Exception(error));
            }
            torBoxRepository = (TorBoxRepository) torBoxRepository$getLibraryItems$12.L$0;
            s38.b(account);
            TorBoxAccount torBoxAccount = (TorBoxAccount) account;
            if (torBoxAccount == null) {
                return s38.a(new DebridError.NoAccount(DebridProvider.TORBOX));
            }
            String authHeader = torBoxAccount.getAuthHeader();
            TorBoxApiService torBoxApiService = torBoxRepository.torBoxApiService;
            Boolean boolBoxBoolean = Boxing.boxBoolean(true);
            torBoxRepository$getLibraryItems$12.L$0 = null;
            torBoxRepository$getLibraryItems$12.label = 2;
            account = TorBoxApiService.DefaultImpls.getTorrentList$default(torBoxApiService, authHeader, boolBoxBoolean, null, null, torBoxRepository$getLibraryItems$12, 12, null);
        } catch (CancellationException e) {
            throw e;
        } catch (HttpException e2) {
            ExecutorService executorService2 = kq.a;
            kq.a(TAG, "Failed to get library items: HTTP " + e2.code(), e2);
            return s38.a(new DebridError.Unknown(DebridProvider.TORBOX, n41.k("HTTP ", e2.code()), e2));
        } catch (Exception e3) {
            ExecutorService executorService3 = kq.a;
            kq.a(TAG, "Failed to get library items", e3);
            return s38.a(new DebridError.Unknown(DebridProvider.TORBOX, e3.getMessage(), e3));
        }
    }

    @Override // com.strmr.ps.data.repository.IDebridProvider
    @kp6
    public DebridProvider getProvider() {
        return this.provider;
    }

    @Override // com.strmr.ps.data.repository.IDebridProvider
    @kp6
    public String getServiceName() {
        return this.serviceName;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00a9 A[Catch: Exception -> 0x0035, HttpException -> 0x0038, CancellationException -> 0x003b, TryCatch #2 {CancellationException -> 0x003b, HttpException -> 0x0038, Exception -> 0x0035, blocks: (B:13:0x0031, B:36:0x008d, B:38:0x0095, B:41:0x009d, B:43:0x00a9, B:44:0x00ba, B:46:0x00c0, B:48:0x00cc, B:56:0x00de, B:55:0x00d9, B:58:0x012b, B:60:0x0133, B:78:0x0162, B:63:0x013d, B:64:0x0141, B:66:0x0147, B:71:0x0153, B:73:0x0159, B:76:0x015e, B:77:0x0161, B:57:0x0129, B:80:0x0192, B:83:0x019c, B:32:0x0075), top: B:89:0x0029 }] */
    /* JADX WARN: Removed duplicated region for block: B:57:0x0129 A[Catch: Exception -> 0x0035, HttpException -> 0x0038, CancellationException -> 0x003b, TryCatch #2 {CancellationException -> 0x003b, HttpException -> 0x0038, Exception -> 0x0035, blocks: (B:13:0x0031, B:36:0x008d, B:38:0x0095, B:41:0x009d, B:43:0x00a9, B:44:0x00ba, B:46:0x00c0, B:48:0x00cc, B:56:0x00de, B:55:0x00d9, B:58:0x012b, B:60:0x0133, B:78:0x0162, B:63:0x013d, B:64:0x0141, B:66:0x0147, B:71:0x0153, B:73:0x0159, B:76:0x015e, B:77:0x0161, B:57:0x0129, B:80:0x0192, B:83:0x019c, B:32:0x0075), top: B:89:0x0029 }] */
    /* JADX WARN: Removed duplicated region for block: B:63:0x013d A[Catch: Exception -> 0x0035, HttpException -> 0x0038, CancellationException -> 0x003b, TryCatch #2 {CancellationException -> 0x003b, HttpException -> 0x0038, Exception -> 0x0035, blocks: (B:13:0x0031, B:36:0x008d, B:38:0x0095, B:41:0x009d, B:43:0x00a9, B:44:0x00ba, B:46:0x00c0, B:48:0x00cc, B:56:0x00de, B:55:0x00d9, B:58:0x012b, B:60:0x0133, B:78:0x0162, B:63:0x013d, B:64:0x0141, B:66:0x0147, B:71:0x0153, B:73:0x0159, B:76:0x015e, B:77:0x0161, B:57:0x0129, B:80:0x0192, B:83:0x019c, B:32:0x0075), top: B:89:0x0029 }] */
    /* JADX WARN: Removed duplicated region for block: B:66:0x0147 A[Catch: Exception -> 0x0035, HttpException -> 0x0038, CancellationException -> 0x003b, TryCatch #2 {CancellationException -> 0x003b, HttpException -> 0x0038, Exception -> 0x0035, blocks: (B:13:0x0031, B:36:0x008d, B:38:0x0095, B:41:0x009d, B:43:0x00a9, B:44:0x00ba, B:46:0x00c0, B:48:0x00cc, B:56:0x00de, B:55:0x00d9, B:58:0x012b, B:60:0x0133, B:78:0x0162, B:63:0x013d, B:64:0x0141, B:66:0x0147, B:71:0x0153, B:73:0x0159, B:76:0x015e, B:77:0x0161, B:57:0x0129, B:80:0x0192, B:83:0x019c, B:32:0x0075), top: B:89:0x0029 }] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0017  */
    /* JADX WARN: Removed duplicated region for block: B:82:0x019a  */
    /* JADX WARN: Type inference failed for: r0v24 */
    /* JADX WARN: Type inference failed for: r3v6, types: [ik2] */
    /* JADX WARN: Type inference failed for: r3v7, types: [java.lang.Object, java.util.List] */
    /* JADX WARN: Type inference failed for: r3v8, types: [java.util.ArrayList] */
    @pq6
    /* JADX INFO: renamed from: getTorrentFilesForLibrary-gIAlu-s, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m141getTorrentFilesForLibrarygIAlus(int i, @kp6 Continuation<? super q38<? extends List<? extends DebridFileItem>>> continuation) {
        TorBoxRepository$getTorrentFilesForLibrary$1 torBoxRepository$getTorrentFilesForLibrary$1;
        int i2;
        TorBoxRepository torBoxRepository;
        int i3;
        TorBoxResponse torBoxResponse;
        String error;
        List<TorBoxFile> files;
        ?? arrayList;
        Iterable<DebridFileItem.File> iterable;
        if (continuation instanceof TorBoxRepository$getTorrentFilesForLibrary$1) {
            torBoxRepository$getTorrentFilesForLibrary$1 = (TorBoxRepository$getTorrentFilesForLibrary$1) continuation;
            int i4 = torBoxRepository$getTorrentFilesForLibrary$1.label;
            if ((i4 & Integer.MIN_VALUE) != 0) {
                torBoxRepository$getTorrentFilesForLibrary$1.label = i4 - Integer.MIN_VALUE;
            } else {
                torBoxRepository$getTorrentFilesForLibrary$1 = new TorBoxRepository$getTorrentFilesForLibrary$1(this, continuation);
            }
        }
        Object account = torBoxRepository$getTorrentFilesForLibrary$1.result;
        ck1 ck1Var = ck1.a;
        int i5 = torBoxRepository$getTorrentFilesForLibrary$1.label;
        try {
            if (i5 == 0) {
                s38.b(account);
                TorBoxAccountDao torBoxAccountDao = this.accountDao;
                torBoxRepository$getTorrentFilesForLibrary$1.L$0 = this;
                i2 = i;
                torBoxRepository$getTorrentFilesForLibrary$1.I$0 = i2;
                torBoxRepository$getTorrentFilesForLibrary$1.label = 1;
                account = torBoxAccountDao.getAccount("torbox", torBoxRepository$getTorrentFilesForLibrary$1);
                if (account != ck1Var) {
                    torBoxRepository = this;
                }
                return ck1Var;
            }
            if (i5 != 1) {
                if (i5 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                i3 = torBoxRepository$getTorrentFilesForLibrary$1.I$0;
                s38.b(account);
                torBoxResponse = (TorBoxResponse) account;
                if (torBoxResponse.getSuccess() && torBoxResponse.getData() != null) {
                    files = ((TorBoxTorrentInfo) torBoxResponse.getData()).getFiles();
                    if (files == null) {
                        List<TorBoxFile> list = files;
                        arrayList = new ArrayList(y41.p(list, 10));
                        for (TorBoxFile torBoxFile : list) {
                            String shortName = torBoxFile.getShortName();
                            if (shortName == null) {
                                shortName = torBoxFile.getName();
                            } else {
                                if (n89.ab(shortName)) {
                                    shortName = null;
                                }
                                if (shortName == null) {
                                    shortName = torBoxFile.getName();
                                }
                            }
                            String str = shortName;
                            arrayList.add(new DebridFileItem.File(i3 + "_" + torBoxFile.getId(), str, "torbox", DebridService.INSTANCE.getDisplayName("torbox"), torBoxFile.getSize(), null, null, null, String.valueOf(i3), Boxing.boxInt(torBoxFile.getId()), VideoExtensions.INSTANCE.isVideoFile(str), false, 2272, null));
                        }
                    } else {
                        arrayList = ik2.a;
                    }
                    iterable = (Iterable) arrayList;
                    int i6 = 0;
                    if ((iterable instanceof Collection) || !((Collection) iterable).isEmpty()) {
                        for (DebridFileItem.File file : iterable) {
                            if (file == null) {
                                file = null;
                            }
                            if (file != null && file.isVideo() && (i6 = i6 + 1) < 0) {
                                y41.bl();
                                throw null;
                            }
                        }
                    }
                    ExecutorService executorService = kq.a;
                    kq.h(TAG, "Torrent " + i3 + ": " + arrayList.size() + " files (" + i6 + " video)");
                    return arrayList;
                }
                error = torBoxResponse.getError();
                if (error == null) {
                    error = "Failed to get torrent";
                }
                return s38.a(new Exception(error));
            }
            i2 = torBoxRepository$getTorrentFilesForLibrary$1.I$0;
            torBoxRepository = (TorBoxRepository) torBoxRepository$getTorrentFilesForLibrary$1.L$0;
            s38.b(account);
            TorBoxAccount torBoxAccount = (TorBoxAccount) account;
            if (torBoxAccount == null) {
                return s38.a(new DebridError.NoAccount(DebridProvider.TORBOX));
            }
            String authHeader = torBoxAccount.getAuthHeader();
            TorBoxApiService torBoxApiService = torBoxRepository.torBoxApiService;
            Boolean boolBoxBoolean = Boxing.boxBoolean(true);
            torBoxRepository$getTorrentFilesForLibrary$1.L$0 = null;
            torBoxRepository$getTorrentFilesForLibrary$1.I$0 = i2;
            torBoxRepository$getTorrentFilesForLibrary$1.label = 2;
            account = torBoxApiService.getTorrent(authHeader, i2, boolBoxBoolean, torBoxRepository$getTorrentFilesForLibrary$1);
            if (account != ck1Var) {
                i3 = i2;
                torBoxResponse = (TorBoxResponse) account;
                if (torBoxResponse.getSuccess()) {
                    files = ((TorBoxTorrentInfo) torBoxResponse.getData()).getFiles();
                    if (files == null) {
                    }
                    iterable = (Iterable) arrayList;
                    int i62 = 0;
                    if (iterable instanceof Collection) {
                        while (r0.hasNext()) {
                        }
                    }
                    ExecutorService executorService2 = kq.a;
                    kq.h(TAG, "Torrent " + i3 + ": " + arrayList.size() + " files (" + i62 + " video)");
                    return arrayList;
                }
                error = torBoxResponse.getError();
                if (error == null) {
                }
                return s38.a(new Exception(error));
            }
            return ck1Var;
        } catch (CancellationException e) {
            throw e;
        } catch (HttpException e2) {
            ExecutorService executorService3 = kq.a;
            kq.a(TAG, "Failed to get torrent files: HTTP " + e2.code(), e2);
            return s38.a(new DebridError.Unknown(DebridProvider.TORBOX, n41.k("HTTP ", e2.code()), e2));
        } catch (Exception e3) {
            ExecutorService executorService4 = kq.a;
            kq.a(TAG, "Failed to get torrent files", e3);
            return s38.a(new DebridError.Unknown(DebridProvider.TORBOX, e3.getMessage(), e3));
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @Override // com.strmr.ps.data.repository.IDebridProvider
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object hasAccount(@kp6 Continuation<? super Boolean> continuation) {
        C04201 c04201;
        if (continuation instanceof C04201) {
            c04201 = (C04201) continuation;
            int i = c04201.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c04201.label = i - Integer.MIN_VALUE;
            } else {
                c04201 = new C04201(continuation);
            }
        }
        Object account = c04201.result;
        ck1 ck1Var = ck1.a;
        int i2 = c04201.label;
        if (i2 == 0) {
            s38.b(account);
            TorBoxAccountDao torBoxAccountDao = this.accountDao;
            c04201.label = 1;
            account = torBoxAccountDao.getAccount("torbox", c04201);
            if (account == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(account);
        }
        return Boxing.boxBoolean(account != null);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /* JADX INFO: renamed from: pollForDeviceToken-gIAlu-s, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m142pollForDeviceTokengIAlus(@kp6 String str, @kp6 Continuation<? super q38<String>> continuation) {
        TorBoxRepository$pollForDeviceToken$1 torBoxRepository$pollForDeviceToken$1;
        if (continuation instanceof TorBoxRepository$pollForDeviceToken$1) {
            torBoxRepository$pollForDeviceToken$1 = (TorBoxRepository$pollForDeviceToken$1) continuation;
            int i = torBoxRepository$pollForDeviceToken$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                torBoxRepository$pollForDeviceToken$1.label = i - Integer.MIN_VALUE;
            } else {
                torBoxRepository$pollForDeviceToken$1 = new TorBoxRepository$pollForDeviceToken$1(this, continuation);
            }
        }
        Object objPollForDeviceToken = torBoxRepository$pollForDeviceToken$1.result;
        ck1 ck1Var = ck1.a;
        int i2 = torBoxRepository$pollForDeviceToken$1.label;
        q38.b bVarA = null;
        try {
            if (i2 == 0) {
                s38.b(objPollForDeviceToken);
                TorBoxDeviceTokenRequest torBoxDeviceTokenRequest = new TorBoxDeviceTokenRequest(str);
                TorBoxApiService torBoxApiService = this.torBoxApiService;
                torBoxRepository$pollForDeviceToken$1.label = 1;
                objPollForDeviceToken = torBoxApiService.pollForDeviceToken(torBoxDeviceTokenRequest, torBoxRepository$pollForDeviceToken$1);
                if (objPollForDeviceToken == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i2 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(objPollForDeviceToken);
            }
            TorBoxResponse torBoxResponse = (TorBoxResponse) objPollForDeviceToken;
            if (!torBoxResponse.getSuccess() || torBoxResponse.getData() == null) {
                String detail = torBoxResponse.getDetail();
                if (detail == null) {
                    detail = torBoxResponse.getError();
                }
                if ((detail == null || !n89.l(detail, "pending", true)) && ((detail == null || !n89.l(detail, "waiting", true)) && (detail == null || !n89.l(detail, "not authorized", true)))) {
                    if (detail != null && n89.l(detail, "expired", true)) {
                        return s38.a(new Exception("Device code expired"));
                    }
                    if (detail != null && n89.l(detail, "denied", true)) {
                        return s38.a(new Exception("Authorization denied"));
                    }
                }
            } else {
                String apiToken = ((TorBoxDeviceTokenData) torBoxResponse.getData()).getApiToken();
                if (apiToken != null) {
                    ExecutorService executorService = kq.a;
                    kq.h(TAG, "Device token received");
                    return apiToken;
                }
            }
            return null;
        } catch (HttpException e) {
            int iCode = e.code();
            if (400 > iCode || iCode >= 500) {
                bVarA = s38.a(e);
            } else {
                e.code();
            }
            return bVarA;
        } catch (Exception e2) {
            Log.e(TAG, "Failed to poll for device token", e2);
            return s38.a(e2);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /* JADX INFO: renamed from: refreshAccountInfo-IoAF18A, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m143refreshAccountInfoIoAF18A(@kp6 Continuation<? super q38<TorBoxAccount>> continuation) {
        TorBoxRepository$refreshAccountInfo$1 torBoxRepository$refreshAccountInfo$1;
        TorBoxRepository torBoxRepository;
        if (continuation instanceof TorBoxRepository$refreshAccountInfo$1) {
            torBoxRepository$refreshAccountInfo$1 = (TorBoxRepository$refreshAccountInfo$1) continuation;
            int i = torBoxRepository$refreshAccountInfo$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                torBoxRepository$refreshAccountInfo$1.label = i - Integer.MIN_VALUE;
            } else {
                torBoxRepository$refreshAccountInfo$1 = new TorBoxRepository$refreshAccountInfo$1(this, continuation);
            }
        }
        Object account = torBoxRepository$refreshAccountInfo$1.result;
        ck1 ck1Var = ck1.a;
        int i2 = torBoxRepository$refreshAccountInfo$1.label;
        if (i2 == 0) {
            s38.b(account);
            TorBoxAccountDao torBoxAccountDao = this.accountDao;
            torBoxRepository$refreshAccountInfo$1.L$0 = this;
            torBoxRepository$refreshAccountInfo$1.label = 1;
            account = torBoxAccountDao.getAccount("torbox", torBoxRepository$refreshAccountInfo$1);
            if (account != ck1Var) {
                torBoxRepository = this;
            }
        }
        if (i2 != 1) {
            if (i2 != 2) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(account);
            return ((q38) account).a;
        }
        torBoxRepository = (TorBoxRepository) torBoxRepository$refreshAccountInfo$1.L$0;
        s38.b(account);
        TorBoxAccount torBoxAccount = (TorBoxAccount) account;
        if (torBoxAccount == null) {
            return vw2.d("No TorBox account configured");
        }
        String apiKey = torBoxAccount.getApiKey();
        torBoxRepository$refreshAccountInfo$1.L$0 = null;
        torBoxRepository$refreshAccountInfo$1.label = 2;
        Object objM146verifyAndSaveApiKeygIAlus = torBoxRepository.m146verifyAndSaveApiKeygIAlus(apiKey, torBoxRepository$refreshAccountInfo$1);
        return objM146verifyAndSaveApiKeygIAlus == ck1Var ? ck1Var : objM146verifyAndSaveApiKeygIAlus;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0017  */
    @pq6
    /* JADX INFO: renamed from: requestDeviceCode-IoAF18A, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m144requestDeviceCodeIoAF18A(@kp6 Continuation<? super q38<TorBoxDeviceCodeData>> continuation) {
        TorBoxRepository$requestDeviceCode$1 torBoxRepository$requestDeviceCode$1;
        if (continuation instanceof TorBoxRepository$requestDeviceCode$1) {
            torBoxRepository$requestDeviceCode$1 = (TorBoxRepository$requestDeviceCode$1) continuation;
            int i = torBoxRepository$requestDeviceCode$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                torBoxRepository$requestDeviceCode$1.label = i - Integer.MIN_VALUE;
            } else {
                torBoxRepository$requestDeviceCode$1 = new TorBoxRepository$requestDeviceCode$1(this, continuation);
            }
        }
        Object objRequestDeviceCode = torBoxRepository$requestDeviceCode$1.result;
        ck1 ck1Var = ck1.a;
        int i2 = torBoxRepository$requestDeviceCode$1.label;
        try {
            if (i2 == 0) {
                s38.b(objRequestDeviceCode);
                TorBoxApiService torBoxApiService = this.torBoxApiService;
                torBoxRepository$requestDeviceCode$1.label = 1;
                objRequestDeviceCode = torBoxApiService.requestDeviceCode("STRMR", torBoxRepository$requestDeviceCode$1);
                if (objRequestDeviceCode == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i2 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(objRequestDeviceCode);
            }
            TorBoxResponse torBoxResponse = (TorBoxResponse) objRequestDeviceCode;
            if (!torBoxResponse.getSuccess() || torBoxResponse.getData() == null) {
                String error = torBoxResponse.getError();
                if (error == null && (error = torBoxResponse.getDetail()) == null) {
                    error = "Failed to get device code";
                }
                Log.w(TAG, "Device code request failed: ".concat(error));
                return s38.a(new Exception(error));
            }
            ExecutorService executorService = kq.a;
            kq.h(TAG, "Device code received: " + ((TorBoxDeviceCodeData) torBoxResponse.getData()).getUserCode());
            return torBoxResponse.getData();
        } catch (Exception e) {
            Log.e(TAG, "Failed to request device code", e);
            return s38.a(e);
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:41:0x00b0, code lost:
    
        if (r13 == r1) goto L42;
     */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0016  */
    @Override // com.strmr.ps.data.repository.IDebridLibraryProvider
    @pq6
    /* JADX INFO: renamed from: resolveLibraryFile-gIAlu-s */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object mo75resolveLibraryFilegIAlus(@kp6 DebridFileItem.File file, @kp6 Continuation<? super q38<String>> continuation) {
        TorBoxRepository$resolveLibraryFile$1 torBoxRepository$resolveLibraryFile$1;
        TorBoxRepository torBoxRepository;
        Integer numBe;
        if (continuation instanceof TorBoxRepository$resolveLibraryFile$1) {
            torBoxRepository$resolveLibraryFile$1 = (TorBoxRepository$resolveLibraryFile$1) continuation;
            int i = torBoxRepository$resolveLibraryFile$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                torBoxRepository$resolveLibraryFile$1.label = i - Integer.MIN_VALUE;
            } else {
                torBoxRepository$resolveLibraryFile$1 = new TorBoxRepository$resolveLibraryFile$1(this, continuation);
            }
        }
        TorBoxRepository$resolveLibraryFile$1 torBoxRepository$resolveLibraryFile$12 = torBoxRepository$resolveLibraryFile$1;
        Object account = torBoxRepository$resolveLibraryFile$12.result;
        ck1 ck1Var = ck1.a;
        int i2 = torBoxRepository$resolveLibraryFile$12.label;
        try {
            if (i2 == 0) {
                s38.b(account);
                TorBoxAccountDao torBoxAccountDao = this.accountDao;
                torBoxRepository$resolveLibraryFile$12.L$0 = this;
                torBoxRepository$resolveLibraryFile$12.L$1 = file;
                torBoxRepository$resolveLibraryFile$12.label = 1;
                account = torBoxAccountDao.getAccount("torbox", torBoxRepository$resolveLibraryFile$12);
                if (account != ck1Var) {
                    torBoxRepository = this;
                }
                return ck1Var;
            }
            if (i2 != 1) {
                if (i2 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                file = (DebridFileItem.File) torBoxRepository$resolveLibraryFile$12.L$0;
                s38.b(account);
                TorBoxResponse torBoxResponse = (TorBoxResponse) account;
                if (!torBoxResponse.getSuccess() || torBoxResponse.getData() == null) {
                    String error = torBoxResponse.getError();
                    if (error == null && (error = torBoxResponse.getDetail()) == null) {
                        error = "Failed to get download link";
                    }
                    return s38.a(new Exception(error));
                }
                ExecutorService executorService = kq.a;
                kq.h(TAG, "Resolved library file: " + file.getName());
                return torBoxResponse.getData();
            }
            file = (DebridFileItem.File) torBoxRepository$resolveLibraryFile$12.L$1;
            torBoxRepository = (TorBoxRepository) torBoxRepository$resolveLibraryFile$12.L$0;
            s38.b(account);
            TorBoxAccount torBoxAccount = (TorBoxAccount) account;
            if (torBoxAccount == null) {
                return s38.a(new DebridError.NoAccount(DebridProvider.TORBOX));
            }
            String authHeader = torBoxAccount.getAuthHeader();
            String torrentId = file.getTorrentId();
            if (torrentId == null || (numBe = n89.be(torrentId)) == null) {
                return s38.a(new Exception("Invalid torrent ID"));
            }
            int iIntValue = numBe.intValue();
            Integer fileIndex = file.getFileIndex();
            if (fileIndex == null) {
                return s38.a(new Exception("Invalid file ID"));
            }
            int iIntValue2 = fileIndex.intValue();
            TorBoxApiService torBoxApiService = torBoxRepository.torBoxApiService;
            String apiKey = torBoxAccount.getApiKey();
            Boolean boolBoxBoolean = Boxing.boxBoolean(false);
            torBoxRepository$resolveLibraryFile$12.L$0 = file;
            torBoxRepository$resolveLibraryFile$12.L$1 = null;
            torBoxRepository$resolveLibraryFile$12.label = 2;
            account = torBoxApiService.requestDownload(authHeader, apiKey, iIntValue, iIntValue2, boolBoxBoolean, torBoxRepository$resolveLibraryFile$12);
        } catch (CancellationException e) {
            throw e;
        } catch (HttpException e2) {
            ExecutorService executorService2 = kq.a;
            kq.a(TAG, "Failed to resolve library file: HTTP " + e2.code(), e2);
            return s38.a(new DebridError.Unknown(DebridProvider.TORBOX, n41.k("HTTP ", e2.code()), e2));
        } catch (Exception e3) {
            ExecutorService executorService3 = kq.a;
            kq.a(TAG, "Failed to resolve library file", e3);
            return s38.a(new DebridError.Unknown(DebridProvider.TORBOX, e3.getMessage(), e3));
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:103:0x02b3 A[Catch: CancellationException -> 0x0072, Exception -> 0x02a1, UnknownHostException -> 0x02a4, SocketTimeoutException -> 0x02a7, HttpException -> 0x02aa, TryCatch #2 {CancellationException -> 0x0072, blocks: (B:221:0x0624, B:220:0x060d, B:19:0x005d, B:204:0x0587, B:206:0x0590, B:208:0x0596, B:222:0x062a, B:224:0x0630, B:227:0x0638, B:229:0x0640, B:231:0x0648, B:234:0x0651, B:236:0x0659, B:238:0x0661, B:241:0x066a, B:244:0x0694, B:242:0x0681, B:243:0x068b, B:32:0x0097, B:81:0x0245, B:83:0x024d, B:86:0x0255, B:88:0x0273, B:91:0x0282, B:101:0x02ad, B:103:0x02b3, B:105:0x02bf, B:106:0x02e1, B:110:0x02ed, B:112:0x0301, B:115:0x030d, B:116:0x0311, B:118:0x0317, B:120:0x0334, B:123:0x0347, B:126:0x03a1, B:128:0x03ab, B:130:0x03bd, B:133:0x03c7, B:134:0x03cb, B:136:0x03d1, B:138:0x03ec, B:144:0x0417, B:146:0x041f, B:147:0x042e, B:149:0x0434, B:150:0x0442, B:153:0x0452, B:154:0x0456, B:156:0x045c, B:160:0x046f, B:162:0x0474, B:167:0x04cc, B:179:0x0501, B:181:0x0505, B:193:0x053d, B:195:0x0541, B:184:0x0514, B:187:0x051f, B:188:0x0526, B:191:0x0537, B:200:0x0554, B:170:0x04d8, B:173:0x04e3, B:174:0x04ea, B:177:0x04fb, B:164:0x049b, B:245:0x069a, B:36:0x00c1, B:70:0x01ff, B:72:0x0207, B:75:0x020f, B:77:0x021b, B:247:0x06a6, B:249:0x06b2, B:251:0x06b8, B:254:0x06c0, B:60:0x01a3, B:64:0x01b4, B:66:0x01ea, B:63:0x01b0), top: B:272:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:105:0x02bf A[Catch: CancellationException -> 0x0072, Exception -> 0x02a1, UnknownHostException -> 0x02a4, SocketTimeoutException -> 0x02a7, HttpException -> 0x02aa, TryCatch #2 {CancellationException -> 0x0072, blocks: (B:221:0x0624, B:220:0x060d, B:19:0x005d, B:204:0x0587, B:206:0x0590, B:208:0x0596, B:222:0x062a, B:224:0x0630, B:227:0x0638, B:229:0x0640, B:231:0x0648, B:234:0x0651, B:236:0x0659, B:238:0x0661, B:241:0x066a, B:244:0x0694, B:242:0x0681, B:243:0x068b, B:32:0x0097, B:81:0x0245, B:83:0x024d, B:86:0x0255, B:88:0x0273, B:91:0x0282, B:101:0x02ad, B:103:0x02b3, B:105:0x02bf, B:106:0x02e1, B:110:0x02ed, B:112:0x0301, B:115:0x030d, B:116:0x0311, B:118:0x0317, B:120:0x0334, B:123:0x0347, B:126:0x03a1, B:128:0x03ab, B:130:0x03bd, B:133:0x03c7, B:134:0x03cb, B:136:0x03d1, B:138:0x03ec, B:144:0x0417, B:146:0x041f, B:147:0x042e, B:149:0x0434, B:150:0x0442, B:153:0x0452, B:154:0x0456, B:156:0x045c, B:160:0x046f, B:162:0x0474, B:167:0x04cc, B:179:0x0501, B:181:0x0505, B:193:0x053d, B:195:0x0541, B:184:0x0514, B:187:0x051f, B:188:0x0526, B:191:0x0537, B:200:0x0554, B:170:0x04d8, B:173:0x04e3, B:174:0x04ea, B:177:0x04fb, B:164:0x049b, B:245:0x069a, B:36:0x00c1, B:70:0x01ff, B:72:0x0207, B:75:0x020f, B:77:0x021b, B:247:0x06a6, B:249:0x06b2, B:251:0x06b8, B:254:0x06c0, B:60:0x01a3, B:64:0x01b4, B:66:0x01ea, B:63:0x01b0), top: B:272:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:142:0x0413  */
    /* JADX WARN: Removed duplicated region for block: B:167:0x04cc A[Catch: CancellationException -> 0x0072, Exception -> 0x02a1, UnknownHostException -> 0x02a4, SocketTimeoutException -> 0x02a7, HttpException -> 0x02aa, TryCatch #2 {CancellationException -> 0x0072, blocks: (B:221:0x0624, B:220:0x060d, B:19:0x005d, B:204:0x0587, B:206:0x0590, B:208:0x0596, B:222:0x062a, B:224:0x0630, B:227:0x0638, B:229:0x0640, B:231:0x0648, B:234:0x0651, B:236:0x0659, B:238:0x0661, B:241:0x066a, B:244:0x0694, B:242:0x0681, B:243:0x068b, B:32:0x0097, B:81:0x0245, B:83:0x024d, B:86:0x0255, B:88:0x0273, B:91:0x0282, B:101:0x02ad, B:103:0x02b3, B:105:0x02bf, B:106:0x02e1, B:110:0x02ed, B:112:0x0301, B:115:0x030d, B:116:0x0311, B:118:0x0317, B:120:0x0334, B:123:0x0347, B:126:0x03a1, B:128:0x03ab, B:130:0x03bd, B:133:0x03c7, B:134:0x03cb, B:136:0x03d1, B:138:0x03ec, B:144:0x0417, B:146:0x041f, B:147:0x042e, B:149:0x0434, B:150:0x0442, B:153:0x0452, B:154:0x0456, B:156:0x045c, B:160:0x046f, B:162:0x0474, B:167:0x04cc, B:179:0x0501, B:181:0x0505, B:193:0x053d, B:195:0x0541, B:184:0x0514, B:187:0x051f, B:188:0x0526, B:191:0x0537, B:200:0x0554, B:170:0x04d8, B:173:0x04e3, B:174:0x04ea, B:177:0x04fb, B:164:0x049b, B:245:0x069a, B:36:0x00c1, B:70:0x01ff, B:72:0x0207, B:75:0x020f, B:77:0x021b, B:247:0x06a6, B:249:0x06b2, B:251:0x06b8, B:254:0x06c0, B:60:0x01a3, B:64:0x01b4, B:66:0x01ea, B:63:0x01b0), top: B:272:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:199:0x0551  */
    /* JADX WARN: Removed duplicated region for block: B:202:0x0583  */
    /* JADX WARN: Removed duplicated region for block: B:203:0x0584  */
    /* JADX WARN: Removed duplicated region for block: B:243:0x068b A[Catch: CancellationException -> 0x0072, Exception -> 0x02a1, UnknownHostException -> 0x02a4, SocketTimeoutException -> 0x02a7, HttpException -> 0x02aa, TryCatch #2 {CancellationException -> 0x0072, blocks: (B:221:0x0624, B:220:0x060d, B:19:0x005d, B:204:0x0587, B:206:0x0590, B:208:0x0596, B:222:0x062a, B:224:0x0630, B:227:0x0638, B:229:0x0640, B:231:0x0648, B:234:0x0651, B:236:0x0659, B:238:0x0661, B:241:0x066a, B:244:0x0694, B:242:0x0681, B:243:0x068b, B:32:0x0097, B:81:0x0245, B:83:0x024d, B:86:0x0255, B:88:0x0273, B:91:0x0282, B:101:0x02ad, B:103:0x02b3, B:105:0x02bf, B:106:0x02e1, B:110:0x02ed, B:112:0x0301, B:115:0x030d, B:116:0x0311, B:118:0x0317, B:120:0x0334, B:123:0x0347, B:126:0x03a1, B:128:0x03ab, B:130:0x03bd, B:133:0x03c7, B:134:0x03cb, B:136:0x03d1, B:138:0x03ec, B:144:0x0417, B:146:0x041f, B:147:0x042e, B:149:0x0434, B:150:0x0442, B:153:0x0452, B:154:0x0456, B:156:0x045c, B:160:0x046f, B:162:0x0474, B:167:0x04cc, B:179:0x0501, B:181:0x0505, B:193:0x053d, B:195:0x0541, B:184:0x0514, B:187:0x051f, B:188:0x0526, B:191:0x0537, B:200:0x0554, B:170:0x04d8, B:173:0x04e3, B:174:0x04ea, B:177:0x04fb, B:164:0x049b, B:245:0x069a, B:36:0x00c1, B:70:0x01ff, B:72:0x0207, B:75:0x020f, B:77:0x021b, B:247:0x06a6, B:249:0x06b2, B:251:0x06b8, B:254:0x06c0, B:60:0x01a3, B:64:0x01b4, B:66:0x01ea, B:63:0x01b0), top: B:272:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:247:0x06a6 A[Catch: CancellationException -> 0x0072, Exception -> 0x02a1, UnknownHostException -> 0x02a4, SocketTimeoutException -> 0x02a7, HttpException -> 0x02aa, TryCatch #2 {CancellationException -> 0x0072, blocks: (B:221:0x0624, B:220:0x060d, B:19:0x005d, B:204:0x0587, B:206:0x0590, B:208:0x0596, B:222:0x062a, B:224:0x0630, B:227:0x0638, B:229:0x0640, B:231:0x0648, B:234:0x0651, B:236:0x0659, B:238:0x0661, B:241:0x066a, B:244:0x0694, B:242:0x0681, B:243:0x068b, B:32:0x0097, B:81:0x0245, B:83:0x024d, B:86:0x0255, B:88:0x0273, B:91:0x0282, B:101:0x02ad, B:103:0x02b3, B:105:0x02bf, B:106:0x02e1, B:110:0x02ed, B:112:0x0301, B:115:0x030d, B:116:0x0311, B:118:0x0317, B:120:0x0334, B:123:0x0347, B:126:0x03a1, B:128:0x03ab, B:130:0x03bd, B:133:0x03c7, B:134:0x03cb, B:136:0x03d1, B:138:0x03ec, B:144:0x0417, B:146:0x041f, B:147:0x042e, B:149:0x0434, B:150:0x0442, B:153:0x0452, B:154:0x0456, B:156:0x045c, B:160:0x046f, B:162:0x0474, B:167:0x04cc, B:179:0x0501, B:181:0x0505, B:193:0x053d, B:195:0x0541, B:184:0x0514, B:187:0x051f, B:188:0x0526, B:191:0x0537, B:200:0x0554, B:170:0x04d8, B:173:0x04e3, B:174:0x04ea, B:177:0x04fb, B:164:0x049b, B:245:0x069a, B:36:0x00c1, B:70:0x01ff, B:72:0x0207, B:75:0x020f, B:77:0x021b, B:247:0x06a6, B:249:0x06b2, B:251:0x06b8, B:254:0x06c0, B:60:0x01a3, B:64:0x01b4, B:66:0x01ea, B:63:0x01b0), top: B:272:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:268:0x074f  */
    /* JADX WARN: Removed duplicated region for block: B:46:0x0142  */
    /* JADX WARN: Removed duplicated region for block: B:48:0x014e  */
    /* JADX WARN: Removed duplicated region for block: B:56:0x0179  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x019b  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x01af  */
    /* JADX WARN: Removed duplicated region for block: B:63:0x01b0 A[Catch: Exception -> 0x0066, UnknownHostException -> 0x006a, SocketTimeoutException -> 0x006e, CancellationException -> 0x0072, HttpException -> 0x0075, TryCatch #2 {CancellationException -> 0x0072, blocks: (B:221:0x0624, B:220:0x060d, B:19:0x005d, B:204:0x0587, B:206:0x0590, B:208:0x0596, B:222:0x062a, B:224:0x0630, B:227:0x0638, B:229:0x0640, B:231:0x0648, B:234:0x0651, B:236:0x0659, B:238:0x0661, B:241:0x066a, B:244:0x0694, B:242:0x0681, B:243:0x068b, B:32:0x0097, B:81:0x0245, B:83:0x024d, B:86:0x0255, B:88:0x0273, B:91:0x0282, B:101:0x02ad, B:103:0x02b3, B:105:0x02bf, B:106:0x02e1, B:110:0x02ed, B:112:0x0301, B:115:0x030d, B:116:0x0311, B:118:0x0317, B:120:0x0334, B:123:0x0347, B:126:0x03a1, B:128:0x03ab, B:130:0x03bd, B:133:0x03c7, B:134:0x03cb, B:136:0x03d1, B:138:0x03ec, B:144:0x0417, B:146:0x041f, B:147:0x042e, B:149:0x0434, B:150:0x0442, B:153:0x0452, B:154:0x0456, B:156:0x045c, B:160:0x046f, B:162:0x0474, B:167:0x04cc, B:179:0x0501, B:181:0x0505, B:193:0x053d, B:195:0x0541, B:184:0x0514, B:187:0x051f, B:188:0x0526, B:191:0x0537, B:200:0x0554, B:170:0x04d8, B:173:0x04e3, B:174:0x04ea, B:177:0x04fb, B:164:0x049b, B:245:0x069a, B:36:0x00c1, B:70:0x01ff, B:72:0x0207, B:75:0x020f, B:77:0x021b, B:247:0x06a6, B:249:0x06b2, B:251:0x06b8, B:254:0x06c0, B:60:0x01a3, B:64:0x01b4, B:66:0x01ea, B:63:0x01b0), top: B:272:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:68:0x01f0  */
    /* JADX WARN: Removed duplicated region for block: B:69:0x01f2  */
    /* JADX WARN: Removed duplicated region for block: B:77:0x021b A[Catch: CancellationException -> 0x0072, Exception -> 0x02a1, UnknownHostException -> 0x02a4, SocketTimeoutException -> 0x02a7, HttpException -> 0x02aa, TryCatch #2 {CancellationException -> 0x0072, blocks: (B:221:0x0624, B:220:0x060d, B:19:0x005d, B:204:0x0587, B:206:0x0590, B:208:0x0596, B:222:0x062a, B:224:0x0630, B:227:0x0638, B:229:0x0640, B:231:0x0648, B:234:0x0651, B:236:0x0659, B:238:0x0661, B:241:0x066a, B:244:0x0694, B:242:0x0681, B:243:0x068b, B:32:0x0097, B:81:0x0245, B:83:0x024d, B:86:0x0255, B:88:0x0273, B:91:0x0282, B:101:0x02ad, B:103:0x02b3, B:105:0x02bf, B:106:0x02e1, B:110:0x02ed, B:112:0x0301, B:115:0x030d, B:116:0x0311, B:118:0x0317, B:120:0x0334, B:123:0x0347, B:126:0x03a1, B:128:0x03ab, B:130:0x03bd, B:133:0x03c7, B:134:0x03cb, B:136:0x03d1, B:138:0x03ec, B:144:0x0417, B:146:0x041f, B:147:0x042e, B:149:0x0434, B:150:0x0442, B:153:0x0452, B:154:0x0456, B:156:0x045c, B:160:0x046f, B:162:0x0474, B:167:0x04cc, B:179:0x0501, B:181:0x0505, B:193:0x053d, B:195:0x0541, B:184:0x0514, B:187:0x051f, B:188:0x0526, B:191:0x0537, B:200:0x0554, B:170:0x04d8, B:173:0x04e3, B:174:0x04ea, B:177:0x04fb, B:164:0x049b, B:245:0x069a, B:36:0x00c1, B:70:0x01ff, B:72:0x0207, B:75:0x020f, B:77:0x021b, B:247:0x06a6, B:249:0x06b2, B:251:0x06b8, B:254:0x06c0, B:60:0x01a3, B:64:0x01b4, B:66:0x01ea, B:63:0x01b0), top: B:272:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:8:0x001c  */
    /* JADX WARN: Type inference failed for: r14v19 */
    /* JADX WARN: Type inference failed for: r14v20 */
    /* JADX WARN: Type inference failed for: r14v21 */
    /* JADX WARN: Type inference failed for: r14v22 */
    /* JADX WARN: Type inference failed for: r14v23 */
    /* JADX WARN: Type inference failed for: r14v24 */
    /* JADX WARN: Type inference failed for: r14v25 */
    /* JADX WARN: Type inference failed for: r14v28, types: [boolean] */
    /* JADX WARN: Type inference failed for: r14v29 */
    /* JADX WARN: Type inference failed for: r14v30 */
    /* JADX WARN: Type inference failed for: r14v31 */
    /* JADX WARN: Type inference failed for: r14v32 */
    /* JADX WARN: Type inference failed for: r14v33 */
    /* JADX WARN: Type inference failed for: r14v34 */
    /* JADX WARN: Type inference failed for: r14v35 */
    /* JADX WARN: Type inference failed for: r14v36 */
    /* JADX WARN: Type inference failed for: r14v37 */
    @Override // com.strmr.ps.data.repository.IDebridProvider
    @pq6
    /* JADX INFO: renamed from: resolveToDirectLink-hUnOzRk */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object mo76resolveToDirectLinkhUnOzRk(@kp6 String str, @pq6 Integer num, @pq6 Integer num2, @pq6 Integer num3, @pq6 String str2, @kp6 Continuation<? super q38<String>> continuation) {
        TorBoxRepository$resolveToDirectLink$1 torBoxRepository$resolveToDirectLink$1;
        String str3;
        Throwable authenticationFailed;
        Integer num4;
        String strConcat;
        String str4;
        Integer num5;
        Integer num6;
        TorBoxRepository torBoxRepository;
        TorBoxAccount torBoxAccount;
        TorBoxAccount torBoxAccount2;
        String str5;
        Integer num7;
        Integer num8;
        Integer num9;
        String str6;
        String authHeader;
        TorBoxRepository$resolveToDirectLink$1 torBoxRepository$resolveToDirectLink$12;
        boolean z;
        Object objCreateTorrent$default;
        TorBoxAccount torBoxAccount3;
        String str7;
        Integer num10;
        Integer num11;
        String str8;
        TorBoxRepository torBoxRepository2;
        Integer num12;
        Integer num13;
        TorBoxResponse torBoxResponse;
        String error;
        Integer torrentId;
        int i;
        Integer num14;
        TorBoxResponse torBoxResponse2;
        TorBoxTorrentInfo torBoxTorrentInfo;
        List<TorBoxFile> files;
        TorBoxFile torBoxFile;
        ?? r14;
        TorBoxFile torBoxFile2;
        ?? r142;
        TorBoxRepository$resolveToDirectLink$1 torBoxRepository$resolveToDirectLink$13;
        ck1 ck1Var;
        List<TorBoxFile> list;
        int i2;
        TorBoxRepository torBoxRepository3;
        ?? r143;
        Object next;
        Object next2;
        Object next3;
        ck1 ck1Var2;
        ?? r144;
        TorBoxResponse torBoxResponse3;
        String error2;
        TorBoxResponse torBoxResponse4;
        if (continuation instanceof TorBoxRepository$resolveToDirectLink$1) {
            torBoxRepository$resolveToDirectLink$1 = (TorBoxRepository$resolveToDirectLink$1) continuation;
            int i3 = torBoxRepository$resolveToDirectLink$1.label;
            if ((i3 & Integer.MIN_VALUE) != 0) {
                torBoxRepository$resolveToDirectLink$1.label = i3 - Integer.MIN_VALUE;
            } else {
                torBoxRepository$resolveToDirectLink$1 = new TorBoxRepository$resolveToDirectLink$1(this, continuation);
            }
        }
        TorBoxRepository$resolveToDirectLink$1 torBoxRepository$resolveToDirectLink$14 = torBoxRepository$resolveToDirectLink$1;
        Object account = torBoxRepository$resolveToDirectLink$14.result;
        dr4.c();
        ck1 ck1Var3 = ck1.a;
        try {
            try {
                switch (torBoxRepository$resolveToDirectLink$14.label) {
                    case 0:
                        s38.b(account);
                        TorBoxAccountDao torBoxAccountDao = this.accountDao;
                        torBoxRepository$resolveToDirectLink$14.L$0 = this;
                        torBoxRepository$resolveToDirectLink$14.L$1 = str;
                        torBoxRepository$resolveToDirectLink$14.L$2 = num;
                        num4 = num2;
                        torBoxRepository$resolveToDirectLink$14.L$3 = num4;
                        torBoxRepository$resolveToDirectLink$14.L$4 = num3;
                        torBoxRepository$resolveToDirectLink$14.L$5 = str2;
                        torBoxRepository$resolveToDirectLink$14.label = 1;
                        account = torBoxAccountDao.getAccount("torbox", torBoxRepository$resolveToDirectLink$14);
                        if (account != ck1Var3) {
                            strConcat = str;
                            str4 = str2;
                            num5 = num;
                            num6 = num3;
                            torBoxRepository = this;
                            torBoxAccount = (TorBoxAccount) account;
                            if (torBoxAccount != null) {
                                return s38.a(new DebridError.NoAccount(DebridProvider.TORBOX));
                            }
                            if (torBoxAccount.getPlan() > 0) {
                                torBoxRepository$resolveToDirectLink$14.L$0 = torBoxRepository;
                                torBoxRepository$resolveToDirectLink$14.L$1 = strConcat;
                                torBoxRepository$resolveToDirectLink$14.L$2 = num5;
                                torBoxRepository$resolveToDirectLink$14.L$3 = num4;
                                torBoxRepository$resolveToDirectLink$14.L$4 = num6;
                                torBoxRepository$resolveToDirectLink$14.L$5 = str4;
                                torBoxRepository$resolveToDirectLink$14.L$6 = torBoxAccount;
                                torBoxRepository$resolveToDirectLink$14.label = 2;
                                Object accountExpirationStatus = torBoxRepository.getAccountExpirationStatus(torBoxRepository$resolveToDirectLink$14);
                                if (accountExpirationStatus != ck1Var3) {
                                    String str9 = str4;
                                    torBoxAccount2 = torBoxAccount;
                                    account = accountExpirationStatus;
                                    str5 = strConcat;
                                    num7 = num5;
                                    num8 = num4;
                                    num9 = num6;
                                    str6 = str9;
                                    num13 = (Integer) account;
                                    if (num13 == null) {
                                        Log.w(TAG, "Account expired " + num13 + " days ago");
                                        return s38.a(new DebridError.AccountExpired(DebridProvider.TORBOX, num13));
                                    }
                                    torBoxAccount = torBoxAccount2;
                                    str4 = str6;
                                    num6 = num9;
                                    num4 = num8;
                                    num5 = num7;
                                    strConcat = str5;
                                    TorBoxRepository torBoxRepository4 = torBoxRepository;
                                    authHeader = torBoxAccount.getAuthHeader();
                                    if (n89.ar(strConcat, "magnet:", false)) {
                                        strConcat = "magnet:?xt=urn:btih:".concat(strConcat);
                                    }
                                    TorBoxApiService torBoxApiService = torBoxRepository4.torBoxApiService;
                                    Integer numBoxInt = Boxing.boxInt(3);
                                    torBoxRepository$resolveToDirectLink$14.L$0 = torBoxRepository4;
                                    torBoxRepository$resolveToDirectLink$14.L$1 = num5;
                                    torBoxRepository$resolveToDirectLink$14.L$2 = num4;
                                    torBoxRepository$resolveToDirectLink$14.L$3 = num6;
                                    torBoxRepository$resolveToDirectLink$14.L$4 = str4;
                                    torBoxRepository$resolveToDirectLink$14.L$5 = torBoxAccount;
                                    torBoxRepository$resolveToDirectLink$14.L$6 = authHeader;
                                    torBoxRepository$resolveToDirectLink$14.label = 3;
                                    Integer num15 = num4;
                                    Integer num16 = num5;
                                    String str10 = strConcat;
                                    torBoxRepository$resolveToDirectLink$12 = torBoxRepository$resolveToDirectLink$14;
                                    Integer num17 = num6;
                                    str3 = TAG;
                                    z = true;
                                    String str11 = str4;
                                    try {
                                        objCreateTorrent$default = TorBoxApiService.DefaultImpls.createTorrent$default(torBoxApiService, authHeader, str10, numBoxInt, null, null, null, torBoxRepository$resolveToDirectLink$12, 56, null);
                                        if (objCreateTorrent$default == ck1Var3) {
                                            torBoxAccount3 = torBoxAccount;
                                            account = objCreateTorrent$default;
                                            str7 = authHeader;
                                            num10 = num17;
                                            num11 = num16;
                                            str8 = str11;
                                            torBoxRepository2 = torBoxRepository4;
                                            num12 = num15;
                                            torBoxResponse = (TorBoxResponse) account;
                                            if (torBoxResponse.getSuccess() && torBoxResponse.getData() != null) {
                                                torrentId = ((TorBoxTorrentData) torBoxResponse.getData()).getTorrentId();
                                                if (torrentId != null) {
                                                    return s38.a(new Exception("No torrent ID returned"));
                                                }
                                                int iIntValue = torrentId.intValue();
                                                TorBoxApiService torBoxApiService2 = torBoxRepository2.torBoxApiService;
                                                Boolean boolBoxBoolean = Boxing.boxBoolean(z);
                                                torBoxRepository$resolveToDirectLink$12.L$0 = torBoxRepository2;
                                                torBoxRepository$resolveToDirectLink$12.L$1 = num11;
                                                torBoxRepository$resolveToDirectLink$12.L$2 = num12;
                                                torBoxRepository$resolveToDirectLink$12.L$3 = num10;
                                                torBoxRepository$resolveToDirectLink$12.L$4 = str8;
                                                torBoxRepository$resolveToDirectLink$12.L$5 = torBoxAccount3;
                                                torBoxRepository$resolveToDirectLink$12.L$6 = str7;
                                                torBoxRepository$resolveToDirectLink$12.I$0 = iIntValue;
                                                torBoxRepository$resolveToDirectLink$12.label = 4;
                                                Object torrent = torBoxApiService2.getTorrent(str7, iIntValue, boolBoxBoolean, torBoxRepository$resolveToDirectLink$12);
                                                if (torrent != ck1Var3) {
                                                    i = iIntValue;
                                                    account = torrent;
                                                    num14 = num10;
                                                    String str12 = str7;
                                                    torBoxResponse2 = (TorBoxResponse) account;
                                                    if (torBoxResponse2.getSuccess() && torBoxResponse2.getData() != null) {
                                                        torBoxTorrentInfo = (TorBoxTorrentInfo) torBoxResponse2.getData();
                                                        if (!y41.q(y41.an("completed", "cached"), torBoxTorrentInfo.getDownloadState()) && !cr4.b(torBoxTorrentInfo.getDownloadPresent(), Boxing.boxBoolean(z))) {
                                                            Log.w(str3, "Torrent not ready: state=" + torBoxTorrentInfo.getDownloadState());
                                                            return s38.a(new DebridError.NotCached(DebridProvider.TORBOX));
                                                        }
                                                        files = torBoxTorrentInfo.getFiles();
                                                        if (files != null) {
                                                            return s38.a(new Exception("No files in torrent"));
                                                        }
                                                        List listAn = y41.an(".mkv", ".mp4", ".avi", ".mov", ".wmv", ".m4v", ".webm");
                                                        ArrayList arrayList = new ArrayList();
                                                        Iterator it = files.iterator();
                                                        while (true) {
                                                            List list2 = listAn;
                                                            if (!it.hasNext()) {
                                                                ck1 ck1Var4 = ck1Var3;
                                                                String str13 = str12;
                                                                TorBoxAccount torBoxAccount4 = torBoxAccount3;
                                                                Log.w(str3, "resolveToDirectLink: torrentId=" + i + ", " + files.size() + " files (" + arrayList.size() + " video), state=" + torBoxTorrentInfo.getDownloadState() + ", season=" + num12 + ", episode=" + num14 + ", fileIdx=" + num11);
                                                                if (num11 == null || num11.intValue() >= files.size()) {
                                                                    torBoxFile = null;
                                                                    if (torBoxFile == null) {
                                                                        if (num12 == null || num14 == null) {
                                                                            r143 = z;
                                                                        } else {
                                                                            ?? r145 = z;
                                                                            r143 = r145;
                                                                            if (arrayList.size() > r145) {
                                                                                ArrayList arrayList2 = new ArrayList(y41.p(arrayList, 10));
                                                                                Iterator it2 = arrayList.iterator();
                                                                                while (it2.hasNext()) {
                                                                                    arrayList2.add(((TorBoxFile) it2.next()).getName());
                                                                                }
                                                                                String strC = vo2.c(arrayList2, num12.intValue(), num14.intValue(), str8);
                                                                                if (strC != null) {
                                                                                    Iterator it3 = arrayList.iterator();
                                                                                    while (true) {
                                                                                        if (it3.hasNext()) {
                                                                                            next3 = it3.next();
                                                                                            if (cr4.b(((TorBoxFile) next3).getName(), strC)) {
                                                                                            }
                                                                                        } else {
                                                                                            next3 = null;
                                                                                        }
                                                                                    }
                                                                                    torBoxFile = (TorBoxFile) next3;
                                                                                    r143 = r145;
                                                                                    if (torBoxFile != null) {
                                                                                        Log.w(str3, "Found episode S" + num12 + "E" + num14 + ": " + torBoxFile.getName());
                                                                                        r14 = r145;
                                                                                    }
                                                                                    if (torBoxFile != null) {
                                                                                        Iterator it4 = arrayList.iterator();
                                                                                        if (it4.hasNext()) {
                                                                                            next = it4.next();
                                                                                            if (it4.hasNext()) {
                                                                                                long size = ((TorBoxFile) next).getSize();
                                                                                                do {
                                                                                                    Object next4 = it4.next();
                                                                                                    long size2 = ((TorBoxFile) next4).getSize();
                                                                                                    if (size < size2) {
                                                                                                        next = next4;
                                                                                                        size = size2;
                                                                                                    }
                                                                                                } while (it4.hasNext());
                                                                                            }
                                                                                        } else {
                                                                                            next = null;
                                                                                        }
                                                                                        TorBoxFile torBoxFile3 = (TorBoxFile) next;
                                                                                        if (torBoxFile3 == null) {
                                                                                            Iterator it5 = files.iterator();
                                                                                            if (it5.hasNext()) {
                                                                                                next2 = it5.next();
                                                                                                if (it5.hasNext()) {
                                                                                                    long size3 = ((TorBoxFile) next2).getSize();
                                                                                                    do {
                                                                                                        Object next5 = it5.next();
                                                                                                        long size4 = ((TorBoxFile) next5).getSize();
                                                                                                        if (size3 < size4) {
                                                                                                            next2 = next5;
                                                                                                            size3 = size4;
                                                                                                        }
                                                                                                    } while (it5.hasNext());
                                                                                                }
                                                                                            } else {
                                                                                                next2 = null;
                                                                                            }
                                                                                            torBoxFile3 = (TorBoxFile) next2;
                                                                                            if (torBoxFile3 == null) {
                                                                                                return s38.a(new Exception("No files found"));
                                                                                            }
                                                                                        }
                                                                                        torBoxFile2 = torBoxFile3;
                                                                                        r142 = r14;
                                                                                    }
                                                                                    TorBoxApiService torBoxApiService3 = torBoxRepository2.torBoxApiService;
                                                                                    String apiKey = torBoxAccount4.getApiKey();
                                                                                    int id = torBoxFile2.getId();
                                                                                    Boolean boolBoxBoolean2 = Boxing.boxBoolean(false);
                                                                                    torBoxRepository$resolveToDirectLink$12.L$0 = torBoxRepository2;
                                                                                    torBoxRepository$resolveToDirectLink$12.L$1 = files;
                                                                                    torBoxRepository$resolveToDirectLink$12.L$2 = torBoxFile2;
                                                                                    torBoxRepository$resolveToDirectLink$12.L$3 = null;
                                                                                    torBoxRepository$resolveToDirectLink$12.L$4 = null;
                                                                                    torBoxRepository$resolveToDirectLink$12.L$5 = null;
                                                                                    torBoxRepository$resolveToDirectLink$12.L$6 = null;
                                                                                    torBoxRepository$resolveToDirectLink$12.I$0 = i;
                                                                                    torBoxRepository$resolveToDirectLink$12.label = 5;
                                                                                    TorBoxRepository$resolveToDirectLink$1 torBoxRepository$resolveToDirectLink$15 = torBoxRepository$resolveToDirectLink$12;
                                                                                    account = torBoxApiService3.requestDownload(str13, apiKey, i, id, boolBoxBoolean2, torBoxRepository$resolveToDirectLink$15);
                                                                                    torBoxRepository$resolveToDirectLink$13 = torBoxRepository$resolveToDirectLink$15;
                                                                                    ck1Var = ck1Var4;
                                                                                    if (account == ck1Var) {
                                                                                        return ck1Var;
                                                                                    }
                                                                                    list = files;
                                                                                    i2 = i;
                                                                                    torBoxRepository3 = torBoxRepository2;
                                                                                    r144 = r142;
                                                                                    torBoxResponse3 = (TorBoxResponse) account;
                                                                                    if (torBoxResponse3.getSuccess() || torBoxResponse3.getData() == null) {
                                                                                        error2 = torBoxResponse3.getError();
                                                                                        if (error2 == null && (error2 = torBoxResponse3.getDetail()) == null) {
                                                                                            error2 = "Failed to get download link";
                                                                                        }
                                                                                        return s38.a((!n89.l(error2, "expired", r144) || n89.l(error2, "premium", r144) || n89.l(error2, "plan", r144)) ? new DebridError.AccountExpired(DebridProvider.TORBOX, null, 2, null) : (n89.l(error2, "auth", r144) || n89.l(error2, "token", r144) || n89.l(error2, "api key", r144)) ? new DebridError.AuthenticationFailed(DebridProvider.TORBOX, null, 2, null) : new DebridError.Unknown(DebridProvider.TORBOX, error2, null, 4, null));
                                                                                    }
                                                                                    Log.w(str3, "Resolved direct link for: " + torBoxFile2.getName());
                                                                                    if (torBoxRepository3.linkFilterPreferences.getCloudSanitizationEnabled()) {
                                                                                        try {
                                                                                            ExecutorService executorService = kq.a;
                                                                                            kq.h(str3, "Cloud sanitization: removing TB torrent " + i2 + " (" + list.size() + " files)");
                                                                                            torBoxRepository$resolveToDirectLink$13.L$0 = torBoxResponse3;
                                                                                            torBoxRepository$resolveToDirectLink$13.L$1 = null;
                                                                                            torBoxRepository$resolveToDirectLink$13.L$2 = null;
                                                                                            torBoxRepository$resolveToDirectLink$13.I$0 = i2;
                                                                                            torBoxRepository$resolveToDirectLink$13.label = 6;
                                                                                        } catch (Exception e) {
                                                                                            e = e;
                                                                                            torBoxResponse4 = torBoxResponse3;
                                                                                            ExecutorService executorService2 = kq.a;
                                                                                            kq.a(str3, "Cloud sanitization failed for TB torrent " + i2, e);
                                                                                            torBoxResponse3 = torBoxResponse4;
                                                                                            return torBoxResponse3.getData();
                                                                                        }
                                                                                        if (torBoxRepository3.m140deleteTorrentgIAlus(i2, torBoxRepository$resolveToDirectLink$13) == ck1Var) {
                                                                                            return ck1Var;
                                                                                        }
                                                                                        torBoxResponse4 = torBoxResponse3;
                                                                                        try {
                                                                                            ExecutorService executorService3 = kq.a;
                                                                                            kq.h(str3, "Cloud sanitization: removed TB torrent " + i2);
                                                                                        } catch (Exception e2) {
                                                                                            e = e2;
                                                                                            ExecutorService executorService22 = kq.a;
                                                                                            kq.a(str3, "Cloud sanitization failed for TB torrent " + i2, e);
                                                                                        }
                                                                                        torBoxResponse3 = torBoxResponse4;
                                                                                    }
                                                                                } else {
                                                                                    Log.w(str3, "Could not find episode S" + num12 + "E" + num14 + " in " + arrayList.size() + " video files");
                                                                                    r143 = r145;
                                                                                }
                                                                            }
                                                                        }
                                                                        torBoxFile = null;
                                                                        r14 = r143;
                                                                        if (torBoxFile != null) {
                                                                        }
                                                                        TorBoxApiService torBoxApiService32 = torBoxRepository2.torBoxApiService;
                                                                        String apiKey2 = torBoxAccount4.getApiKey();
                                                                        int id2 = torBoxFile2.getId();
                                                                        Boolean boolBoxBoolean22 = Boxing.boxBoolean(false);
                                                                        torBoxRepository$resolveToDirectLink$12.L$0 = torBoxRepository2;
                                                                        torBoxRepository$resolveToDirectLink$12.L$1 = files;
                                                                        torBoxRepository$resolveToDirectLink$12.L$2 = torBoxFile2;
                                                                        torBoxRepository$resolveToDirectLink$12.L$3 = null;
                                                                        torBoxRepository$resolveToDirectLink$12.L$4 = null;
                                                                        torBoxRepository$resolveToDirectLink$12.L$5 = null;
                                                                        torBoxRepository$resolveToDirectLink$12.L$6 = null;
                                                                        torBoxRepository$resolveToDirectLink$12.I$0 = i;
                                                                        torBoxRepository$resolveToDirectLink$12.label = 5;
                                                                        TorBoxRepository$resolveToDirectLink$1 torBoxRepository$resolveToDirectLink$152 = torBoxRepository$resolveToDirectLink$12;
                                                                        account = torBoxApiService32.requestDownload(str13, apiKey2, i, id2, boolBoxBoolean22, torBoxRepository$resolveToDirectLink$152);
                                                                        torBoxRepository$resolveToDirectLink$13 = torBoxRepository$resolveToDirectLink$152;
                                                                        ck1Var = ck1Var4;
                                                                        if (account == ck1Var) {
                                                                        }
                                                                    } else {
                                                                        r14 = z;
                                                                    }
                                                                    torBoxFile2 = torBoxFile;
                                                                    r142 = r14;
                                                                    TorBoxApiService torBoxApiService322 = torBoxRepository2.torBoxApiService;
                                                                    String apiKey22 = torBoxAccount4.getApiKey();
                                                                    int id22 = torBoxFile2.getId();
                                                                    Boolean boolBoxBoolean222 = Boxing.boxBoolean(false);
                                                                    torBoxRepository$resolveToDirectLink$12.L$0 = torBoxRepository2;
                                                                    torBoxRepository$resolveToDirectLink$12.L$1 = files;
                                                                    torBoxRepository$resolveToDirectLink$12.L$2 = torBoxFile2;
                                                                    torBoxRepository$resolveToDirectLink$12.L$3 = null;
                                                                    torBoxRepository$resolveToDirectLink$12.L$4 = null;
                                                                    torBoxRepository$resolveToDirectLink$12.L$5 = null;
                                                                    torBoxRepository$resolveToDirectLink$12.L$6 = null;
                                                                    torBoxRepository$resolveToDirectLink$12.I$0 = i;
                                                                    torBoxRepository$resolveToDirectLink$12.label = 5;
                                                                    TorBoxRepository$resolveToDirectLink$1 torBoxRepository$resolveToDirectLink$1522 = torBoxRepository$resolveToDirectLink$12;
                                                                    account = torBoxApiService322.requestDownload(str13, apiKey22, i, id22, boolBoxBoolean222, torBoxRepository$resolveToDirectLink$1522);
                                                                    torBoxRepository$resolveToDirectLink$13 = torBoxRepository$resolveToDirectLink$1522;
                                                                    ck1Var = ck1Var4;
                                                                    if (account == ck1Var) {
                                                                    }
                                                                    break;
                                                                } else {
                                                                    TorBoxFile torBoxFile4 = files.get(num11.intValue());
                                                                    List<String> list3 = list2;
                                                                    if (!(list3 instanceof Collection) || !list3.isEmpty()) {
                                                                        for (String str14 : list3) {
                                                                            TorBoxFile torBoxFile5 = torBoxFile4;
                                                                            String lowerCase = torBoxFile4.getName().toLowerCase(Locale.ROOT);
                                                                            cr4.f(lowerCase, "toLowerCase(...)");
                                                                            if (n89.r(lowerCase, str14, false)) {
                                                                                Log.w(str3, "Using specified fileIdx " + num11 + ": " + torBoxFile5.getName());
                                                                                torBoxFile = torBoxFile5;
                                                                                if (torBoxFile == null) {
                                                                                }
                                                                                torBoxFile2 = torBoxFile;
                                                                                r142 = r14;
                                                                                TorBoxApiService torBoxApiService3222 = torBoxRepository2.torBoxApiService;
                                                                                String apiKey222 = torBoxAccount4.getApiKey();
                                                                                int id222 = torBoxFile2.getId();
                                                                                Boolean boolBoxBoolean2222 = Boxing.boxBoolean(false);
                                                                                torBoxRepository$resolveToDirectLink$12.L$0 = torBoxRepository2;
                                                                                torBoxRepository$resolveToDirectLink$12.L$1 = files;
                                                                                torBoxRepository$resolveToDirectLink$12.L$2 = torBoxFile2;
                                                                                torBoxRepository$resolveToDirectLink$12.L$3 = null;
                                                                                torBoxRepository$resolveToDirectLink$12.L$4 = null;
                                                                                torBoxRepository$resolveToDirectLink$12.L$5 = null;
                                                                                torBoxRepository$resolveToDirectLink$12.L$6 = null;
                                                                                torBoxRepository$resolveToDirectLink$12.I$0 = i;
                                                                                torBoxRepository$resolveToDirectLink$12.label = 5;
                                                                                TorBoxRepository$resolveToDirectLink$1 torBoxRepository$resolveToDirectLink$15222 = torBoxRepository$resolveToDirectLink$12;
                                                                                account = torBoxApiService3222.requestDownload(str13, apiKey222, i, id222, boolBoxBoolean2222, torBoxRepository$resolveToDirectLink$15222);
                                                                                torBoxRepository$resolveToDirectLink$13 = torBoxRepository$resolveToDirectLink$15222;
                                                                                ck1Var = ck1Var4;
                                                                                if (account == ck1Var) {
                                                                                }
                                                                            } else {
                                                                                torBoxFile4 = torBoxFile5;
                                                                            }
                                                                        }
                                                                    }
                                                                    torBoxFile = null;
                                                                    if (torBoxFile == null) {
                                                                    }
                                                                    torBoxFile2 = torBoxFile;
                                                                    r142 = r14;
                                                                    TorBoxApiService torBoxApiService32222 = torBoxRepository2.torBoxApiService;
                                                                    String apiKey2222 = torBoxAccount4.getApiKey();
                                                                    int id2222 = torBoxFile2.getId();
                                                                    Boolean boolBoxBoolean22222 = Boxing.boxBoolean(false);
                                                                    torBoxRepository$resolveToDirectLink$12.L$0 = torBoxRepository2;
                                                                    torBoxRepository$resolveToDirectLink$12.L$1 = files;
                                                                    torBoxRepository$resolveToDirectLink$12.L$2 = torBoxFile2;
                                                                    torBoxRepository$resolveToDirectLink$12.L$3 = null;
                                                                    torBoxRepository$resolveToDirectLink$12.L$4 = null;
                                                                    torBoxRepository$resolveToDirectLink$12.L$5 = null;
                                                                    torBoxRepository$resolveToDirectLink$12.L$6 = null;
                                                                    torBoxRepository$resolveToDirectLink$12.I$0 = i;
                                                                    torBoxRepository$resolveToDirectLink$12.label = 5;
                                                                    TorBoxRepository$resolveToDirectLink$1 torBoxRepository$resolveToDirectLink$152222 = torBoxRepository$resolveToDirectLink$12;
                                                                    account = torBoxApiService32222.requestDownload(str13, apiKey2222, i, id2222, boolBoxBoolean22222, torBoxRepository$resolveToDirectLink$152222);
                                                                    torBoxRepository$resolveToDirectLink$13 = torBoxRepository$resolveToDirectLink$152222;
                                                                    ck1Var = ck1Var4;
                                                                    if (account == ck1Var) {
                                                                    }
                                                                }
                                                                return torBoxResponse3.getData();
                                                            }
                                                            String str15 = str12;
                                                            Object next6 = it.next();
                                                            TorBoxFile torBoxFile6 = (TorBoxFile) next6;
                                                            TorBoxAccount torBoxAccount5 = torBoxAccount3;
                                                            List list4 = list2;
                                                            Iterator it6 = it;
                                                            if ((list4 instanceof Collection) && list4.isEmpty()) {
                                                                ck1Var2 = ck1Var3;
                                                            } else {
                                                                Iterator it7 = list4.iterator();
                                                                while (it7.hasNext()) {
                                                                    String str16 = (String) it7.next();
                                                                    Iterator it8 = it7;
                                                                    ck1Var2 = ck1Var3;
                                                                    String lowerCase2 = torBoxFile6.getName().toLowerCase(Locale.ROOT);
                                                                    cr4.f(lowerCase2, "toLowerCase(...)");
                                                                    if (n89.r(lowerCase2, str16, false)) {
                                                                        arrayList.add(next6);
                                                                    } else {
                                                                        it7 = it8;
                                                                        ck1Var3 = ck1Var2;
                                                                    }
                                                                }
                                                                ck1Var2 = ck1Var3;
                                                            }
                                                            listAn = list2;
                                                            str12 = str15;
                                                            torBoxAccount3 = torBoxAccount5;
                                                            it = it6;
                                                            ck1Var3 = ck1Var2;
                                                        }
                                                    }
                                                    return s38.a(new Exception("Failed to get torrent info"));
                                                }
                                            }
                                            error = torBoxResponse.getError();
                                            if (error == null && (error = torBoxResponse.getDetail()) == null) {
                                                error = "Failed to create torrent";
                                            }
                                            return s38.a(new Exception(error));
                                        }
                                    } catch (SocketTimeoutException e3) {
                                        e = e3;
                                        Log.e(str3, "Failed to resolve direct link: timeout", e);
                                        return s38.a(new DebridError.ServiceDown(DebridProvider.TORBOX, null, e, 2, null));
                                    } catch (UnknownHostException e4) {
                                        e = e4;
                                        Log.e(str3, "Failed to resolve direct link: DNS error", e);
                                        return s38.a(new DebridError.DnsError(DebridProvider.TORBOX, e));
                                    } catch (HttpException e5) {
                                        e = e5;
                                        Log.e(str3, "Failed to resolve direct link: HTTP " + e.code(), e);
                                        int iCode = e.code();
                                        if (iCode == 401 || iCode == 403) {
                                            authenticationFailed = new DebridError.AuthenticationFailed(DebridProvider.TORBOX, e);
                                        } else if (iCode != 500) {
                                            switch (iCode) {
                                                case 502:
                                                case 503:
                                                case 504:
                                                    authenticationFailed = new DebridError.ServiceDown(DebridProvider.TORBOX, Boxing.boxInt(e.code()), e);
                                                    break;
                                                default:
                                                    authenticationFailed = new DebridError.Unknown(DebridProvider.TORBOX, n41.k("HTTP ", e.code()), e);
                                                    break;
                                            }
                                        }
                                        return s38.a(authenticationFailed);
                                    } catch (Exception e6) {
                                        e = e6;
                                        Log.e(str3, "Failed to resolve direct link", e);
                                        return s38.a(new DebridError.Unknown(DebridProvider.TORBOX, e.getMessage(), e));
                                    }
                                }
                            } else {
                                TorBoxRepository torBoxRepository42 = torBoxRepository;
                                authHeader = torBoxAccount.getAuthHeader();
                                if (n89.ar(strConcat, "magnet:", false)) {
                                }
                                TorBoxApiService torBoxApiService4 = torBoxRepository42.torBoxApiService;
                                Integer numBoxInt2 = Boxing.boxInt(3);
                                torBoxRepository$resolveToDirectLink$14.L$0 = torBoxRepository42;
                                torBoxRepository$resolveToDirectLink$14.L$1 = num5;
                                torBoxRepository$resolveToDirectLink$14.L$2 = num4;
                                torBoxRepository$resolveToDirectLink$14.L$3 = num6;
                                torBoxRepository$resolveToDirectLink$14.L$4 = str4;
                                torBoxRepository$resolveToDirectLink$14.L$5 = torBoxAccount;
                                torBoxRepository$resolveToDirectLink$14.L$6 = authHeader;
                                torBoxRepository$resolveToDirectLink$14.label = 3;
                                Integer num152 = num4;
                                Integer num162 = num5;
                                String str102 = strConcat;
                                torBoxRepository$resolveToDirectLink$12 = torBoxRepository$resolveToDirectLink$14;
                                Integer num172 = num6;
                                str3 = TAG;
                                z = true;
                                String str112 = str4;
                                objCreateTorrent$default = TorBoxApiService.DefaultImpls.createTorrent$default(torBoxApiService4, authHeader, str102, numBoxInt2, null, null, null, torBoxRepository$resolveToDirectLink$12, 56, null);
                                if (objCreateTorrent$default == ck1Var3) {
                                }
                            }
                        }
                        return ck1Var3;
                    case 1:
                        str4 = (String) torBoxRepository$resolveToDirectLink$14.L$5;
                        num6 = (Integer) torBoxRepository$resolveToDirectLink$14.L$4;
                        num4 = (Integer) torBoxRepository$resolveToDirectLink$14.L$3;
                        num5 = (Integer) torBoxRepository$resolveToDirectLink$14.L$2;
                        strConcat = (String) torBoxRepository$resolveToDirectLink$14.L$1;
                        TorBoxRepository torBoxRepository5 = (TorBoxRepository) torBoxRepository$resolveToDirectLink$14.L$0;
                        s38.b(account);
                        torBoxRepository = torBoxRepository5;
                        torBoxAccount = (TorBoxAccount) account;
                        if (torBoxAccount != null) {
                        }
                        break;
                    case 2:
                        torBoxAccount2 = (TorBoxAccount) torBoxRepository$resolveToDirectLink$14.L$6;
                        str6 = (String) torBoxRepository$resolveToDirectLink$14.L$5;
                        num9 = (Integer) torBoxRepository$resolveToDirectLink$14.L$4;
                        num8 = (Integer) torBoxRepository$resolveToDirectLink$14.L$3;
                        num7 = (Integer) torBoxRepository$resolveToDirectLink$14.L$2;
                        str5 = (String) torBoxRepository$resolveToDirectLink$14.L$1;
                        torBoxRepository = (TorBoxRepository) torBoxRepository$resolveToDirectLink$14.L$0;
                        s38.b(account);
                        num13 = (Integer) account;
                        if (num13 == null) {
                        }
                        break;
                    case 3:
                        String str17 = (String) torBoxRepository$resolveToDirectLink$14.L$6;
                        TorBoxAccount torBoxAccount6 = (TorBoxAccount) torBoxRepository$resolveToDirectLink$14.L$5;
                        String str18 = (String) torBoxRepository$resolveToDirectLink$14.L$4;
                        Integer num18 = (Integer) torBoxRepository$resolveToDirectLink$14.L$3;
                        Integer num19 = (Integer) torBoxRepository$resolveToDirectLink$14.L$2;
                        Integer num20 = (Integer) torBoxRepository$resolveToDirectLink$14.L$1;
                        torBoxRepository2 = (TorBoxRepository) torBoxRepository$resolveToDirectLink$14.L$0;
                        s38.b(account);
                        z = true;
                        str3 = TAG;
                        num10 = num18;
                        num12 = num19;
                        num11 = num20;
                        torBoxAccount3 = torBoxAccount6;
                        str8 = str18;
                        torBoxRepository$resolveToDirectLink$12 = torBoxRepository$resolveToDirectLink$14;
                        str7 = str17;
                        torBoxResponse = (TorBoxResponse) account;
                        if (torBoxResponse.getSuccess()) {
                            torrentId = ((TorBoxTorrentData) torBoxResponse.getData()).getTorrentId();
                            if (torrentId != null) {
                            }
                        }
                        error = torBoxResponse.getError();
                        if (error == null) {
                            error = "Failed to create torrent";
                        }
                        return s38.a(new Exception(error));
                    case 4:
                        int i4 = torBoxRepository$resolveToDirectLink$14.I$0;
                        str7 = (String) torBoxRepository$resolveToDirectLink$14.L$6;
                        torBoxAccount3 = (TorBoxAccount) torBoxRepository$resolveToDirectLink$14.L$5;
                        str8 = (String) torBoxRepository$resolveToDirectLink$14.L$4;
                        Integer num21 = (Integer) torBoxRepository$resolveToDirectLink$14.L$3;
                        Integer num22 = (Integer) torBoxRepository$resolveToDirectLink$14.L$2;
                        num11 = (Integer) torBoxRepository$resolveToDirectLink$14.L$1;
                        TorBoxRepository torBoxRepository6 = (TorBoxRepository) torBoxRepository$resolveToDirectLink$14.L$0;
                        s38.b(account);
                        z = true;
                        str3 = TAG;
                        num12 = num22;
                        torBoxRepository2 = torBoxRepository6;
                        i = i4;
                        num14 = num21;
                        torBoxRepository$resolveToDirectLink$12 = torBoxRepository$resolveToDirectLink$14;
                        String str122 = str7;
                        torBoxResponse2 = (TorBoxResponse) account;
                        if (torBoxResponse2.getSuccess()) {
                            torBoxTorrentInfo = (TorBoxTorrentInfo) torBoxResponse2.getData();
                            if (!y41.q(y41.an("completed", "cached"), torBoxTorrentInfo.getDownloadState())) {
                                Log.w(str3, "Torrent not ready: state=" + torBoxTorrentInfo.getDownloadState());
                                return s38.a(new DebridError.NotCached(DebridProvider.TORBOX));
                            }
                            files = torBoxTorrentInfo.getFiles();
                            if (files != null) {
                            }
                        }
                        return s38.a(new Exception("Failed to get torrent info"));
                    case 5:
                        i2 = torBoxRepository$resolveToDirectLink$14.I$0;
                        torBoxFile2 = (TorBoxFile) torBoxRepository$resolveToDirectLink$14.L$2;
                        list = (List) torBoxRepository$resolveToDirectLink$14.L$1;
                        torBoxRepository3 = (TorBoxRepository) torBoxRepository$resolveToDirectLink$14.L$0;
                        s38.b(account);
                        ck1Var = ck1Var3;
                        r144 = 1;
                        str3 = TAG;
                        torBoxRepository$resolveToDirectLink$13 = torBoxRepository$resolveToDirectLink$14;
                        torBoxResponse3 = (TorBoxResponse) account;
                        if (torBoxResponse3.getSuccess()) {
                            break;
                        }
                        error2 = torBoxResponse3.getError();
                        if (error2 == null) {
                            error2 = "Failed to get download link";
                        }
                        return s38.a((!n89.l(error2, "expired", r144) || n89.l(error2, "premium", r144) || n89.l(error2, "plan", r144)) ? new DebridError.AccountExpired(DebridProvider.TORBOX, null, 2, null) : (n89.l(error2, "auth", r144) || n89.l(error2, "token", r144) || n89.l(error2, "api key", r144)) ? new DebridError.AuthenticationFailed(DebridProvider.TORBOX, null, 2, null) : new DebridError.Unknown(DebridProvider.TORBOX, error2, null, 4, null));
                    case 6:
                        i2 = torBoxRepository$resolveToDirectLink$14.I$0;
                        torBoxResponse4 = (TorBoxResponse) torBoxRepository$resolveToDirectLink$14.L$0;
                        try {
                            s38.b(account);
                            ((q38) account).getClass();
                            str3 = TAG;
                            ExecutorService executorService32 = kq.a;
                            kq.h(str3, "Cloud sanitization: removed TB torrent " + i2);
                            break;
                        } catch (Exception e7) {
                            e = e7;
                            str3 = TAG;
                            ExecutorService executorService222 = kq.a;
                            kq.a(str3, "Cloud sanitization failed for TB torrent " + i2, e);
                            torBoxResponse3 = torBoxResponse4;
                            return torBoxResponse3.getData();
                        }
                        torBoxResponse3 = torBoxResponse4;
                        return torBoxResponse3.getData();
                    default:
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
            } catch (CancellationException e8) {
                throw e8;
            }
        } catch (SocketTimeoutException e9) {
            e = e9;
            str3 = TAG;
        } catch (UnknownHostException e10) {
            e = e10;
            str3 = TAG;
        } catch (HttpException e11) {
            e = e11;
            str3 = TAG;
        } catch (Exception e12) {
            e = e12;
            str3 = TAG;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /* JADX INFO: renamed from: saveDeviceToken-gIAlu-s, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m145saveDeviceTokengIAlus(@kp6 String str, @kp6 Continuation<? super q38<TorBoxAccount>> continuation) {
        TorBoxRepository$saveDeviceToken$1 torBoxRepository$saveDeviceToken$1;
        if (continuation instanceof TorBoxRepository$saveDeviceToken$1) {
            torBoxRepository$saveDeviceToken$1 = (TorBoxRepository$saveDeviceToken$1) continuation;
            int i = torBoxRepository$saveDeviceToken$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                torBoxRepository$saveDeviceToken$1.label = i - Integer.MIN_VALUE;
            } else {
                torBoxRepository$saveDeviceToken$1 = new TorBoxRepository$saveDeviceToken$1(this, continuation);
            }
        }
        Object obj = torBoxRepository$saveDeviceToken$1.result;
        Object obj2 = ck1.a;
        int i2 = torBoxRepository$saveDeviceToken$1.label;
        if (i2 != 0) {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(obj);
            return ((q38) obj).a;
        }
        s38.b(obj);
        torBoxRepository$saveDeviceToken$1.label = 1;
        Object objM146verifyAndSaveApiKeygIAlus = m146verifyAndSaveApiKeygIAlus(str, torBoxRepository$saveDeviceToken$1);
        return objM146verifyAndSaveApiKeygIAlus == obj2 ? obj2 : objM146verifyAndSaveApiKeygIAlus;
    }

    /* JADX WARN: Removed duplicated region for block: B:49:0x0128 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:50:0x0129 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x001f  */
    @pq6
    /* JADX INFO: renamed from: verifyAndSaveApiKey-gIAlu-s, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m146verifyAndSaveApiKeygIAlus(@kp6 String str, @kp6 Continuation<? super q38<TorBoxAccount>> continuation) {
        TorBoxRepository$verifyAndSaveApiKey$1 torBoxRepository$verifyAndSaveApiKey$1;
        TorBoxRepository torBoxRepository;
        TorBoxUserData torBoxUserData;
        TorBoxAccount torBoxAccount;
        String str2 = str;
        if (continuation instanceof TorBoxRepository$verifyAndSaveApiKey$1) {
            torBoxRepository$verifyAndSaveApiKey$1 = (TorBoxRepository$verifyAndSaveApiKey$1) continuation;
            int i = torBoxRepository$verifyAndSaveApiKey$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                torBoxRepository$verifyAndSaveApiKey$1.label = i - Integer.MIN_VALUE;
            } else {
                torBoxRepository$verifyAndSaveApiKey$1 = new TorBoxRepository$verifyAndSaveApiKey$1(this, continuation);
            }
        }
        Object user = torBoxRepository$verifyAndSaveApiKey$1.result;
        ck1 ck1Var = ck1.a;
        int i2 = torBoxRepository$verifyAndSaveApiKey$1.label;
        try {
            if (i2 == 0) {
                s38.b(user);
                TorBoxApiService torBoxApiService = this.torBoxApiService;
                torBoxRepository$verifyAndSaveApiKey$1.L$0 = this;
                torBoxRepository$verifyAndSaveApiKey$1.L$1 = str2;
                torBoxRepository$verifyAndSaveApiKey$1.label = 1;
                user = torBoxApiService.getUser("Bearer " + str2, torBoxRepository$verifyAndSaveApiKey$1);
                if (user != ck1Var) {
                    torBoxRepository = this;
                }
            } else {
                if (i2 != 1) {
                    if (i2 != 2) {
                        if (i2 != 3) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        TorBoxAccount torBoxAccount2 = (TorBoxAccount) torBoxRepository$verifyAndSaveApiKey$1.L$0;
                        s38.b(user);
                        return torBoxAccount2;
                    }
                    torBoxAccount = (TorBoxAccount) torBoxRepository$verifyAndSaveApiKey$1.L$2;
                    torBoxUserData = (TorBoxUserData) torBoxRepository$verifyAndSaveApiKey$1.L$1;
                    torBoxRepository = (TorBoxRepository) torBoxRepository$verifyAndSaveApiKey$1.L$0;
                    s38.b(user);
                    ExecutorService executorService = kq.a;
                    kq.h(TAG, "TorBox account saved: " + torBoxUserData.getEmail() + " (" + torBoxUserData.getPlanName() + ")");
                    torBoxRepository$verifyAndSaveApiKey$1.L$0 = torBoxAccount;
                    torBoxRepository$verifyAndSaveApiKey$1.L$1 = null;
                    torBoxRepository$verifyAndSaveApiKey$1.L$2 = null;
                    torBoxRepository$verifyAndSaveApiKey$1.label = 3;
                    return torBoxRepository.triggerCloudSync(torBoxRepository$verifyAndSaveApiKey$1) != ck1Var ? ck1Var : torBoxAccount;
                }
                str2 = (String) torBoxRepository$verifyAndSaveApiKey$1.L$1;
                torBoxRepository = (TorBoxRepository) torBoxRepository$verifyAndSaveApiKey$1.L$0;
                s38.b(user);
            }
            String str3 = str2;
            TorBoxResponse torBoxResponse = (TorBoxResponse) user;
            if (!torBoxResponse.getSuccess() || torBoxResponse.getData() == null) {
                String error = torBoxResponse.getError();
                if (error == null && (error = torBoxResponse.getDetail()) == null) {
                    error = "Failed to verify API key";
                }
                Log.w(TAG, "TorBox verification failed: ".concat(error));
                return s38.a(new Exception(error));
            }
            torBoxUserData = (TorBoxUserData) torBoxResponse.getData();
            long jCurrentTimeMillis = System.currentTimeMillis();
            String email = torBoxUserData.getEmail();
            int plan = torBoxUserData.getPlan();
            String planName = torBoxUserData.getPlanName();
            String premiumExpiresAt = torBoxUserData.getPremiumExpiresAt();
            if (premiumExpiresAt == null) {
                premiumExpiresAt = torBoxUserData.getExpiration();
            }
            String str4 = premiumExpiresAt;
            Boolean boolIsSubscribed = torBoxUserData.isSubscribed();
            TorBoxAccount torBoxAccount3 = new TorBoxAccount("torbox", str3, email, plan, planName, str4, boolIsSubscribed != null ? boolIsSubscribed.booleanValue() : false, torBoxUserData.getTotalDownloaded(), Boxing.boxInt(torBoxUserData.getId()), jCurrentTimeMillis, jCurrentTimeMillis);
            TorBoxAccountDao torBoxAccountDao = torBoxRepository.accountDao;
            torBoxRepository$verifyAndSaveApiKey$1.L$0 = torBoxRepository;
            torBoxRepository$verifyAndSaveApiKey$1.L$1 = torBoxUserData;
            torBoxRepository$verifyAndSaveApiKey$1.L$2 = torBoxAccount3;
            torBoxRepository$verifyAndSaveApiKey$1.label = 2;
            if (torBoxAccountDao.upsert(torBoxAccount3, torBoxRepository$verifyAndSaveApiKey$1) != ck1Var) {
                torBoxAccount = torBoxAccount3;
                ExecutorService executorService2 = kq.a;
                kq.h(TAG, "TorBox account saved: " + torBoxUserData.getEmail() + " (" + torBoxUserData.getPlanName() + ")");
                torBoxRepository$verifyAndSaveApiKey$1.L$0 = torBoxAccount;
                torBoxRepository$verifyAndSaveApiKey$1.L$1 = null;
                torBoxRepository$verifyAndSaveApiKey$1.L$2 = null;
                torBoxRepository$verifyAndSaveApiKey$1.label = 3;
                if (torBoxRepository.triggerCloudSync(torBoxRepository$verifyAndSaveApiKey$1) != ck1Var) {
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "Failed to verify API key", e);
            return s38.a(e);
        }
    }
}
