From 9b00508ef8565aedde954c109a4bb79a13f0f8fb Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Thu, 16 Nov 2023 10:52:29 -0800
Subject: feat(wrapped): media format filters

---
 src/lib/Tools/Wrapped.svelte | 132 ++++++++++++++++++++++++-------------------
 1 file changed, 75 insertions(+), 57 deletions(-)

(limited to 'src/lib/Tools/Wrapped.svelte')

diff --git a/src/lib/Tools/Wrapped.svelte b/src/lib/Tools/Wrapped.svelte
index 1d0c6761..107d70b0 100644
--- a/src/lib/Tools/Wrapped.svelte
+++ b/src/lib/Tools/Wrapped.svelte
@@ -25,6 +25,15 @@
 	let transparency = false;
 	let darkTheme = true;
 	let watermark = false;
+	let includeMusic = false;
+	let includeSpecials = false;
+
+	$: {
+		includeMusic = includeMusic;
+		includeSpecials = includeSpecials;
+
+		update().then(() => {});
+	}
 
 	onMount(async () => {
 		if (user !== undefined) {
@@ -34,68 +43,73 @@
 
 			currentUserIdentity = JSON.parse($userIdentity);
 			currentUserIdentity.name = currentUserIdentity.name;
-
-			const currentYear = new Date(Date.now()).getFullYear();
-
-			animeList = (
-				await mediaListCollection(
-					user,
-					currentUserIdentity,
-					Type.Anime,
-					$anime,
-					$lastPruneTimes.anime,
-					true,
-					true
-				)
-			)
-				.filter(
-					(item, index, self) =>
-						self.findIndex((itemToCompare) => itemToCompare.id === item.id) === index &&
-						item.mediaListEntry?.startedAt.year === currentYear
-				)
-				.sort((a, b) => {
-					if (a.mediaListEntry?.score === undefined) {
-						return 1;
-					} else if (b.mediaListEntry?.score === undefined) {
-						return -1;
-					} else {
-						return b.mediaListEntry?.score - a.mediaListEntry?.score;
-					}
-				});
-			mangaList = (
-				await mediaListCollection(
-					user,
-					currentUserIdentity,
-					Type.Manga,
-					$manga,
-					$lastPruneTimes.manga,
-					true,
-					true
-				)
-			)
-				.filter(
-					(item, index, self) =>
-						self.findIndex((itemToCompare) => itemToCompare.id === item.id) === index &&
-						item.mediaListEntry?.startedAt.year === currentYear
-				)
-				.sort((a, b) => {
-					if (a.mediaListEntry?.score === undefined) {
-						return 1;
-					} else if (b.mediaListEntry?.score === undefined) {
-						return -1;
-					} else {
-						return b.mediaListEntry?.score - a.mediaListEntry?.score;
-					}
-				});
-
-			for (const media of animeList) {
-				episodes += media.mediaListEntry?.progress || 0;
-			}
 		} else {
 			currentUserIdentity.id = -2;
 		}
+
+		await update();
 	});
 
+	const update = async () => {
+		const currentYear = new Date(Date.now()).getFullYear();
+
+		animeList = (
+			await mediaListCollection(
+				user,
+				currentUserIdentity,
+				Type.Anime,
+				$anime,
+				$lastPruneTimes.anime,
+				true,
+				true
+			)
+		)
+			.filter(
+				(item, index, self) =>
+					self.findIndex((itemToCompare) => itemToCompare.id === item.id) === index &&
+					item.mediaListEntry?.startedAt.year === currentYear &&
+					(includeMusic ? true : item.format !== 'MUSIC')
+			)
+			.sort((a, b) => {
+				if (a.mediaListEntry?.score === undefined) {
+					return 1;
+				} else if (b.mediaListEntry?.score === undefined) {
+					return -1;
+				} else {
+					return b.mediaListEntry?.score - a.mediaListEntry?.score;
+				}
+			});
+		mangaList = (
+			await mediaListCollection(
+				user,
+				currentUserIdentity,
+				Type.Manga,
+				$manga,
+				$lastPruneTimes.manga,
+				true,
+				true
+			)
+		)
+			.filter(
+				(item, index, self) =>
+					self.findIndex((itemToCompare) => itemToCompare.id === item.id) === index &&
+					item.mediaListEntry?.startedAt.year === currentYear
+			)
+			.sort((a, b) => {
+				if (a.mediaListEntry?.score === undefined) {
+					return 1;
+				} else if (b.mediaListEntry?.score === undefined) {
+					return -1;
+				} else {
+					return b.mediaListEntry?.score - a.mediaListEntry?.score;
+				}
+			});
+
+		for (const media of animeList) {
+			episodes += media.mediaListEntry?.progress || 0;
+		}
+	};
+
 	/* eslint-disable @typescript-eslint/no-explicit-any */
 	const year = (statistic: { startYears: any }) => {
 		return statistic.startYears.find((y: { startYear: number }) => y.startYear === 2023);
@@ -322,6 +336,10 @@
 			<li>
 				<input type="checkbox" bind:checked={transparency} /> Enable background transparency
 			</li>
+			<li>
+				<input type="checkbox" bind:checked={includeMusic} /> Include music
+				<input type="checkbox" bind:checked={includeSpecials} /> Include specials and OVAs
+			</li>
 			<li>
 				<a href={'#'} on:click={() => screenshot(true)}>Generate dark themed image</a>
 			</li>
-- 
cgit v1.2.3

