fixed simkl and anilist syncing bugs

This commit is contained in:
John O'Keefe 2024-08-19 08:09:03 -04:00
parent 4d9012b43c
commit e3ed5bb2b9
7 changed files with 149 additions and 73 deletions

View File

@ -138,7 +138,7 @@ func (a *App) GetAniListItem(aniId int, login bool) AniListGetSingleAnime {
Variables: neededVariables,
}
returnedBody, _ := AniListQuery(body, false)
returnedBody, _ := AniListQuery(body, login)
var post AniListGetSingleAnime
err := json.Unmarshal(returnedBody, &post)

View File

@ -83,7 +83,7 @@ func (a *App) SimklGetUserWatchlist() SimklWatchList {
return watchlist
}
func (a *App) SimklSyncEpisodes(anime SimklAnime, progress int) interface{} {
func (a *App) SimklSyncEpisodes(anime SimklAnime, progress int) SimklAnime {
var episodes []Episode
var url string
@ -124,10 +124,18 @@ func (a *App) SimklSyncEpisodes(anime SimklAnime, progress int) interface{} {
log.Printf("Failed at unmarshal, %s\n", err)
}
return success
for i, simklAnime := range WatchList.Anime {
if anime.Show.Ids.Simkl == simklAnime.Show.Ids.Simkl {
WatchList.Anime[i].WatchedEpisodesCount = progress
}
}
anime.WatchedEpisodesCount = progress
return anime
}
func (a *App) SimklSyncRating(anime SimklAnime, rating int) interface{} {
func (a *App) SimklSyncRating(anime SimklAnime, rating int) SimklAnime {
var url string
var showWithRating = ShowWithRating{
Title: anime.Show.Title,
@ -171,10 +179,18 @@ func (a *App) SimklSyncRating(anime SimklAnime, rating int) interface{} {
log.Printf("Failed at unmarshal, %s\n", err)
}
return success
for i, simklAnime := range WatchList.Anime {
if anime.Show.Ids.Simkl == simklAnime.Show.Ids.Simkl {
WatchList.Anime[i].UserRating = rating
}
}
anime.UserRating = rating
return anime
}
func (a *App) SimklSyncStatus(anime SimklAnime, status string) interface{} {
func (a *App) SimklSyncStatus(anime SimklAnime, status string) SimklAnime {
url := "https://api.simkl.com/sync/add-to-list"
var show = SimklShowStatus{
Title: anime.Show.Title,
@ -203,11 +219,18 @@ func (a *App) SimklSyncStatus(anime SimklAnime, status string) interface{} {
log.Printf("Failed at unmarshal, %s\n", err)
}
return success
for i, simklAnime := range WatchList.Anime {
if anime.Show.Ids.Simkl == simklAnime.Show.Ids.Simkl {
WatchList.Anime[i].Status = status
}
}
anime.Status = status
return anime
}
func (a *App) SimklSearch(aniId int) SimklAnime {
fmt.Println(aniId)
var result SimklAnime
if reflect.DeepEqual(WatchList, SimklWatchList{}) {

View File

@ -31,14 +31,14 @@ type SimklWatchList struct {
}
type SimklAnime struct {
LastWatchedAt string `json:"last_watched_at" ts_type:"last_watched_at"`
Status string `json:"status" ts_type:"status"`
UserRating float64 `json:"user_rating" ts_type:"user_rating"`
LastWatched string `json:"last_watched" ts_type:"last_watched"`
NextToWatch string `json:"next_to_watch" ts_type:"next_to_watch"`
WatchedEpisodesCount int `json:"watched_episodes_count" ts_type:"watched_episodes_count"`
TotalEpisodesCount int `json:"total_episodes_count" ts_type:"total_episodes_count"`
NotAiredEpisodesCount int `json:"not_aired_episodes_count" ts_type:"not_aired_episodes_count"`
LastWatchedAt string `json:"last_watched_at" ts_type:"last_watched_at"`
Status string `json:"status" ts_type:"status"`
UserRating int `json:"user_rating" ts_type:"user_rating"`
LastWatched string `json:"last_watched" ts_type:"last_watched"`
NextToWatch string `json:"next_to_watch" ts_type:"next_to_watch"`
WatchedEpisodesCount int `json:"watched_episodes_count" ts_type:"watched_episodes_count"`
TotalEpisodesCount int `json:"total_episodes_count" ts_type:"total_episodes_count"`
NotAiredEpisodesCount int `json:"not_aired_episodes_count" ts_type:"not_aired_episodes_count"`
Show struct {
Title string `json:"title" ts_type:"title"`
Poster string `json:"poster" ts_type:"poster"`

View File

@ -13,6 +13,7 @@ post {
headers {
Content-Type: "application/json"
Accept: "application/json"
Authorization: Bearer {{ANILIST_ACCESS_TOKEN}}
}
body:graphql {
@ -92,7 +93,7 @@ body:graphql {
body:graphql:vars {
{
"userId": 413504,
"mediaId": 157371,
"mediaId": 110,
"listType": "ANIME"
}
}

View File

@ -1,21 +1,20 @@
<script lang="ts">
import {
anilistModal,
simklWatchList,
aniListLoggedIn,
simklLoggedIn,
malLoggedIn,
malAnime,
simklAnime,
aniListAnime,
} from "./GlobalVariablesAndHelperFunctions.svelte";
import {aniListAnime} from "./GlobalVariablesAndHelperFunctions.svelte";
import {Button} from "flowbite-svelte";
// @ts-ignore
import StarRatting from "@ernane/svelte-star-rating"
import moment from 'moment'
import { Table, TableBody, TableBodyCell, TableBodyRow, TableHead, TableHeadCell } from 'flowbite-svelte';
import { writable } from 'svelte/store';
import type {SimklAnime, SimklWatchList} from "./simkl/types/simklTypes";
import type {SimklAnime} from "./simkl/types/simklTypes";
import {
AniListUpdateEntry, MyAnimeListUpdate,
SimklSyncEpisodes,
@ -24,8 +23,8 @@
} from "../wailsjs/go/main/App";
import type {MALAnime, MALUploadStatus, MyListStatus} from "./mal/types/MALTypes";
import type {AniListUpdateVariables} from "./anilist/types/AniListTypes";
import type {AniListGetSingleAnime} from "./anilist/types/AniListCurrentUserWatchListType";
let simklWatch: SimklWatchList
let isAniListLoggedIn: boolean
let isMalLoggedIn: boolean
let isSimklLoggedIn: boolean
@ -33,14 +32,15 @@
let currentSimklAnime: SimklAnime
let submitting = writable(false)
let isSubmitting: boolean
let currentAniListAnime: AniListGetSingleAnime
aniListLoggedIn.subscribe((value) => isAniListLoggedIn = value)
malLoggedIn.subscribe((value) => isMalLoggedIn = value)
simklLoggedIn.subscribe((value) => isSimklLoggedIn = value)
malAnime.subscribe((value) => currentMalAnime = value)
submitting.subscribe((value) => isSubmitting = value)
simklWatchList.subscribe((value) => simklWatch = value)
simklAnime.subscribe((value) => currentSimklAnime = value)
aniListAnime.subscribe((value) => currentAniListAnime = value)
type statusOption = {
id: number,
@ -60,7 +60,7 @@
let startingAnilistStatusOption: statusOption
startingAnilistStatusOption = statusOptions.filter(option => aniListAnime.data.MediaList.status === option.aniList)[0]
startingAnilistStatusOption = statusOptions.filter(option => currentAniListAnime.data.MediaList.status === option.aniList)[0]
let items = [] as {
id: number
@ -76,15 +76,15 @@
if(isAniListLoggedIn) {
items.push({
id: aniListAnime.data.MediaList.id,
id: currentAniListAnime.data.MediaList.id,
service: "AniList",
progress: aniListAnime.data.MediaList.progress,
status: aniListAnime.data.MediaList.status,
startedAt: `${aniListAnime.data.MediaList.startedAt.month}-${aniListAnime.data.MediaList.startedAt.day}-${aniListAnime.data.MediaList.startedAt.year}`,
completedAt: `${aniListAnime.data.MediaList.completedAt.month}-${aniListAnime.data.MediaList.completedAt.day}-${aniListAnime.data.MediaList.completedAt.year}`,
score: aniListAnime.data.MediaList.score,
repeat: aniListAnime.data.MediaList.repeat,
notes: aniListAnime.data.MediaList.notes
progress: currentAniListAnime.data.MediaList.progress,
status: currentAniListAnime.data.MediaList.status,
startedAt: `${currentAniListAnime.data.MediaList.startedAt.month}-${currentAniListAnime.data.MediaList.startedAt.day}-${currentAniListAnime.data.MediaList.startedAt.year}`,
completedAt: `${currentAniListAnime.data.MediaList.completedAt.month}-${currentAniListAnime.data.MediaList.completedAt.day}-${currentAniListAnime.data.MediaList.completedAt.year}`,
score: currentAniListAnime.data.MediaList.score,
repeat: currentAniListAnime.data.MediaList.repeat,
notes: currentAniListAnime.data.MediaList.notes
})
}
@ -166,9 +166,9 @@
anilistModal.set(false)
};
const title = aniListAnime.data.MediaList.media.title.english !== "" ?
aniListAnime.data.MediaList.media.title.english :
aniListAnime.data.MediaList.media.title.romaji
const title = currentAniListAnime.data.MediaList.media.title.english !== "" ?
currentAniListAnime.data.MediaList.media.title.english :
currentAniListAnime.data.MediaList.media.title.romaji
let config = {
readOnly: false,
@ -178,7 +178,7 @@
max: 5,
step: 0.5
},
score: aniListAnime.data.MediaList.score / 2,
score: currentAniListAnime.data.MediaList.score / 2,
showScore: false,
scoreFormat: function () {
return `(${this.score.toFixed(1)}/${this.countStars})`
@ -194,21 +194,21 @@
}
let values = {
progress: aniListAnime.data.MediaList.progress,
progress: currentAniListAnime.data.MediaList.progress,
status: startingAnilistStatusOption,
startedAt: {
year: aniListAnime.data.MediaList.startedAt.year,
month: aniListAnime.data.MediaList.startedAt.month,
day: aniListAnime.data.MediaList.startedAt.day
year: currentAniListAnime.data.MediaList.startedAt.year,
month: currentAniListAnime.data.MediaList.startedAt.month,
day: currentAniListAnime.data.MediaList.startedAt.day
},
completedAt: {
year: aniListAnime.data.MediaList.completedAt.year,
month: aniListAnime.data.MediaList.completedAt.month,
day: aniListAnime.data.MediaList.completedAt.day
year: currentAniListAnime.data.MediaList.completedAt.year,
month: currentAniListAnime.data.MediaList.completedAt.month,
day: currentAniListAnime.data.MediaList.completedAt.day
},
repeat: aniListAnime.data.MediaList.repeat,
score: aniListAnime.data.MediaList.score,
notes: aniListAnime.data.MediaList.notes
repeat: currentAniListAnime.data.MediaList.repeat,
score: currentAniListAnime.data.MediaList.score,
notes: currentAniListAnime.data.MediaList.notes
}
let startedAtDate: string
let completedAtDate: string
@ -250,7 +250,7 @@
const submitData = async () => {
submitting.set(true)
let body: AniListUpdateVariables = {
mediaId: aniListAnime.data.MediaList.mediaId,
mediaId: currentAniListAnime.data.MediaList.mediaId,
progress: values.progress,
status: values.status.aniList,
score: values.score,
@ -268,7 +268,49 @@
}
}
await AniListUpdateEntry(body).then((value) => {
console.log(value)
aniListAnime.update(anime => {
anime.data.MediaList.status = value.data.SaveMediaListEntry.status
anime.data.MediaList.progress = value.data.SaveMediaListEntry.progress
anime.data.MediaList.repeat = value.data.SaveMediaListEntry.repeat
anime.data.MediaList.score = value.data.SaveMediaListEntry.score
anime.data.MediaList.startedAt.day = value.data.SaveMediaListEntry.startedAt.day
anime.data.MediaList.startedAt.month = value.data.SaveMediaListEntry.startedAt.month
anime.data.MediaList.startedAt.year = value.data.SaveMediaListEntry.startedAt.year
if (value.data.SaveMediaListEntry.notes === null) {
anime.data.MediaList.notes = ""
} else {
anime.data.MediaList.notes = value.data.SaveMediaListEntry.notes
}
if (value.data.SaveMediaListEntry.completedAt.year === null) {
anime.data.MediaList.completedAt.year = 0
} else {
anime.data.MediaList.completedAt.year = value.data.SaveMediaListEntry.completedAt.year
}
if (value.data.SaveMediaListEntry.completedAt.month === null) {
anime.data.MediaList.completedAt.month = 0
} else {
anime.data.MediaList.completedAt.month = value.data.SaveMediaListEntry.completedAt.month
}
if (value.data.SaveMediaListEntry.completedAt.day === null) {
anime.data.MediaList.completedAt.day = 0
} else {
anime.data.MediaList.completedAt.day = value.data.SaveMediaListEntry.completedAt.day
}
for (let item of items) {
if (item.service === "AniList") {
item.id = anime.data.MediaList.id
item.progress = anime.data.MediaList.progress
item.status = anime.data.MediaList.status
item.startedAt = `${anime.data.MediaList.startedAt.month}-${anime.data.MediaList.startedAt.day}-${anime.data.MediaList.startedAt.year}`
item.completedAt = `${anime.data.MediaList.completedAt.month}-${anime.data.MediaList.completedAt.day}-${anime.data.MediaList.completedAt.year}`
item.score = anime.data.MediaList.score
item.repeat = anime.data.MediaList.repeat
item.notes = anime.data.MediaList.notes
}
}
return anime
})
})
if(malLoggedIn) {
@ -294,23 +336,20 @@
if (simklLoggedIn) {
if (currentSimklAnime.watched_episodes_count !== values.progress) {
await SimklSyncEpisodes(currentSimklAnime, values.progress).then(() => {
currentSimklAnime.watched_episodes_count = values.progress
simklWatch.anime[simklWatch.currentIndex].watched_episodes_count = values.progress
await SimklSyncEpisodes(currentSimklAnime, values.progress).then((value) => {
simklAnime.set(value)
})
}
if (currentSimklAnime.user_rating !== values.score) {
await SimklSyncRating(currentSimklAnime, values.score).then(() => {
currentSimklAnime.user_rating = values.score
simklWatch.anime[simklWatch.currentIndex].user_rating = values.score
await SimklSyncRating(currentSimklAnime, values.score).then((value) => {
simklAnime.set(value)
})
}
if (currentSimklAnime.status !== values.status.simkl) {
await SimklSyncStatus(currentSimklAnime, values.status.simkl).then(() => {
currentSimklAnime.status = values.status.simkl
simklWatch.anime[simklWatch.currentIndex].status = values.status.simkl
await SimklSyncStatus(currentSimklAnime, values.status.simkl).then((value) => {
simklAnime.set(value)
})
}
}
@ -321,7 +360,7 @@
<div id="inapp-data">
<div class="grid grid-cols-1 md:grid-cols-10 grid-flow-col gap-4">
<div class="md:col-span-2 space-y-3">
<img class="rounded-lg" src={aniListAnime.data.MediaList.media.coverImage.large} alt="{title} Cover Image">
<img class="rounded-lg" src={currentAniListAnime.data.MediaList.media.coverImage.large} alt="{title} Cover Image">
<StarRatting bind:config on:change={changeRating}/>
<p>Rating: {config.score * 2}</p>
<p>{ratingInWords[config.score * 2]}</p>
@ -460,7 +499,7 @@
<TableBodyRow>
<TableBodyCell class="overflow-x-auto">{item.id}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.service}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.progress}</TableBodyCell>
<TableBodyCell class="overflow-x-auto" bind:value={item.progress}>{item.progress}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.status}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.startedAt}</TableBodyCell>
<TableBodyCell class="overflow-x-auto">{item.completedAt}</TableBodyCell>
@ -523,6 +562,6 @@
<h3 class="text-2xl">
Summary
</h3>
<p>{@html aniListAnime.data.MediaList.media.description}</p>
<p>{@html currentAniListAnime.data.MediaList.media.description}</p>
</div>
</div>

View File

@ -21,7 +21,7 @@
import {type AniListUser, MediaListSort} from "./anilist/types/AniListTypes";
import type {MALAnime, MALWatchlist, MyAnimeListUser} from "./mal/types/MALTypes";
export let aniListAnime: AniListGetSingleAnime
export let aniListAnime = writable({} as AniListGetSingleAnime)
export let title = writable("")
export let anilistModal = writable(false);
export let aniListLoggedIn = writable(false)
@ -46,8 +46,7 @@
let page: number
let perPage: number
let aniWatchlist: AniListCurrentUserWatchList
let simklWatch: SimklWatchList
let currentSimklAnime: SimklAnime
let currentAniListAnime: AniListGetSingleAnime
let isMalLoggedIn: boolean
let isSimklLoggedIn: boolean
@ -58,24 +57,38 @@
aniListWatchlist.subscribe(value => aniWatchlist = value)
malLoggedIn.subscribe(value => isMalLoggedIn = value)
simklLoggedIn.subscribe(value => isSimklLoggedIn = value)
simklWatchList.subscribe(value => simklWatch = value)
simklAnime.subscribe(value => currentSimklAnime = value)
aniListAnime.subscribe(value => currentAniListAnime = value)
export async function GetAniListSingleItemAndOpenModal(aniId: number, login: boolean): Promise<""> {
await GetAniListItem(aniId, login).then(aniListResult => {
aniListAnime = aniListResult
title.set(aniListAnime.data.MediaList.media.title.english === "" ?
aniListAnime.data.MediaList.media.title.romaji :
aniListAnime.data.MediaList.media.title.english)
let finalResult: AniListGetSingleAnime
finalResult = aniListResult
if (login === false) {
finalResult.data.MediaList.status = ""
finalResult.data.MediaList.score = 0
finalResult.data.MediaList.progress = 0
finalResult.data.MediaList.notes = ""
finalResult.data.MediaList.repeat = 0
finalResult.data.MediaList.startedAt.day = 0
finalResult.data.MediaList.startedAt.month = 0
finalResult.data.MediaList.startedAt.year = 0
finalResult.data.MediaList.completedAt.day = 0
finalResult.data.MediaList.completedAt.month = 0
finalResult.data.MediaList.completedAt.year = 0
}
aniListAnime.set(finalResult)
title.set(currentAniListAnime.data.MediaList.media.title.english === "" ?
currentAniListAnime.data.MediaList.media.title.romaji :
currentAniListAnime.data.MediaList.media.title.english)
})
if (isMalLoggedIn) {
await GetMyAnimeListAnime(aniListAnime.data.MediaList.media.idMal).then(malResult => {
await GetMyAnimeListAnime(currentAniListAnime.data.MediaList.media.idMal).then(malResult => {
malAnime.set(malResult)
})
}
if (isSimklLoggedIn) {
await SimklSearch(aniListAnime.data.MediaList.media.id).then((value: SimklAnime) => {
await SimklSearch(currentAniListAnime.data.MediaList.media.id).then((value: SimklAnime) => {
simklAnime.set(value)
})
}

View File

@ -44,8 +44,8 @@ export function SimklLogin():Promise<void>;
export function SimklSearch(arg1:number):Promise<main.SimklAnime>;
export function SimklSyncEpisodes(arg1:main.SimklAnime,arg2:number):Promise<any>;
export function SimklSyncEpisodes(arg1:main.SimklAnime,arg2:number):Promise<main.SimklAnime>;
export function SimklSyncRating(arg1:main.SimklAnime,arg2:number):Promise<any>;
export function SimklSyncRating(arg1:main.SimklAnime,arg2:number):Promise<main.SimklAnime>;
export function SimklSyncStatus(arg1:main.SimklAnime,arg2:string):Promise<any>;
export function SimklSyncStatus(arg1:main.SimklAnime,arg2:string):Promise<main.SimklAnime>;