added watch url input support
This commit is contained in:
parent
adc262a3ab
commit
55c45b9c0b
@ -1,7 +1,7 @@
|
|||||||
import type { CrunchyrollSearchResults } from '../Search/Types'
|
import type { CrunchyrollSearchResults } from '../Search/Types'
|
||||||
import { crunchyLogin } from './Account'
|
import { crunchyLogin } from './Account'
|
||||||
import { getProxies } from './Proxy'
|
import { getProxies } from './Proxy'
|
||||||
import type { CrunchyAnimeFetch, CrunchySearchFetch } from './Types'
|
import type { CrunchyAnimeFetch, CrunchyEpisodeFetch, CrunchyEpisodesFetch, CrunchySearchFetch } from './Types'
|
||||||
|
|
||||||
export async function searchCrunchy(q: string) {
|
export async function searchCrunchy(q: string) {
|
||||||
var isProxyActive: boolean | undefined
|
var isProxyActive: boolean | undefined
|
||||||
@ -123,7 +123,13 @@ export async function getCRSeries(q: string) {
|
|||||||
isProxyActive = result
|
isProxyActive = result
|
||||||
})
|
})
|
||||||
|
|
||||||
const { data: proxies } = await getProxies()
|
var proxies
|
||||||
|
|
||||||
|
if (isProxyActive) {
|
||||||
|
const { data: prox } = await getProxies()
|
||||||
|
|
||||||
|
proxies = prox.value
|
||||||
|
}
|
||||||
|
|
||||||
const { data: token, error: tokenerror } = await crunchyLogin('LOCAL')
|
const { data: token, error: tokenerror } = await crunchyLogin('LOCAL')
|
||||||
|
|
||||||
@ -143,8 +149,8 @@ export async function getCRSeries(q: string) {
|
|||||||
throw new Error(JSON.stringify(error.value))
|
throw new Error(JSON.stringify(error.value))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.value && proxies.value && isProxyActive) {
|
if (!data.value && proxies && isProxyActive) {
|
||||||
for (const p of proxies.value) {
|
for (const p of proxies) {
|
||||||
if (p.status !== 'offline') {
|
if (p.status !== 'offline') {
|
||||||
const { data: tokeng, error: tokenerrorg } = await crunchyLogin(p.code)
|
const { data: tokeng, error: tokenerrorg } = await crunchyLogin(p.code)
|
||||||
|
|
||||||
@ -192,3 +198,68 @@ export async function getCRSeries(q: string) {
|
|||||||
Geo: undefined
|
Geo: undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getCREpisodeSeriesID(q: string) {
|
||||||
|
var isProxyActive: boolean | undefined
|
||||||
|
;(window as any).myAPI.getProxyActive().then((result: boolean) => {
|
||||||
|
isProxyActive = result
|
||||||
|
})
|
||||||
|
|
||||||
|
var proxies
|
||||||
|
|
||||||
|
if (isProxyActive) {
|
||||||
|
const { data: prox } = await getProxies()
|
||||||
|
|
||||||
|
proxies = prox.value
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data: token, error: tokenerror } = await crunchyLogin('LOCAL')
|
||||||
|
|
||||||
|
if (!token.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data, error } = await useFetch<CrunchyEpisodeFetch>(`https://beta-api.crunchyroll.com/content/v2/cms/objects/${q}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token.value.access_token}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (error.value) {
|
||||||
|
console.error(error.value)
|
||||||
|
throw new Error(JSON.stringify(error.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data.value && proxies && isProxyActive) {
|
||||||
|
for (const p of proxies) {
|
||||||
|
if (p.status !== 'offline') {
|
||||||
|
const { data: tokeng, error: tokenerrorg } = await crunchyLogin(p.code)
|
||||||
|
|
||||||
|
if (!tokeng.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data: fdata, error: ferror } = await useFetch<CrunchyEpisodeFetch>(`https://beta-api.crunchyroll.com/content/v2/cms/series/${q}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${tokeng.value.access_token}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (ferror.value) {
|
||||||
|
console.error(ferror.value)
|
||||||
|
throw new Error(JSON.stringify(ferror.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
data.value = fdata.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data.value) return
|
||||||
|
|
||||||
|
const episode = data.value.data[0]
|
||||||
|
|
||||||
|
return episode.episode_metadata.series_id
|
||||||
|
}
|
||||||
|
@ -239,6 +239,18 @@ export interface CrunchyEpisodesFetch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CrunchyEpisodeFetch {
|
||||||
|
total: number
|
||||||
|
data: Array<{
|
||||||
|
episode_metadata: {
|
||||||
|
series_id: string
|
||||||
|
}
|
||||||
|
}>
|
||||||
|
meta: {
|
||||||
|
versions_considered: boolean
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export interface Proxy {
|
export interface Proxy {
|
||||||
name: string
|
name: string
|
||||||
code: string
|
code: string
|
||||||
|
@ -347,7 +347,7 @@ import { searchADN } from '~/components/ADN/ListAnimes'
|
|||||||
import { getEpisodesWithShowIdADN } from '~/components/ADN/ListEpisodes'
|
import { getEpisodesWithShowIdADN } from '~/components/ADN/ListEpisodes'
|
||||||
import type { ADNEpisode, ADNEpisodes } from '~/components/ADN/Types'
|
import type { ADNEpisode, ADNEpisodes } from '~/components/ADN/Types'
|
||||||
import { checkAccount } from '~/components/Crunchyroll/Account'
|
import { checkAccount } from '~/components/Crunchyroll/Account'
|
||||||
import { getCRSeries, searchCrunchy } from '~/components/Crunchyroll/ListAnimes'
|
import { getCREpisodeSeriesID, getCRSeries, searchCrunchy } from '~/components/Crunchyroll/ListAnimes'
|
||||||
import { listEpisodeCrunchy } from '~/components/Crunchyroll/ListEpisodes'
|
import { listEpisodeCrunchy } from '~/components/Crunchyroll/ListEpisodes'
|
||||||
import { listSeasonCrunchy } from '~/components/Crunchyroll/ListSeasons'
|
import { listSeasonCrunchy } from '~/components/Crunchyroll/ListSeasons'
|
||||||
import type { CrunchyEpisode, CrunchyEpisodes } from '~/components/Episode/Types'
|
import type { CrunchyEpisode, CrunchyEpisodes } from '~/components/Episode/Types'
|
||||||
@ -674,7 +674,7 @@ const switchToSeason = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.value && url.value.includes('crunchyroll') && !CRselectedShow.value) {
|
if (url.value && url.value.includes('crunchyroll') && url.value.includes('/series/') && !CRselectedShow.value) {
|
||||||
const seriesID = url.value.split('/')
|
const seriesID = url.value.split('/')
|
||||||
CRselectedShow.value = await getCRSeries(seriesID[5])
|
CRselectedShow.value = await getCRSeries(seriesID[5])
|
||||||
if (!CRselectedShow.value) return
|
if (!CRselectedShow.value) return
|
||||||
@ -715,6 +715,49 @@ const switchToSeason = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (url.value && url.value.includes('crunchyroll') && url.value.includes('/watch/') && !CRselectedShow.value) {
|
||||||
|
const episodeID = url.value.split('/')
|
||||||
|
const seriesID = await getCREpisodeSeriesID(episodeID[5])
|
||||||
|
if (!seriesID) return
|
||||||
|
CRselectedShow.value = await getCRSeries(seriesID)
|
||||||
|
if (!CRselectedShow.value) return
|
||||||
|
seasons.value = await listSeasonCrunchy(CRselectedShow.value.ID, CRselectedShow.value.Geo)
|
||||||
|
if (!seasons.value) {
|
||||||
|
isFetchingSeasons.value--
|
||||||
|
return
|
||||||
|
}
|
||||||
|
selectedSeason.value = seasons.value[0]
|
||||||
|
episodes.value = await listEpisodeCrunchy(selectedSeason.value.id, CRselectedShow.value.Geo)
|
||||||
|
if (episodes.value) {
|
||||||
|
selectedStartEpisode.value = episodes.value[0]
|
||||||
|
selectedEndEpisode.value = episodes.value[0]
|
||||||
|
}
|
||||||
|
tab.value = 2
|
||||||
|
|
||||||
|
selectedDubs.value = []
|
||||||
|
selectedSubs.value = []
|
||||||
|
|
||||||
|
if (dubLocales.value && dubLocales.value.length !== 0) {
|
||||||
|
for (const a of dubLocales.value) {
|
||||||
|
if (CRselectedShow.value.Dubs.find((cr) => cr === a.locale)) {
|
||||||
|
toggleDub(a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
selectedDubs.value = [{ locale: 'ja-JP', name: 'JP' }]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subLocales.value && subLocales.value.length !== 0) {
|
||||||
|
for (const a of subLocales.value) {
|
||||||
|
if (CRselectedShow.value.Subs.find((cr) => cr === a.locale)) {
|
||||||
|
toggleSub(a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
selectedSubs.value = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isFetchingSeasons.value--
|
isFetchingSeasons.value--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user