summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@protonmail.com>2019-05-20 20:22:01 -0500
committerOmar Roth <omarroth@protonmail.com>2019-05-20 20:22:01 -0500
commit8b50c8515fac6a956d48292d23d76cfa1b21be7e (patch)
tree25d7b4bc0e0de07ecc0b58c5dbfe92b8caa59968
parent1eaa377583fca5f34428f6783e7926237abdcc8b (diff)
downloadinvidious-8b50c8515fac6a956d48292d23d76cfa1b21be7e.tar.gz
invidious-8b50c8515fac6a956d48292d23d76cfa1b21be7e.tar.bz2
invidious-8b50c8515fac6a956d48292d23d76cfa1b21be7e.zip
Fix content-type for captions
-rw-r--r--src/invidious.cr12
-rw-r--r--src/invidious/videos.cr14
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