summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr92
-rw-r--r--src/invidious/comments.cr3
-rw-r--r--src/invidious/config.cr1
-rw-r--r--src/invidious/frontend/watch_page.cr108
-rw-r--r--src/invidious/helpers/i18n.cr1
-rw-r--r--src/invidious/routes/api/v1/authenticated.cr10
-rw-r--r--src/invidious/routes/api/v1/misc.cr6
-rw-r--r--src/invidious/routes/api/v1/videos.cr8
-rw-r--r--src/invidious/routes/channels.cr33
-rw-r--r--src/invidious/routes/login.cr7
-rw-r--r--src/invidious/routes/playlists.cr11
-rw-r--r--src/invidious/routes/preferences.cr5
-rw-r--r--src/invidious/routes/video_playback.cr40
-rw-r--r--src/invidious/routes/watch.cr55
-rw-r--r--src/invidious/routing.cr4
-rw-r--r--src/invidious/user/preferences.cr1
-rw-r--r--src/invidious/views/user/preferences.ecr5
-rw-r--r--src/invidious/views/watch.ecr36
18 files changed, 282 insertions, 144 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index d4878759..1bdf3097 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -29,6 +29,8 @@ require "protodec/utils"
require "./invidious/database/*"
require "./invidious/helpers/*"
require "./invidious/yt_backend/*"
+require "./invidious/frontend/*"
+
require "./invidious/*"
require "./invidious/channels/*"
require "./invidious/user/*"
@@ -154,8 +156,8 @@ if CONFIG.popular_enabled
Invidious::Jobs.register Invidious::Jobs::PullPopularVideosJob.new(PG_DB)
end
-connection_channel = Channel({Bool, Channel(PQ::Notification)}).new(32)
-Invidious::Jobs.register Invidious::Jobs::NotificationJob.new(connection_channel, CONFIG.database_url)
+CONNECTION_CHANNEL = Channel({Bool, Channel(PQ::Notification)}).new(32)
+Invidious::Jobs.register Invidious::Jobs::NotificationJob.new(CONNECTION_CHANNEL, CONFIG.database_url)
Invidious::Jobs.start_all
@@ -234,6 +236,7 @@ before_all do |env|
"/api/manifest/",
"/videoplayback",
"/latest_version",
+ "/download",
}.any? { |r| env.request.resource.starts_with? r }
if env.request.cookies.has_key? "SID"
@@ -324,6 +327,9 @@ end
Invidious::Routing.get "/channel/:ucid/playlists", Invidious::Routes::Channels, :playlists
Invidious::Routing.get "/channel/:ucid/community", Invidious::Routes::Channels, :community
Invidious::Routing.get "/channel/:ucid/about", Invidious::Routes::Channels, :about
+ Invidious::Routing.get "/channel/:ucid/live", Invidious::Routes::Channels, :live
+ Invidious::Routing.get "/user/:user/live", Invidious::Routes::Channels, :live
+ Invidious::Routing.get "/c/:user/live", Invidious::Routes::Channels, :live
["", "/videos", "/playlists", "/community", "/about"].each do |path|
# /c/LinusTechTips
@@ -346,6 +352,8 @@ end
Invidious::Routing.get "/e/:id", Invidious::Routes::Watch, :redirect
Invidious::Routing.get "/redirect", Invidious::Routes::Misc, :cross_instance_redirect
+ Invidious::Routing.post "/download", Invidious::Routes::Watch, :download
+
Invidious::Routing.get "/embed/", Invidious::Routes::Embed, :redirect
Invidious::Routing.get "/embed/:id", Invidious::Routes::Embed, :show
@@ -360,6 +368,7 @@ end
Invidious::Routing.post "/playlist_ajax", Invidious::Routes::Playlists, :playlist_ajax
Invidious::Routing.get "/playlist", Invidious::Routes::Playlists, :show
Invidious::Routing.get "/mix", Invidious::Routes::Playlists, :mix
+ Invidious::Routing.get "/watch_videos", Invidious::Routes::Playlists, :watch_videos
Invidious::Routing.get "/opensearch.xml", Invidious::Routes::Search, :opensearch
Invidious::Routing.get "/results", Invidious::Routes::Search, :results
@@ -406,85 +415,6 @@ define_v1_api_routes()
define_api_manifest_routes()
define_video_playback_routes()
-# Channels
-
-{"/channel/:ucid/live", "/user/:user/live", "/c/:user/live"}.each do |route|
- get route do |env|
- locale = env.get("preferences").as(Preferences).locale
-
- # Appears to be a bug in routing, having several routes configured
- # as `/a/:a`, `/b/:a`, `/c/:a` results in 404
- value = env.request.resource.split("/")[2]
- body = ""
- {"channel", "user", "c"}.each do |type|
- response = YT_POOL.client &.get("/#{type}/#{value}/live?disable_polymer=1")
- if response.status_code == 200
- body = response.body
- end
- end
-
- video_id = body.match(/'VIDEO_ID': "(?<id>[a-zA-Z0-9_-]{11})"/).try &.["id"]?
- if video_id
- params = [] of String
- env.params.query.each do |k, v|
- params << "#{k}=#{v}"
- end
- params = params.join("&")
-
- url = "/watch?v=#{video_id}"
- if !params.empty?
- url += "&#{params}"
- end
-
- env.redirect url
- else
- env.redirect "/channel/#{value}"
- end
- end
-end
-
-# Authenticated endpoints
-
-# The notification APIs can't be extracted yet
-# due to the requirement of the `connection_channel`
-# used by the `NotificationJob`
-
-get "/api/v1/auth/notifications" do |env|
- env.response.content_type = "text/event-stream"
-
- topics = env.params.query["topics"]?.try &.split(",").uniq.first(1000)
- topics ||= [] of String
-
- create_notification_stream(env, topics, connection_channel)
-end
-
-post "/api/v1/auth/notifications" do |env|
- env.response.content_type = "text/event-stream"
-
- topics = env.params.body["topics"]?.try &.split(",").uniq.first(1000)
- topics ||= [] of String
-
- create_notification_stream(env, topics, connection_channel)
-end
-
-get "/Captcha" do |env|
- headers = HTTP::Headers{":authority" => "accounts.google.com"}
- response = YT_POOL.client &.get(env.request.resource, headers)
- env.response.headers["Content-Type"] = response.headers["Content-Type"]
- response.body
-end
-
-# Undocumented, creates anonymous playlist with specified 'video_ids', max 50 videos
-get "/watch_videos" do |env|
- response = YT_POOL.client &.get(env.request.resource)
- if url = response.headers["Location"]?
- url = URI.parse(url).request_target
- next env.redirect url
- end
-
- env.response.status_code = response.status_code
-end
-
error 404 do |env|
if md = env.request.path.match(/^\/(?<id>([a-zA-Z0-9_-]{11})|(\w+))$/)
item = md["id"]
diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr
index 65f4b135..ab9fcc8b 100644
--- a/src/invidious/comments.cr
+++ b/src/invidious/comments.cr
@@ -78,7 +78,8 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
when "RELOAD_CONTINUATION_SLOT_HEADER"
header = item["reloadContinuationItemsCommand"]["continuationItems"][0]
when "RELOAD_CONTINUATION_SLOT_BODY"
- contents = item["reloadContinuationItemsCommand"]["continuationItems"]
+ # continuationItems is nil when video has no comments
+ contents = item["reloadContinuationItemsCommand"]["continuationItems"]?
end
elsif item["appendContinuationItemsAction"]?
contents = item["appendContinuationItemsAction"]["continuationItems"]
diff --git a/src/invidious/config.cr b/src/invidious/config.cr
index bebb9ae5..93c4c0f7 100644
--- a/src/invidious/config.cr
+++ b/src/invidious/config.cr
@@ -23,6 +23,7 @@ struct ConfigPreferences
property listen : Bool = false
property local : Bool = false
property locale : String = "en-US"
+ property watch_history : Bool = true
property max_results : Int32 = 40
property notifications_only : Bool = false
property player_style : String = "invidious"
diff --git a/src/invidious/frontend/watch_page.cr b/src/invidious/frontend/watch_page.cr
new file mode 100644
index 00000000..80b67641
--- /dev/null
+++ b/src/invidious/frontend/watch_page.cr
@@ -0,0 +1,108 @@
+module Invidious::Frontend::WatchPage
+ extend self
+
+ # A handy structure to pass many elements at
+ # once to the download widget function
+ struct VideoAssets
+ getter full_videos : Array(Hash(String, JSON::Any))
+ getter video_streams : Array(Hash(String, JSON::Any))
+ getter audio_streams : Array(Hash(String, JSON::Any))
+ getter captions : Array(Caption)
+
+ def initialize(
+ @full_videos,
+ @video_streams,
+ @audio_streams,
+ @captions
+ )
+ end
+ end
+
+ def download_widget(locale : String, video : Video, video_assets : VideoAssets) : String
+ if CONFIG.disabled?("downloads")
+ return "<p id=\"download\">#{translate(locale, "Download is disabled.")}</p>"
+ end
+
+ return String.build(4000) do |str|
+ str << "<form"
+ str << " class=\"pure-form pure-form-stacked\""
+ str << " action='/download'"
+ str << " method='post'"
+ str << " rel='noopener'"
+ str << " target='_blank'>"
+ str << '\n'
+
+ # Hidden inputs for video id and title
+ str << "<input type='hidden' name='id' value='" << video.id << "'/>\n"
+ str << "<input type='hidden' name='title' value='" << HTML.escape(video.title) << "'/>\n"
+
+ str << "\t<div class=\"pure-control-group\">\n"
+
+ str << "\t\t<label for='download_widget'>"
+ str << translate(locale, "Download as: ")
+ str << "</label>\n"
+
+ # TODO: remove inline style
+ str << "\t\t<select style=\"width:100%\" name='download_widget' id='download_widget'>\n"
+
+ # Non-DASH videos (audio+video)
+
+ video_assets.full_videos.each do |option|
+ mimetype = option["mimeType"].as_s.split(";")[0]
+
+ height = itag_to_metadata?(option["itag"]).try &.["height"]?
+
+ value = {"itag": option["itag"], "ext": mimetype.split("/")[1]}.to_json
+
+ str << "\t\t\t<option value='" << value << "'>"
+ str << (height || "~240") << "p - " << mimetype
+ str << "</option>\n"
+ end
+
+ # DASH video streams
+
+ video_assets.video_streams.each do |option|
+ mimetype = option["mimeType"].as_s.split(";")[0]
+
+ value = {"itag": option["itag"], "ext": mimetype.split("/")[1]}.to_json
+
+ str << "\t\t\t<option value='" << value << "'>"
+ str << option["qualityLabel"] << " - " << mimetype << " @ " << option["fps"] << "fps - video only"
+ str << "</option>\n"
+ end
+
+ # DASH audio streams
+
+ video_assets.audio_streams.each do |option|
+ mimetype = option["mimeType"].as_s.split(";")[0]
+
+ value = {"itag": option["itag"], "ext": mimetype.split("/")[1]}.to_json
+
+ str << "\t\t\t<option value='" << value << "'>"
+ str << mimetype << " @ " << (option["bitrate"]?.try &.as_i./ 1000) << "k - audio only"
+ str << "</option>\n"
+ end
+
+ # Subtitles (a.k.a "closed captions")
+
+ video_assets.captions.each do |caption|
+ value = {"label": caption.name, "ext": "#{caption.language_code}.vtt"}.to_json
+
+ str << "\t\t\t<option value='" << value << "'>"
+ str << translate(locale, "download_subtitles", translate(locale, caption.name))
+ str << "</option>\n"
+ end
+
+ # End of form
+
+ str << "\t\t</select>\n"
+ str << "\t</div>\n"
+
+ str << "\t<button type=\"submit\" class=\"pure-button pure-button-primary\">\n"
+ str << "\t\t<b>" << translate(locale, "Download") << "</b>\n"
+ str << "\t</button>\n"
+
+ str << "</form>\n"
+ end
+ end
+end
diff --git a/src/invidious/helpers/i18n.cr b/src/invidious/helpers/i18n.cr
index 6571dbe6..39e183f2 100644
--- a/src/invidious/helpers/i18n.cr
+++ b/src/invidious/helpers/i18n.cr
@@ -30,6 +30,7 @@ LOCALES_LIST = {
"pt-PT" => "Português de Portugal", # Portuguese (Portugal)
"ro" => "Română", # Romanian
"ru" => "русский", # Russian
+ "sq" => "Shqip", # Albanian
"sr" => "srpski (latinica)", # Serbian (Latin)
"sr_Cyrl" => "српски (ћирилица)", # Serbian (Cyrillic)
"sv-SE" => "Svenska", # Swedish
diff --git a/src/invidious/routes/api/v1/authenticated.cr b/src/invidious/routes/api/v1/authenticated.cr
index c27853ca..b559a01a 100644
--- a/src/invidious/routes/api/v1/authenticated.cr
+++ b/src/invidious/routes/api/v1/authenticated.cr
@@ -397,4 +397,14 @@ module Invidious::Routes::API::V1::Authenticated
env.response.status_code = 204
end
+
+ def self.notifications(env)
+ env.response.content_type = "text/event-stream"
+
+ raw_topics = env.params.body["topics"]? || env.params.query["topics"]?
+ topics = raw_topics.try &.split(",").uniq.first(1000)
+ topics ||= [] of String
+
+ create_notification_stream(env, topics, CONNECTION_CHANNEL)
+ end
end
diff --git a/src/invidious/routes/api/v1/misc.cr b/src/invidious/routes/api/v1/misc.cr
index a1ce0cbc..844fedb8 100644
--- a/src/invidious/routes/api/v1/misc.cr
+++ b/src/invidious/routes/api/v1/misc.cr
@@ -4,10 +4,10 @@ module Invidious::Routes::API::V1::Misc
env.response.content_type = "application/json"
if !CONFIG.statistics_enabled
- return error_json(400, "Statistics are not enabled.")
+ return {"software" => SOFTWARE}.to_json
+ else
+ return Invidious::Jobs::StatisticsRefreshJob::STATISTICS.to_json
end
-
- Invidious::Jobs::StatisticsRefreshJob::STATISTICS.to_json
end
# APIv1 currently uses the same logic for both
diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.cr
index 2b23d2ad..a9f891f5 100644
--- a/src/invidious/routes/api/v1/videos.cr
+++ b/src/invidious/routes/api/v1/videos.cr
@@ -23,7 +23,11 @@ module Invidious::Routes::API::V1::Videos
env.response.content_type = "application/json"
id = env.params.url["id"]
- region = env.params.query["region"]?
+ region = env.params.query["region"]? || env.params.body["region"]?
+
+ if id.nil? || id.size != 11 || !id.matches?(/^[\w-]+$/)
+ return error_json(400, "Invalid video ID")
+ end
# 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
@@ -136,7 +140,7 @@ module Invidious::Routes::API::V1::Videos
#
# See: https://github.com/iv-org/invidious/issues/2391
webvtt = YT_POOL.client &.get("#{url}&format=vtt").body
- .gsub(/([0-9:.]+ --> [0-9:.]+).+/, "\\1")
+ .gsub(/([0-9:.]{12} --> [0-9:.]{12}).+/, "\\1")
end
if title = env.params.query["title"]?
diff --git a/src/invidious/routes/channels.cr b/src/invidious/routes/channels.cr
index 6cb1e1f7..cd2e3323 100644
--- a/src/invidious/routes/channels.cr
+++ b/src/invidious/routes/channels.cr
@@ -147,6 +147,39 @@ module Invidious::Routes::Channels
end
end
+ def self.live(env)
+ locale = env.get("preferences").as(Preferences).locale
+
+ # Appears to be a bug in routing, having several routes configured
+ # as `/a/:a`, `/b/:a`, `/c/:a` results in 404
+ value = env.request.resource.split("/")[2]
+ body = ""
+ {"channel", "user", "c"}.each do |type|
+ response = YT_POOL.client &.get("/#{type}/#{value}/live?disable_polymer=1")
+ if response.status_code == 200
+ body = response.body
+ end
+ end
+
+ video_id = body.match(/'VIDEO_ID': "(?<id>[a-zA-Z0-9_-]{11})"/).try &.["id"]?
+ if video_id
+ params = [] of String
+ env.params.query.each do |k, v|
+ params << "#{k}=#{v}"
+ end
+ params = params.join("&")
+
+ url = "/watch?v=#{video_id}"
+ if !params.empty?
+ url += "&#{params}"
+ end
+
+ env.redirect url
+ else
+ env.redirect "/channel/#{value}"
+ end
+ end
+
private def self.fetch_basic_information(env)
locale = env.get("preferences").as(Preferences).locale
diff --git a/src/invidious/routes/login.cr b/src/invidious/routes/login.cr
index 65b337d1..99fc13a2 100644
--- a/src/invidious/routes/login.cr
+++ b/src/invidious/routes/login.cr
@@ -481,4 +481,11 @@ module Invidious::Routes::Login
env.redirect referer
end
+
+ def self.captcha(env)
+ headers = HTTP::Headers{":authority" => "accounts.google.com"}
+ response = YT_POOL.client &.get(env.request.resource, headers)
+ env.response.headers["Content-Type"] = response.headers["Content-Type"]
+ response.body
+ end
end
diff --git a/src/invidious/routes/playlists.cr b/src/invidious/routes/playlists.cr
index 1ed29e79..dbeb4f97 100644
--- a/src/invidious/routes/playlists.cr
+++ b/src/invidious/routes/playlists.cr
@@ -443,4 +443,15 @@ module Invidious::Routes::Playlists
templated "mix"
end
+
+ # Undocumented, creates anonymous playlist with specified 'video_ids', max 50 videos
+ def self.watch_videos(env)
+ response = YT_POOL.client &.get(env.request.resource)
+ if url = response.headers["Location"]?
+ url = URI.parse(url).request_target
+ return env.redirect url
+ end
+
+ env.response.status_code = response.status_code
+ end
end
diff --git a/src/invidious/routes/preferences.cr b/src/invidious/routes/preferences.cr
index 68d61fd1..570cba69 100644
--- a/src/invidious/routes/preferences.cr
+++ b/src/invidious/routes/preferences.cr
@@ -47,6 +47,10 @@ module Invidious::Routes::PreferencesRoute
local ||= "off"
local = local == "on"
+ watch_history = env.params.body["watch_history"]?.try &.as(String)
+ watch_history ||= "off"
+ watch_history = watch_history == "on"
+
speed = env.params.body["speed"]?.try &.as(String).to_f32?
speed ||= CONFIG.default_user_preferences.speed
@@ -149,6 +153,7 @@ module Invidious::Routes::PreferencesRoute
latest_only: latest_only,
listen: listen,
local: local,
+ watch_history: watch_history,
locale: locale,
max_results: max_results,
notifications_only: notifications_only,
diff --git a/src/invidious/routes/video_playback.cr b/src/invidious/routes/video_playback.cr
index 6ac1e780..3a92ef96 100644
--- a/src/invidious/routes/video_playback.cr
+++ b/src/invidious/routes/video_playback.cr
@@ -164,7 +164,9 @@ module Invidious::Routes::VideoPlayback
if title = query_params["title"]?
# https://blog.fastmail.com/2011/06/24/download-non-english-filenames/
- env.response.headers["Content-Disposition"] = "attachment; filename=\"#{URI.encode_www_form(title)}\"; filename*=UTF-8''#{URI.encode_www_form(title)}"
+ filename = URI.encode_www_form(title, space_to_plus: false)
+ header = "attachment; filename=\"#{filename}\"; filename*=UTF-8''#{filename}"
+ env.response.headers["Content-Disposition"] = header
end
if !resp.headers.includes_word?("Transfer-Encoding", "chunked")
@@ -242,31 +244,25 @@ module Invidious::Routes::VideoPlayback
# YouTube /videoplayback links expire after 6 hours,
# so we have a mechanism here to redirect to the latest version
def self.latest_version(env)
- if env.params.query["download_widget"]?
- download_widget = JSON.parse(env.params.query["download_widget"])
+ id = env.params.query["id"]?
+ itag = env.params.query["itag"]?.try &.to_i?
- id = download_widget["id"].as_s
- title = URI.decode_www_form(download_widget["title"].as_s)
-
- if label = download_widget["label"]?
- return env.redirect "/api/v1/captions/#{id}?label=#{label}&title=#{title}"
- else
- itag = download_widget["itag"].as_s.to_i
- local = "true"
- end
+ # Sanity checks
+ if id.nil? || id.size != 11 || !id.matches?(/^[\w-]+$/)
+ return error_template(400, "Invalid video ID")
end
- id ||= env.params.query["id"]?
- itag ||= env.params.query["itag"]?.try &.to_i
+ if itag.nil? || itag <= 0 || itag >= 1000
+ return error_template(400, "Invalid itag")
+ end
region = env.params.query["region"]?
+ local = (env.params.query["local"]? == "true")
- local ||= env.params.query["local"]?
- local ||= "false"
- local = local == "true"
+ title = env.params.query["title"]?
- if !id || !itag
- haltf env, status_code: 400, response: "TESTING"
+ if title && CONFIG.disabled?("downloads")
+ return error_template(403, "Administrator has disabled this endpoint.")
end
video = get_video(id, region: region)
@@ -278,8 +274,10 @@ module Invidious::Routes::VideoPlayback
haltf env, status_code: 404
end
- url = URI.parse(url).request_target.not_nil! if local
- url = "#{url}&title=#{title}" if title
+ if local
+ url = URI.parse(url).request_target.not_nil!
+ url += "&title=#{URI.encode_www_form(title, space_to_plus: false)}" if title
+ end
return env.redirect url
end
diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr
index 42bc4219..867ffa6a 100644
--- a/src/invidious/routes/watch.cr
+++ b/src/invidious/routes/watch.cr
@@ -75,7 +75,7 @@ module Invidious::Routes::Watch
end
env.params.query.delete_all("iv_load_policy")
- if watched && !watched.includes? id
+ if watched && preferences.watch_history && !watched.includes? id
Invidious::Database::Users.mark_watched(user.as(User), id)
end
@@ -189,6 +189,14 @@ module Invidious::Routes::Watch
return env.redirect url
end
+ # Structure used for the download widget
+ video_assets = Invidious::Frontend::WatchPage::VideoAssets.new(
+ full_videos: fmt_stream,
+ video_streams: video_streams,
+ audio_streams: audio_streams,
+ captions: video.captions
+ )
+
templated "watch"
end
@@ -281,4 +289,49 @@ module Invidious::Routes::Watch
return error_template(404, "The requested clip doesn't exist")
end
end
+
+ def self.download(env)
+ if CONFIG.disabled?("downloads")
+ return error_template(403, "Administrator has disabled this endpoint.")
+ end
+
+ title = env.params.body["title"]? || ""
+ video_id = env.params.body["id"]? || ""
+ selection = env.params.body["download_widget"]?
+
+ if title.empty? || video_id.empty? || selection.nil?
+ return error_template(400, "Missing form data")
+ end
+
+ download_widget = JSON.parse(selection)
+
+ extension = download_widget["ext"].as_s
+ filename = "#{video_id}-#{title}.#{extension}"
+
+ # Pass form parameters as URL parameters for the handlers of both
+ # /latest_version and /api/v1/captions. This avoids an un-necessary
+ # redirect and duplicated (and hazardous) sanity checks.
+ env.params.query["id"] = video_id
+ env.params.query["title"] = filename
+
+ # Delete the useless ones
+ env.params.body.delete("id")
+ env.params.body.delete("title")
+ env.params.body.delete("download_widget")
+
+ if label = download_widget["label"]?
+ # URL params specific to /api/v1/captions/:id
+ env.params.query["label"] = URI.encode_www_form(label.as_s, space_to_plus: false)
+
+ return Invidious::Routes::API::V1::Videos.captions(env)
+ elsif itag = download_widget["itag"]?.try &.as_i
+ # URL params specific to /latest_version
+ env.params.query["itag"] = itag.to_s
+ env.params.query["local"] = "true"
+
+ return Invidious::Routes::VideoPlayback.latest_version(env)
+ else
+ return error_template(400, "Invalid label or itag")
+ end
+ end
end
diff --git a/src/invidious/routing.cr b/src/invidious/routing.cr
index 5efe1bd8..bd72c577 100644
--- a/src/invidious/routing.cr
+++ b/src/invidious/routing.cr
@@ -15,6 +15,7 @@ macro define_user_routes
Invidious::Routing.get "/login", Invidious::Routes::Login, :login_page
Invidious::Routing.post "/login", Invidious::Routes::Login, :login
Invidious::Routing.post "/signout", Invidious::Routes::Login, :signout
+ Invidious::Routing.get "/Captcha", Invidious::Routes::Login, :captcha
# User preferences
Invidious::Routing.get "/preferences", Invidious::Routes::PreferencesRoute, :show
@@ -95,6 +96,9 @@ macro define_v1_api_routes
Invidious::Routing.post "/api/v1/auth/tokens/register", {{namespace}}::Authenticated, :register_token
Invidious::Routing.post "/api/v1/auth/tokens/unregister", {{namespace}}::Authenticated, :unregister_token
+ Invidious::Routing.get "/api/v1/auth/notifications", {{namespace}}::Authenticated, :notifications
+ Invidious::Routing.post "/api/v1/auth/notifications", {{namespace}}::Authenticated, :notifications
+
# Misc
Invidious::Routing.get "/api/v1/stats", {{namespace}}::Misc, :stats
Invidious::Routing.get "/api/v1/playlists/:plid", {{namespace}}::Misc, :get_playlist
diff --git a/src/invidious/user/preferences.cr b/src/invidious/user/preferences.cr
index 9eeed53f..b3059403 100644
--- a/src/invidious/user/preferences.cr
+++ b/src/invidious/user/preferences.cr
@@ -23,6 +23,7 @@ struct Preferences
property latest_only : Bool = CONFIG.default_user_preferences.latest_only
property listen : Bool = CONFIG.default_user_preferences.listen
property local : Bool = CONFIG.default_user_preferences.local
+ property watch_history : Bool = CONFIG.default_user_preferences.watch_history
property vr_mode : Bool = CONFIG.default_user_preferences.vr_mode
property show_nick : Bool = CONFIG.default_user_preferences.show_nick
diff --git a/src/invidious/views/user/preferences.ecr b/src/invidious/views/user/preferences.ecr
index 3606d140..dbb5e9db 100644
--- a/src/invidious/views/user/preferences.ecr
+++ b/src/invidious/views/user/preferences.ecr
@@ -207,6 +207,11 @@
<legend><%= translate(locale, "preferences_category_subscription") %></legend>
<div class="pure-control-group">
+ <label for="watch_history"><%= translate(locale, "preferences_watch_history_label") %></label>
+ <input name="watch_history" id="watch_history" type="checkbox" <% if preferences.watch_history %>checked<% end %>>
+ </div>
+
+ <div class="pure-control-group">
<label for="annotations_subscribed"><%= translate(locale, "preferences_annotations_subscribed_label") %></label>
<input name="annotations_subscribed" id="annotations_subscribed" type="checkbox" <% if preferences.annotations_subscribed %>checked<% end %>>
</div>
diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr
index 2e0aee99..0e4af3ab 100644
--- a/src/invidious/views/watch.ecr
+++ b/src/invidious/views/watch.ecr
@@ -168,41 +168,7 @@ we're going to need to do it here in order to allow for translations.
<% end %>
<% end %>
- <% if CONFIG.dmca_content.includes?(video.id) || CONFIG.disabled?("downloads") %>
- <p id="download"><%= translate(locale, "Download is disabled.") %></p>
- <% else %>
- <form class="pure-form pure-form-stacked" action="/latest_version" method="get" rel="noopener" target="_blank">
- <div class="pure-control-group">
- <label for="download_widget"><%= translate(locale, "Download as: ") %></label>
- <select style="width:100%" name="download_widget" id="download_widget">
- <% fmt_stream.each do |option| %>
- <option value='{"id":"<%= video.id %>","itag":"<%= option["itag"] %>","title":"<%= URI.encode_www_form(video.title) %>-<%= video.id %>.<%= option["mimeType"].as_s.split(";")[0].split("/")[1] %>"}'>
- <%= itag_to_metadata?(option["itag"]).try &.["height"]? || "~240" %>p - <%= option["mimeType"].as_s.split(";")[0] %>
- </option>
- <% end %>
- <% video_streams.each do |option| %>
- <option value='{"id":"<%= video.id %>","itag":"<%= option["itag"] %>","title":"<%= URI.encode_www_form(video.title) %>-<%= video.id %>.<%= option["mimeType"].as_s.split(";")[0].split("/")[1] %>"}'>
- <%= option["qualityLabel"] %> - <%= option["mimeType"].as_s.split(";")[0] %> @ <%= option["fps"] %>fps - video only
- </option>
- <% end %>
- <% audio_streams.each do |option| %>
- <option value='{"id":"<%= video.id %>","itag":"<%= option["itag"] %>","title":"<%= URI.encode_www_form(video.title) %>-<%= video.id %>.<%= option["mimeType"].as_s.split(";")[0].split("/")[1] %>"}'>
- <%= option["mimeType"].as_s.split(";")[0] %> @ <%= option["bitrate"]?.try &.as_i./ 1000 %>k - audio only
- </option>
- <% end %>
- <% captions.each do |caption| %>
- <option value='{"id":"<%= video.id %>","label":"<%= caption.name %>","title":"<%= URI.encode_www_form(video.title) %>-<%= video.id %>.<%= caption.language_code %>.vtt"}'>
- <%= translate(locale, "download_subtitles", translate(locale, caption.name)) %>
- </option>
- <% end %>
- </select>
- </div>
-
- <button type="submit" class="pure-button pure-button-primary">
- <b><%= translate(locale, "Download") %></b>
- </button>
- </form>
- <% end %>
+ <%= Invidious::Frontend::WatchPage.download_widget(locale, video, video_assets) %>
<p id="views"><i class="icon ion-ios-eye"></i> <%= number_with_separator(video.views) %></p>
<p id="likes"><i class="icon ion-ios-thumbs-up"></i> <%= number_with_separator(video.likes) %></p>