diff --git a/app/js/animeHandler.js b/app/js/animeHandler.js index 36228f6..1427bd9 100644 --- a/app/js/animeHandler.js +++ b/app/js/animeHandler.js @@ -261,9 +261,9 @@ query ($page: Int, $perPage: Int, $from: Int, $to: Int) { return json } async function alEntry () { - if (playerData.nowPlaying && playerData.nowPlaying[0] && localStorage.getItem('ALtoken')) { - const res = await alRequest({ method: 'SearchIDStatus', id: playerData.nowPlaying[0].id }) - if ((res.errors && res.errors[0].status === 404) || res.data.MediaList.progress <= parseInt(playerData.nowPlaying[1])) { + if (client.nowPlaying.media && localStorage.getItem('ALtoken')) { + const res = await alRequest({ method: 'SearchIDStatus', id: client.nowPlaying.media.id }) + if ((res.errors && res.errors[0].status === 404) || res.data.MediaList.progress <= client.nowPlaying.episodeNumber) { const query = ` mutation ($id: Int, $status: MediaListStatus, $episode: Int, $repeat: Int) { SaveMediaListEntry (mediaId: $id, status: $status, progress: $episode, repeat: $repeat) { @@ -275,11 +275,11 @@ mutation ($id: Int, $status: MediaListStatus, $episode: Int, $repeat: Int) { }` const variables = { repeat: 0, - id: playerData.nowPlaying[0].id, + id: client.nowPlaying.media.id, status: 'CURRENT', - episode: parseInt(playerData.nowPlaying[1]) + episode: client.nowPlaying.episodeNumber } - if (parseInt(playerData.nowPlaying[1]) === playerData.nowPlaying[0].episodes) { + if (client.nowPlaying.episodeNumber === client.nowPlaying.media.episodes) { variables.status = 'COMPLETED' if (res.data.MediaList.status === 'COMPLETED') { variables.repeat = res.data.MediaList.repeat + 1 @@ -614,8 +614,6 @@ async function resolveFileMedia (opts) { res = await alRequest(method) } if (res.data.Page.media[0]) store[elems.anime_title] = res.data.Page.media[0] - } else { - store[elems.anime_title] = await alRequest({ id: store[elems.anime_title].id, method: 'SearchIDSingle' }).then(res => res.data.Media) } let episode; let media = store[elems.anime_title] // resolve episode, if movie, dont. @@ -721,7 +719,7 @@ async function releasesCards (items, frag, limit) { results.forEach((mediaInformation, index) => { const o = items[index].querySelector.bind(items[index]) template = cardCreator(mediaInformation) - template.onclick = () => client.addTorrent(o('link').innerHTML, { media: mediaInformation.media, episode: mediaInformation.episode }) + template.onclick = () => client.addTorrent(o('link').innerHTML, { media: mediaInformation, episode: mediaInformation.episode }) frag.appendChild(template) }) }) diff --git a/app/js/interface.js b/app/js/interface.js index 5945bdc..102883a 100644 --- a/app/js/interface.js +++ b/app/js/interface.js @@ -64,7 +64,7 @@ async function loadHomePage () { }) notification.onclick = async () => { window.parent.focus() - client.addTorrent(doc.querySelector('item').querySelector('link').innerHTML, { media: mediaInformation.media, episode: mediaInformation.episode }) + client.addTorrent(doc.querySelector('item').querySelector('link').innerHTML, { media: mediaInformation, episode: mediaInformation.episode }) store[mediaInformation.parseObject.anime_title] = await alRequest({ id: mediaInformation.media.id, method: 'SearchIDSingle' }).then(res => res.data.Media) } } diff --git a/app/js/player.js b/app/js/player.js index b8cc007..4f791a8 100644 --- a/app/js/player.js +++ b/app/js/player.js @@ -167,7 +167,7 @@ Style: Default,${options.defaultSSAStyles || 'Roboto Medium,26,&H00FFFFFF,&H0000 navigator.mediaSession.setActionHandler('seekforward', () => this.seek(seekTime)) navigator.mediaSession.setActionHandler('nexttrack', () => this.playNext()) } - if ('setPositionState' in navigator.mediaSession) video.addEventListener('timeupdate', () => this.updatePositionState()) + if ('setPositionState' in navigator.mediaSession) this.video.addEventListener('timeupdate', () => this.updatePositionState()) this.videoExtensions = ['.3g2', '.3gp', '.asf', '.avi', '.dv', '.flv', '.gxf', '.m2ts', '.m4a', '.m4b', '.m4p', '.m4r', '.m4v', '.mkv', '.mov', '.mp4', '.mpd', '.mpeg', '.mpg', '.mxf', '.nut', '.ogm', '.ogv', '.swf', '.ts', '.vob', '.webm', '.wmv', '.wtv'] this.videoFiles = undefined @@ -355,16 +355,6 @@ Style: Default,${options.defaultSSAStyles || 'Roboto Medium,26,&H00FFFFFF,&H0000 this.controls.nowPlaying.textContent = 'EP ' + episodeInfo document.title = [this.nowPlaying.mediaTitle, episodeInfo ? 'EP ' + episodeInfo : false, this.nowPlaying.name || 'TorrentPlayer'].filter(s => s).join(' - ') } - - // if (opts.media && this.videoFiles.length === 1) { - // // if this is a single file, then the media is most likely accurate, just update it! - // this.nowPlaying = [await alRequest({ id: opts.media.id, method: 'SearchIDSingle' }).then(res => res.data.Media), opts.episode || 1] - // // update store with entry, but dont really do anything with it - // resolveFileMedia({ fileName: this.currentFile.name, method: 'SearchName' }) - // } else { - // // if this is a batch or single unresolved file, then resolve the single selected file, batches can include specials - // const mediaInformation = await resolveFileMedia({ fileName: this.currentFile.name, method: 'SearchName' }) - // } } cleanupVideo () { // cleans up objects, attemps to clear as much video caching as possible @@ -381,12 +371,7 @@ Style: Default,${options.defaultSSAStyles || 'Roboto Medium,26,&H00FFFFFF,&H0000 this.onDone = undefined document.title = 'Miru' this.setProgress(0) - // if (typeof client !== 'undefined' && client.torrents[0] && client.torrents[0].files.length > 1) { - // client.torrents[0].files.forEach(file => file.deselect()); - // client.torrents[0].deselect(0, client.torrents[0].pieces.length - 1, false); - // console.log(videoFiles.filter(file => `${scope}webtorrent/${client.torrents[0].infoHash}/${encodeURI(file.path)}` == video.src)) - // look for file and delete its store - // } + // look for file and delete its store, idk how to do this this.subtitleData = { fonts: [], headers: [], @@ -471,11 +456,11 @@ Style: Default,${options.defaultSSAStyles || 'Roboto Medium,26,&H00FFFFFF,&H0000 playNext () { clearTimeout(this.nextTimeout) this.nextTimeout = setTimeout(() => { - if (this.videoFiles?.length > 1 && this.videoFiles.indexOf(this.currentFile) < this.videoFiles.length) { - const fileIndex = this.videoFiles.indexOf(this.currentFile) + 1 - const nowPlaying = [this.nowPlaying[0], parseInt(this.nowPlaying[1]) + 1] // TODO: fix + if (this.videoFiles?.indexOf(this.currentFile) < this.videoFiles?.length) { + const nowPlaying = this.nowPlaying + nowPlaying.episodeNumber += 1 this.cleanupVideo() - this.buildVideo(this.videoFiles[fileIndex], nowPlaying) // TODO: fix + this.buildVideo(this.currentTorrent, { media: nowPlaying, file: this.videoFiles[this.videoFiles.indexOf(this.currentFile) + 1] }) } else { if (this.onNext) this.onNext() } @@ -590,10 +575,9 @@ Style: Default,${options.defaultSSAStyles || 'Roboto Medium,26,&H00FFFFFF,&H0000 } checkCompletion () { - if (!this.completed && video.duration - 180 < video.currentTime) { - this.onWatched() - } else { + if (!this.completed && this.video.duration - 180 < this.video.currentTime) { this.completed = true + this.onWatched() } } @@ -1019,11 +1003,12 @@ const client = new TorrentPlayer({ }) }, onWatched: () => { // TODO: fix - if (settings.other2 && !(!(playerData.nowPlaying[0].episodes || playerData.nowPlaying[0].nextAiringEpisode.episode) && playerData.nowPlaying[0].streamingEpisodes.length && parseInt(playerData.nowPlaying[1] > 12))) { + console.log('ran') + if (settings.other2 && (client.nowPlaying.media?.episodes || client.nowPlaying.media?.nextAiringEpisode?.episode)) { alEntry() } else { halfmoon.initStickyAlert({ - content: `Do You Want To Mark
${playerData.nowPlaying[0].title.userPreferred}
Episode ${playerData.nowPlaying[1]} As Completed?
+ content: `Do You Want To Mark
${client.nowPlaying.mediaTitle}
Episode ${client.nowPlaying.episodeNumber} As Completed?
`, title: 'Episode Complete', @@ -1035,8 +1020,8 @@ const client = new TorrentPlayer({ window.location.hash = '#playlist' }, onNext: () => { - if (playerData.nowPlaying[0]) { - nyaaSearch(playerData.nowPlaying[0], parseInt(playerData.nowPlaying[1]) + 1) + if (client.nowPlaying.media) { + nyaaSearch(client.nowPlaying.media, client.nowPlaying.episodeNumber) } else { halfmoon.initStickyAlert({ content: 'Couldn\'t find anime name! Try specifying a torrent manually.',