mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
🥡 set madiator scrap api version to 2
This commit is contained in:
parent
7f3f8919f0
commit
79ba91a1f1
2 changed files with 17 additions and 7 deletions
|
@ -111,7 +111,8 @@ export const SingleValueAtATime = Symbol()
|
|||
export type YtUrlResolveResponsePath = (string | number | typeof Keys | typeof Values)[]
|
||||
export interface YtUrlResolveFunction {
|
||||
pathname: string
|
||||
paramName: string
|
||||
defaultParams: Record<string, string | number>
|
||||
valueParamName: string
|
||||
paramArraySeperator: string | typeof SingleValueAtATime
|
||||
responsePath: YtUrlResolveResponsePath
|
||||
}
|
||||
|
@ -131,13 +132,15 @@ export const ytUrlResolversSettings: Record<YTUrlResolverName, YTUrlResolver> =
|
|||
functions: {
|
||||
getChannelId: {
|
||||
pathname: "/yt/resolve",
|
||||
paramName: "channel_ids",
|
||||
defaultParams: {},
|
||||
valueParamName: "channel_ids",
|
||||
paramArraySeperator: ',',
|
||||
responsePath: ["data", "channels", Values]
|
||||
},
|
||||
getVideoId: {
|
||||
pathname: "/yt/resolve",
|
||||
paramName: "video_ids",
|
||||
defaultParams: {},
|
||||
valueParamName: "video_ids",
|
||||
paramArraySeperator: ",",
|
||||
responsePath: ["data", "videos", Values]
|
||||
}
|
||||
|
@ -149,13 +152,19 @@ export const ytUrlResolversSettings: Record<YTUrlResolverName, YTUrlResolver> =
|
|||
functions: {
|
||||
getChannelId: {
|
||||
pathname: "/api/get-lbry-channel",
|
||||
paramName: "url",
|
||||
defaultParams: {
|
||||
v: 2
|
||||
},
|
||||
valueParamName: "url",
|
||||
paramArraySeperator: SingleValueAtATime,
|
||||
responsePath: ["lbrych"]
|
||||
},
|
||||
getVideoId: {
|
||||
pathname: "/api/get-lbry-video",
|
||||
paramName: "url",
|
||||
defaultParams: {
|
||||
v: 2
|
||||
},
|
||||
valueParamName: "url",
|
||||
paramArraySeperator: SingleValueAtATime,
|
||||
responsePath: ["lbryurl"]
|
||||
}
|
||||
|
|
|
@ -59,10 +59,11 @@ export async function resolveById(descriptors: YtIdResolverDescriptor[], progres
|
|||
|
||||
async function requestGroup(urlResolverFunction: YtUrlResolveFunction, descriptorsGroup: typeof descriptorsPayload) {
|
||||
url.pathname = urlResolverFunction.pathname
|
||||
Object.entries(urlResolverFunction.defaultParams).forEach(([name, value]) => url.searchParams.set(name, value.toString()))
|
||||
|
||||
if (urlResolverFunction.paramArraySeperator === SingleValueAtATime) {
|
||||
await Promise.all(descriptorsGroup.map(async (descriptor) => {
|
||||
url.searchParams.set(urlResolverFunction.paramName, descriptor.id)
|
||||
url.searchParams.set(urlResolverFunction.valueParamName, descriptor.id)
|
||||
|
||||
const apiResponse = await fetch(url.toString(), { cache: 'no-store' })
|
||||
if (apiResponse.ok) {
|
||||
|
@ -77,7 +78,7 @@ export async function resolveById(descriptors: YtIdResolverDescriptor[], progres
|
|||
}))
|
||||
}
|
||||
else {
|
||||
url.searchParams.set(urlResolverFunction.paramName, descriptorsGroup
|
||||
url.searchParams.set(urlResolverFunction.valueParamName, descriptorsGroup
|
||||
.map((descriptor) => descriptor.id)
|
||||
.join(urlResolverFunction.paramArraySeperator))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue