-
-
Notifications
You must be signed in to change notification settings - Fork 3k
api/ntv: initial support #1390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
veselcraft
wants to merge
1
commit into
imputnet:main
Choose a base branch
from
veselcraft:ntv-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
api/ntv: initial support #1390
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,101 @@ | ||
import { env } from "../../config.js"; | ||
|
||
const ntvApi = 'https://www.ntv.ru/api/player/?id='; | ||
|
||
// the most generic user agent | ||
export const clientAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:139.0) Gecko/20100101 Firefox/139.0"; | ||
|
||
const getVideo = async (videoID) => { | ||
const video = await fetch(`${ntvApi}${videoID}`, { | ||
method: "GET", | ||
headers: { | ||
"user-agent": clientAgent, | ||
} | ||
}) | ||
.then(r => { | ||
if (r.status === 200) { | ||
return r.json(); | ||
} | ||
}); | ||
|
||
return video; | ||
} | ||
|
||
export default async function (obj) { | ||
let video = null; | ||
|
||
if (obj.name && obj.name.length > 0) { | ||
const fetchID = await fetch(`https://www.ntv.ru/peredacha/${obj.name}/m${obj.showid}/o${obj.videoid}`, { | ||
method: "GET", | ||
headers: { | ||
"user-agent": clientAgent, | ||
} | ||
}) | ||
.then(r => { | ||
if (r.status === 200) { | ||
return r.text(); | ||
} | ||
}); | ||
|
||
let figuredVideoId = null; | ||
const match = String(fetchID).match(/<meta\s+property="og:video:url"\s+content="https:\/\/www\.ntv\.ru\/embed\/(\d+)\/?"/i); | ||
if (match && match[1]) { | ||
figuredVideoId = match[1]; | ||
} else { | ||
return { error: "fetch.fail" }; | ||
} | ||
|
||
video = await getVideo(figuredVideoId); | ||
} else { | ||
video = await getVideo(obj.videoid); | ||
} | ||
|
||
if (!video) { | ||
return { error: "fetch.empty" }; | ||
} | ||
|
||
if (!video.playback || !video.totaltime) { | ||
return { error: "fetch.fail" }; | ||
} | ||
|
||
if (video.totaltime > env.durationLimit) { | ||
return { error: "content.too_long" }; | ||
} | ||
|
||
const userQuality = obj.quality === "max" ? "1080" : obj.quality; | ||
let url = null; | ||
|
||
// for hls there's 144p, 360p, 720p and 1080p available, but for mp4 only 360p and 1080p | ||
// we'll use mp4 to simplify things | ||
switch (userQuality) { | ||
case "1080": | ||
url = video.playback.hd_video; | ||
break; | ||
case "720": | ||
case "480": | ||
case "360": | ||
url = video.playback.video; | ||
break; | ||
default: | ||
// 360 by default | ||
url = video.playback.video; | ||
} | ||
|
||
if (!url) return { error: "fetch.fail" }; | ||
|
||
const fileMetadata = { | ||
title: video.description.trim(), | ||
// despite the param name, it actually contains the video title with the name of the show | ||
} | ||
|
||
return { | ||
urls: url, | ||
fileMetadata, | ||
filenameAttributes: { | ||
service: "ntv", | ||
id: `${obj.videoid}`, | ||
title: fileMetadata.title, | ||
extension: "mp4" | ||
} | ||
} | ||
} |
This file contains hidden or 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,20 @@ | ||
[ | ||
{ | ||
"name": "tv show video", | ||
"url": "https://www.ntv.ru/peredacha/dacha_otvet/m18960/o806491", | ||
"params": {}, | ||
"expected": { | ||
"code": 200, | ||
"status": "redirect" | ||
} | ||
}, | ||
{ | ||
"name": "newsfeed video", | ||
"url": "https://www.ntv.ru/video/2483380", | ||
"params": {}, | ||
"expected": { | ||
"code": 200, | ||
"status": "redirect" | ||
} | ||
} | ||
] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cobalt has a generic user agent already
cobalt/api/src/config.js
Line 8 in 63ee694