From 8b50c8515fac6a956d48292d23d76cfa1b21be7e Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Mon, 20 May 2019 20:22:01 -0500 Subject: [PATCH] Fix content-type for captions --- src/invidious.cr | 12 ++++++++++-- src/invidious/videos.cr | 14 +++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index d9bf9f8a..a6b23504 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -3065,7 +3065,7 @@ get "/api/v1/stats" do |env| statistics.to_json end -# YouTube provides "storyboards", which are sprites containing of x * y +# YouTube provides "storyboards", which are sprites containing x * y # preview thumbnails for individual scenes in a video. # See https://support.jwplayer.com/articles/how-to-add-preview-thumbnails get "/api/v1/storyboards/:id" do |env| @@ -3153,6 +3153,14 @@ get "/api/v1/captions/:id" do |env| id = env.params.url["id"] region = env.params.query["region"]? + # See https://github.com/ytdl-org/youtube-dl/blob/6ab30ff50bf6bd0585927cb73c7421bef184f87a/youtube_dl/extractor/youtube.py#L1354 + # It is possible to use `/api/timedtext?type=list&v=#{id}` and + # `/api/timedtext?type=track&v=#{id}&lang=#{lang_code}` directly, + # but this does not provide links for auto-generated captions. + # + # In future this should be investigated as an alternative, since it does not require + # getting video info. + client = make_client(YT_URL) begin video = get_video(id, PG_DB, proxies, region: region) @@ -3189,7 +3197,7 @@ get "/api/v1/captions/:id" do |env| next response end - env.response.content_type = "text/vtt" + env.response.content_type = "text/vtt; charset=UTF-8" caption = captions.select { |caption| caption.name.simpleText == label } diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 46a028c9..0a468fa3 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -825,17 +825,17 @@ struct Video end struct Caption - JSON.mapping( - name: CaptionName, - baseUrl: String, - languageCode: String - ) + json_mapping({ + name: CaptionName, + baseUrl: String, + languageCode: String, + }) end struct CaptionName - JSON.mapping( + json_mapping({ simpleText: String, - ) + }) end class VideoRedirect < Exception