-
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
fe54e5c
commit 7f996fb
Showing
5 changed files
with
90 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { BaseHelper } from "./base"; | ||
import { MinimalVideoData } from "../types/client"; | ||
|
||
import { proxyMedia } from "@vot.js/shared/utils/utils"; | ||
|
||
export default class RtNewsHelper extends BaseHelper { | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
async getVideoData(videoId: string): Promise<MinimalVideoData | undefined> { | ||
const videoEl = document.querySelector(".jw-video, .media__video_noscript"); | ||
if (!videoEl) { | ||
return undefined; | ||
} | ||
|
||
let videoSrc = videoEl.getAttribute("src"); | ||
if (!videoSrc) { | ||
return undefined; | ||
} | ||
|
||
// yandex has case sensitive check of video format | ||
if (videoSrc.endsWith(".MP4")) { | ||
videoSrc = proxyMedia(videoSrc); | ||
} | ||
|
||
return { | ||
videoId, | ||
url: videoSrc, | ||
}; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
async getVideoId(url: URL) { | ||
return url.pathname.slice(1); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { parseFromString } from "dom-parser"; | ||
|
||
import { BaseHelper } from "./base"; | ||
import { MinimalVideoData } from "../types/client"; | ||
|
||
import Logger from "@vot.js/shared/utils/logger"; | ||
import { proxyMedia } from "@vot.js/shared/utils/utils"; | ||
|
||
export default class RtNewsHelper extends BaseHelper { | ||
async getVideoData(videoId: string): Promise<MinimalVideoData | undefined> { | ||
try { | ||
const res = await this.fetch(this.service?.url + videoId); | ||
const content = await res.text(); | ||
|
||
const doc = parseFromString(content.replace(/<!DOCTYPE html>/i, "")); | ||
const videoEl = doc.getElementsByClassName("media__video_noscript")?.[0]; | ||
if (!videoEl) { | ||
return undefined; | ||
} | ||
|
||
let videoSrc = videoEl.getAttribute("src"); | ||
if (!videoSrc) { | ||
return undefined; | ||
} | ||
|
||
// yandex has case sensitive check of video format | ||
if (videoSrc.endsWith(".MP4")) { | ||
videoSrc = proxyMedia(videoSrc); | ||
} | ||
|
||
return { | ||
videoId, | ||
url: videoSrc, | ||
}; | ||
} catch (err) { | ||
Logger.error( | ||
`Failed to get rt news video data by video ID: ${videoId}, because: ${ | ||
(err as Error).message | ||
}`, | ||
); | ||
return undefined; | ||
} | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
async getVideoId(url: URL) { | ||
return url.pathname.slice(1); | ||
} | ||
} |