fix: rewatch progress

This commit is contained in:
ThaUnknown 2022-09-16 16:15:18 +02:00
parent 8eb5f4581b
commit 4660b2494f
4 changed files with 114 additions and 111 deletions

View file

@ -1,6 +1,6 @@
{
"name": "Miru",
"version": "3.1.8",
"version": "3.1.9",
"author": "ThaUnknown_ <ThaUnknown@users.noreply.github.com>",
"description": "Stream anime torrents, real-time with no waiting for downloads.",
"main": "src/index.js",

View file

@ -1,103 +1,103 @@
<script>
import { alToken } from '../Settings.svelte'
import { addToast } from '../Toasts.svelte'
import { alRequest } from '@/modules/anilist.js'
import { getContext } from 'svelte'
import { getMediaMaxEp } from '@/modules/anime.js'
import { playAnime } from '../RSSView.svelte'
export let media = null
import { alToken } from '../Settings.svelte'
import { addToast } from '../Toasts.svelte'
import { alRequest } from '@/modules/anilist.js'
import { getContext } from 'svelte'
import { getMediaMaxEp } from '@/modules/anime.js'
import { playAnime } from '../RSSView.svelte'
export let media = null
const toggleStatusMap = {
CURRENT: 'DROPPED',
COMPLETED: 'REPEATING',
PAUSED: 'CURRENT',
REPEATING: 'CURRENT',
DROPPED: 'PLANNING'
}
async function toggleStatus () {
if (media.mediaListEntry?.status !== 'PLANNING') {
// add
await setStatus(toggleStatusMap[media.mediaListEntry?.status] || 'PLANNING')
} else {
// delete
const toggleStatusMap = {
CURRENT: 'DROPPED',
COMPLETED: 'REPEATING',
PAUSED: 'CURRENT',
REPEATING: 'CURRENT',
DROPPED: 'PLANNING'
}
async function toggleStatus () {
if (media.mediaListEntry?.status !== 'PLANNING') {
// add
await setStatus(toggleStatusMap[media.mediaListEntry?.status] || 'PLANNING')
} else {
// delete
const variables = {
method: 'Delete',
id: media.mediaListEntry.id
}
await alRequest(variables)
}
update()
}
function getStatusText () {
if (media.mediaListEntry) {
const { status } = media.mediaListEntry
if (status === 'PLANNING') return 'Remove From List'
if (media.mediaListEntry?.status in toggleStatusMap) return 'Drop From Watching'
}
return 'Add To List'
}
function setStatus (status, other = {}) {
const variables = {
method: 'Delete',
id: media.mediaListEntry.id
method: 'Entry',
id: media.id,
status,
...other
}
return alRequest(variables)
}
async function update () {
media = (await alRequest({ method: 'SearchIDSingle', id: media.id })).data.Media
}
async function score (media, score) {
const variables = {
method: 'Entry',
id: media.id,
score: score * 10
}
await alRequest(variables)
media = (await alRequest({ method: 'SearchIDSingle', id: media.id })).data.Media
}
update()
}
function getStatusText () {
if (media.mediaListEntry) {
const { status } = media.mediaListEntry
if (status === 'PLANNING') return 'Remove From List'
if (media.mediaListEntry?.status in toggleStatusMap) return 'Drop From Watching'
const trailer = getContext('trailer')
function viewTrailer (media) {
$trailer = media.trailer.id
}
return 'Add To List'
}
function setStatus (status, other = {}) {
const variables = {
method: 'Entry',
id: media.id,
status,
...other
function copyToClipboard (text) {
navigator.clipboard.writeText(text)
addToast({
title: 'Copied to clipboard',
text: 'Copied share URL to clipboard',
type: 'primary',
duration: '5000'
})
}
return alRequest(variables)
}
async function update () {
media = (await alRequest({ method: 'SearchIDSingle', id: media.id })).data.Media
}
async function score (media, score) {
const variables = {
method: 'Entry',
id: media.id,
score: score * 10
function openInBrowser (url) {
window.IPC.emit('open', url)
}
await alRequest(variables)
media = (await alRequest({ method: 'SearchIDSingle', id: media.id })).data.Media
}
const trailer = getContext('trailer')
function viewTrailer (media) {
$trailer = media.trailer.id
}
function copyToClipboard (text) {
navigator.clipboard.writeText(text)
addToast({
title: 'Copied to clipboard',
text: 'Copied share URL to clipboard',
type: 'primary',
duration: '5000'
})
}
function openInBrowser (url) {
window.IPC.emit('open', url)
}
function getPlayText (media) {
if (media.mediaListEntry) {
const { status, progress } = media.mediaListEntry
if (progress) {
if (status === 'COMPLETED') return 'Rewatch'
return 'Continue ' + Math.min(getMediaMaxEp(media, true), progress + 1)
}
}
return 'Play'
}
async function play () {
let ep = 1
if (media.mediaListEntry) {
const { status, progress } = media.mediaListEntry
if (progress) {
if (status === 'COMPLETED') {
setStatus('REPEATING', { episode: 0 })
} else {
ep = Math.min(getMediaMaxEp(media, true), progress + 1)
function getPlayText (media) {
if (media.mediaListEntry) {
const { status, progress } = media.mediaListEntry
if (progress) {
if (status === 'COMPLETED') return 'Rewatch'
return 'Continue ' + Math.min(getMediaMaxEp(media, true), progress + 1)
}
}
return 'Play'
}
async function play () {
let ep = 1
if (media.mediaListEntry) {
const { status, progress } = media.mediaListEntry
if (progress) {
if (status === 'COMPLETED') {
await setStatus('REPEATING', { episode: 0 })
} else {
ep = Math.min(getMediaMaxEp(media, true), progress + 1)
}
}
}
playAnime(media, ep, true)
media = null
}
playAnime(media, ep, true)
media = null
}
</script>
<div class='col-md-4 d-flex justify-content-end flex-column'>

View file

@ -1,26 +1,26 @@
<script>
import { playAnime } from '../RSSView.svelte'
import { alRequest } from '@/modules/anilist.js'
import { getMediaMaxEp } from '@/modules/anime.js'
import { getContext } from 'svelte'
import Details from './Details.svelte'
import Following from './Following.svelte'
import Controls from './Controls.svelte'
import ToggleList from './ToggleList.svelte'
import { playAnime } from '../RSSView.svelte'
import { alRequest } from '@/modules/anilist.js'
import { getMediaMaxEp } from '@/modules/anime.js'
import { getContext } from 'svelte'
import Details from './Details.svelte'
import Following from './Following.svelte'
import Controls from './Controls.svelte'
import ToggleList from './ToggleList.svelte'
const view = getContext('view')
const trailer = getContext('trailer')
function close () {
$view = null
}
$: media = $view
let modal
$: media && modal?.focus()
$: !$trailer && modal?.focus()
$: maxPlayEp = getMediaMaxEp($view || {}, true)
function checkClose ({ keyCode }) {
if (keyCode === 27) close()
}
const view = getContext('view')
const trailer = getContext('trailer')
function close () {
$view = null
}
$: media = $view
let modal
$: media && modal?.focus()
$: !$trailer && modal?.focus()
$: maxPlayEp = getMediaMaxEp($view || {}, true)
function checkClose ({ keyCode }) {
if (keyCode === 27) close()
}
</script>
<div class='modal modal-full' class:show={media} on:keydown={checkClose} tabindex='-1' bind:this={modal}>

View file

@ -121,12 +121,15 @@ export function alEntry (filemedia) {
if (videoEpisode && mediaEpisode && (mediaEpisode >= videoEpisode)) {
// check user's own watch progress
const lists = media.mediaListEntry?.customLists.filter(list => list.enabled).map(list => list.name) || []
const status = media.mediaListEntry?.status === 'REPEATING' ? 'REPEATING' : 'CURRENT'
if (!media.mediaListEntry || (media.mediaListEntry?.progress <= videoEpisode) || singleEpisode) {
const variables = {
method: 'Entry',
repeat: media.mediaListEntry?.repeat || 0,
id: media.id,
status: 'CURRENT',
status,
episode: videoEpisode,
lists
}