-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Videos: Use start time and end time for clips (#4264)
This PR parses the start and end time for clips. It also adds a new, dedicated API endpoint (`/api/v1/clips/{id}`) for retrieving the start and end time of a clip. Here is a sample response from that new endpoint (`video` is a video object, as described in https://docs.invidious.io/api/common_types/#videoobject): GET `/api/v1/clips/UgkxxPM3BRphCAPLP88YoUGuj79KXPfpNNO_?pretty=1` Response: ``` { "startTime": 8842.645, "endTime": 8855.856, "clipTitle": "✂️ Kirby is pink!", "video": {} } ``` Closes issue 3921
- Loading branch information
Showing
4 changed files
with
72 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
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,22 @@ | ||
require "json" | ||
|
||
# returns start_time, end_time and clip_title | ||
def parse_clip_parameters(params) : {Float64?, Float64?, String?} | ||
decoded_protobuf = params.try { |i| URI.decode_www_form(i) } | ||
.try { |i| Base64.decode(i) } | ||
.try { |i| IO::Memory.new(i) } | ||
.try { |i| Protodec::Any.parse(i) } | ||
|
||
start_time = decoded_protobuf | ||
.try(&.["50:0:embedded"]["2:1:varint"].as_i64) | ||
.try { |i| i/1000 } | ||
|
||
end_time = decoded_protobuf | ||
.try(&.["50:0:embedded"]["3:2:varint"].as_i64) | ||
.try { |i| i/1000 } | ||
|
||
clip_title = decoded_protobuf | ||
.try(&.["50:0:embedded"]["4:3:string"].as_s) | ||
|
||
return start_time, end_time, clip_title | ||
end |