package com.strmr.ps.data.repository;

import com.strmr.ps.data.model.tmdb.TMDBGenre;
import com.strmr.ps.data.model.tmdb.TMDBImagesKt;
import com.strmr.ps.data.model.tmdb.TMDBShowDetails;
import com.strmr.ps.data.model.trakt.TraktIds;
import com.strmr.ps.data.model.trakt.TraktShow;
import com.strmr.ps.data.remote.RateLimiter;
import defpackage.ak1;
import defpackage.bt5;
import defpackage.ck1;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.hx9;
import defpackage.js5;
import defpackage.n89;
import defpackage.os5;
import defpackage.q38;
import defpackage.s38;
import defpackage.vx8;
import defpackage.y41;
import java.util.List;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0005\u001a\u0016\u0012\u0004\u0012\u00020\u0002\u0012\u0004\u0012\u00020\u0003\u0012\u0004\u0012\u00020\u0004\u0018\u00010\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0005\u0010\u0006"}, d2 = {"Lak1;", "Lhx9;", "Ljs5;", "Los5;", "Lbt5;", "<anonymous>", "(Lak1;)Lhx9;"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.data.repository.MediaRepository$fetchShows$2$results$1$1$1", f = "MediaRepository.kt", i = {0, 0, 1}, l = {387, 389}, m = "invokeSuspend", n = {"$this$async", "tmdbId", "tmdbId"}, s = {"L$0", "I$0", "I$0"})
@vx8
public final class MediaRepository$fetchShows$2$results$1$1$1 extends SuspendLambda implements gr3<ak1, Continuation<? super hx9<? extends js5, ? extends os5, ? extends bt5>>, Object> {
    final /* synthetic */ int $basePosition;
    final /* synthetic */ String $category;
    final /* synthetic */ int $index;
    final /* synthetic */ TraktShow $show;
    int I$0;
    int I$1;
    int I$2;
    private /* synthetic */ Object L$0;
    Object L$1;
    Object L$2;
    int label;
    final /* synthetic */ MediaRepository this$0;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public MediaRepository$fetchShows$2$results$1$1$1(TraktShow traktShow, MediaRepository mediaRepository, String str, int i, int i2, Continuation<? super MediaRepository$fetchShows$2$results$1$1$1> continuation) {
        super(2, continuation);
        this.$show = traktShow;
        this.this$0 = mediaRepository;
        this.$category = str;
        this.$basePosition = i;
        this.$index = i2;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
        MediaRepository$fetchShows$2$results$1$1$1 mediaRepository$fetchShows$2$results$1$1$1 = new MediaRepository$fetchShows$2$results$1$1$1(this.$show, this.this$0, this.$category, this.$basePosition, this.$index, continuation);
        mediaRepository$fetchShows$2$results$1$1$1.L$0 = obj;
        return mediaRepository$fetchShows$2$results$1$1$1;
    }

    @Override // defpackage.gr3
    public final Object invoke(ak1 ak1Var, Continuation<? super hx9<js5, os5, bt5>> continuation) {
        return ((MediaRepository$fetchShows$2$results$1$1$1) create(ak1Var, continuation)).invokeSuspend(e6a.a);
    }

