package com.strmr.ps.data.repository;

import android.util.Log;
import androidx.credentials.exceptions.publickeycredential.DomExceptionUtils;
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.AllDebridAccountDao;
import com.strmr.ps.data.local.entity.AllDebridAccount;
import com.strmr.ps.data.local.entity.PlaybackProgress;
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.AllDebridApiService;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridAllMagnetsData;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridError;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridFileNode;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridMagnetDetail;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridMagnetFilesData;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridMagnetFilesEntry;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridMagnetLink;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridMagnetStatusData;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridMagnetUploadData;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridPinCheckData;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridPinData;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridResponse;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridUnlockData;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridUploadedMagnet;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridUser;
import com.strmr.ps.data.remote.model.alldebrid.AllDebridUserData;
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.fi7;
import defpackage.h32;
import defpackage.ik2;
import defpackage.jk2;
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.tp5;
import defpackage.vo2;
import defpackage.vw2;
import defpackage.vx8;
import defpackage.wo5;
import defpackage.x71;
import defpackage.y41;
import defpackage.yw7;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
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.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 \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\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\r\n\u0002\u0010 \n\u0000\n\u0002\u0010$\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0010\b\n\u0002\b\t\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\t\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u000e\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u000f\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0018\u0002\n\u0002\b\u0005\b\u0007\u0018\u0000 q2\u00020\u0001:\u0002qrB=\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\u0012\u0010\u0010\u001a\u0004\u0018\u00010\u000fH\u0086@¢\u0006\u0004\b\u0010\u0010\u0011J\u0016\u0010\u0015\u001a\b\u0012\u0004\u0012\u00020\u00130\u0012H\u0086@¢\u0006\u0004\b\u0014\u0010\u0011J(\u0010\u001b\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u00160\u00122\u0006\u0010\u0017\u001a\u00020\u00162\u0006\u0010\u0018\u001a\u00020\u0016H\u0086@¢\u0006\u0004\b\u0019\u0010\u001aJ\u001e\u0010\u001f\u001a\b\u0012\u0004\u0012\u00020\u000f0\u00122\u0006\u0010\u001c\u001a\u00020\u0016H\u0086@¢\u0006\u0004\b\u001d\u0010\u001eJ\u0016\u0010!\u001a\b\u0012\u0004\u0012\u00020\u000f0\u0012H\u0086@¢\u0006\u0004\b \u0010\u0011J\u001e\u0010#\u001a\b\u0012\u0004\u0012\u00020\u000f0\u00122\u0006\u0010\u001c\u001a\u00020\u0016H\u0086@¢\u0006\u0004\b\"\u0010\u001eJ2\u0010*\u001a\u0016\u0012\u0012\u0012\u0010\u0012\u0004\u0012\u00020\u0016\u0012\u0006\u0012\u0004\u0018\u00010'0&0\u00122\f\u0010%\u001a\b\u0012\u0004\u0012\u00020\u00160$H\u0096@¢\u0006\u0004\b(\u0010)J\u0012\u0010,\u001a\u0004\u0018\u00010+H\u0096@¢\u0006\u0004\b,\u0010\u0011JF\u00104\u001a\b\u0012\u0004\u0012\u00020\u00160\u00122\u0006\u0010-\u001a\u00020\u00162\b\u0010.\u001a\u0004\u0018\u00010+2\b\u0010/\u001a\u0004\u0018\u00010+2\b\u00100\u001a\u0004\u0018\u00010+2\b\u00101\u001a\u0004\u0018\u00010\u0016H\u0096@¢\u0006\u0004\b2\u00103J\u0010\u00106\u001a\u000205H\u0096@¢\u0006\u0004\b6\u0010\u0011J\u0010\u00107\u001a\u00020'H\u0096@¢\u0006\u0004\b7\u0010\u0011J\u0012\u00108\u001a\u0004\u0018\u00010\u0016H\u0096@¢\u0006\u0004\b8\u0010\u0011J\u0017\u0010:\u001a\u0004\u0018\u00010+2\u0006\u00109\u001a\u00020\u000f¢\u0006\u0004\b:\u0010;J\u001c\u0010>\u001a\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u00020<0$0\u0012H\u0096@¢\u0006\u0004\b=\u0010\u0011J$\u0010C\u001a\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u00020<0$0\u00122\u0006\u0010@\u001a\u00020?H\u0086@¢\u0006\u0004\bA\u0010BJ\u001e\u0010H\u001a\b\u0012\u0004\u0012\u00020\u00160\u00122\u0006\u0010E\u001a\u00020DH\u0096@¢\u0006\u0004\bF\u0010GJ\u001e\u0010J\u001a\b\u0012\u0004\u0012\u0002050\u00122\u0006\u0010@\u001a\u00020?H\u0086@¢\u0006\u0004\bI\u0010BJ\u001e\u0010M\u001a\b\u0012\u0004\u0012\u00020'0\u00122\u0006\u0010K\u001a\u00020\u0016H\u0086@¢\u0006\u0004\bL\u0010\u001eJ*\u0010R\u001a\b\u0012\u0004\u0012\u0002050\u00122\u0006\u0010N\u001a\u00020?2\n\b\u0002\u0010O\u001a\u0004\u0018\u00010\u0016H\u0086@¢\u0006\u0004\bP\u0010QJ%\u0010V\u001a\b\u0012\u0004\u0012\u00020U0$2\u000e\u0010T\u001a\n\u0012\u0004\u0012\u00020S\u0018\u00010$H\u0002¢\u0006\u0004\bV\u0010WJ\u0019\u0010Y\u001a\u0004\u0018\u00010\u00162\u0006\u0010X\u001a\u00020\u0016H\u0002¢\u0006\u0004\bY\u0010ZJ7\u0010\\\u001a\b\u0012\u0004\u0012\u00020<0$2\u000e\u0010T\u001a\n\u0012\u0004\u0012\u00020S\u0018\u00010$2\u0006\u0010@\u001a\u00020\u00162\b\b\u0002\u0010[\u001a\u00020\u0016H\u0002¢\u0006\u0004\b\\\u0010]J\u0017\u0010_\u001a\u00020\u00162\u0006\u0010^\u001a\u00020\u0016H\u0002¢\u0006\u0004\b_\u0010ZJ\u0010\u0010`\u001a\u000205H\u0082@¢\u0006\u0004\b`\u0010\u0011R\u0014\u0010\u0003\u001a\u00020\u00028\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0003\u0010aR\u0014\u0010\u0005\u001a\u00020\u00048\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0005\u0010bR\u001a\u0010\b\u001a\b\u0012\u0004\u0012\u00020\u00070\u00068\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\b\u0010cR\u001a\u0010\n\u001a\b\u0012\u0004\u0012\u00020\t0\u00068\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\n\u0010cR\u0014\u0010\f\u001a\u00020\u000b8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\f\u0010dR\u001a\u0010f\u001a\u00020e8\u0016X\u0096\u0004¢\u0006\f\n\u0004\bf\u0010g\u001a\u0004\bh\u0010iR\u001a\u0010j\u001a\u00020\u00168\u0016X\u0096D¢\u0006\f\n\u0004\bj\u0010k\u001a\u0004\bl\u0010mR\u0014\u0010o\u001a\u00020n8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\bo\u0010p¨\u0006s"}, d2 = {"Lcom/strmr/ps/data/repository/AllDebridRepository;", "Lcom/strmr/ps/data/repository/IDebridLibraryProvider;", "Lcom/strmr/ps/data/remote/api/AllDebridApiService;", "allDebridApiService", "Lcom/strmr/ps/data/local/dao/AllDebridAccountDao;", "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/AllDebridApiService;Lcom/strmr/ps/data/local/dao/AllDebridAccountDao;Ldagger/Lazy;Ldagger/Lazy;Lcom/strmr/ps/data/repository/LinkFilterPreferences;)V", "Lcom/strmr/ps/data/local/entity/AllDebridAccount;", "getAccount", "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "Lq38;", "Lcom/strmr/ps/data/remote/model/alldebrid/AllDebridPinData;", "requestPinCode-IoAF18A", "requestPinCode", "", "pin", "check", "pollForApiKey-0E7RQCE", "(Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "pollForApiKey", "apiKey", "saveApiKey-gIAlu-s", "(Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "saveApiKey", "refreshAccountInfo-IoAF18A", "refreshAccountInfo", "verifyAndSaveApiKey-gIAlu-s", "verifyAndSaveApiKey", "", "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", "Le6a;", "clearAccount", "hasAccount", "getApiKey", "account", "getDaysRemaining", "(Lcom/strmr/ps/data/local/entity/AllDebridAccount;)Ljava/lang/Integer;", "Lcom/strmr/ps/data/model/debrid/DebridFileItem;", "getLibraryItems-IoAF18A", "getLibraryItems", "", "magnetId", "getMagnetFilesForLibrary-gIAlu-s", "(JLkotlin/coroutines/Continuation;)Ljava/lang/Object;", "getMagnetFilesForLibrary", "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", "deleteMagnet-gIAlu-s", "deleteMagnet", "hash", "deleteByHash-gIAlu-s", "deleteByHash", "resolveTimestamp", "fileName", "deleteMostRecent-0E7RQCE", "(JLjava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "deleteMostRecent", "Lcom/strmr/ps/data/remote/model/alldebrid/AllDebridFileNode;", "nodes", "Lcom/strmr/ps/data/repository/AllDebridRepository$FileInfo;", "flattenFileTree", "(Ljava/util/List;)Ljava/util/List;", "magnet", "extractHashFromMagnet", "(Ljava/lang/String;)Ljava/lang/String;", "prefix", "flattenFileTreeToDebridItems", "(Ljava/util/List;Ljava/lang/String;Ljava/lang/String;)Ljava/util/List;", AppMeasurementSdk.ConditionalUserProperty.NAME, "normalizeForMatch", "triggerCloudSync", "Lcom/strmr/ps/data/remote/api/AllDebridApiService;", "Lcom/strmr/ps/data/local/dao/AllDebridAccountDao;", "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", "FileInfo", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class AllDebridRepository implements IDebridLibraryProvider {

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

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

    @kp6
    private final AllDebridAccountDao accountDao;

    @kp6
    private final AllDebridApiService allDebridApiService;

    @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;

    @Metadata(d1 = {"\u0000(\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\t\n\u0002\b\r\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0002\b\u0082\b\u0018\u00002\u00020\u0001B\u001f\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0003¢\u0006\u0004\b\u0007\u0010\bJ\t\u0010\u000e\u001a\u00020\u0003HÆ\u0003J\t\u0010\u000f\u001a\u00020\u0005HÆ\u0003J\t\u0010\u0010\u001a\u00020\u0003HÆ\u0003J'\u0010\u0011\u001a\u00020\u00002\b\b\u0002\u0010\u0002\u001a\u00020\u00032\b\b\u0002\u0010\u0004\u001a\u00020\u00052\b\b\u0002\u0010\u0006\u001a\u00020\u0003HÆ\u0001J\u0013\u0010\u0012\u001a\u00020\u00132\b\u0010\u0014\u001a\u0004\u0018\u00010\u0001HÖ\u0003J\t\u0010\u0015\u001a\u00020\u0016HÖ\u0001J\t\u0010\u0017\u001a\u00020\u0003HÖ\u0001R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\t\u0010\nR\u0011\u0010\u0004\u001a\u00020\u0005¢\u0006\b\n\u0000\u001a\u0004\b\u000b\u0010\fR\u0011\u0010\u0006\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\r\u0010\n¨\u0006\u0018"}, d2 = {"Lcom/strmr/ps/data/repository/AllDebridRepository$FileInfo;", "", AppMeasurementSdk.ConditionalUserProperty.NAME, "", "size", "", "link", "<init>", "(Ljava/lang/String;JLjava/lang/String;)V", "getName", "()Ljava/lang/String;", "getSize", "()J", "getLink", "component1", "component2", "component3", "copy", "equals", "", "other", "hashCode", "", "toString", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final /* data */ class FileInfo {

        @kp6
        private final String link;

        @kp6
        private final String name;
        private final long size;

        public FileInfo(@kp6 String str, long j, @kp6 String str2) {
            cr4.g(str, AppMeasurementSdk.ConditionalUserProperty.NAME);
            cr4.g(str2, "link");
            this.name = str;
            this.size = j;
            this.link = str2;
        }

        public static /* synthetic */ FileInfo copy$default(FileInfo fileInfo, String str, long j, String str2, int i, Object obj) {
            if ((i & 1) != 0) {
                str = fileInfo.name;
            }
            if ((i & 2) != 0) {
                j = fileInfo.size;
            }
            if ((i & 4) != 0) {
                str2 = fileInfo.link;
            }
            return fileInfo.copy(str, j, str2);
        }

        @kp6
        /* JADX INFO: renamed from: component1, reason: from getter */
        public final String getName() {
            return this.name;
        }

        /* JADX INFO: renamed from: component2, reason: from getter */
        public final long getSize() {
            return this.size;
        }

        @kp6
        /* JADX INFO: renamed from: component3, reason: from getter */
        public final String getLink() {
            return this.link;
        }

        @kp6
        public final FileInfo copy(@kp6 String name, long size, @kp6 String link) {
            cr4.g(name, AppMeasurementSdk.ConditionalUserProperty.NAME);
            cr4.g(link, "link");
            return new FileInfo(name, size, link);
        }

        public boolean equals(@pq6 Object other) {
            if (this == other) {
                return true;
            }
            if (!(other instanceof FileInfo)) {
                return false;
            }
            FileInfo fileInfo = (FileInfo) other;
            return cr4.b(this.name, fileInfo.name) && this.size == fileInfo.size && cr4.b(this.link, fileInfo.link);
        }

        @kp6
        public final String getLink() {
            return this.link;
        }

        @kp6
        public final String getName() {
            return this.name;
        }

        public final long getSize() {
            return this.size;
        }

        public int hashCode() {
            return this.link.hashCode() + fi7.b(this.name.hashCode() * 31, 31, this.size);
        }

        @kp6
        public String toString() {
            String str = this.name;
            long j = this.size;
            String str2 = this.link;
            StringBuilder sb = new StringBuilder("FileInfo(name=");
            sb.append(str);
            sb.append(", size=");
            sb.append(j);
            return n41.t(sb, ", link=", str2, ")");
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.AllDebridRepository$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.AllDebridRepository", f = "AllDebridRepository.kt", i = {0}, l = {436, 439}, 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 AllDebridRepository.this.clearAccount(this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.AllDebridRepository$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.AllDebridRepository", f = "AllDebridRepository.kt", i = {}, l = {199}, m = "getAccountExpirationStatus", n = {}, s = {})
    public static final class C02801 extends ContinuationImpl {
        int label;
        /* synthetic */ Object result;

        public C02801(Continuation<? super C02801> 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 AllDebridRepository.this.getAccountExpirationStatus(this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.AllDebridRepository$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.AllDebridRepository", f = "AllDebridRepository.kt", i = {}, l = {447}, m = "getApiKey", n = {}, s = {})
    public static final class C02811 extends ContinuationImpl {
        int label;
        /* synthetic */ Object result;

        public C02811(Continuation<? super C02811> 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 AllDebridRepository.this.getApiKey(this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.AllDebridRepository$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.AllDebridRepository", f = "AllDebridRepository.kt", i = {}, l = {445}, m = "hasAccount", n = {}, s = {})
    public static final class C02821 extends ContinuationImpl {
        int label;
        /* synthetic */ Object result;

        public C02821(Continuation<? super C02821> 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 AllDebridRepository.this.hasAccount(this);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.AllDebridRepository$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.AllDebridRepository", f = "AllDebridRepository.kt", i = {}, l = {770}, m = "triggerCloudSync", n = {}, s = {})
    public static final class C02831 extends ContinuationImpl {
        int label;
        /* synthetic */ Object result;

        public C02831(Continuation<? super C02831> 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 AllDebridRepository.this.triggerCloudSync(this);
        }
    }

    @Inject
    public AllDebridRepository(@kp6 AllDebridApiService allDebridApiService, @kp6 AllDebridAccountDao allDebridAccountDao, @kp6 Lazy<SettingsSyncManager> lazy, @kp6 Lazy<DeviceManager> lazy2, @kp6 LinkFilterPreferences linkFilterPreferences) {
        cr4.g(allDebridApiService, "allDebridApiService");
        cr4.g(allDebridAccountDao, "accountDao");
        cr4.g(lazy, "settingsSyncManager");
        cr4.g(lazy2, "deviceManager");
        cr4.g(linkFilterPreferences, "linkFilterPreferences");
        this.allDebridApiService = allDebridApiService;
        this.accountDao = allDebridAccountDao;
        this.settingsSyncManager = lazy;
        this.deviceManager = lazy2;
        this.linkFilterPreferences = linkFilterPreferences;
        this.provider = DebridProvider.ALL_DEBRID;
        this.serviceName = "alldebrid";
        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 m65deleteMostRecent0E7RQCE$default(AllDebridRepository allDebridRepository, long j, String str, Continuation continuation, int i, Object obj) {
        if ((i & 2) != 0) {
            str = null;
        }
        return allDebridRepository.m69deleteMostRecent0E7RQCE(j, str, continuation);
    }

    private final String extractHashFromMagnet(String magnet) {
        tp5 tp5VarB = new pw7("btih:([a-fA-F0-9]{40})", yw7.b).b(magnet);
        if (tp5VarB != null) {
            return (String) tp5VarB.b().get(1);
        }
        return null;
    }

    private final List<FileInfo> flattenFileTree(List<AllDebridFileNode> nodes) {
        if (nodes == null) {
            return ik2.a;
        }
        ArrayList arrayList = new ArrayList();
        for (AllDebridFileNode allDebridFileNode : nodes) {
            if (allDebridFileNode.getLink() != null && allDebridFileNode.getSize() != null) {
                arrayList.add(new FileInfo(allDebridFileNode.getName(), allDebridFileNode.getSize().longValue(), allDebridFileNode.getLink()));
            }
            if (allDebridFileNode.getEntries() != null) {
                arrayList.addAll(flattenFileTree(allDebridFileNode.getEntries()));
            }
        }
        return arrayList;
    }

    private final List<DebridFileItem> flattenFileTreeToDebridItems(List<AllDebridFileNode> nodes, String magnetId, String prefix) {
        ArrayList arrayList;
        String str;
        if (nodes == null) {
            return ik2.a;
        }
        ArrayList arrayList2 = new ArrayList();
        int i = 0;
        for (AllDebridFileNode allDebridFileNode : nodes) {
            String name = prefix.length() == 0 ? allDebridFileNode.getName() : vw2.l(prefix, DomExceptionUtils.SEPARATOR, allDebridFileNode.getName());
            if (allDebridFileNode.getLink() == null || allDebridFileNode.getSize() == null) {
                arrayList = arrayList2;
                str = name;
                i = i;
            } else {
                str = name;
                arrayList = arrayList2;
                arrayList.add(new DebridFileItem.File(magnetId + "_" + i, allDebridFileNode.getName(), "alldebrid", DebridService.INSTANCE.getDisplayName("alldebrid"), allDebridFileNode.getSize().longValue(), null, allDebridFileNode.getLink(), null, magnetId, null, VideoExtensions.INSTANCE.isVideoFile(allDebridFileNode.getName()), false, 2720, null));
                i++;
            }
            if (allDebridFileNode.getEntries() != null) {
                arrayList.addAll(flattenFileTreeToDebridItems(allDebridFileNode.getEntries(), magnetId, str));
            }
            arrayList2 = arrayList;
        }
        return arrayList2;
    }

    public static /* synthetic */ List flattenFileTreeToDebridItems$default(AllDebridRepository allDebridRepository, List list, String str, String str2, int i, Object obj) {
        if ((i & 4) != 0) {
            str2 = "";
        }
        return allDebridRepository.flattenFileTreeToDebridItems(list, str, str2);
    }

    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) {
        C02831 c02831;
        if (continuation instanceof C02831) {
            c02831 = (C02831) continuation;
            int i = c02831.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c02831.label = i - Integer.MIN_VALUE;
            } else {
                c02831 = new C02831(continuation);
            }
        }
        Object objC = c02831.result;
        ck1 ck1Var = ck1.a;
        int i2 = c02831.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;
                }
                AllDebridRepository$triggerCloudSync$result$1 allDebridRepository$triggerCloudSync$result$1 = new AllDebridRepository$triggerCloudSync$result$1(this, strE, null);
                c02831.label = 1;
                objC = qo9.c(5000L, allDebridRepository$triggerCloudSync$result$1, c02831);
                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, "AllDebrid cloud sync completed successfully");
            } else {
                Log.w(TAG, "AllDebrid cloud sync timed out or returned false — pending deletion flag preserved");
            }
        } catch (Exception e) {
            Log.w(TAG, "AllDebrid cloud sync failed — pending deletion flag preserved", e);
        }
        return e6aVar;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @Override // com.strmr.ps.data.repository.IDebridProvider
    @pq6
    /* JADX INFO: renamed from: checkCacheStatus-gIAlu-s, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object mo66checkCacheStatusgIAlus(@kp6 List<String> list, @kp6 Continuation<? super q38<? extends Map<String, Boolean>>> continuation) {
        AllDebridRepository$checkCacheStatus$1 allDebridRepository$checkCacheStatus$1;
        if (continuation instanceof AllDebridRepository$checkCacheStatus$1) {
            allDebridRepository$checkCacheStatus$1 = (AllDebridRepository$checkCacheStatus$1) continuation;
            int i = allDebridRepository$checkCacheStatus$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                allDebridRepository$checkCacheStatus$1.label = i - Integer.MIN_VALUE;
            } else {
                allDebridRepository$checkCacheStatus$1 = new AllDebridRepository$checkCacheStatus$1(this, continuation);
            }
        }
        Object account = allDebridRepository$checkCacheStatus$1.result;
        ck1 ck1Var = ck1.a;
        int i2 = allDebridRepository$checkCacheStatus$1.label;
        if (i2 == 0) {
            s38.b(account);
            AllDebridAccountDao allDebridAccountDao = this.accountDao;
            allDebridRepository$checkCacheStatus$1.L$0 = list;
            allDebridRepository$checkCacheStatus$1.label = 1;
            account = allDebridAccountDao.getAccount("alldebrid", allDebridRepository$checkCacheStatus$1);
            if (account == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            list = (List) allDebridRepository$checkCacheStatus$1.L$0;
            s38.b(account);
        }
        if (((AllDebridAccount) account) == null) {
            return vw2.d("No AllDebrid account configured");
        }
        ExecutorService executorService = kq.a;
        kq.h(TAG, "AllDebrid cache check skipped (instant endpoint removed), " + list.size() + " hashes");
        return jk2.a;
    }

    /* 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;
        AllDebridRepository allDebridRepository;
        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);
            AllDebridAccountDao allDebridAccountDao = this.accountDao;
            anonymousClass1.L$0 = this;
            anonymousClass1.label = 1;
            if (allDebridAccountDao.deleteAccount("alldebrid", anonymousClass1) != ck1Var) {
                allDebridRepository = 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;
        }
        allDebridRepository = (AllDebridRepository) anonymousClass1.L$0;
        s38.b(obj);
        ExecutorService executorService = kq.a;
        kq.h(TAG, "AllDebrid account cleared");
        allDebridRepository.settingsSyncManager.get().e("alldebrid");
        anonymousClass1.L$0 = null;
        anonymousClass1.label = 2;
    }

    /* JADX WARN: Code restructure failed: missing block: B:77:0x0250, code lost:
    
        if (r6 == r3) goto L78;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Path cross not found for [B:59:0x0180, B:61:0x0186], limit reached: 108 */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00f2  */
    /* JADX WARN: Removed duplicated region for block: B:56:0x016b  */
    /* JADX WARN: Removed duplicated region for block: B:76:0x020b A[Catch: Exception -> 0x0056, TryCatch #1 {Exception -> 0x0056, blocks: (B:15:0x0048, B:79:0x0253, B:74:0x0205, B:76:0x020b, B:86:0x0287, B:81:0x0257, B:83:0x0263, B:85:0x0269, B:53:0x0146), top: B:99:0x002a }] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0017  */
    /* JADX WARN: Removed duplicated region for block: B:86:0x0287 A[Catch: Exception -> 0x0056, TRY_LEAVE, TryCatch #1 {Exception -> 0x0056, blocks: (B:15:0x0048, B:79:0x0253, B:74:0x0205, B:76:0x020b, B:86:0x0287, B:81:0x0257, B:83:0x0263, B:85:0x0269, B:53:0x0146), top: B:99:0x002a }] */
    /* JADX WARN: Removed duplicated region for block: B:91:0x02db A[Catch: Exception -> 0x0140, TRY_LEAVE, TryCatch #0 {Exception -> 0x0140, blocks: (B:57:0x0172, B:59:0x0180, B:62:0x018b, B:63:0x01d9, B:65:0x01df, B:67:0x01ec, B:69:0x01f3, B:70:0x01f7, B:72:0x01fd, B:90:0x02cf, B:44:0x00f4, B:91:0x02db, B:89:0x02b4), top: B:98:0x0172 }] */
    /* JADX WARN: Type inference failed for: r14v3, types: [java.lang.StringBuilder] */
    /* JADX WARN: Type inference failed for: r2v17, types: [java.lang.StringBuilder] */
    /* JADX WARN: Type inference failed for: r2v4, types: [java.lang.StringBuilder] */
    /* JADX WARN: Type inference failed for: r4v23 */
    /* JADX WARN: Type inference failed for: r4v24 */
    /* 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: 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: r9v0 */
    /* JADX WARN: Type inference failed for: r9v1 */
    /* JADX WARN: Type inference failed for: r9v14 */
    /* JADX WARN: Type inference failed for: r9v19, types: [java.lang.Object, java.lang.String] */
    /* JADX WARN: Type inference failed for: r9v2, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r9v20 */
    /* JADX WARN: Type inference failed for: r9v21 */
    /* JADX WARN: Type inference failed for: r9v22 */
    /* JADX WARN: Type inference failed for: r9v25 */
    /* JADX WARN: Type inference failed for: r9v26 */
    /* JADX WARN: Type inference failed for: r9v27 */
    /* JADX WARN: Type inference failed for: r9v28 */
    /* JADX WARN: Type inference failed for: r9v3 */
    /* JADX WARN: Type inference failed for: r9v9 */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:56:0x016b -> B:98:0x0172). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:77:0x0250 -> B:79:0x0253). 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 m67deleteByHashgIAlus(@kp6 String str, @kp6 Continuation<? super q38<Boolean>> continuation) {
        AllDebridRepository$deleteByHash$1 allDebridRepository$deleteByHash$1;
        boolean z;
        String str2;
        AllDebridRepository allDebridRepository;
        String authHeader;
        AllDebridRepository allDebridRepository2;
        int i;
        long[] jArr;
        String str3;
        ?? r4;
        String str4;
        ?? r42;
        char c;
        String str5;
        Object allMagnets$default;
        String str6;
        long[] jArr2;
        ?? r43;
        char c2;
        boolean z2;
        Iterator it;
        List list;
        AllDebridRepository allDebridRepository3;
        if (continuation instanceof AllDebridRepository$deleteByHash$1) {
            allDebridRepository$deleteByHash$1 = (AllDebridRepository$deleteByHash$1) continuation;
            int i2 = allDebridRepository$deleteByHash$1.label;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                allDebridRepository$deleteByHash$1.label = i2 - Integer.MIN_VALUE;
            } else {
                allDebridRepository$deleteByHash$1 = new AllDebridRepository$deleteByHash$1(this, continuation);
            }
        }
        Object account = allDebridRepository$deleteByHash$1.result;
        ck1 ck1Var = ck1.a;
        int i3 = allDebridRepository$deleteByHash$1.label;
        int i4 = 2;
        ?? r9 = 3;
        try {
        } catch (Exception e) {
            e = e;
        }
        if (i3 == 0) {
            z = false;
            s38.b(account);
            AllDebridAccountDao allDebridAccountDao = this.accountDao;
            allDebridRepository$deleteByHash$1.L$0 = this;
            str2 = str;
            allDebridRepository$deleteByHash$1.L$1 = str2;
            allDebridRepository$deleteByHash$1.label = 1;
            account = allDebridAccountDao.getAccount("alldebrid", allDebridRepository$deleteByHash$1);
            if (account != ck1Var) {
                allDebridRepository = this;
            }
            return ck1Var;
        }
        if (i3 != 1) {
            if (i3 == 2) {
                z = false;
                int i5 = allDebridRepository$deleteByHash$1.I$1;
                i = allDebridRepository$deleteByHash$1.I$0;
                jArr2 = (long[]) allDebridRepository$deleteByHash$1.L$3;
                authHeader = (String) allDebridRepository$deleteByHash$1.L$2;
                str6 = (String) allDebridRepository$deleteByHash$1.L$1;
                allDebridRepository2 = (AllDebridRepository) allDebridRepository$deleteByHash$1.L$0;
                try {
                    s38.b(account);
                    r43 = i5;
                    jArr = jArr2;
                    str4 = str6;
                    r42 = r43;
                    int i6 = i;
                    AllDebridRepository allDebridRepository4 = allDebridRepository2;
                    AllDebridApiService allDebridApiService = allDebridRepository4.allDebridApiService;
                    allDebridRepository$deleteByHash$1.L$0 = allDebridRepository4;
                    allDebridRepository$deleteByHash$1.L$1 = str4;
                    allDebridRepository$deleteByHash$1.L$2 = authHeader;
                    allDebridRepository$deleteByHash$1.L$3 = jArr;
                    allDebridRepository$deleteByHash$1.I$0 = i6;
                    allDebridRepository$deleteByHash$1.I$1 = r42;
                    c = 3;
                    allDebridRepository$deleteByHash$1.label = 3;
                    AllDebridRepository$deleteByHash$1 allDebridRepository$deleteByHash$12 = allDebridRepository$deleteByHash$1;
                    str5 = authHeader;
                    allMagnets$default = AllDebridApiService.DefaultImpls.getAllMagnets$default(allDebridApiService, str5, null, allDebridRepository$deleteByHash$12, 2, null);
                    if (allMagnets$default != ck1Var) {
                    }
                    return ck1Var;
                } catch (Exception e2) {
                    e = e2;
                    r9 = str6;
                }
            } else if (i3 == 3) {
                int i7 = allDebridRepository$deleteByHash$1.I$1;
                int i8 = allDebridRepository$deleteByHash$1.I$0;
                long[] jArr3 = (long[]) allDebridRepository$deleteByHash$1.L$3;
                String str7 = (String) allDebridRepository$deleteByHash$1.L$2;
                String str8 = (String) allDebridRepository$deleteByHash$1.L$1;
                z = false;
                AllDebridRepository allDebridRepository5 = (AllDebridRepository) allDebridRepository$deleteByHash$1.L$0;
                try {
                    s38.b(account);
                    allDebridRepository2 = allDebridRepository5;
                    i = i8;
                    str3 = str8;
                    str5 = str7;
                    c = 3;
                    ?? r44 = i7;
                    try {
                        AllDebridResponse allDebridResponse = (AllDebridResponse) account;
                        if (cr4.b(allDebridResponse.getStatus(), "success") || allDebridResponse.getData() == null) {
                            c2 = 4;
                            z2 = true;
                            ExecutorService executorService = kq.a;
                            kq.h(TAG, "Cloud sanitization: failed to list AD magnets (attempt " + (r44 + 1) + ")");
                        } else {
                            ExecutorService executorService2 = kq.a;
                            kq.h(TAG, "Cloud sanitization: AD magnet list has " + ((AllDebridAllMagnetsData) allDebridResponse.getData()).getMagnets().size() + " items, searching for hash=" + str3 + " (attempt " + (r44 + 1) + ")");
                            List<AllDebridMagnetDetail> magnets = ((AllDebridAllMagnetsData) allDebridResponse.getData()).getMagnets();
                            ArrayList arrayList = new ArrayList();
                            for (Object obj : magnets) {
                                String hash = ((AllDebridMagnetDetail) obj).getHash();
                                if (hash != null && hash.equalsIgnoreCase(str3)) {
                                    arrayList.add(obj);
                                }
                            }
                            if (arrayList.isEmpty()) {
                                c2 = 4;
                                z2 = true;
                            } else {
                                it = arrayList.iterator();
                                list = arrayList;
                                r9 = str3;
                                allDebridRepository3 = allDebridRepository2;
                                if (it.hasNext()) {
                                }
                            }
                        }
                        jArr = jArr3;
                        authHeader = str5;
                        i4 = 2;
                        r4 = r44 + 1;
                        if (r4 >= i) {
                            ExecutorService executorService3 = kq.a;
                            kq.h(TAG, "Cloud sanitization: no AD magnet found for hash " + str3 + " after " + i + " attempts");
                            return Boxing.boxBoolean(z);
                        }
                        if (r4 <= 0) {
                            str4 = str3;
                            r42 = r4;
                            int i62 = i;
                            AllDebridRepository allDebridRepository42 = allDebridRepository2;
                            AllDebridApiService allDebridApiService2 = allDebridRepository42.allDebridApiService;
                            allDebridRepository$deleteByHash$1.L$0 = allDebridRepository42;
                            allDebridRepository$deleteByHash$1.L$1 = str4;
                            allDebridRepository$deleteByHash$1.L$2 = authHeader;
                            allDebridRepository$deleteByHash$1.L$3 = jArr;
                            allDebridRepository$deleteByHash$1.I$0 = i62;
                            allDebridRepository$deleteByHash$1.I$1 = r42;
                            c = 3;
                            allDebridRepository$deleteByHash$1.label = 3;
                            AllDebridRepository$deleteByHash$1 allDebridRepository$deleteByHash$122 = allDebridRepository$deleteByHash$1;
                            str5 = authHeader;
                            allMagnets$default = AllDebridApiService.DefaultImpls.getAllMagnets$default(allDebridApiService2, str5, null, allDebridRepository$deleteByHash$122, 2, null);
                            if (allMagnets$default != ck1Var) {
                            }
                            return ck1Var;
                        }
                        ExecutorService executorService4 = kq.a;
                        kq.h(TAG, "Cloud sanitization: AD retry " + r4 + " for hash=" + str3 + " (waiting " + jArr[r4] + "ms)");
                        long j = jArr[r4];
                        allDebridRepository$deleteByHash$1.L$0 = allDebridRepository2;
                        allDebridRepository$deleteByHash$1.L$1 = str3;
                        allDebridRepository$deleteByHash$1.L$2 = authHeader;
                        allDebridRepository$deleteByHash$1.L$3 = jArr;
                        allDebridRepository$deleteByHash$1.I$0 = i;
                        allDebridRepository$deleteByHash$1.I$1 = r4;
                        allDebridRepository$deleteByHash$1.label = i4;
                        if (h32.a(j, allDebridRepository$deleteByHash$1) != ck1Var) {
                            str6 = str3;
                            jArr2 = jArr;
                            r43 = r4;
                            jArr = jArr2;
                            str4 = str6;
                            r42 = r43;
                            int i622 = i;
                            AllDebridRepository allDebridRepository422 = allDebridRepository2;
                            AllDebridApiService allDebridApiService22 = allDebridRepository422.allDebridApiService;
                            allDebridRepository$deleteByHash$1.L$0 = allDebridRepository422;
                            allDebridRepository$deleteByHash$1.L$1 = str4;
                            allDebridRepository$deleteByHash$1.L$2 = authHeader;
                            allDebridRepository$deleteByHash$1.L$3 = jArr;
                            allDebridRepository$deleteByHash$1.I$0 = i622;
                            allDebridRepository$deleteByHash$1.I$1 = r42;
                            c = 3;
                            allDebridRepository$deleteByHash$1.label = 3;
                            AllDebridRepository$deleteByHash$1 allDebridRepository$deleteByHash$1222 = allDebridRepository$deleteByHash$1;
                            str5 = authHeader;
                            allMagnets$default = AllDebridApiService.DefaultImpls.getAllMagnets$default(allDebridApiService22, str5, null, allDebridRepository$deleteByHash$1222, 2, null);
                            if (allMagnets$default != ck1Var) {
                                jArr3 = jArr;
                                account = allMagnets$default;
                                allDebridRepository2 = allDebridRepository422;
                                i = i622;
                                allDebridRepository$deleteByHash$1 = allDebridRepository$deleteByHash$1222;
                                str3 = str4;
                                r44 = r42;
                                AllDebridResponse allDebridResponse2 = (AllDebridResponse) account;
                                if (cr4.b(allDebridResponse2.getStatus(), "success")) {
                                }
                                c2 = 4;
                                z2 = true;
                                ExecutorService executorService5 = kq.a;
                                kq.h(TAG, "Cloud sanitization: failed to list AD magnets (attempt " + (r44 + 1) + ")");
                                jArr = jArr3;
                                authHeader = str5;
                                i4 = 2;
                                r4 = r44 + 1;
                                if (r4 >= i) {
                                }
                            }
                        }
                        return ck1Var;
                    } catch (Exception e3) {
                        e = e3;
                        r9 = str3;
                    }
                } catch (Exception e4) {
                    e = e4;
                    r9 = str8;
                }
            } else {
                if (i3 != 4) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                AllDebridMagnetDetail allDebridMagnetDetail = (AllDebridMagnetDetail) allDebridRepository$deleteByHash$1.L$4;
                it = (Iterator) allDebridRepository$deleteByHash$1.L$3;
                list = (List) allDebridRepository$deleteByHash$1.L$2;
                String str9 = (String) allDebridRepository$deleteByHash$1.L$1;
                allDebridRepository3 = (AllDebridRepository) allDebridRepository$deleteByHash$1.L$0;
                s38.b(account);
                Object objM68deleteMagnetgIAlus = ((q38) account).a;
                ?? r92 = str9;
                r9 = r92;
                if (objM68deleteMagnetgIAlus instanceof q38.b) {
                    ExecutorService executorService6 = kq.a;
                    long id = allDebridMagnetDetail.getId();
                    Throwable thA = q38.a(objM68deleteMagnetgIAlus);
                    kq.h(TAG, "Cloud sanitization: AD delete " + id + " failed: " + (thA != null ? thA.getMessage() : null));
                    r9 = r92;
                }
                if (it.hasNext()) {
                    ExecutorService executorService7 = kq.a;
                    kq.h(TAG, "Cloud sanitization: processed " + list.size() + " AD magnet(s) for hash " + r9);
                    return Boxing.boxBoolean(true);
                }
                allDebridMagnetDetail = (AllDebridMagnetDetail) it.next();
                ExecutorService executorService8 = kq.a;
                kq.h(TAG, "Cloud sanitization: deleting AD magnet " + allDebridMagnetDetail.getId() + " (" + allDebridMagnetDetail.getFilename() + ")");
                long id2 = allDebridMagnetDetail.getId();
                allDebridRepository$deleteByHash$1.L$0 = allDebridRepository3;
                allDebridRepository$deleteByHash$1.L$1 = r9;
                allDebridRepository$deleteByHash$1.L$2 = list;
                allDebridRepository$deleteByHash$1.L$3 = it;
                allDebridRepository$deleteByHash$1.L$4 = allDebridMagnetDetail;
                allDebridRepository$deleteByHash$1.label = 4;
                objM68deleteMagnetgIAlus = allDebridRepository3.m68deleteMagnetgIAlus(id2, allDebridRepository$deleteByHash$1);
                r92 = r9;
            }
            ExecutorService executorService9 = kq.a;
            kq.a(TAG, "Cloud sanitization AD deleteByHash failed for " + r9, e);
            return s38.a(e);
        }
        z = false;
        str2 = (String) allDebridRepository$deleteByHash$1.L$1;
        allDebridRepository = (AllDebridRepository) allDebridRepository$deleteByHash$1.L$0;
        s38.b(account);
        AllDebridAccount allDebridAccount = (AllDebridAccount) account;
        if (allDebridAccount == null) {
            return s38.a(new DebridError.NoAccount(DebridProvider.ALL_DEBRID));
        }
        try {
            long[] jArr4 = {0, 5000, 10000};
            authHeader = allDebridAccount.getAuthHeader();
            allDebridRepository2 = allDebridRepository;
            i = 3;
            jArr = jArr4;
            str3 = str2;
            r4 = z;
            if (r4 >= i) {
            }
        } catch (Exception e5) {
            e = e5;
            r9 = str2;
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:32:0x0088, code lost:
    
        if (r15 == r1) goto L33;
     */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0016  */
    @pq6
    /* JADX INFO: renamed from: deleteMagnet-gIAlu-s, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m68deleteMagnetgIAlus(long j, @kp6 Continuation<? super q38<e6a>> continuation) {
        AllDebridRepository$deleteMagnet$1 allDebridRepository$deleteMagnet$1;
        AllDebridRepository allDebridRepository;
        String message;
        if (continuation instanceof AllDebridRepository$deleteMagnet$1) {
            allDebridRepository$deleteMagnet$1 = (AllDebridRepository$deleteMagnet$1) continuation;
            int i = allDebridRepository$deleteMagnet$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                allDebridRepository$deleteMagnet$1.label = i - Integer.MIN_VALUE;
            } else {
                allDebridRepository$deleteMagnet$1 = new AllDebridRepository$deleteMagnet$1(this, continuation);
            }
        }
        AllDebridRepository$deleteMagnet$1 allDebridRepository$deleteMagnet$12 = allDebridRepository$deleteMagnet$1;
        Object account = allDebridRepository$deleteMagnet$12.result;
        ck1 ck1Var = ck1.a;
        int i2 = allDebridRepository$deleteMagnet$12.label;
        try {
            if (i2 == 0) {
                s38.b(account);
                AllDebridAccountDao allDebridAccountDao = this.accountDao;
                allDebridRepository$deleteMagnet$12.L$0 = this;
                allDebridRepository$deleteMagnet$12.J$0 = j;
                allDebridRepository$deleteMagnet$12.label = 1;
                account = allDebridAccountDao.getAccount("alldebrid", allDebridRepository$deleteMagnet$12);
                if (account != ck1Var) {
                    allDebridRepository = this;
                }
                return ck1Var;
            }
            if (i2 != 1) {
                if (i2 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(account);
                AllDebridResponse allDebridResponse = (AllDebridResponse) account;
                if (cr4.b(allDebridResponse.getStatus(), "success")) {
                    return e6a.a;
                }
                AllDebridError error = allDebridResponse.getError();
                if (error == null || (message = error.getMessage()) == null) {
                    message = "Failed to delete magnet";
                }
                Log.e(TAG, "Failed to delete magnet: ".concat(message));
                return s38.a(new Exception(message));
            }
            j = allDebridRepository$deleteMagnet$12.J$0;
            allDebridRepository = (AllDebridRepository) allDebridRepository$deleteMagnet$12.L$0;
            s38.b(account);
            long j2 = j;
            AllDebridAccount allDebridAccount = (AllDebridAccount) account;
            if (allDebridAccount == null) {
                return s38.a(new DebridError.NoAccount(DebridProvider.ALL_DEBRID));
            }
            String authHeader = allDebridAccount.getAuthHeader();
            AllDebridApiService allDebridApiService = allDebridRepository.allDebridApiService;
            allDebridRepository$deleteMagnet$12.L$0 = null;
            allDebridRepository$deleteMagnet$12.J$0 = j2;
            allDebridRepository$deleteMagnet$12.label = 2;
            account = AllDebridApiService.DefaultImpls.deleteMagnet$default(allDebridApiService, authHeader, j2, null, allDebridRepository$deleteMagnet$12, 4, null);
        } catch (HttpException e) {
            Log.e(TAG, "Failed to delete magnet: HTTP " + e.code(), e);
            return s38.a(new DebridError.Unknown(DebridProvider.ALL_DEBRID, n41.k("HTTP ", e.code()), e));
        } catch (Exception e2) {
            Log.e(TAG, "Failed to delete magnet", e2);
            return s38.a(new DebridError.Unknown(DebridProvider.ALL_DEBRID, e2.getMessage(), e2));
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:102:0x0324 A[Catch: Exception -> 0x0171, TryCatch #3 {Exception -> 0x0171, blocks: (B:100:0x031f, B:102:0x0324, B:104:0x033f, B:106:0x034b, B:108:0x0351, B:47:0x0127, B:48:0x014c, B:50:0x0154, B:52:0x016a, B:56:0x0174, B:57:0x01a4, B:58:0x01b9, B:60:0x01c3, B:62:0x01d0, B:64:0x01de, B:66:0x01e5, B:68:0x01ea, B:71:0x01fb, B:73:0x0220, B:74:0x0235, B:76:0x023b, B:79:0x024a, B:81:0x0254, B:83:0x025b, B:85:0x0261, B:87:0x0268, B:88:0x0278, B:90:0x0281, B:91:0x02a4, B:94:0x02ac, B:96:0x02d1, B:114:0x0375), top: B:120:0x0031 }] */
    /* JADX WARN: Removed duplicated region for block: B:104:0x033f A[Catch: Exception -> 0x0171, TryCatch #3 {Exception -> 0x0171, blocks: (B:100:0x031f, B:102:0x0324, B:104:0x033f, B:106:0x034b, B:108:0x0351, B:47:0x0127, B:48:0x014c, B:50:0x0154, B:52:0x016a, B:56:0x0174, B:57:0x01a4, B:58:0x01b9, B:60:0x01c3, B:62:0x01d0, B:64:0x01de, B:66:0x01e5, B:68:0x01ea, B:71:0x01fb, B:73:0x0220, B:74:0x0235, B:76:0x023b, B:79:0x024a, B:81:0x0254, B:83:0x025b, B:85:0x0261, B:87:0x0268, B:88:0x0278, B:90:0x0281, B:91:0x02a4, B:94:0x02ac, B:96:0x02d1, B:114:0x0375), top: B:120:0x0031 }] */
    /* JADX WARN: Removed duplicated region for block: B:41:0x00db A[Catch: Exception -> 0x0372, TRY_LEAVE, TryCatch #2 {Exception -> 0x0372, blocks: (B:39:0x00cd, B:41:0x00db, B:35:0x00c0), top: B:121:0x00c0 }] */
    /* JADX WARN: Removed duplicated region for block: B:8:0x001e  */
    /* JADX WARN: Type inference failed for: r7v0 */
    /* JADX WARN: Type inference failed for: r7v1 */
    /* JADX WARN: Type inference failed for: r7v5 */
    /* JADX WARN: Type inference failed for: r7v7 */
    @pq6
    /* JADX INFO: renamed from: deleteMostRecent-0E7RQCE, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m69deleteMostRecent0E7RQCE(long j, @pq6 String str, @kp6 Continuation<? super q38<e6a>> continuation) {
        AllDebridRepository$deleteMostRecent$1 allDebridRepository$deleteMostRecent$1;
        long j2;
        Object obj;
        String str2;
        AllDebridRepository allDebridRepository;
        String str3;
        String str4;
        AllDebridRepository allDebridRepository2;
        long j3;
        AllDebridResponse allDebridResponse;
        String str5;
        e6a e6aVar;
        String str6;
        AllDebridMagnetDetail allDebridMagnetDetail;
        Object obj2;
        if (continuation instanceof AllDebridRepository$deleteMostRecent$1) {
            allDebridRepository$deleteMostRecent$1 = (AllDebridRepository$deleteMostRecent$1) continuation;
            int i = allDebridRepository$deleteMostRecent$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                allDebridRepository$deleteMostRecent$1.label = i - Integer.MIN_VALUE;
            } else {
                allDebridRepository$deleteMostRecent$1 = new AllDebridRepository$deleteMostRecent$1(this, continuation);
            }
        }
        AllDebridRepository$deleteMostRecent$1 allDebridRepository$deleteMostRecent$12 = allDebridRepository$deleteMostRecent$1;
        Object obj3 = allDebridRepository$deleteMostRecent$12.result;
        ck1 ck1Var = ck1.a;
        int i2 = allDebridRepository$deleteMostRecent$12.label;
        e6a e6aVar2 = e6a.a;
        String str7 = 2;
        try {
            try {
                if (i2 == 0) {
                    s38.b(obj3);
                    AllDebridAccountDao allDebridAccountDao = this.accountDao;
                    allDebridRepository$deleteMostRecent$12.L$0 = this;
                    allDebridRepository$deleteMostRecent$12.L$1 = str;
                    j2 = j;
                    allDebridRepository$deleteMostRecent$12.J$0 = j2;
                    allDebridRepository$deleteMostRecent$12.label = 1;
                    Object account = allDebridAccountDao.getAccount("alldebrid", allDebridRepository$deleteMostRecent$12);
                    if (account != ck1Var) {
                        obj = account;
                        str2 = str;
                        allDebridRepository = this;
                    }
                    return ck1Var;
                }
                if (i2 != 1) {
                    if (i2 != 2) {
                        if (i2 != 3) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        allDebridMagnetDetail = (AllDebridMagnetDetail) allDebridRepository$deleteMostRecent$12.L$0;
                        s38.b(obj3);
                        obj2 = ((q38) obj3).a;
                        str5 = TAG;
                        e6aVar = e6aVar2;
                        str6 = null;
                        if (obj2 instanceof q38.b) {
                            ExecutorService executorService = kq.a;
                            kq.h(str5, "Cloud sanitization: removed AD magnet " + allDebridMagnetDetail.getId());
                            return e6aVar;
                        }
                        ExecutorService executorService2 = kq.a;
                        long id = allDebridMagnetDetail.getId();
                        Throwable thA = q38.a(obj2);
                        kq.h(str5, "Cloud sanitization: AD delete " + id + " failed: " + (thA != null ? thA.getMessage() : str6));
                        return e6aVar;
                    }
                    j3 = allDebridRepository$deleteMostRecent$12.J$0;
                    str4 = (String) allDebridRepository$deleteMostRecent$12.L$1;
                    allDebridRepository2 = (AllDebridRepository) allDebridRepository$deleteMostRecent$12.L$0;
                    s38.b(obj3);
                    str3 = TAG;
                    allDebridResponse = (AllDebridResponse) obj3;
                    if (cr4.b(allDebridResponse.getStatus(), "success")) {
                        if (allDebridResponse.getData() != null) {
                            String str8 = str3;
                            long j4 = 1000;
                            try {
                                long j5 = j3 / j4;
                                ExecutorService executorService3 = kq.a;
                                str5 = str8;
                                kq.h(str5, "Cloud sanitization: AD has " + ((AllDebridAllMagnetsData) allDebridResponse.getData()).getMagnets().size() + " magnets, resolveTimestamp=" + j3 + " (" + new Date(j3) + "), fileName=" + str4);
                                Iterator it = y41.bk(y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.AllDebridRepository$deleteMostRecent-0E7RQCE$$inlined$sortedByDescending$1
                                    /* JADX WARN: Multi-variable type inference failed */
                                    @Override // java.util.Comparator
                                    public final int compare(T t, T t2) {
                                        Long uploadDate = ((AllDebridMagnetDetail) t2).getUploadDate();
                                        Long lValueOf = Long.valueOf(uploadDate != null ? uploadDate.longValue() : 0L);
                                        Long uploadDate2 = ((AllDebridMagnetDetail) t).getUploadDate();
                                        return x71.b(lValueOf, Long.valueOf(uploadDate2 != null ? uploadDate2.longValue() : 0L));
                                    }
                                }, ((AllDebridAllMagnetsData) allDebridResponse.getData()).getMagnets()), 5).iterator();
                                while (true) {
                                    if (!it.hasNext()) {
                                        break;
                                    }
                                    AllDebridMagnetDetail allDebridMagnetDetail2 = (AllDebridMagnetDetail) it.next();
                                    ExecutorService executorService4 = kq.a;
                                    String filename = allDebridMagnetDetail2.getFilename();
                                    Long uploadDate = allDebridMagnetDetail2.getUploadDate();
                                    Long uploadDate2 = allDebridMagnetDetail2.getUploadDate();
                                    Iterator it2 = it;
                                    kq.h(str5, "Cloud sanitization: AD magnet '" + filename + "' uploadDate=" + uploadDate + " (diff=" + ((uploadDate2 != null ? uploadDate2.longValue() : 0L) - j5) + "s)");
                                    it = it2;
                                }
                                List<AllDebridMagnetDetail> magnets = ((AllDebridAllMagnetsData) allDebridResponse.getData()).getMagnets();
                                ArrayList arrayList = new ArrayList();
                                Iterator<T> it3 = magnets.iterator();
                                while (true) {
                                    e6aVar = e6aVar2;
                                    if (!it3.hasNext()) {
                                        break;
                                    }
                                    Object next = it3.next();
                                    Long uploadDate3 = ((AllDebridMagnetDetail) next).getUploadDate();
                                    if (uploadDate3 != null) {
                                        long jLongValue = uploadDate3.longValue();
                                        if (jLongValue - (j5 - (MediaSessionService.DEFAULT_FOREGROUND_SERVICE_TIMEOUT_MS / j4)) > 0 && jLongValue - j5 < MediaSessionService.DEFAULT_FOREGROUND_SERVICE_TIMEOUT_MS / j4) {
                                            arrayList.add(next);
                                        }
                                    }
                                    e6aVar2 = e6aVar;
                                }
                                List listBj = y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.AllDebridRepository$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(((AllDebridMagnetDetail) t2).getUploadDate(), ((AllDebridMagnetDetail) t).getUploadDate());
                                    }
                                }, arrayList);
                                if (listBj.isEmpty() && str4 != null) {
                                    ExecutorService executorService5 = kq.a;
                                    kq.h(str5, "Cloud sanitization: AD timestamp match failed, trying filename match for '" + str4 + "'");
                                    String strNormalizeForMatch = allDebridRepository2.normalizeForMatch(str4);
                                    if (strNormalizeForMatch.length() >= 8) {
                                        List<AllDebridMagnetDetail> magnets2 = ((AllDebridAllMagnetsData) allDebridResponse.getData()).getMagnets();
                                        ArrayList arrayList2 = new ArrayList();
                                        for (Object obj4 : magnets2) {
                                            String filename2 = ((AllDebridMagnetDetail) obj4).getFilename();
                                            if (filename2 == null) {
                                                filename2 = "";
                                            }
                                            String strNormalizeForMatch2 = allDebridRepository2.normalizeForMatch(filename2);
                                            if (strNormalizeForMatch2.length() >= 8 && (n89.l(strNormalizeForMatch2, strNormalizeForMatch, false) || n89.l(strNormalizeForMatch, strNormalizeForMatch2, false))) {
                                                arrayList2.add(obj4);
                                            }
                                        }
                                        listBj = y41.bk(y41.bj(new Comparator() { // from class: com.strmr.ps.data.repository.AllDebridRepository$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(((AllDebridMagnetDetail) t2).getUploadDate(), ((AllDebridMagnetDetail) t).getUploadDate());
                                            }
                                        }, arrayList2), 1);
                                    }
                                    if (!listBj.isEmpty()) {
                                        ExecutorService executorService6 = kq.a;
                                        kq.h(str5, "Cloud sanitization: AD filename match found: '" + ((AllDebridMagnetDetail) y41.z(listBj)).getFilename() + "'");
                                    }
                                }
                                if (listBj.isEmpty()) {
                                    ExecutorService executorService7 = kq.a;
                                    kq.h(str5, "Cloud sanitization: no matching AD magnet found (window=" + MediaSessionService.DEFAULT_FOREGROUND_SERVICE_TIMEOUT_MS + "ms, fileName=" + str4 + ")");
                                    return e6aVar;
                                }
                                AllDebridMagnetDetail allDebridMagnetDetail3 = (AllDebridMagnetDetail) y41.z(listBj);
                                ExecutorService executorService8 = kq.a;
                                kq.h(str5, "Cloud sanitization: deleting AD magnet " + allDebridMagnetDetail3.getId() + " (" + allDebridMagnetDetail3.getFilename() + ", uploadDate=" + allDebridMagnetDetail3.getUploadDate() + ")");
                                long id2 = allDebridMagnetDetail3.getId();
                                allDebridRepository$deleteMostRecent$12.L$0 = allDebridMagnetDetail3;
                                str6 = null;
                                allDebridRepository$deleteMostRecent$12.L$1 = null;
                                allDebridRepository$deleteMostRecent$12.label = 3;
                                Object objM68deleteMagnetgIAlus = allDebridRepository2.m68deleteMagnetgIAlus(id2, allDebridRepository$deleteMostRecent$12);
                                if (objM68deleteMagnetgIAlus != ck1Var) {
                                    allDebridMagnetDetail = allDebridMagnetDetail3;
                                    obj2 = objM68deleteMagnetgIAlus;
                                    if (obj2 instanceof q38.b) {
                                    }
                                }
                                return ck1Var;
                            } catch (Exception e) {
                                e = e;
                                str7 = str8;
                                ExecutorService executorService9 = kq.a;
                                kq.a(str7, "Cloud sanitization AD deleteMostRecent failed", e);
                                return s38.a(e);
                            }
                        }
                    }
                    String str9 = str3;
                    ExecutorService executorService10 = kq.a;
                    kq.h(str9, "Cloud sanitization: failed to list AD magnets for recency check");
                    return e6aVar2;
                }
                j2 = allDebridRepository$deleteMostRecent$12.J$0;
                String str10 = (String) allDebridRepository$deleteMostRecent$12.L$1;
                allDebridRepository = (AllDebridRepository) allDebridRepository$deleteMostRecent$12.L$0;
                s38.b(obj3);
                obj = obj3;
                str2 = str10;
                AllDebridAccount allDebridAccount = (AllDebridAccount) obj;
                if (allDebridAccount == null) {
                    return s38.a(new DebridError.NoAccount(DebridProvider.ALL_DEBRID));
                }
                String authHeader = allDebridAccount.getAuthHeader();
                AllDebridApiService allDebridApiService = allDebridRepository.allDebridApiService;
                allDebridRepository$deleteMostRecent$12.L$0 = allDebridRepository;
                allDebridRepository$deleteMostRecent$12.L$1 = str2;
                allDebridRepository$deleteMostRecent$12.J$0 = j2;
                allDebridRepository$deleteMostRecent$12.label = 2;
                long j6 = j2;
                str3 = TAG;
                try {
                    Object allMagnets$default = AllDebridApiService.DefaultImpls.getAllMagnets$default(allDebridApiService, authHeader, null, allDebridRepository$deleteMostRecent$12, 2, null);
                    if (allMagnets$default == ck1Var) {
                        return ck1Var;
                    }
                    str4 = str2;
                    obj3 = allMagnets$default;
                    allDebridRepository2 = allDebridRepository;
                    j3 = j6;
                    allDebridResponse = (AllDebridResponse) obj3;
                    if (cr4.b(allDebridResponse.getStatus(), "success")) {
                    }
                    String str92 = str3;
                    ExecutorService executorService102 = kq.a;
                    kq.h(str92, "Cloud sanitization: failed to list AD magnets for recency check");
                    return e6aVar2;
                } catch (Exception e2) {
                    e = e2;
                    str7 = str3;
                    ExecutorService executorService92 = kq.a;
                    kq.a(str7, "Cloud sanitization AD deleteMostRecent failed", e);
                    return s38.a(e);
                }
            } catch (Exception e3) {
                e = e3;
                str7 = TAG;
            }
        } catch (Exception e4) {
            e = e4;
        }
    }

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

    /* 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) {
        C02801 c02801;
        Long premiumUntil;
        if (continuation instanceof C02801) {
            c02801 = (C02801) continuation;
            int i = c02801.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c02801.label = i - Integer.MIN_VALUE;
            } else {
                c02801 = new C02801(continuation);
            }
        }
        Object account = c02801.result;
        ck1 ck1Var = ck1.a;
        int i2 = c02801.label;
        if (i2 == 0) {
            s38.b(account);
            AllDebridAccountDao allDebridAccountDao = this.accountDao;
            c02801.label = 1;
            account = allDebridAccountDao.getAccount("alldebrid", c02801);
            if (account == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(account);
        }
        AllDebridAccount allDebridAccount = (AllDebridAccount) account;
        if (allDebridAccount != null && (premiumUntil = allDebridAccount.getPremiumUntil()) != null) {
            long jLongValue = premiumUntil.longValue();
            long jCurrentTimeMillis = System.currentTimeMillis() / ((long) 1000);
            if (jLongValue <= jCurrentTimeMillis) {
                return Boxing.boxInt((int) ((jCurrentTimeMillis - jLongValue) / ((long) 86400)));
            }
        }
        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) {
        C02811 c02811;
        if (continuation instanceof C02811) {
            c02811 = (C02811) continuation;
            int i = c02811.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c02811.label = i - Integer.MIN_VALUE;
            } else {
                c02811 = new C02811(continuation);
            }
        }
        Object account = c02811.result;
        ck1 ck1Var = ck1.a;
        int i2 = c02811.label;
        if (i2 == 0) {
            s38.b(account);
            AllDebridAccountDao allDebridAccountDao = this.accountDao;
            c02811.label = 1;
            account = allDebridAccountDao.getAccount("alldebrid", c02811);
            if (account == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(account);
        }
        AllDebridAccount allDebridAccount = (AllDebridAccount) account;
        if (allDebridAccount != null) {
            return allDebridAccount.getApiKey();
        }
        return null;
    }

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

    /* JADX WARN: Code restructure failed: missing block: B:31:0x007e, code lost:
    
        if (r0 == r2) goto L32;
     */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0018  */
    @Override // com.strmr.ps.data.repository.IDebridLibraryProvider
    @pq6
    /* JADX INFO: renamed from: getLibraryItems-IoAF18A, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object mo70getLibraryItemsIoAF18A(@kp6 Continuation<? super q38<? extends List<? extends DebridFileItem>>> continuation) {
        AllDebridRepository$getLibraryItems$1 allDebridRepository$getLibraryItems$1;
        AllDebridRepository allDebridRepository;
        String message;
        if (continuation instanceof AllDebridRepository$getLibraryItems$1) {
            allDebridRepository$getLibraryItems$1 = (AllDebridRepository$getLibraryItems$1) continuation;
            int i = allDebridRepository$getLibraryItems$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                allDebridRepository$getLibraryItems$1.label = i - Integer.MIN_VALUE;
            } else {
                allDebridRepository$getLibraryItems$1 = new AllDebridRepository$getLibraryItems$1(this, continuation);
            }
        }
        AllDebridRepository$getLibraryItems$1 allDebridRepository$getLibraryItems$12 = allDebridRepository$getLibraryItems$1;
        Object account = allDebridRepository$getLibraryItems$12.result;
        ck1 ck1Var = ck1.a;
        int i2 = allDebridRepository$getLibraryItems$12.label;
        try {
            if (i2 == 0) {
                s38.b(account);
                AllDebridAccountDao allDebridAccountDao = this.accountDao;
                allDebridRepository$getLibraryItems$12.L$0 = this;
                allDebridRepository$getLibraryItems$12.label = 1;
                account = allDebridAccountDao.getAccount("alldebrid", allDebridRepository$getLibraryItems$12);
                if (account != ck1Var) {
                    allDebridRepository = this;
                }
                return ck1Var;
            }
            if (i2 != 1) {
                if (i2 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(account);
                AllDebridResponse allDebridResponse = (AllDebridResponse) account;
                if (cr4.b(allDebridResponse.getStatus(), "success") && allDebridResponse.getData() != null) {
                    int size = ((AllDebridAllMagnetsData) allDebridResponse.getData()).getMagnets().size();
                    List<AllDebridMagnetDetail> magnets = ((AllDebridAllMagnetsData) allDebridResponse.getData()).getMagnets();
                    LinkedHashMap linkedHashMap = new LinkedHashMap();
                    for (Object obj : magnets) {
                        String status = ((AllDebridMagnetDetail) obj).getStatus();
                        Object arrayList = linkedHashMap.get(status);
                        if (arrayList == null) {
                            arrayList = new ArrayList();
                            linkedHashMap.put(status, 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()));
                    }
                    List<AllDebridMagnetDetail> magnets2 = ((AllDebridAllMagnetsData) allDebridResponse.getData()).getMagnets();
                    ArrayList<AllDebridMagnetDetail> arrayList2 = new ArrayList();
                    for (Object obj3 : magnets2) {
                        if (cr4.b(((AllDebridMagnetDetail) obj3).getStatus(), "Ready")) {
                            arrayList2.add(obj3);
                        }
                    }
                    ArrayList arrayList3 = new ArrayList(y41.p(arrayList2, 10));
                    for (AllDebridMagnetDetail allDebridMagnetDetail : arrayList2) {
                        String strValueOf = String.valueOf(allDebridMagnetDetail.getId());
                        String filename = allDebridMagnetDetail.getFilename();
                        String displayName = DebridService.INSTANCE.getDisplayName("alldebrid");
                        List<AllDebridMagnetLink> links = allDebridMagnetDetail.getLinks();
                        arrayList3.add(new DebridFileItem.Folder(strValueOf, filename, "alldebrid", displayName, links != null ? Boxing.boxInt(links.size()) : null, null, String.valueOf(allDebridMagnetDetail.getId()), 32, null));
                    }
                    ExecutorService executorService = kq.a;
                    kq.h(TAG, "Library: " + arrayList3.size() + " ready of " + size + " total magnets (statuses: " + linkedHashMap2 + ")");
                    return arrayList3;
                }
                AllDebridError error = allDebridResponse.getError();
                if (error == null || (message = error.getMessage()) == null) {
                    message = "Failed to get magnets";
                }
                return s38.a(new Exception(message));
            }
            allDebridRepository = (AllDebridRepository) allDebridRepository$getLibraryItems$12.L$0;
            s38.b(account);
            AllDebridAccount allDebridAccount = (AllDebridAccount) account;
            if (allDebridAccount == null) {
                return s38.a(new DebridError.NoAccount(DebridProvider.ALL_DEBRID));
            }
            String authHeader = allDebridAccount.getAuthHeader();
            AllDebridApiService allDebridApiService = allDebridRepository.allDebridApiService;
            allDebridRepository$getLibraryItems$12.L$0 = null;
            allDebridRepository$getLibraryItems$12.label = 2;
            account = AllDebridApiService.DefaultImpls.getAllMagnets$default(allDebridApiService, authHeader, null, allDebridRepository$getLibraryItems$12, 2, null);
        } catch (HttpException e) {
            ExecutorService executorService2 = kq.a;
            kq.a(TAG, "Failed to get library items: HTTP " + e.code(), e);
            return s38.a(new DebridError.Unknown(DebridProvider.ALL_DEBRID, n41.k("HTTP ", e.code()), e));
        } catch (Exception e2) {
            ExecutorService executorService3 = kq.a;
            kq.a(TAG, "Failed to get library items", e2);
            return s38.a(new DebridError.Unknown(DebridProvider.ALL_DEBRID, e2.getMessage(), e2));
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:42:0x00bc A[Catch: Exception -> 0x0034, HttpException -> 0x0038, TryCatch #2 {HttpException -> 0x0038, Exception -> 0x0034, blocks: (B:14:0x0030, B:35:0x0094, B:37:0x00a2, B:40:0x00aa, B:42:0x00bc, B:44:0x00c8, B:46:0x00df, B:64:0x0113, B:49:0x00e9, B:50:0x00ed, B:52:0x00f3, B:54:0x00fe, B:57:0x0104, B:59:0x010a, B:62:0x010f, B:63:0x0112, B:66:0x0143, B:68:0x014b, B:71:0x0153, B:31:0x0074), top: B:76:0x0024 }] */
    /* JADX WARN: Removed duplicated region for block: B:44:0x00c8 A[Catch: Exception -> 0x0034, HttpException -> 0x0038, TryCatch #2 {HttpException -> 0x0038, Exception -> 0x0034, blocks: (B:14:0x0030, B:35:0x0094, B:37:0x00a2, B:40:0x00aa, B:42:0x00bc, B:44:0x00c8, B:46:0x00df, B:64:0x0113, B:49:0x00e9, B:50:0x00ed, B:52:0x00f3, B:54:0x00fe, B:57:0x0104, B:59:0x010a, B:62:0x010f, B:63:0x0112, B:66:0x0143, B:68:0x014b, B:71:0x0153, B:31:0x0074), top: B:76:0x0024 }] */
    /* JADX WARN: Removed duplicated region for block: B:70:0x0151  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0014  */
    @pq6
    /* JADX INFO: renamed from: getMagnetFilesForLibrary-gIAlu-s, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m71getMagnetFilesForLibrarygIAlus(long j, @kp6 Continuation<? super q38<? extends List<? extends DebridFileItem>>> continuation) {
        AllDebridRepository$getMagnetFilesForLibrary$1 allDebridRepository$getMagnetFilesForLibrary$1;
        AllDebridRepository allDebridRepository;
        AllDebridRepository allDebridRepository2;
        AllDebridResponse allDebridResponse;
        AllDebridError error;
        String message;
        AllDebridMagnetFilesEntry allDebridMagnetFilesEntry;
        if (continuation instanceof AllDebridRepository$getMagnetFilesForLibrary$1) {
            allDebridRepository$getMagnetFilesForLibrary$1 = (AllDebridRepository$getMagnetFilesForLibrary$1) continuation;
            int i = allDebridRepository$getMagnetFilesForLibrary$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                allDebridRepository$getMagnetFilesForLibrary$1.label = i - Integer.MIN_VALUE;
            } else {
                allDebridRepository$getMagnetFilesForLibrary$1 = new AllDebridRepository$getMagnetFilesForLibrary$1(this, continuation);
            }
        }
        AllDebridRepository$getMagnetFilesForLibrary$1 allDebridRepository$getMagnetFilesForLibrary$12 = allDebridRepository$getMagnetFilesForLibrary$1;
        Object account = allDebridRepository$getMagnetFilesForLibrary$12.result;
        ck1 ck1Var = ck1.a;
        int i2 = allDebridRepository$getMagnetFilesForLibrary$12.label;
        try {
            if (i2 == 0) {
                s38.b(account);
                AllDebridAccountDao allDebridAccountDao = this.accountDao;
                allDebridRepository$getMagnetFilesForLibrary$12.L$0 = this;
                allDebridRepository$getMagnetFilesForLibrary$12.J$0 = j;
                allDebridRepository$getMagnetFilesForLibrary$12.label = 1;
                account = allDebridAccountDao.getAccount("alldebrid", allDebridRepository$getMagnetFilesForLibrary$12);
                if (account != ck1Var) {
                    allDebridRepository = this;
                }
                return ck1Var;
            }
            if (i2 != 1) {
                if (i2 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                j = allDebridRepository$getMagnetFilesForLibrary$12.J$0;
                allDebridRepository2 = (AllDebridRepository) allDebridRepository$getMagnetFilesForLibrary$12.L$0;
                s38.b(account);
                allDebridResponse = (AllDebridResponse) account;
                if (cr4.b(allDebridResponse.getStatus(), "success") && allDebridResponse.getData() != null) {
                    allDebridMagnetFilesEntry = (AllDebridMagnetFilesEntry) y41.ab(((AllDebridMagnetFilesData) allDebridResponse.getData()).getMagnets());
                    if (allDebridMagnetFilesEntry != null) {
                        return s38.a(new Exception("No files in response"));
                    }
                    List listFlattenFileTreeToDebridItems$default = flattenFileTreeToDebridItems$default(allDebridRepository2, allDebridMagnetFilesEntry.getFiles(), String.valueOf(j), null, 4, null);
                    List<DebridFileItem> list = listFlattenFileTreeToDebridItems$default;
                    int i3 = 0;
                    if (!(list instanceof Collection) || !list.isEmpty()) {
                        for (DebridFileItem debridFileItem : list) {
                            DebridFileItem.File file = debridFileItem instanceof DebridFileItem.File ? (DebridFileItem.File) debridFileItem : null;
                            if (file != null && file.isVideo() && (i3 = i3 + 1) < 0) {
                                y41.bl();
                                throw null;
                            }
                        }
                    }
                    ExecutorService executorService = kq.a;
                    kq.h(TAG, "Magnet " + j + ": " + listFlattenFileTreeToDebridItems$default.size() + " files (" + i3 + " video)");
                    return listFlattenFileTreeToDebridItems$default;
                }
                error = allDebridResponse.getError();
                if (error != null || (message = error.getMessage()) == null) {
                    message = "Failed to get files";
                }
                return s38.a(new Exception(message));
            }
            j = allDebridRepository$getMagnetFilesForLibrary$12.J$0;
            AllDebridRepository allDebridRepository3 = (AllDebridRepository) allDebridRepository$getMagnetFilesForLibrary$12.L$0;
            s38.b(account);
            allDebridRepository = allDebridRepository3;
            AllDebridAccount allDebridAccount = (AllDebridAccount) account;
            if (allDebridAccount == null) {
                return s38.a(new DebridError.NoAccount(DebridProvider.ALL_DEBRID));
            }
            String authHeader = allDebridAccount.getAuthHeader();
            AllDebridApiService allDebridApiService = allDebridRepository.allDebridApiService;
            List listAm = y41.am(Boxing.boxLong(j));
            allDebridRepository$getMagnetFilesForLibrary$12.L$0 = allDebridRepository;
            allDebridRepository$getMagnetFilesForLibrary$12.J$0 = j;
            allDebridRepository$getMagnetFilesForLibrary$12.label = 2;
            account = AllDebridApiService.DefaultImpls.getMagnetFiles$default(allDebridApiService, authHeader, listAm, null, allDebridRepository$getMagnetFilesForLibrary$12, 4, null);
            if (account != ck1Var) {
                allDebridRepository2 = allDebridRepository;
                allDebridResponse = (AllDebridResponse) account;
                if (cr4.b(allDebridResponse.getStatus(), "success")) {
                    allDebridMagnetFilesEntry = (AllDebridMagnetFilesEntry) y41.ab(((AllDebridMagnetFilesData) allDebridResponse.getData()).getMagnets());
                    if (allDebridMagnetFilesEntry != null) {
                    }
                }
                error = allDebridResponse.getError();
                if (error != null) {
                    message = "Failed to get files";
                }
                return s38.a(new Exception(message));
            }
            return ck1Var;
        } catch (HttpException e) {
            ExecutorService executorService2 = kq.a;
            kq.a(TAG, "Failed to get magnet files: HTTP " + e.code(), e);
            return s38.a(new DebridError.Unknown(DebridProvider.ALL_DEBRID, n41.k("HTTP ", e.code()), e));
        } catch (Exception e2) {
            ExecutorService executorService3 = kq.a;
            kq.a(TAG, "Failed to get magnet files", e2);
            return s38.a(new DebridError.Unknown(DebridProvider.ALL_DEBRID, e2.getMessage(), e2));
        }
    }

    @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: 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) {
        C02821 c02821;
        if (continuation instanceof C02821) {
            c02821 = (C02821) continuation;
            int i = c02821.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                c02821.label = i - Integer.MIN_VALUE;
            } else {
                c02821 = new C02821(continuation);
            }
        }
        Object account = c02821.result;
        ck1 ck1Var = ck1.a;
        int i2 = c02821.label;
        if (i2 == 0) {
            s38.b(account);
            AllDebridAccountDao allDebridAccountDao = this.accountDao;
            c02821.label = 1;
            account = allDebridAccountDao.getAccount("alldebrid", c02821);
            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:8:0x0014  */
    @pq6
    /* JADX INFO: renamed from: pollForApiKey-0E7RQCE, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m72pollForApiKey0E7RQCE(@kp6 String str, @kp6 String str2, @kp6 Continuation<? super q38<String>> continuation) {
        AllDebridRepository$pollForApiKey$1 allDebridRepository$pollForApiKey$1;
        String message;
        if (continuation instanceof AllDebridRepository$pollForApiKey$1) {
            allDebridRepository$pollForApiKey$1 = (AllDebridRepository$pollForApiKey$1) continuation;
            int i = allDebridRepository$pollForApiKey$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                allDebridRepository$pollForApiKey$1.label = i - Integer.MIN_VALUE;
            } else {
                allDebridRepository$pollForApiKey$1 = new AllDebridRepository$pollForApiKey$1(this, continuation);
            }
        }
        AllDebridRepository$pollForApiKey$1 allDebridRepository$pollForApiKey$12 = allDebridRepository$pollForApiKey$1;
        Object objCheckPinStatus$default = allDebridRepository$pollForApiKey$12.result;
        ck1 ck1Var = ck1.a;
        int i2 = allDebridRepository$pollForApiKey$12.label;
        try {
            if (i2 == 0) {
                s38.b(objCheckPinStatus$default);
                AllDebridApiService allDebridApiService = this.allDebridApiService;
                allDebridRepository$pollForApiKey$12.label = 1;
                objCheckPinStatus$default = AllDebridApiService.DefaultImpls.checkPinStatus$default(allDebridApiService, null, str2, str, allDebridRepository$pollForApiKey$12, 1, null);
                if (objCheckPinStatus$default == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i2 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(objCheckPinStatus$default);
            }
            AllDebridResponse allDebridResponse = (AllDebridResponse) objCheckPinStatus$default;
            if (!cr4.b(allDebridResponse.getStatus(), "success") || allDebridResponse.getData() == null) {
                AllDebridError error = allDebridResponse.getError();
                if (error == null || (message = error.getMessage()) == null) {
                    message = "Unknown error";
                }
                AllDebridError error2 = allDebridResponse.getError();
                if (cr4.b(error2 != null ? error2.getCode() : null, "PIN_NOT_ACTIVATED")) {
                    return null;
                }
                return s38.a(new Exception(message));
            }
            AllDebridPinCheckData allDebridPinCheckData = (AllDebridPinCheckData) allDebridResponse.getData();
            if (!allDebridPinCheckData.getActivated() || allDebridPinCheckData.getApikey() == null) {
                allDebridPinCheckData.getExpiresIn();
                return null;
            }
            ExecutorService executorService = kq.a;
            kq.h(TAG, "API key received successfully");
            return allDebridPinCheckData.getApikey();
        } catch (Exception e) {
            Log.e(TAG, "Failed to poll for API key", e);
            return s38.a(e);
        }
    }

    /* 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 m73refreshAccountInfoIoAF18A(@kp6 Continuation<? super q38<AllDebridAccount>> continuation) {
        AllDebridRepository$refreshAccountInfo$1 allDebridRepository$refreshAccountInfo$1;
        AllDebridRepository allDebridRepository;
        if (continuation instanceof AllDebridRepository$refreshAccountInfo$1) {
            allDebridRepository$refreshAccountInfo$1 = (AllDebridRepository$refreshAccountInfo$1) continuation;
            int i = allDebridRepository$refreshAccountInfo$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                allDebridRepository$refreshAccountInfo$1.label = i - Integer.MIN_VALUE;
            } else {
                allDebridRepository$refreshAccountInfo$1 = new AllDebridRepository$refreshAccountInfo$1(this, continuation);
            }
        }
        Object account = allDebridRepository$refreshAccountInfo$1.result;
        ck1 ck1Var = ck1.a;
        int i2 = allDebridRepository$refreshAccountInfo$1.label;
        if (i2 == 0) {
            s38.b(account);
            AllDebridAccountDao allDebridAccountDao = this.accountDao;
            allDebridRepository$refreshAccountInfo$1.L$0 = this;
            allDebridRepository$refreshAccountInfo$1.label = 1;
            account = allDebridAccountDao.getAccount("alldebrid", allDebridRepository$refreshAccountInfo$1);
            if (account != ck1Var) {
                allDebridRepository = this;
            }
        }
        if (i2 != 1) {
            if (i2 != 2) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(account);
            return ((q38) account).a;
        }
        allDebridRepository = (AllDebridRepository) allDebridRepository$refreshAccountInfo$1.L$0;
        s38.b(account);
        AllDebridAccount allDebridAccount = (AllDebridAccount) account;
        if (allDebridAccount == null) {
            return vw2.d("No AllDebrid account configured");
        }
        String apiKey = allDebridAccount.getApiKey();
        allDebridRepository$refreshAccountInfo$1.L$0 = null;
        allDebridRepository$refreshAccountInfo$1.label = 2;
        Object objM77saveApiKeygIAlus = allDebridRepository.m77saveApiKeygIAlus(apiKey, allDebridRepository$refreshAccountInfo$1);
        return objM77saveApiKeygIAlus == ck1Var ? ck1Var : objM77saveApiKeygIAlus;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0017  */
    @pq6
    /* JADX INFO: renamed from: requestPinCode-IoAF18A, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m74requestPinCodeIoAF18A(@kp6 Continuation<? super q38<AllDebridPinData>> continuation) {
        AllDebridRepository$requestPinCode$1 allDebridRepository$requestPinCode$1;
        String message;
        if (continuation instanceof AllDebridRepository$requestPinCode$1) {
            allDebridRepository$requestPinCode$1 = (AllDebridRepository$requestPinCode$1) continuation;
            int i = allDebridRepository$requestPinCode$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                allDebridRepository$requestPinCode$1.label = i - Integer.MIN_VALUE;
            } else {
                allDebridRepository$requestPinCode$1 = new AllDebridRepository$requestPinCode$1(this, continuation);
            }
        }
        Object pinCode$default = allDebridRepository$requestPinCode$1.result;
        ck1 ck1Var = ck1.a;
        int i2 = allDebridRepository$requestPinCode$1.label;
        try {
            if (i2 == 0) {
                s38.b(pinCode$default);
                AllDebridApiService allDebridApiService = this.allDebridApiService;
                allDebridRepository$requestPinCode$1.label = 1;
                pinCode$default = AllDebridApiService.DefaultImpls.getPinCode$default(allDebridApiService, null, allDebridRepository$requestPinCode$1, 1, null);
                if (pinCode$default == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i2 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(pinCode$default);
            }
            AllDebridResponse allDebridResponse = (AllDebridResponse) pinCode$default;
            if (!cr4.b(allDebridResponse.getStatus(), "success") || allDebridResponse.getData() == null) {
                AllDebridError error = allDebridResponse.getError();
                if (error == null || (message = error.getMessage()) == null) {
                    message = "Failed to get PIN code";
                }
                Log.w(TAG, "PIN request failed: ".concat(message));
                return s38.a(new Exception(message));
            }
            ExecutorService executorService = kq.a;
            kq.h(TAG, "PIN code requested: " + ((AllDebridPinData) allDebridResponse.getData()).getPin());
            return allDebridResponse.getData();
        } catch (Exception e) {
            Log.e(TAG, "Failed to request PIN code", e);
            return s38.a(e);
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:36:0x009f, code lost:
    
        if (r13 == r1) goto L37;
     */
    /* 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, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object mo75resolveLibraryFilegIAlus(@kp6 DebridFileItem.File file, @kp6 Continuation<? super q38<String>> continuation) {
        AllDebridRepository$resolveLibraryFile$1 allDebridRepository$resolveLibraryFile$1;
        AllDebridRepository allDebridRepository;
        String message;
        if (continuation instanceof AllDebridRepository$resolveLibraryFile$1) {
            allDebridRepository$resolveLibraryFile$1 = (AllDebridRepository$resolveLibraryFile$1) continuation;
            int i = allDebridRepository$resolveLibraryFile$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                allDebridRepository$resolveLibraryFile$1.label = i - Integer.MIN_VALUE;
            } else {
                allDebridRepository$resolveLibraryFile$1 = new AllDebridRepository$resolveLibraryFile$1(this, continuation);
            }
        }
        AllDebridRepository$resolveLibraryFile$1 allDebridRepository$resolveLibraryFile$12 = allDebridRepository$resolveLibraryFile$1;
        Object account = allDebridRepository$resolveLibraryFile$12.result;
        ck1 ck1Var = ck1.a;
        int i2 = allDebridRepository$resolveLibraryFile$12.label;
        try {
            if (i2 == 0) {
                s38.b(account);
                AllDebridAccountDao allDebridAccountDao = this.accountDao;
                allDebridRepository$resolveLibraryFile$12.L$0 = this;
                allDebridRepository$resolveLibraryFile$12.L$1 = file;
                allDebridRepository$resolveLibraryFile$12.label = 1;
                account = allDebridAccountDao.getAccount("alldebrid", allDebridRepository$resolveLibraryFile$12);
                if (account != ck1Var) {
                    allDebridRepository = this;
                }
                return ck1Var;
            }
            if (i2 != 1) {
                if (i2 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                file = (DebridFileItem.File) allDebridRepository$resolveLibraryFile$12.L$0;
                s38.b(account);
                AllDebridResponse allDebridResponse = (AllDebridResponse) account;
                if (!cr4.b(allDebridResponse.getStatus(), "success") || allDebridResponse.getData() == null) {
                    AllDebridError error = allDebridResponse.getError();
                    if (error == null || (message = error.getMessage()) == null) {
                        message = "Failed to unlock link";
                    }
                    return s38.a(new Exception(message));
                }
                ExecutorService executorService = kq.a;
                kq.h(TAG, "Resolved library file: " + file.getName());
                return ((AllDebridUnlockData) allDebridResponse.getData()).getLink();
            }
            file = (DebridFileItem.File) allDebridRepository$resolveLibraryFile$12.L$1;
            allDebridRepository = (AllDebridRepository) allDebridRepository$resolveLibraryFile$12.L$0;
            s38.b(account);
            AllDebridAccount allDebridAccount = (AllDebridAccount) account;
            if (allDebridAccount == null) {
                return s38.a(new DebridError.NoAccount(DebridProvider.ALL_DEBRID));
            }
            String streamUrl = file.getStreamUrl();
            if (streamUrl == null) {
                return s38.a(new Exception("No link available for file"));
            }
            String authHeader = allDebridAccount.getAuthHeader();
            AllDebridApiService allDebridApiService = allDebridRepository.allDebridApiService;
            allDebridRepository$resolveLibraryFile$12.L$0 = file;
            allDebridRepository$resolveLibraryFile$12.L$1 = null;
            allDebridRepository$resolveLibraryFile$12.label = 2;
            account = AllDebridApiService.DefaultImpls.unlockLink$default(allDebridApiService, authHeader, streamUrl, null, null, allDebridRepository$resolveLibraryFile$12, 12, null);
        } catch (HttpException e) {
            ExecutorService executorService2 = kq.a;
            kq.a(TAG, "Failed to resolve library file: HTTP " + e.code(), e);
            return s38.a(new DebridError.Unknown(DebridProvider.ALL_DEBRID, n41.k("HTTP ", e.code()), e));
        } catch (Exception e2) {
            ExecutorService executorService3 = kq.a;
            kq.a(TAG, "Failed to resolve library file", e2);
            return s38.a(new DebridError.Unknown(DebridProvider.ALL_DEBRID, e2.getMessage(), e2));
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:101:0x02e5  */
    /* JADX WARN: Removed duplicated region for block: B:107:0x032f  */
    /* JADX WARN: Removed duplicated region for block: B:108:0x0331  */
    /* JADX WARN: Removed duplicated region for block: B:116:0x035f A[Catch: Exception -> 0x0063, UnknownHostException -> 0x0066, SocketTimeoutException -> 0x0069, HttpException -> 0x006c, TryCatch #4 {SocketTimeoutException -> 0x0069, UnknownHostException -> 0x0066, HttpException -> 0x006c, Exception -> 0x0063, blocks: (B:232:0x06e0, B:231:0x06c9, B:19:0x0057, B:217:0x063a, B:219:0x0649, B:221:0x064f, B:233:0x06ec, B:235:0x06f2, B:240:0x06fe, B:242:0x0707, B:245:0x0710, B:247:0x0718, B:250:0x0721, B:253:0x073d, B:251:0x072c, B:252:0x0735, B:30:0x0089, B:109:0x0339, B:111:0x0345, B:114:0x034d, B:116:0x035f, B:118:0x036b, B:120:0x0379, B:122:0x0385, B:123:0x03a8, B:127:0x03b4, B:129:0x03c8, B:132:0x03d4, B:133:0x03d8, B:135:0x03de, B:137:0x03fb, B:140:0x040e, B:143:0x045e, B:145:0x0468, B:147:0x047b, B:150:0x0485, B:151:0x0489, B:153:0x048f, B:155:0x04ac, B:161:0x04d9, B:163:0x04e0, B:164:0x04ef, B:166:0x04f5, B:167:0x0503, B:170:0x0513, B:171:0x0517, B:173:0x051d, B:177:0x0530, B:179:0x0534, B:183:0x0589, B:195:0x05be, B:197:0x05c2, B:209:0x05fa, B:211:0x05fe, B:200:0x05d1, B:203:0x05dc, B:204:0x05e3, B:207:0x05f4, B:186:0x0595, B:189:0x05a0, B:190:0x05a7, B:193:0x05b8, B:181:0x055b, B:213:0x060a, B:254:0x0743, B:256:0x074b, B:259:0x0753, B:33:0x00b0, B:86:0x0299, B:88:0x02a5, B:91:0x02ac, B:93:0x02c2, B:105:0x0301, B:97:0x02d7, B:99:0x02df, B:102:0x02e7, B:36:0x00d8, B:65:0x0207, B:67:0x0213, B:70:0x021b, B:72:0x022d, B:74:0x0239, B:76:0x023f, B:78:0x0251, B:80:0x0257, B:82:0x0261, B:261:0x075b, B:263:0x0767, B:265:0x076f, B:268:0x0777, B:57:0x01bc, B:61:0x01cd, B:60:0x01c9), top: B:289:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:118:0x036b A[Catch: Exception -> 0x0063, UnknownHostException -> 0x0066, SocketTimeoutException -> 0x0069, HttpException -> 0x006c, TryCatch #4 {SocketTimeoutException -> 0x0069, UnknownHostException -> 0x0066, HttpException -> 0x006c, Exception -> 0x0063, blocks: (B:232:0x06e0, B:231:0x06c9, B:19:0x0057, B:217:0x063a, B:219:0x0649, B:221:0x064f, B:233:0x06ec, B:235:0x06f2, B:240:0x06fe, B:242:0x0707, B:245:0x0710, B:247:0x0718, B:250:0x0721, B:253:0x073d, B:251:0x072c, B:252:0x0735, B:30:0x0089, B:109:0x0339, B:111:0x0345, B:114:0x034d, B:116:0x035f, B:118:0x036b, B:120:0x0379, B:122:0x0385, B:123:0x03a8, B:127:0x03b4, B:129:0x03c8, B:132:0x03d4, B:133:0x03d8, B:135:0x03de, B:137:0x03fb, B:140:0x040e, B:143:0x045e, B:145:0x0468, B:147:0x047b, B:150:0x0485, B:151:0x0489, B:153:0x048f, B:155:0x04ac, B:161:0x04d9, B:163:0x04e0, B:164:0x04ef, B:166:0x04f5, B:167:0x0503, B:170:0x0513, B:171:0x0517, B:173:0x051d, B:177:0x0530, B:179:0x0534, B:183:0x0589, B:195:0x05be, B:197:0x05c2, B:209:0x05fa, B:211:0x05fe, B:200:0x05d1, B:203:0x05dc, B:204:0x05e3, B:207:0x05f4, B:186:0x0595, B:189:0x05a0, B:190:0x05a7, B:193:0x05b8, B:181:0x055b, B:213:0x060a, B:254:0x0743, B:256:0x074b, B:259:0x0753, B:33:0x00b0, B:86:0x0299, B:88:0x02a5, B:91:0x02ac, B:93:0x02c2, B:105:0x0301, B:97:0x02d7, B:99:0x02df, B:102:0x02e7, B:36:0x00d8, B:65:0x0207, B:67:0x0213, B:70:0x021b, B:72:0x022d, B:74:0x0239, B:76:0x023f, B:78:0x0251, B:80:0x0257, B:82:0x0261, B:261:0x075b, B:263:0x0767, B:265:0x076f, B:268:0x0777, B:57:0x01bc, B:61:0x01cd, B:60:0x01c9), top: B:289:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:159:0x04d5  */
    /* JADX WARN: Removed duplicated region for block: B:183:0x0589 A[Catch: Exception -> 0x0063, UnknownHostException -> 0x0066, SocketTimeoutException -> 0x0069, HttpException -> 0x006c, TryCatch #4 {SocketTimeoutException -> 0x0069, UnknownHostException -> 0x0066, HttpException -> 0x006c, Exception -> 0x0063, blocks: (B:232:0x06e0, B:231:0x06c9, B:19:0x0057, B:217:0x063a, B:219:0x0649, B:221:0x064f, B:233:0x06ec, B:235:0x06f2, B:240:0x06fe, B:242:0x0707, B:245:0x0710, B:247:0x0718, B:250:0x0721, B:253:0x073d, B:251:0x072c, B:252:0x0735, B:30:0x0089, B:109:0x0339, B:111:0x0345, B:114:0x034d, B:116:0x035f, B:118:0x036b, B:120:0x0379, B:122:0x0385, B:123:0x03a8, B:127:0x03b4, B:129:0x03c8, B:132:0x03d4, B:133:0x03d8, B:135:0x03de, B:137:0x03fb, B:140:0x040e, B:143:0x045e, B:145:0x0468, B:147:0x047b, B:150:0x0485, B:151:0x0489, B:153:0x048f, B:155:0x04ac, B:161:0x04d9, B:163:0x04e0, B:164:0x04ef, B:166:0x04f5, B:167:0x0503, B:170:0x0513, B:171:0x0517, B:173:0x051d, B:177:0x0530, B:179:0x0534, B:183:0x0589, B:195:0x05be, B:197:0x05c2, B:209:0x05fa, B:211:0x05fe, B:200:0x05d1, B:203:0x05dc, B:204:0x05e3, B:207:0x05f4, B:186:0x0595, B:189:0x05a0, B:190:0x05a7, B:193:0x05b8, B:181:0x055b, B:213:0x060a, B:254:0x0743, B:256:0x074b, B:259:0x0753, B:33:0x00b0, B:86:0x0299, B:88:0x02a5, B:91:0x02ac, B:93:0x02c2, B:105:0x0301, B:97:0x02d7, B:99:0x02df, B:102:0x02e7, B:36:0x00d8, B:65:0x0207, B:67:0x0213, B:70:0x021b, B:72:0x022d, B:74:0x0239, B:76:0x023f, B:78:0x0251, B:80:0x0257, B:82:0x0261, B:261:0x075b, B:263:0x0767, B:265:0x076f, B:268:0x0777, B:57:0x01bc, B:61:0x01cd, B:60:0x01c9), top: B:289:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:215:0x0637  */
    /* JADX WARN: Removed duplicated region for block: B:216:0x0638  */
    /* JADX WARN: Removed duplicated region for block: B:239:0x06fb  */
    /* JADX WARN: Removed duplicated region for block: B:252:0x0735 A[Catch: Exception -> 0x0063, UnknownHostException -> 0x0066, SocketTimeoutException -> 0x0069, HttpException -> 0x006c, TryCatch #4 {SocketTimeoutException -> 0x0069, UnknownHostException -> 0x0066, HttpException -> 0x006c, Exception -> 0x0063, blocks: (B:232:0x06e0, B:231:0x06c9, B:19:0x0057, B:217:0x063a, B:219:0x0649, B:221:0x064f, B:233:0x06ec, B:235:0x06f2, B:240:0x06fe, B:242:0x0707, B:245:0x0710, B:247:0x0718, B:250:0x0721, B:253:0x073d, B:251:0x072c, B:252:0x0735, B:30:0x0089, B:109:0x0339, B:111:0x0345, B:114:0x034d, B:116:0x035f, B:118:0x036b, B:120:0x0379, B:122:0x0385, B:123:0x03a8, B:127:0x03b4, B:129:0x03c8, B:132:0x03d4, B:133:0x03d8, B:135:0x03de, B:137:0x03fb, B:140:0x040e, B:143:0x045e, B:145:0x0468, B:147:0x047b, B:150:0x0485, B:151:0x0489, B:153:0x048f, B:155:0x04ac, B:161:0x04d9, B:163:0x04e0, B:164:0x04ef, B:166:0x04f5, B:167:0x0503, B:170:0x0513, B:171:0x0517, B:173:0x051d, B:177:0x0530, B:179:0x0534, B:183:0x0589, B:195:0x05be, B:197:0x05c2, B:209:0x05fa, B:211:0x05fe, B:200:0x05d1, B:203:0x05dc, B:204:0x05e3, B:207:0x05f4, B:186:0x0595, B:189:0x05a0, B:190:0x05a7, B:193:0x05b8, B:181:0x055b, B:213:0x060a, B:254:0x0743, B:256:0x074b, B:259:0x0753, B:33:0x00b0, B:86:0x0299, B:88:0x02a5, B:91:0x02ac, B:93:0x02c2, B:105:0x0301, B:97:0x02d7, B:99:0x02df, B:102:0x02e7, B:36:0x00d8, B:65:0x0207, B:67:0x0213, B:70:0x021b, B:72:0x022d, B:74:0x0239, B:76:0x023f, B:78:0x0251, B:80:0x0257, B:82:0x0261, B:261:0x075b, B:263:0x0767, B:265:0x076f, B:268:0x0777, B:57:0x01bc, B:61:0x01cd, B:60:0x01c9), top: B:289:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:258:0x0751  */
    /* JADX WARN: Removed duplicated region for block: B:267:0x0775  */
    /* JADX WARN: Removed duplicated region for block: B:281:0x0803  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x0163  */
    /* JADX WARN: Removed duplicated region for block: B:49:0x016f  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x019a  */
    /* JADX WARN: Removed duplicated region for block: B:57:0x01bc A[Catch: Exception -> 0x0063, UnknownHostException -> 0x0066, SocketTimeoutException -> 0x0069, HttpException -> 0x006c, TRY_ENTER, TryCatch #4 {SocketTimeoutException -> 0x0069, UnknownHostException -> 0x0066, HttpException -> 0x006c, Exception -> 0x0063, blocks: (B:232:0x06e0, B:231:0x06c9, B:19:0x0057, B:217:0x063a, B:219:0x0649, B:221:0x064f, B:233:0x06ec, B:235:0x06f2, B:240:0x06fe, B:242:0x0707, B:245:0x0710, B:247:0x0718, B:250:0x0721, B:253:0x073d, B:251:0x072c, B:252:0x0735, B:30:0x0089, B:109:0x0339, B:111:0x0345, B:114:0x034d, B:116:0x035f, B:118:0x036b, B:120:0x0379, B:122:0x0385, B:123:0x03a8, B:127:0x03b4, B:129:0x03c8, B:132:0x03d4, B:133:0x03d8, B:135:0x03de, B:137:0x03fb, B:140:0x040e, B:143:0x045e, B:145:0x0468, B:147:0x047b, B:150:0x0485, B:151:0x0489, B:153:0x048f, B:155:0x04ac, B:161:0x04d9, B:163:0x04e0, B:164:0x04ef, B:166:0x04f5, B:167:0x0503, B:170:0x0513, B:171:0x0517, B:173:0x051d, B:177:0x0530, B:179:0x0534, B:183:0x0589, B:195:0x05be, B:197:0x05c2, B:209:0x05fa, B:211:0x05fe, B:200:0x05d1, B:203:0x05dc, B:204:0x05e3, B:207:0x05f4, B:186:0x0595, B:189:0x05a0, B:190:0x05a7, B:193:0x05b8, B:181:0x055b, B:213:0x060a, B:254:0x0743, B:256:0x074b, B:259:0x0753, B:33:0x00b0, B:86:0x0299, B:88:0x02a5, B:91:0x02ac, B:93:0x02c2, B:105:0x0301, B:97:0x02d7, B:99:0x02df, B:102:0x02e7, B:36:0x00d8, B:65:0x0207, B:67:0x0213, B:70:0x021b, B:72:0x022d, B:74:0x0239, B:76:0x023f, B:78:0x0251, B:80:0x0257, B:82:0x0261, B:261:0x075b, B:263:0x0767, B:265:0x076f, B:268:0x0777, B:57:0x01bc, B:61:0x01cd, B:60:0x01c9), top: B:289:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:72:0x022d A[Catch: Exception -> 0x0063, UnknownHostException -> 0x0066, SocketTimeoutException -> 0x0069, HttpException -> 0x006c, TryCatch #4 {SocketTimeoutException -> 0x0069, UnknownHostException -> 0x0066, HttpException -> 0x006c, Exception -> 0x0063, blocks: (B:232:0x06e0, B:231:0x06c9, B:19:0x0057, B:217:0x063a, B:219:0x0649, B:221:0x064f, B:233:0x06ec, B:235:0x06f2, B:240:0x06fe, B:242:0x0707, B:245:0x0710, B:247:0x0718, B:250:0x0721, B:253:0x073d, B:251:0x072c, B:252:0x0735, B:30:0x0089, B:109:0x0339, B:111:0x0345, B:114:0x034d, B:116:0x035f, B:118:0x036b, B:120:0x0379, B:122:0x0385, B:123:0x03a8, B:127:0x03b4, B:129:0x03c8, B:132:0x03d4, B:133:0x03d8, B:135:0x03de, B:137:0x03fb, B:140:0x040e, B:143:0x045e, B:145:0x0468, B:147:0x047b, B:150:0x0485, B:151:0x0489, B:153:0x048f, B:155:0x04ac, B:161:0x04d9, B:163:0x04e0, B:164:0x04ef, B:166:0x04f5, B:167:0x0503, B:170:0x0513, B:171:0x0517, B:173:0x051d, B:177:0x0530, B:179:0x0534, B:183:0x0589, B:195:0x05be, B:197:0x05c2, B:209:0x05fa, B:211:0x05fe, B:200:0x05d1, B:203:0x05dc, B:204:0x05e3, B:207:0x05f4, B:186:0x0595, B:189:0x05a0, B:190:0x05a7, B:193:0x05b8, B:181:0x055b, B:213:0x060a, B:254:0x0743, B:256:0x074b, B:259:0x0753, B:33:0x00b0, B:86:0x0299, B:88:0x02a5, B:91:0x02ac, B:93:0x02c2, B:105:0x0301, B:97:0x02d7, B:99:0x02df, B:102:0x02e7, B:36:0x00d8, B:65:0x0207, B:67:0x0213, B:70:0x021b, B:72:0x022d, B:74:0x0239, B:76:0x023f, B:78:0x0251, B:80:0x0257, B:82:0x0261, B:261:0x075b, B:263:0x0767, B:265:0x076f, B:268:0x0777, B:57:0x01bc, B:61:0x01cd, B:60:0x01c9), top: B:289:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:74:0x0239 A[Catch: Exception -> 0x0063, UnknownHostException -> 0x0066, SocketTimeoutException -> 0x0069, HttpException -> 0x006c, TryCatch #4 {SocketTimeoutException -> 0x0069, UnknownHostException -> 0x0066, HttpException -> 0x006c, Exception -> 0x0063, blocks: (B:232:0x06e0, B:231:0x06c9, B:19:0x0057, B:217:0x063a, B:219:0x0649, B:221:0x064f, B:233:0x06ec, B:235:0x06f2, B:240:0x06fe, B:242:0x0707, B:245:0x0710, B:247:0x0718, B:250:0x0721, B:253:0x073d, B:251:0x072c, B:252:0x0735, B:30:0x0089, B:109:0x0339, B:111:0x0345, B:114:0x034d, B:116:0x035f, B:118:0x036b, B:120:0x0379, B:122:0x0385, B:123:0x03a8, B:127:0x03b4, B:129:0x03c8, B:132:0x03d4, B:133:0x03d8, B:135:0x03de, B:137:0x03fb, B:140:0x040e, B:143:0x045e, B:145:0x0468, B:147:0x047b, B:150:0x0485, B:151:0x0489, B:153:0x048f, B:155:0x04ac, B:161:0x04d9, B:163:0x04e0, B:164:0x04ef, B:166:0x04f5, B:167:0x0503, B:170:0x0513, B:171:0x0517, B:173:0x051d, B:177:0x0530, B:179:0x0534, B:183:0x0589, B:195:0x05be, B:197:0x05c2, B:209:0x05fa, B:211:0x05fe, B:200:0x05d1, B:203:0x05dc, B:204:0x05e3, B:207:0x05f4, B:186:0x0595, B:189:0x05a0, B:190:0x05a7, B:193:0x05b8, B:181:0x055b, B:213:0x060a, B:254:0x0743, B:256:0x074b, B:259:0x0753, B:33:0x00b0, B:86:0x0299, B:88:0x02a5, B:91:0x02ac, B:93:0x02c2, B:105:0x0301, B:97:0x02d7, B:99:0x02df, B:102:0x02e7, B:36:0x00d8, B:65:0x0207, B:67:0x0213, B:70:0x021b, B:72:0x022d, B:74:0x0239, B:76:0x023f, B:78:0x0251, B:80:0x0257, B:82:0x0261, B:261:0x075b, B:263:0x0767, B:265:0x076f, B:268:0x0777, B:57:0x01bc, B:61:0x01cd, B:60:0x01c9), top: B:289:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:8:0x001a  */
    /* JADX WARN: Removed duplicated region for block: B:93:0x02c2 A[Catch: Exception -> 0x0063, UnknownHostException -> 0x0066, SocketTimeoutException -> 0x0069, HttpException -> 0x006c, TryCatch #4 {SocketTimeoutException -> 0x0069, UnknownHostException -> 0x0066, HttpException -> 0x006c, Exception -> 0x0063, blocks: (B:232:0x06e0, B:231:0x06c9, B:19:0x0057, B:217:0x063a, B:219:0x0649, B:221:0x064f, B:233:0x06ec, B:235:0x06f2, B:240:0x06fe, B:242:0x0707, B:245:0x0710, B:247:0x0718, B:250:0x0721, B:253:0x073d, B:251:0x072c, B:252:0x0735, B:30:0x0089, B:109:0x0339, B:111:0x0345, B:114:0x034d, B:116:0x035f, B:118:0x036b, B:120:0x0379, B:122:0x0385, B:123:0x03a8, B:127:0x03b4, B:129:0x03c8, B:132:0x03d4, B:133:0x03d8, B:135:0x03de, B:137:0x03fb, B:140:0x040e, B:143:0x045e, B:145:0x0468, B:147:0x047b, B:150:0x0485, B:151:0x0489, B:153:0x048f, B:155:0x04ac, B:161:0x04d9, B:163:0x04e0, B:164:0x04ef, B:166:0x04f5, B:167:0x0503, B:170:0x0513, B:171:0x0517, B:173:0x051d, B:177:0x0530, B:179:0x0534, B:183:0x0589, B:195:0x05be, B:197:0x05c2, B:209:0x05fa, B:211:0x05fe, B:200:0x05d1, B:203:0x05dc, B:204:0x05e3, B:207:0x05f4, B:186:0x0595, B:189:0x05a0, B:190:0x05a7, B:193:0x05b8, B:181:0x055b, B:213:0x060a, B:254:0x0743, B:256:0x074b, B:259:0x0753, B:33:0x00b0, B:86:0x0299, B:88:0x02a5, B:91:0x02ac, B:93:0x02c2, B:105:0x0301, B:97:0x02d7, B:99:0x02df, B:102:0x02e7, B:36:0x00d8, B:65:0x0207, B:67:0x0213, B:70:0x021b, B:72:0x022d, B:74:0x0239, B:76:0x023f, B:78:0x0251, B:80:0x0257, B:82:0x0261, B:261:0x075b, B:263:0x0767, B:265:0x076f, B:268:0x0777, B:57:0x01bc, B:61:0x01cd, B:60:0x01c9), top: B:289:0x002f }] */
    /* JADX WARN: Removed duplicated region for block: B:95:0x02ce  */
    /* JADX WARN: Type inference failed for: r0v64, types: [java.lang.Integer, java.lang.Object, java.lang.Throwable, uz1] */
    /* JADX WARN: Type inference failed for: r0v69 */
    /* JADX WARN: Type inference failed for: r0v80 */
    /* JADX WARN: Type inference failed for: r11v27 */
    /* JADX WARN: Type inference failed for: r11v28 */
    /* JADX WARN: Type inference failed for: r11v29, types: [com.strmr.ps.data.repository.AllDebridRepository$FileInfo] */
    /* JADX WARN: Type inference failed for: r11v31 */
    /* JADX WARN: Type inference failed for: r11v32 */
    /* JADX WARN: Type inference failed for: r11v38, types: [com.strmr.ps.data.repository.AllDebridRepository$FileInfo] */
    /* JADX WARN: Type inference failed for: r11v44, types: [com.strmr.ps.data.repository.AllDebridRepository$FileInfo] */
    /* JADX WARN: Type inference failed for: r11v57 */
    /* JADX WARN: Type inference failed for: r11v64 */
    @Override // com.strmr.ps.data.repository.IDebridProvider
    @pq6
    /* JADX INFO: renamed from: resolveToDirectLink-hUnOzRk, reason: not valid java name */
    /*
        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) {
        AllDebridRepository$resolveToDirectLink$1 allDebridRepository$resolveToDirectLink$1;
        Throwable authenticationFailed;
        String str3;
        Integer num4;
        Integer num5;
        Integer num6;
        String str4;
        AllDebridRepository allDebridRepository;
        AllDebridAccount allDebridAccount;
        AllDebridAccount allDebridAccount2;
        String strConcat;
        Integer num7;
        Integer num8;
        AllDebridRepository allDebridRepository2;
        String str5;
        Integer num9;
        AllDebridRepository$resolveToDirectLink$1 allDebridRepository$resolveToDirectLink$12;
        String str6;
        Object obj;
        Integer num10;
        AllDebridRepository allDebridRepository3;
        Integer num11;
        Integer num12;
        String str7;
        AllDebridResponse allDebridResponse;
        AllDebridError error;
        String message;
        AllDebridUploadedMagnet allDebridUploadedMagnet;
        Integer num13;
        Object obj2;
        Integer num14;
        String str8;
        String str9;
        long j;
        AllDebridRepository allDebridRepository4;
        Integer num15;
        long j2;
        Object obj3;
        Object magnetStatus$default;
        String str10;
        AllDebridRepository allDebridRepository5;
        Integer num16;
        String str11;
        Object magnetFiles$default;
        Integer num17;
        String str12;
        Integer num18;
        AllDebridRepository allDebridRepository6;
        Integer num19;
        long j3;
        AllDebridResponse allDebridResponse2;
        AllDebridError error2;
        String message2;
        Object obj4;
        AllDebridResponse allDebridResponse3;
        AllDebridError error3;
        String message3;
        AllDebridMagnetFilesEntry allDebridMagnetFilesEntry;
        String str13;
        ?? r11;
        Object objUnlockLink$default;
        AllDebridRepository$resolveToDirectLink$1 allDebridRepository$resolveToDirectLink$13;
        ck1 ck1Var;
        AllDebridRepository allDebridRepository7;
        List<FileInfo> list;
        Object next;
        Object next2;
        Object obj5;
        AllDebridRepository$resolveToDirectLink$1 allDebridRepository$resolveToDirectLink$14;
        ?? r0;
        AllDebridResponse allDebridResponse4;
        AllDebridError error4;
        String message4;
        AllDebridResponse allDebridResponse5;
        long j4;
        if (continuation instanceof AllDebridRepository$resolveToDirectLink$1) {
            allDebridRepository$resolveToDirectLink$1 = (AllDebridRepository$resolveToDirectLink$1) continuation;
            int i = allDebridRepository$resolveToDirectLink$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                allDebridRepository$resolveToDirectLink$1.label = i - Integer.MIN_VALUE;
            } else {
                allDebridRepository$resolveToDirectLink$1 = new AllDebridRepository$resolveToDirectLink$1(this, continuation);
            }
        }
        AllDebridRepository$resolveToDirectLink$1 allDebridRepository$resolveToDirectLink$15 = allDebridRepository$resolveToDirectLink$1;
        Object account = allDebridRepository$resolveToDirectLink$15.result;
        dr4.c();
        ck1 ck1Var2 = ck1.a;
        String str14 = "success";
        try {
            switch (allDebridRepository$resolveToDirectLink$15.label) {
                case 0:
                    s38.b(account);
                    AllDebridAccountDao allDebridAccountDao = this.accountDao;
                    allDebridRepository$resolveToDirectLink$15.L$0 = this;
                    str3 = str;
                    allDebridRepository$resolveToDirectLink$15.L$1 = str3;
                    num4 = num;
                    allDebridRepository$resolveToDirectLink$15.L$2 = num4;
                    num5 = num2;
                    allDebridRepository$resolveToDirectLink$15.L$3 = num5;
                    num6 = num3;
                    allDebridRepository$resolveToDirectLink$15.L$4 = num6;
                    str4 = str2;
                    allDebridRepository$resolveToDirectLink$15.L$5 = str4;
                    allDebridRepository$resolveToDirectLink$15.label = 1;
                    account = allDebridAccountDao.getAccount("alldebrid", allDebridRepository$resolveToDirectLink$15);
                    if (account != ck1Var2) {
                        allDebridRepository = this;
                        allDebridAccount = (AllDebridAccount) account;
                        if (allDebridAccount != null) {
                            return s38.a(new DebridError.NoAccount(DebridProvider.ALL_DEBRID));
                        }
                        allDebridRepository$resolveToDirectLink$15.L$0 = allDebridRepository;
                        allDebridRepository$resolveToDirectLink$15.L$1 = str3;
                        allDebridRepository$resolveToDirectLink$15.L$2 = num4;
                        allDebridRepository$resolveToDirectLink$15.L$3 = num5;
                        allDebridRepository$resolveToDirectLink$15.L$4 = num6;
                        allDebridRepository$resolveToDirectLink$15.L$5 = str4;
                        allDebridRepository$resolveToDirectLink$15.L$6 = allDebridAccount;
                        allDebridRepository$resolveToDirectLink$15.label = 2;
                        Object accountExpirationStatus = allDebridRepository.getAccountExpirationStatus(allDebridRepository$resolveToDirectLink$15);
                        if (accountExpirationStatus != ck1Var2) {
                            String str15 = str3;
                            allDebridAccount2 = allDebridAccount;
                            account = accountExpirationStatus;
                            strConcat = str15;
                            Integer num20 = num6;
                            num7 = num4;
                            num8 = num20;
                            allDebridRepository2 = allDebridRepository;
                            str5 = str4;
                            AllDebridRepository allDebridRepository8 = allDebridRepository2;
                            num9 = (Integer) account;
                            if (num9 == null) {
                                Log.w(TAG, "Account expired " + num9 + " days ago");
                                return s38.a(new DebridError.AccountExpired(DebridProvider.ALL_DEBRID, num9));
                            }
                            String authHeader = allDebridAccount2.getAuthHeader();
                            if (!n89.ar(strConcat, "magnet:", false)) {
                                strConcat = "magnet:?xt=urn:btih:".concat(strConcat);
                            }
                            AllDebridApiService allDebridApiService = allDebridRepository8.allDebridApiService;
                            List listAm = y41.am(strConcat);
                            allDebridRepository$resolveToDirectLink$15.L$0 = allDebridRepository8;
                            allDebridRepository$resolveToDirectLink$15.L$1 = num7;
                            allDebridRepository$resolveToDirectLink$15.L$2 = num5;
                            allDebridRepository$resolveToDirectLink$15.L$3 = num8;
                            allDebridRepository$resolveToDirectLink$15.L$4 = str5;
                            allDebridRepository$resolveToDirectLink$15.L$5 = authHeader;
                            allDebridRepository$resolveToDirectLink$15.L$6 = null;
                            allDebridRepository$resolveToDirectLink$15.label = 3;
                            Integer num21 = num7;
                            allDebridRepository$resolveToDirectLink$12 = allDebridRepository$resolveToDirectLink$15;
                            Integer num22 = num8;
                            str6 = authHeader;
                            Integer num23 = num5;
                            obj = null;
                            Object objUploadMagnet$default = AllDebridApiService.DefaultImpls.uploadMagnet$default(allDebridApiService, str6, listAm, null, allDebridRepository$resolveToDirectLink$12, 4, null);
                            if (objUploadMagnet$default != ck1Var2) {
                                num10 = num23;
                                account = objUploadMagnet$default;
                                allDebridRepository3 = allDebridRepository8;
                                num11 = num21;
                                num12 = num22;
                                str7 = str5;
                                allDebridResponse = (AllDebridResponse) account;
                                if (cr4.b(allDebridResponse.getStatus(), "success") && allDebridResponse.getData() != null) {
                                    allDebridUploadedMagnet = (AllDebridUploadedMagnet) y41.ab(((AllDebridMagnetUploadData) allDebridResponse.getData()).getMagnets());
                                    if (allDebridUploadedMagnet != null) {
                                        return s38.a(new Exception("No magnet in response"));
                                    }
                                    if (allDebridUploadedMagnet.getError() != null) {
                                        return s38.a(new Exception(allDebridUploadedMagnet.getError().getMessage()));
                                    }
                                    Long id = allDebridUploadedMagnet.getId();
                                    if (id == null) {
                                        return s38.a(new Exception("No magnet ID returned"));
                                    }
                                    long jLongValue = id.longValue();
                                    if (allDebridUploadedMagnet.getReady()) {
                                        num13 = num10;
                                        Integer num24 = num11;
                                        obj2 = obj;
                                        num14 = num12;
                                        str8 = str7;
                                        str9 = str6;
                                        j = jLongValue;
                                        allDebridRepository4 = allDebridRepository3;
                                        num15 = num24;
                                        Integer num25 = num13;
                                        Integer num26 = num14;
                                        AllDebridApiService allDebridApiService2 = allDebridRepository4.allDebridApiService;
                                        List listAm2 = y41.am(Boxing.boxLong(j));
                                        allDebridRepository$resolveToDirectLink$12.L$0 = allDebridRepository4;
                                        allDebridRepository$resolveToDirectLink$12.L$1 = num15;
                                        allDebridRepository$resolveToDirectLink$12.L$2 = num25;
                                        allDebridRepository$resolveToDirectLink$12.L$3 = num26;
                                        allDebridRepository$resolveToDirectLink$12.L$4 = str8;
                                        allDebridRepository$resolveToDirectLink$12.L$5 = str9;
                                        allDebridRepository$resolveToDirectLink$12.J$0 = j;
                                        allDebridRepository$resolveToDirectLink$12.label = 5;
                                        AllDebridRepository allDebridRepository9 = allDebridRepository4;
                                        Integer num27 = num15;
                                        long j5 = j;
                                        str11 = str9;
                                        magnetFiles$default = AllDebridApiService.DefaultImpls.getMagnetFiles$default(allDebridApiService2, str11, listAm2, null, allDebridRepository$resolveToDirectLink$12, 4, null);
                                        if (magnetFiles$default == ck1Var2) {
                                        }
                                    } else {
                                        AllDebridApiService allDebridApiService3 = allDebridRepository3.allDebridApiService;
                                        allDebridRepository$resolveToDirectLink$12.L$0 = allDebridRepository3;
                                        allDebridRepository$resolveToDirectLink$12.L$1 = num11;
                                        allDebridRepository$resolveToDirectLink$12.L$2 = num10;
                                        allDebridRepository$resolveToDirectLink$12.L$3 = num12;
                                        allDebridRepository$resolveToDirectLink$12.L$4 = str7;
                                        allDebridRepository$resolveToDirectLink$12.L$5 = str6;
                                        allDebridRepository$resolveToDirectLink$12.J$0 = jLongValue;
                                        allDebridRepository$resolveToDirectLink$12.label = 4;
                                        AllDebridRepository allDebridRepository10 = allDebridRepository3;
                                        AllDebridRepository$resolveToDirectLink$1 allDebridRepository$resolveToDirectLink$16 = allDebridRepository$resolveToDirectLink$12;
                                        Integer num28 = num11;
                                        Integer num29 = num10;
                                        j2 = jLongValue;
                                        num13 = num29;
                                        obj3 = obj;
                                        num14 = num12;
                                        magnetStatus$default = AllDebridApiService.DefaultImpls.getMagnetStatus$default(allDebridApiService3, str6, j2, null, allDebridRepository$resolveToDirectLink$16, 4, null);
                                        allDebridRepository$resolveToDirectLink$12 = allDebridRepository$resolveToDirectLink$16;
                                        if (magnetStatus$default != ck1Var2) {
                                            String str16 = str6;
                                            str10 = str7;
                                            str9 = str16;
                                            allDebridRepository5 = allDebridRepository10;
                                            num16 = num28;
                                            allDebridResponse2 = (AllDebridResponse) magnetStatus$default;
                                            if (cr4.b(allDebridResponse2.getStatus(), "success") && allDebridResponse2.getData() != null) {
                                                if (cr4.b(((AllDebridMagnetStatusData) allDebridResponse2.getData()).getMagnets().getStatus(), "Ready")) {
                                                    return s38.a(new DebridError.NotCached(DebridProvider.ALL_DEBRID));
                                                }
                                                AllDebridRepository allDebridRepository11 = allDebridRepository5;
                                                str8 = str10;
                                                j = j2;
                                                allDebridRepository4 = allDebridRepository11;
                                                num15 = num16;
                                                obj2 = obj3;
                                                Integer num252 = num13;
                                                Integer num262 = num14;
                                                AllDebridApiService allDebridApiService22 = allDebridRepository4.allDebridApiService;
                                                List listAm22 = y41.am(Boxing.boxLong(j));
                                                allDebridRepository$resolveToDirectLink$12.L$0 = allDebridRepository4;
                                                allDebridRepository$resolveToDirectLink$12.L$1 = num15;
                                                allDebridRepository$resolveToDirectLink$12.L$2 = num252;
                                                allDebridRepository$resolveToDirectLink$12.L$3 = num262;
                                                allDebridRepository$resolveToDirectLink$12.L$4 = str8;
                                                allDebridRepository$resolveToDirectLink$12.L$5 = str9;
                                                allDebridRepository$resolveToDirectLink$12.J$0 = j;
                                                allDebridRepository$resolveToDirectLink$12.label = 5;
                                                AllDebridRepository allDebridRepository92 = allDebridRepository4;
                                                Integer num272 = num15;
                                                long j52 = j;
                                                str11 = str9;
                                                magnetFiles$default = AllDebridApiService.DefaultImpls.getMagnetFiles$default(allDebridApiService22, str11, listAm22, null, allDebridRepository$resolveToDirectLink$12, 4, null);
                                                if (magnetFiles$default == ck1Var2) {
                                                    num17 = num252;
                                                    str12 = str8;
                                                    num18 = num262;
                                                    allDebridRepository6 = allDebridRepository92;
                                                    num19 = num272;
                                                    j3 = j52;
                                                    obj4 = obj2;
                                                    allDebridResponse3 = (AllDebridResponse) magnetFiles$default;
                                                    if (cr4.b(allDebridResponse3.getStatus(), "success") && allDebridResponse3.getData() != null) {
                                                        allDebridMagnetFilesEntry = (AllDebridMagnetFilesEntry) y41.ab(((AllDebridMagnetFilesData) allDebridResponse3.getData()).getMagnets());
                                                        if (allDebridMagnetFilesEntry != null) {
                                                            return s38.a(new Exception("No files in response"));
                                                        }
                                                        List<FileInfo> listFlattenFileTree = allDebridRepository6.flattenFileTree(allDebridMagnetFilesEntry.getFiles());
                                                        if (listFlattenFileTree.isEmpty()) {
                                                            return s38.a(new Exception("No files available"));
                                                        }
                                                        List listAn = y41.an(".mkv", ".mp4", ".avi", ".mov", ".wmv", ".m4v", ".webm");
                                                        ArrayList arrayList = new ArrayList();
                                                        Iterator it = listFlattenFileTree.iterator();
                                                        while (true) {
                                                            String str17 = str11;
                                                            if (!it.hasNext()) {
                                                                ck1 ck1Var3 = ck1Var2;
                                                                AllDebridRepository$resolveToDirectLink$1 allDebridRepository$resolveToDirectLink$17 = allDebridRepository$resolveToDirectLink$12;
                                                                List list2 = listAn;
                                                                str13 = str14;
                                                                Log.w(TAG, "resolveToDirectLink: magnetId=" + j3 + ", " + listFlattenFileTree.size() + " files (" + arrayList.size() + " video), season=" + num17 + ", episode=" + num18 + ", fileIdx=" + num19);
                                                                if (num19 == null || num19.intValue() >= listFlattenFileTree.size()) {
                                                                    r11 = obj4;
                                                                    if (r11 == 0) {
                                                                        if (num17 == null || num18 == null || arrayList.size() <= 1) {
                                                                            r11 = obj4;
                                                                            if (r11 == 0) {
                                                                                Iterator it2 = arrayList.iterator();
                                                                                if (it2.hasNext()) {
                                                                                    next = it2.next();
                                                                                    if (it2.hasNext()) {
                                                                                        long size = ((FileInfo) next).getSize();
                                                                                        do {
                                                                                            Object next3 = it2.next();
                                                                                            long size2 = ((FileInfo) next3).getSize();
                                                                                            next = next;
                                                                                            if (size < size2) {
                                                                                                next = next3;
                                                                                                size = size2;
                                                                                            }
                                                                                        } while (it2.hasNext());
                                                                                    }
                                                                                } else {
                                                                                    next = obj4;
                                                                                }
                                                                                r11 = (FileInfo) next;
                                                                                if (r11 == 0) {
                                                                                    Iterator it3 = listFlattenFileTree.iterator();
                                                                                    if (it3.hasNext()) {
                                                                                        next2 = it3.next();
                                                                                        if (it3.hasNext()) {
                                                                                            long size3 = ((FileInfo) next2).getSize();
                                                                                            do {
                                                                                                Object next4 = it3.next();
                                                                                                long size4 = ((FileInfo) next4).getSize();
                                                                                                next2 = next2;
                                                                                                if (size3 < size4) {
                                                                                                    next2 = next4;
                                                                                                    size3 = size4;
                                                                                                }
                                                                                            } while (it3.hasNext());
                                                                                        }
                                                                                    } else {
                                                                                        next2 = obj4;
                                                                                    }
                                                                                    r11 = (FileInfo) next2;
                                                                                    if (r11 == 0) {
                                                                                        return s38.a(new Exception("No files found"));
                                                                                    }
                                                                                }
                                                                            }
                                                                        } else {
                                                                            ArrayList arrayList2 = new ArrayList(y41.p(arrayList, 10));
                                                                            Iterator it4 = arrayList.iterator();
                                                                            while (it4.hasNext()) {
                                                                                arrayList2.add(((FileInfo) it4.next()).getName());
                                                                            }
                                                                            String strC = vo2.c(arrayList2, num17.intValue(), num18.intValue(), str12);
                                                                            if (strC != null) {
                                                                                Iterator it5 = arrayList.iterator();
                                                                                while (true) {
                                                                                    if (it5.hasNext()) {
                                                                                        Object next5 = it5.next();
                                                                                        if (cr4.b(((FileInfo) next5).getName(), strC)) {
                                                                                            obj5 = next5;
                                                                                        }
                                                                                    } else {
                                                                                        obj5 = obj4;
                                                                                    }
                                                                                }
                                                                                FileInfo fileInfo = (FileInfo) obj5;
                                                                                if (fileInfo != null) {
                                                                                    Log.w(TAG, "Found episode S" + num17 + "E" + num18 + ": " + fileInfo.getName());
                                                                                    r11 = fileInfo;
                                                                                }
                                                                                if (r11 == 0) {
                                                                                }
                                                                            } else {
                                                                                Log.w(TAG, "Could not find episode S" + num17 + "E" + num18 + " in " + arrayList.size() + " video files");
                                                                            }
                                                                            r11 = obj4;
                                                                            if (r11 == 0) {
                                                                            }
                                                                        }
                                                                    }
                                                                    AllDebridApiService allDebridApiService4 = allDebridRepository6.allDebridApiService;
                                                                    String link = r11.getLink();
                                                                    allDebridRepository$resolveToDirectLink$17.L$0 = allDebridRepository6;
                                                                    allDebridRepository$resolveToDirectLink$17.L$1 = listFlattenFileTree;
                                                                    allDebridRepository$resolveToDirectLink$17.L$2 = obj4;
                                                                    allDebridRepository$resolveToDirectLink$17.L$3 = obj4;
                                                                    allDebridRepository$resolveToDirectLink$17.L$4 = obj4;
                                                                    allDebridRepository$resolveToDirectLink$17.L$5 = obj4;
                                                                    allDebridRepository$resolveToDirectLink$17.J$0 = j3;
                                                                    allDebridRepository$resolveToDirectLink$17.label = 6;
                                                                    objUnlockLink$default = AllDebridApiService.DefaultImpls.unlockLink$default(allDebridApiService4, str17, link, null, null, allDebridRepository$resolveToDirectLink$17, 12, null);
                                                                    allDebridRepository$resolveToDirectLink$13 = allDebridRepository$resolveToDirectLink$17;
                                                                    ck1Var = ck1Var3;
                                                                    if (objUnlockLink$default == ck1Var) {
                                                                        return ck1Var;
                                                                    }
                                                                    allDebridRepository7 = allDebridRepository6;
                                                                    list = listFlattenFileTree;
                                                                    r0 = obj4;
                                                                    allDebridResponse4 = (AllDebridResponse) objUnlockLink$default;
                                                                    if (cr4.b(allDebridResponse4.getStatus(), str13) || allDebridResponse4.getData() == null) {
                                                                        error4 = allDebridResponse4.getError();
                                                                        if (error4 != null || (message4 = error4.getMessage()) == null) {
                                                                            message4 = "Failed to unlock link";
                                                                        }
                                                                        String str18 = message4;
                                                                        return s38.a((!n89.l(str18, "expired", true) || n89.l(str18, "premium", true)) ? new DebridError.AccountExpired(DebridProvider.ALL_DEBRID, r0, 2, r0) : (n89.l(str18, "auth", true) || n89.l(str18, "apikey", true)) ? new DebridError.AuthenticationFailed(DebridProvider.ALL_DEBRID, r0, 2, r0) : new DebridError.Unknown(DebridProvider.ALL_DEBRID, str18, null, 4, null));
                                                                    }
                                                                    Log.w(TAG, "Resolved direct link: " + ((AllDebridUnlockData) allDebridResponse4.getData()).getFilename());
                                                                    if (allDebridRepository7.linkFilterPreferences.getCloudSanitizationEnabled()) {
                                                                        try {
                                                                            ExecutorService executorService = kq.a;
                                                                            kq.h(TAG, "Cloud sanitization: removing AD magnet " + j3 + " (" + list.size() + " files)");
                                                                            allDebridRepository$resolveToDirectLink$13.L$0 = allDebridResponse4;
                                                                            allDebridRepository$resolveToDirectLink$13.L$1 = r0;
                                                                            allDebridRepository$resolveToDirectLink$13.J$0 = j3;
                                                                            allDebridRepository$resolveToDirectLink$13.label = 7;
                                                                        } catch (Exception e) {
                                                                            e = e;
                                                                            allDebridResponse5 = allDebridResponse4;
                                                                            j4 = j3;
                                                                            ExecutorService executorService2 = kq.a;
                                                                            kq.a(TAG, "Cloud sanitization failed for AD magnet " + j4, e);
                                                                        }
                                                                        if (allDebridRepository7.m68deleteMagnetgIAlus(j3, allDebridRepository$resolveToDirectLink$13) == ck1Var) {
                                                                            return ck1Var;
                                                                        }
                                                                        allDebridResponse5 = allDebridResponse4;
                                                                        j4 = j3;
                                                                        ExecutorService executorService3 = kq.a;
                                                                        kq.h(TAG, "Cloud sanitization: removed AD magnet " + j4);
                                                                        allDebridResponse4 = allDebridResponse5;
                                                                    }
                                                                    break;
                                                                } else {
                                                                    FileInfo fileInfo2 = listFlattenFileTree.get(num19.intValue());
                                                                    List list3 = list2;
                                                                    if (!(list3 instanceof Collection) || !list3.isEmpty()) {
                                                                        Iterator it6 = list3.iterator();
                                                                        while (it6.hasNext()) {
                                                                            String str19 = (String) it6.next();
                                                                            Iterator it7 = it6;
                                                                            FileInfo fileInfo3 = fileInfo2;
                                                                            String lowerCase = fileInfo2.getName().toLowerCase(Locale.ROOT);
                                                                            cr4.f(lowerCase, "toLowerCase(...)");
                                                                            if (n89.r(lowerCase, str19, false)) {
                                                                                Log.w(TAG, "Using specified fileIdx " + num19 + ": " + fileInfo3.getName());
                                                                                r11 = fileInfo3;
                                                                                if (r11 == 0) {
                                                                                }
                                                                                AllDebridApiService allDebridApiService42 = allDebridRepository6.allDebridApiService;
                                                                                String link2 = r11.getLink();
                                                                                allDebridRepository$resolveToDirectLink$17.L$0 = allDebridRepository6;
                                                                                allDebridRepository$resolveToDirectLink$17.L$1 = listFlattenFileTree;
                                                                                allDebridRepository$resolveToDirectLink$17.L$2 = obj4;
                                                                                allDebridRepository$resolveToDirectLink$17.L$3 = obj4;
                                                                                allDebridRepository$resolveToDirectLink$17.L$4 = obj4;
                                                                                allDebridRepository$resolveToDirectLink$17.L$5 = obj4;
                                                                                allDebridRepository$resolveToDirectLink$17.J$0 = j3;
                                                                                allDebridRepository$resolveToDirectLink$17.label = 6;
                                                                                objUnlockLink$default = AllDebridApiService.DefaultImpls.unlockLink$default(allDebridApiService42, str17, link2, null, null, allDebridRepository$resolveToDirectLink$17, 12, null);
                                                                                allDebridRepository$resolveToDirectLink$13 = allDebridRepository$resolveToDirectLink$17;
                                                                                ck1Var = ck1Var3;
                                                                                if (objUnlockLink$default == ck1Var) {
                                                                                }
                                                                            } else {
                                                                                it6 = it7;
                                                                                fileInfo2 = fileInfo3;
                                                                            }
                                                                        }
                                                                    }
                                                                    r11 = obj4;
                                                                    if (r11 == 0) {
                                                                    }
                                                                    AllDebridApiService allDebridApiService422 = allDebridRepository6.allDebridApiService;
                                                                    String link22 = r11.getLink();
                                                                    allDebridRepository$resolveToDirectLink$17.L$0 = allDebridRepository6;
                                                                    allDebridRepository$resolveToDirectLink$17.L$1 = listFlattenFileTree;
                                                                    allDebridRepository$resolveToDirectLink$17.L$2 = obj4;
                                                                    allDebridRepository$resolveToDirectLink$17.L$3 = obj4;
                                                                    allDebridRepository$resolveToDirectLink$17.L$4 = obj4;
                                                                    allDebridRepository$resolveToDirectLink$17.L$5 = obj4;
                                                                    allDebridRepository$resolveToDirectLink$17.J$0 = j3;
                                                                    allDebridRepository$resolveToDirectLink$17.label = 6;
                                                                    objUnlockLink$default = AllDebridApiService.DefaultImpls.unlockLink$default(allDebridApiService422, str17, link22, null, null, allDebridRepository$resolveToDirectLink$17, 12, null);
                                                                    allDebridRepository$resolveToDirectLink$13 = allDebridRepository$resolveToDirectLink$17;
                                                                    ck1Var = ck1Var3;
                                                                    if (objUnlockLink$default == ck1Var) {
                                                                    }
                                                                }
                                                                return ((AllDebridUnlockData) allDebridResponse4.getData()).getLink();
                                                            }
                                                            List list4 = listAn;
                                                            Object next6 = it.next();
                                                            FileInfo fileInfo4 = (FileInfo) next6;
                                                            String str20 = str14;
                                                            List list5 = list4;
                                                            ck1 ck1Var4 = ck1Var2;
                                                            if ((list5 instanceof Collection) && list5.isEmpty()) {
                                                                allDebridRepository$resolveToDirectLink$14 = allDebridRepository$resolveToDirectLink$12;
                                                            } else {
                                                                Iterator it8 = list5.iterator();
                                                                while (it8.hasNext()) {
                                                                    String str21 = (String) it8.next();
                                                                    Iterator it9 = it8;
                                                                    allDebridRepository$resolveToDirectLink$14 = allDebridRepository$resolveToDirectLink$12;
                                                                    String lowerCase2 = fileInfo4.getName().toLowerCase(Locale.ROOT);
                                                                    cr4.f(lowerCase2, "toLowerCase(...)");
                                                                    if (n89.r(lowerCase2, str21, false)) {
                                                                        arrayList.add(next6);
                                                                    } else {
                                                                        it8 = it9;
                                                                        allDebridRepository$resolveToDirectLink$12 = allDebridRepository$resolveToDirectLink$14;
                                                                    }
                                                                }
                                                                allDebridRepository$resolveToDirectLink$14 = allDebridRepository$resolveToDirectLink$12;
                                                            }
                                                            str11 = str17;
                                                            listAn = list4;
                                                            str14 = str20;
                                                            ck1Var2 = ck1Var4;
                                                            allDebridRepository$resolveToDirectLink$12 = allDebridRepository$resolveToDirectLink$14;
                                                        }
                                                    }
                                                    error3 = allDebridResponse3.getError();
                                                    if (error3 != null || (message3 = error3.getMessage()) == null) {
                                                        message3 = "Failed to get magnet files";
                                                    }
                                                    return s38.a(new Exception(message3));
                                                }
                                            }
                                            error2 = allDebridResponse2.getError();
                                            if (error2 != null || (message2 = error2.getMessage()) == null) {
                                                message2 = "Failed to get magnet status";
                                            }
                                            return s38.a(new Exception(message2));
                                        }
                                    }
                                }
                                error = allDebridResponse.getError();
                                if (error != null || (message = error.getMessage()) == null) {
                                    message = "Failed to upload magnet";
                                }
                                return s38.a(new Exception(message));
                            }
                        }
                    }
                    return ck1Var2;
                case 1:
                    String str22 = (String) allDebridRepository$resolveToDirectLink$15.L$5;
                    Integer num30 = (Integer) allDebridRepository$resolveToDirectLink$15.L$4;
                    num5 = (Integer) allDebridRepository$resolveToDirectLink$15.L$3;
                    Integer num31 = (Integer) allDebridRepository$resolveToDirectLink$15.L$2;
                    String str23 = (String) allDebridRepository$resolveToDirectLink$15.L$1;
                    AllDebridRepository allDebridRepository12 = (AllDebridRepository) allDebridRepository$resolveToDirectLink$15.L$0;
                    s38.b(account);
                    str4 = str22;
                    str3 = str23;
                    num6 = num30;
                    num4 = num31;
                    allDebridRepository = allDebridRepository12;
                    allDebridAccount = (AllDebridAccount) account;
                    if (allDebridAccount != null) {
                    }
                    break;
                case 2:
                    allDebridAccount2 = (AllDebridAccount) allDebridRepository$resolveToDirectLink$15.L$6;
                    String str24 = (String) allDebridRepository$resolveToDirectLink$15.L$5;
                    Integer num32 = (Integer) allDebridRepository$resolveToDirectLink$15.L$4;
                    Integer num33 = (Integer) allDebridRepository$resolveToDirectLink$15.L$3;
                    Integer num34 = (Integer) allDebridRepository$resolveToDirectLink$15.L$2;
                    strConcat = (String) allDebridRepository$resolveToDirectLink$15.L$1;
                    AllDebridRepository allDebridRepository13 = (AllDebridRepository) allDebridRepository$resolveToDirectLink$15.L$0;
                    s38.b(account);
                    allDebridRepository2 = allDebridRepository13;
                    str5 = str24;
                    num8 = num32;
                    num5 = num33;
                    num7 = num34;
                    AllDebridRepository allDebridRepository82 = allDebridRepository2;
                    num9 = (Integer) account;
                    if (num9 == null) {
                    }
                    break;
                case 3:
                    String str25 = (String) allDebridRepository$resolveToDirectLink$15.L$5;
                    String str26 = (String) allDebridRepository$resolveToDirectLink$15.L$4;
                    Integer num35 = (Integer) allDebridRepository$resolveToDirectLink$15.L$3;
                    num10 = (Integer) allDebridRepository$resolveToDirectLink$15.L$2;
                    num11 = (Integer) allDebridRepository$resolveToDirectLink$15.L$1;
                    AllDebridRepository allDebridRepository14 = (AllDebridRepository) allDebridRepository$resolveToDirectLink$15.L$0;
                    s38.b(account);
                    str6 = str25;
                    str7 = str26;
                    num12 = num35;
                    allDebridRepository3 = allDebridRepository14;
                    allDebridRepository$resolveToDirectLink$12 = allDebridRepository$resolveToDirectLink$15;
                    obj = null;
                    allDebridResponse = (AllDebridResponse) account;
                    if (cr4.b(allDebridResponse.getStatus(), "success")) {
                        allDebridUploadedMagnet = (AllDebridUploadedMagnet) y41.ab(((AllDebridMagnetUploadData) allDebridResponse.getData()).getMagnets());
                        if (allDebridUploadedMagnet != null) {
                        }
                    }
                    error = allDebridResponse.getError();
                    if (error != null) {
                        message = "Failed to upload magnet";
                    }
                    return s38.a(new Exception(message));
                case 4:
                    long j6 = allDebridRepository$resolveToDirectLink$15.J$0;
                    str9 = (String) allDebridRepository$resolveToDirectLink$15.L$5;
                    String str27 = (String) allDebridRepository$resolveToDirectLink$15.L$4;
                    Integer num36 = (Integer) allDebridRepository$resolveToDirectLink$15.L$3;
                    Integer num37 = (Integer) allDebridRepository$resolveToDirectLink$15.L$2;
                    num16 = (Integer) allDebridRepository$resolveToDirectLink$15.L$1;
                    allDebridRepository5 = (AllDebridRepository) allDebridRepository$resolveToDirectLink$15.L$0;
                    s38.b(account);
                    num14 = num36;
                    num13 = num37;
                    allDebridRepository$resolveToDirectLink$12 = allDebridRepository$resolveToDirectLink$15;
                    magnetStatus$default = account;
                    str10 = str27;
                    obj3 = null;
                    j2 = j6;
                    allDebridResponse2 = (AllDebridResponse) magnetStatus$default;
                    if (cr4.b(allDebridResponse2.getStatus(), "success")) {
                        if (cr4.b(((AllDebridMagnetStatusData) allDebridResponse2.getData()).getMagnets().getStatus(), "Ready")) {
                        }
                    }
                    error2 = allDebridResponse2.getError();
                    if (error2 != null) {
                        message2 = "Failed to get magnet status";
                    }
                    return s38.a(new Exception(message2));
                case 5:
                    long j7 = allDebridRepository$resolveToDirectLink$15.J$0;
                    String str28 = (String) allDebridRepository$resolveToDirectLink$15.L$5;
                    str12 = (String) allDebridRepository$resolveToDirectLink$15.L$4;
                    num18 = (Integer) allDebridRepository$resolveToDirectLink$15.L$3;
                    Integer num38 = (Integer) allDebridRepository$resolveToDirectLink$15.L$2;
                    num19 = (Integer) allDebridRepository$resolveToDirectLink$15.L$1;
                    AllDebridRepository allDebridRepository15 = (AllDebridRepository) allDebridRepository$resolveToDirectLink$15.L$0;
                    s38.b(account);
                    num17 = num38;
                    allDebridRepository$resolveToDirectLink$12 = allDebridRepository$resolveToDirectLink$15;
                    j3 = j7;
                    magnetFiles$default = account;
                    str11 = str28;
                    allDebridRepository6 = allDebridRepository15;
                    obj4 = null;
                    allDebridResponse3 = (AllDebridResponse) magnetFiles$default;
                    if (cr4.b(allDebridResponse3.getStatus(), "success")) {
                        allDebridMagnetFilesEntry = (AllDebridMagnetFilesEntry) y41.ab(((AllDebridMagnetFilesData) allDebridResponse3.getData()).getMagnets());
                        if (allDebridMagnetFilesEntry != null) {
                        }
                    }
                    error3 = allDebridResponse3.getError();
                    if (error3 != null) {
                        message3 = "Failed to get magnet files";
                    }
                    return s38.a(new Exception(message3));
                case 6:
                    long j8 = allDebridRepository$resolveToDirectLink$15.J$0;
                    list = (List) allDebridRepository$resolveToDirectLink$15.L$1;
                    allDebridRepository7 = (AllDebridRepository) allDebridRepository$resolveToDirectLink$15.L$0;
                    s38.b(account);
                    j3 = j8;
                    allDebridRepository$resolveToDirectLink$13 = allDebridRepository$resolveToDirectLink$15;
                    str13 = "success";
                    ck1Var = ck1Var2;
                    objUnlockLink$default = account;
                    r0 = 0;
                    allDebridResponse4 = (AllDebridResponse) objUnlockLink$default;
                    if (cr4.b(allDebridResponse4.getStatus(), str13)) {
                        break;
                    }
                    error4 = allDebridResponse4.getError();
                    if (error4 != null) {
                        message4 = "Failed to unlock link";
                    }
                    String str182 = message4;
                    return s38.a((!n89.l(str182, "expired", true) || n89.l(str182, "premium", true)) ? new DebridError.AccountExpired(DebridProvider.ALL_DEBRID, r0, 2, r0) : (n89.l(str182, "auth", true) || n89.l(str182, "apikey", true)) ? new DebridError.AuthenticationFailed(DebridProvider.ALL_DEBRID, r0, 2, r0) : new DebridError.Unknown(DebridProvider.ALL_DEBRID, str182, null, 4, null));
                case 7:
                    j4 = allDebridRepository$resolveToDirectLink$15.J$0;
                    allDebridResponse5 = (AllDebridResponse) allDebridRepository$resolveToDirectLink$15.L$0;
                    try {
                        s38.b(account);
                        ((q38) account).getClass();
                        ExecutorService executorService32 = kq.a;
                        kq.h(TAG, "Cloud sanitization: removed AD magnet " + j4);
                        break;
                    } catch (Exception e2) {
                        e = e2;
                        ExecutorService executorService22 = kq.a;
                        kq.a(TAG, "Cloud sanitization failed for AD magnet " + j4, e);
                    }
                    allDebridResponse4 = allDebridResponse5;
                    return ((AllDebridUnlockData) allDebridResponse4.getData()).getLink();
                default:
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
        } catch (SocketTimeoutException e3) {
            Log.e(TAG, "Failed to resolve direct link: timeout", e3);
            return s38.a(new DebridError.ServiceDown(DebridProvider.ALL_DEBRID, null, e3, 2, null));
        } catch (UnknownHostException e4) {
            Log.e(TAG, "Failed to resolve direct link: DNS error", e4);
            return s38.a(new DebridError.DnsError(DebridProvider.ALL_DEBRID, e4));
        } catch (HttpException e5) {
            Log.e(TAG, "Failed to resolve direct link: HTTP " + e5.code(), e5);
            int iCode = e5.code();
            if (iCode == 401 || iCode == 403) {
                authenticationFailed = new DebridError.AuthenticationFailed(DebridProvider.ALL_DEBRID, e5);
            } else if (iCode != 500) {
                switch (iCode) {
                    case 502:
                    case 503:
                    case 504:
                        authenticationFailed = new DebridError.ServiceDown(DebridProvider.ALL_DEBRID, Boxing.boxInt(e5.code()), e5);
                        break;
                    default:
                        authenticationFailed = new DebridError.Unknown(DebridProvider.ALL_DEBRID, n41.k("HTTP ", e5.code()), e5);
                        break;
                }
            }
            return s38.a(authenticationFailed);
        } catch (Exception e6) {
            Log.e(TAG, "Failed to resolve direct link", e6);
            return s38.a(new DebridError.Unknown(DebridProvider.ALL_DEBRID, e6.getMessage(), e6));
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:42:0x010f A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0020  */
    @pq6
    /* JADX INFO: renamed from: saveApiKey-gIAlu-s, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m77saveApiKeygIAlus(@kp6 String str, @kp6 Continuation<? super q38<AllDebridAccount>> continuation) {
        AllDebridRepository$saveApiKey$1 allDebridRepository$saveApiKey$1;
        AllDebridRepository allDebridRepository;
        String message;
        AllDebridUser user;
        AllDebridAccount allDebridAccount;
        String str2 = str;
        if (continuation instanceof AllDebridRepository$saveApiKey$1) {
            allDebridRepository$saveApiKey$1 = (AllDebridRepository$saveApiKey$1) continuation;
            int i = allDebridRepository$saveApiKey$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                allDebridRepository$saveApiKey$1.label = i - Integer.MIN_VALUE;
            } else {
                allDebridRepository$saveApiKey$1 = new AllDebridRepository$saveApiKey$1(this, continuation);
            }
        }
        AllDebridRepository$saveApiKey$1 allDebridRepository$saveApiKey$12 = allDebridRepository$saveApiKey$1;
        Object user$default = allDebridRepository$saveApiKey$12.result;
        ck1 ck1Var = ck1.a;
        int i2 = allDebridRepository$saveApiKey$12.label;
        try {
            if (i2 == 0) {
                s38.b(user$default);
                AllDebridApiService allDebridApiService = this.allDebridApiService;
                allDebridRepository$saveApiKey$12.L$0 = this;
                allDebridRepository$saveApiKey$12.L$1 = str2;
                allDebridRepository$saveApiKey$12.label = 1;
                user$default = AllDebridApiService.DefaultImpls.getUser$default(allDebridApiService, "Bearer " + str2, null, allDebridRepository$saveApiKey$12, 2, null);
                if (user$default != ck1Var) {
                    allDebridRepository = this;
                }
            } else {
                if (i2 != 1) {
                    if (i2 != 2) {
                        if (i2 != 3) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        AllDebridAccount allDebridAccount2 = (AllDebridAccount) allDebridRepository$saveApiKey$12.L$0;
                        s38.b(user$default);
                        return allDebridAccount2;
                    }
                    allDebridAccount = (AllDebridAccount) allDebridRepository$saveApiKey$12.L$2;
                    user = (AllDebridUser) allDebridRepository$saveApiKey$12.L$1;
                    allDebridRepository = (AllDebridRepository) allDebridRepository$saveApiKey$12.L$0;
                    s38.b(user$default);
                    ExecutorService executorService = kq.a;
                    kq.h(TAG, "AllDebrid account saved: " + user.getUsername());
                    allDebridRepository$saveApiKey$12.L$0 = allDebridAccount;
                    allDebridRepository$saveApiKey$12.L$1 = null;
                    allDebridRepository$saveApiKey$12.L$2 = null;
                    allDebridRepository$saveApiKey$12.label = 3;
                    return allDebridRepository.triggerCloudSync(allDebridRepository$saveApiKey$12) != ck1Var ? ck1Var : allDebridAccount;
                }
                str2 = (String) allDebridRepository$saveApiKey$12.L$1;
                allDebridRepository = (AllDebridRepository) allDebridRepository$saveApiKey$12.L$0;
                s38.b(user$default);
            }
            String str3 = str2;
            AllDebridResponse allDebridResponse = (AllDebridResponse) user$default;
            if (!cr4.b(allDebridResponse.getStatus(), "success") || allDebridResponse.getData() == null) {
                AllDebridError error = allDebridResponse.getError();
                if (error == null || (message = error.getMessage()) == null) {
                    message = "Failed to get user info";
                }
                Log.w(TAG, "AllDebrid verification failed: ".concat(message));
                return s38.a(new Exception(message));
            }
            user = ((AllDebridUserData) allDebridResponse.getData()).getUser();
            long jCurrentTimeMillis = System.currentTimeMillis();
            allDebridAccount = new AllDebridAccount("alldebrid", str3, user.getUsername(), user.getEmail(), user.isPremium(), user.isSubscribed(), user.isTrial(), user.getPremiumUntil(), user.getFidelityPoints(), jCurrentTimeMillis, jCurrentTimeMillis);
            AllDebridAccountDao allDebridAccountDao = allDebridRepository.accountDao;
            allDebridRepository$saveApiKey$12.L$0 = allDebridRepository;
            allDebridRepository$saveApiKey$12.L$1 = user;
            allDebridRepository$saveApiKey$12.L$2 = allDebridAccount;
            allDebridRepository$saveApiKey$12.label = 2;
            if (allDebridAccountDao.upsert(allDebridAccount, allDebridRepository$saveApiKey$12) != ck1Var) {
                ExecutorService executorService2 = kq.a;
                kq.h(TAG, "AllDebrid account saved: " + user.getUsername());
                allDebridRepository$saveApiKey$12.L$0 = allDebridAccount;
                allDebridRepository$saveApiKey$12.L$1 = null;
                allDebridRepository$saveApiKey$12.L$2 = null;
                allDebridRepository$saveApiKey$12.label = 3;
                if (allDebridRepository.triggerCloudSync(allDebridRepository$saveApiKey$12) != ck1Var) {
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "Failed to save API key", e);
            return s38.a(e);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /* JADX INFO: renamed from: verifyAndSaveApiKey-gIAlu-s, reason: not valid java name */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object m78verifyAndSaveApiKeygIAlus(@kp6 String str, @kp6 Continuation<? super q38<AllDebridAccount>> continuation) {
        AllDebridRepository$verifyAndSaveApiKey$1 allDebridRepository$verifyAndSaveApiKey$1;
        if (continuation instanceof AllDebridRepository$verifyAndSaveApiKey$1) {
            allDebridRepository$verifyAndSaveApiKey$1 = (AllDebridRepository$verifyAndSaveApiKey$1) continuation;
            int i = allDebridRepository$verifyAndSaveApiKey$1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                allDebridRepository$verifyAndSaveApiKey$1.label = i - Integer.MIN_VALUE;
            } else {
                allDebridRepository$verifyAndSaveApiKey$1 = new AllDebridRepository$verifyAndSaveApiKey$1(this, continuation);
            }
        }
        Object obj = allDebridRepository$verifyAndSaveApiKey$1.result;
        Object obj2 = ck1.a;
        int i2 = allDebridRepository$verifyAndSaveApiKey$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);
        allDebridRepository$verifyAndSaveApiKey$1.label = 1;
        Object objM77saveApiKeygIAlus = m77saveApiKeygIAlus(str, allDebridRepository$verifyAndSaveApiKey$1);
        return objM77saveApiKeygIAlus == obj2 ? obj2 : objM77saveApiKeygIAlus;
    }
}
