mirror of https://github.com/iv-org/invidious
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 3921pull/4431/head
commit
dcbe52c9fb
@ -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
|
Loading…
Reference in New Issue