    /* JADX WARN: Can't wrap try/catch for region: R(8:0|2|(1:(1:(29:6|83|7|8|81|27|(1:29)(1:32)|33|(1:37)|38|(1:40)(1:41)|42|(1:44)(1:45)|46|(1:48)(1:49)|50|51|52|(1:54)|(1:56)(1:57)|58|(1:60)(1:61)|62|(1:64)(1:65)|66|71|(1:73)|74|(1:87)(2:77|78))(2:11|12))(1:13))(2:14|(1:86)(3:18|(1:21)|25))|22|79|23|(26:26|81|27|(0)(0)|33|(2:35|37)|38|(0)(0)|42|(0)(0)|46|(0)(0)|50|51|52|(0)|(0)(0)|58|(0)(0)|62|(0)(0)|66|71|(0)|74|(0)(0))|25) */
    /* JADX WARN: Code restructure failed: missing block: B:68:0x0181, code lost:
    
        r0 = th;
     */
    /* JADX WARN: Code restructure failed: missing block: B:69:0x0182, code lost:
    
        r2 = r11;
     */
    /* JADX WARN: Removed duplicated region for block: B:29:0x00ac A[Catch: all -> 0x00b3, TryCatch #1 {all -> 0x00b3, blocks: (B:27:0x00a2, B:29:0x00ac, B:33:0x00ba, B:35:0x00c0, B:38:0x00c8, B:40:0x00d4, B:42:0x00de, B:44:0x00e4, B:46:0x00ef, B:48:0x00fd, B:50:0x011b), top: B:81:0x00a2 }] */
    /* JADX WARN: Removed duplicated region for block: B:32:0x00b8  */
    /* JADX WARN: Removed duplicated region for block: B:40:0x00d4 A[Catch: all -> 0x00b3, TryCatch #1 {all -> 0x00b3, blocks: (B:27:0x00a2, B:29:0x00ac, B:33:0x00ba, B:35:0x00c0, B:38:0x00c8, B:40:0x00d4, B:42:0x00de, B:44:0x00e4, B:46:0x00ef, B:48:0x00fd, B:50:0x011b), top: B:81:0x00a2 }] */
    /* JADX WARN: Removed duplicated region for block: B:41:0x00dc  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x00e4 A[Catch: all -> 0x00b3, TryCatch #1 {all -> 0x00b3, blocks: (B:27:0x00a2, B:29:0x00ac, B:33:0x00ba, B:35:0x00c0, B:38:0x00c8, B:40:0x00d4, B:42:0x00de, B:44:0x00e4, B:46:0x00ef, B:48:0x00fd, B:50:0x011b), top: B:81:0x00a2 }] */
    /* JADX WARN: Removed duplicated region for block: B:45:0x00ed  */
    /* JADX WARN: Removed duplicated region for block: B:48:0x00fd A[Catch: all -> 0x00b3, TryCatch #1 {all -> 0x00b3, blocks: (B:27:0x00a2, B:29:0x00ac, B:33:0x00ba, B:35:0x00c0, B:38:0x00c8, B:40:0x00d4, B:42:0x00de, B:44:0x00e4, B:46:0x00ef, B:48:0x00fd, B:50:0x011b), top: B:81:0x00a2 }] */
    /* JADX WARN: Removed duplicated region for block: B:49:0x0119  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x013b A[Catch: all -> 0x002f, TryCatch #2 {all -> 0x002f, blocks: (B:7:0x0023, B:52:0x0125, B:54:0x013b, B:56:0x0141, B:58:0x0147, B:60:0x015c, B:62:0x0167, B:64:0x016d, B:66:0x0178), top: B:83:0x0023 }] */
    /* JADX WARN: Removed duplicated region for block: B:56:0x0141 A[Catch: all -> 0x002f, TryCatch #2 {all -> 0x002f, blocks: (B:7:0x0023, B:52:0x0125, B:54:0x013b, B:56:0x0141, B:58:0x0147, B:60:0x015c, B:62:0x0167, B:64:0x016d, B:66:0x0178), top: B:83:0x0023 }] */
    /* JADX WARN: Removed duplicated region for block: B:57:0x0146  */
    /* JADX WARN: Removed duplicated region for block: B:60:0x015c A[Catch: all -> 0x002f, TryCatch #2 {all -> 0x002f, blocks: (B:7:0x0023, B:52:0x0125, B:54:0x013b, B:56:0x0141, B:58:0x0147, B:60:0x015c, B:62:0x0167, B:64:0x016d, B:66:0x0178), top: B:83:0x0023 }] */
    /* JADX WARN: Removed duplicated region for block: B:61:0x0166  */
    /* JADX WARN: Removed duplicated region for block: B:64:0x016d A[Catch: all -> 0x002f, TryCatch #2 {all -> 0x002f, blocks: (B:7:0x0023, B:52:0x0125, B:54:0x013b, B:56:0x0141, B:58:0x0147, B:60:0x015c, B:62:0x0167, B:64:0x016d, B:66:0x0178), top: B:83:0x0023 }] */
    /* JADX WARN: Removed duplicated region for block: B:65:0x0177  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x0191  */
    /* JADX WARN: Removed duplicated region for block: B:77:0x0199  */
    /* JADX WARN: Removed duplicated region for block: B:87:? A[RETURN, SYNTHETIC] */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        Integer tmdb;
        int i;
        int i2;
        int i3;
        Object objRetryWithBackoff$default;
        MediaRepository mediaRepository;
        int i4;
        TraktShow traktShow;
        String str;
        int i5;
        Object objA;
        Throwable thA;
        String name;
        String preferredBackdropPath;
        ck1 ck1Var = ck1.a;
        int i6 = this.label;
        if (i6 == 0) {
            s38.b(obj);
            ak1 ak1Var = (ak1) this.L$0;
            TraktIds ids = this.$show.getIds();
            if (ids == null || (tmdb = ids.getTmdb()) == null) {
                return null;
            }
            int iIntValue = tmdb.intValue();
            RateLimiter rateLimiter = this.this$0.rateLimiter;
            this.L$0 = ak1Var;
            this.I$0 = iIntValue;
            this.label = 1;
            if (rateLimiter.a(this) != ck1Var) {
                i = iIntValue;
            }
            return ck1Var;
        }
        if (i6 != 1) {
            if (i6 != 2) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            i5 = this.I$2;
            int i7 = this.I$1;
            i3 = this.I$0;
            String str2 = (String) this.L$2;
            traktShow = (TraktShow) this.L$1;
            mediaRepository = (MediaRepository) this.L$0;
            try {
                s38.b(obj);
                i2 = i7;
                i4 = i3;
                str = str2;
                objRetryWithBackoff$default = obj;
                try {
                    TMDBShowDetails tMDBShowDetails = (TMDBShowDetails) objRetryWithBackoff$default;
                    TraktIds ids2 = traktShow.getIds();
                    String imdb = ids2 == null ? ids2.getImdb() : null;
                    name = tMDBShowDetails.getName();
                    if (name == null && (name = traktShow.getTitle()) == null) {
                        name = "";
                    }
                    String str3 = name;
                    String overview = tMDBShowDetails.getOverview();
                    String firstAirDate = tMDBShowDetails.getFirstAirDate();
                    String strBb = firstAirDate == null ? n89.bb(4, firstAirDate) : null;
                    List<Integer> episodeRunTime = tMDBShowDetails.getEpisodeRunTime();
                    Integer num = episodeRunTime == null ? (Integer) y41.ab(episodeRunTime) : null;
                    String certification = tMDBShowDetails.getCertification();
                    int i8 = i2 + i5;
                    List<TMDBGenre> genres = tMDBShowDetails.getGenres();
                    js5 js5Var = new js5(i4, imdb, str3, overview, strBb, num, certification, "tv", str, i8, genres == null ? y41.ai(genres, ",", null, null, new a(15), 30) : null, tMDBShowDetails.getCastNames(5));
                    i3 = i4;
                    String posterUrl = tMDBShowDetails.getPosterUrl(mediaRepository.getImgLang());
                    preferredBackdropPath = TMDBImagesKt.getPreferredBackdropPath(tMDBShowDetails.getImages(), mediaRepository.getImgLang());
                    if (preferredBackdropPath == null) {
                        preferredBackdropPath = tMDBShowDetails.getBackdropPath();
                    }
                    os5 os5Var = new os5(i3, posterUrl, preferredBackdropPath == null ? "https://image.tmdb.org/t/p/w1280".concat(preferredBackdropPath) : null, tMDBShowDetails.getLogoUrl(mediaRepository.getImgLang()));
                    Double voteAverage = tMDBShowDetails.getVoteAverage();
                    Float fBoxFloat = voteAverage == null ? Boxing.boxFloat((float) voteAverage.doubleValue()) : null;
                    Double rating = traktShow.getRating();
                    objA = new hx9(js5Var, os5Var, new bt5(i3, fBoxFloat, rating == null ? Boxing.boxFloat((float) rating.doubleValue()) : null));
                } catch (Throwable th) {
                    th = th;
                    i3 = i4;
                    objA = s38.a(th);
                }
            } catch (Throwable th2) {
                th = th2;
                objA = s38.a(th);
                MediaRepository mediaRepository2 = this.this$0;
                String str4 = this.$category;
                thA = q38.a(objA);
                if (thA != null) {
                }
                if (objA instanceof q38.b) {
                }
            }
            MediaRepository mediaRepository22 = this.this$0;
            String str42 = this.$category;
            thA = q38.a(objA);
            if (thA != null) {
                mediaRepository22.logItemEnrichmentError(thA, i3, str42);
            }
            if (objA instanceof q38.b) {
                return objA;
            }
            return null;
        }
        int i9 = this.I$0;
        s38.b(obj);
        i = i9;
        MediaRepository mediaRepository3 = this.this$0;
        TraktShow traktShow2 = this.$show;
        String str5 = this.$category;
        i2 = this.$basePosition;
        int i10 = this.$index;
        MediaRepository$fetchShows$2$results$1$1$1$1$tmdbDetails$1 mediaRepository$fetchShows$2$results$1$1$1$1$tmdbDetails$1 = new MediaRepository$fetchShows$2$results$1$1$1$1$tmdbDetails$1(mediaRepository3, i, null);
        this.L$0 = mediaRepository3;
        this.L$1 = traktShow2;
        this.L$2 = str5;
        this.I$0 = i;
        this.I$1 = i2;
        this.I$2 = i10;
        this.label = 2;
        objRetryWithBackoff$default = MediaRepository.retryWithBackoff$default(mediaRepository3, 0, 0L, mediaRepository$fetchShows$2$results$1$1$1$1$tmdbDetails$1, this, 3, null);
        if (objRetryWithBackoff$default != ck1Var) {
            mediaRepository = mediaRepository3;
            i4 = i;
            traktShow = traktShow2;
            str = str5;
            i5 = i10;
            TMDBShowDetails tMDBShowDetails2 = (TMDBShowDetails) objRetryWithBackoff$default;
            TraktIds ids22 = traktShow.getIds();
            if (ids22 == null) {
            }
            name = tMDBShowDetails2.getName();
            if (name == null) {
                name = "";
            }
            String str32 = name;
            String overview2 = tMDBShowDetails2.getOverview();
            String firstAirDate2 = tMDBShowDetails2.getFirstAirDate();
            if (firstAirDate2 == null) {
            }
            List<Integer> episodeRunTime2 = tMDBShowDetails2.getEpisodeRunTime();
            if (episodeRunTime2 == null) {
            }
            String certification2 = tMDBShowDetails2.getCertification();
            int i82 = i2 + i5;
            List<TMDBGenre> genres2 = tMDBShowDetails2.getGenres();
            js5 js5Var2 = new js5(i4, imdb, str32, overview2, strBb, num, certification2, "tv", str, i82, genres2 == null ? y41.ai(genres2, ",", null, null, new a(15), 30) : null, tMDBShowDetails2.getCastNames(5));
            i3 = i4;
            String posterUrl2 = tMDBShowDetails2.getPosterUrl(mediaRepository.getImgLang());
            preferredBackdropPath = TMDBImagesKt.getPreferredBackdropPath(tMDBShowDetails2.getImages(), mediaRepository.getImgLang());
            if (preferredBackdropPath == null) {
            }
            os5 os5Var2 = new os5(i3, posterUrl2, preferredBackdropPath == null ? "https://image.tmdb.org/t/p/w1280".concat(preferredBackdropPath) : null, tMDBShowDetails2.getLogoUrl(mediaRepository.getImgLang()));
            Double voteAverage2 = tMDBShowDetails2.getVoteAverage();
            if (voteAverage2 == null) {
            }
            Double rating2 = traktShow.getRating();
            objA = new hx9(js5Var2, os5Var2, new bt5(i3, fBoxFloat, rating2 == null ? Boxing.boxFloat((float) rating2.doubleValue()) : null));
            MediaRepository mediaRepository222 = this.this$0;
            String str422 = this.$category;
            thA = q38.a(objA);
            if (thA != null) {
            }
            if (objA instanceof q38.b) {
            }
        }
        return ck1Var;
    }
}
