-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26bc44a
commit 3c44cd6
Showing
257 changed files
with
470 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,45 @@ | ||
import sites from "../config/sites.js"; | ||
import { BaseHelper } from "./base.js"; | ||
import { VideoService } from "../types/yandex.js"; | ||
export default class KickHelper extends BaseHelper { | ||
API_ORIGIN = "https://kick.com/api/v2"; | ||
API_ORIGIN = "https://kick.com/api"; | ||
async getClipInfo(clipId) { | ||
try { | ||
const res = await this.fetch(`${this.API_ORIGIN}/clips/${clipId}`); | ||
return (await res.json()); | ||
const res = await this.fetch(`${this.API_ORIGIN}/v2/clips/${clipId}`); | ||
const data = (await res.json()); | ||
const { clip_url: url, duration, title } = data.clip; | ||
return { | ||
url, | ||
duration, | ||
title, | ||
}; | ||
} | ||
catch (err) { | ||
console.error(`Failed to get kick clip info by clipId: ${clipId}.`, err.message); | ||
return false; | ||
return undefined; | ||
} | ||
} | ||
async getVideoData(videoId) { | ||
if (!videoId.startsWith("clip_")) { | ||
async getVideoInfo(videoId) { | ||
try { | ||
const res = await this.fetch(`${this.API_ORIGIN}/v1/video/${videoId}`); | ||
const data = (await res.json()); | ||
const { source: url, livestream } = data; | ||
const { session_title: title, duration } = livestream; | ||
return { | ||
url: sites.find((s) => s.host === VideoService.kick).url + videoId, | ||
url, | ||
duration: Math.round(duration / 1000), | ||
title, | ||
}; | ||
} | ||
const clipInfo = await this.getClipInfo(videoId); | ||
if (!clipInfo) { | ||
catch (err) { | ||
console.error(`Failed to get kick video info by videoId: ${videoId}.`, err.message); | ||
return undefined; | ||
} | ||
const { clip_url, duration, title } = clipInfo.clip; | ||
return { | ||
url: clip_url, | ||
duration, | ||
title, | ||
}; | ||
} | ||
async getVideoData(videoId) { | ||
return videoId.startsWith("videos") | ||
? await this.getVideoInfo(videoId.replace("videos/", "")) | ||
: await this.getClipInfo(videoId.replace("clips/", "")); | ||
} | ||
async getVideoId(url) { | ||
return /([^/]+)\/(videos|clips)\/([^/]+)/.exec(url.pathname)?.[0]; | ||
return /([^/]+)\/((videos|clips)\/([^/]+))/.exec(url.pathname)?.[2]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.