diff options
38 files changed, 428 insertions, 253 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index adde39c9..db0987cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: crystal: - 1.0.0 - 1.1.1 - - 1.2.1 + - 1.2.2 include: - crystal: nightly stable: false diff --git a/.github/workflows/container-release.yml b/.github/workflows/container-release.yml index 77b92c6f..36fb566e 100644 --- a/.github/workflows/container-release.yml +++ b/.github/workflows/container-release.yml @@ -27,7 +27,7 @@ jobs: - name: Install Crystal uses: oprypin/install-crystal@v1.2.4 with: - crystal: 1.1.1 + crystal: 1.2.2 - name: Run lint run: | diff --git a/config/config.example.yml b/config/config.example.yml index 4cc6e7f4..c3d52d32 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -157,10 +157,14 @@ https_only: false ## Note 2: Using QUIC prevents some captcha challenges from appearing. ## See: https://github.com/iv-org/invidious/issues/957#issuecomment-576424042 ## +## Note 3: As of 2021-11-12, Google seems to have disabled QUIC on +## their servers. The default has been changed to 'false'.Read more +## at: https://github.com/iv-org/invidious/issues/2577 +## ## Accepted values: true, false -## Default: true +## Default: false ## -#use_quic: true +#use_quic: false ## ## Additionnal cookies to be sent when requesting the youtube API. @@ -466,9 +470,9 @@ default_user_preferences: ## ## Default user interface language (locale). ## - ## Note: overridin the default (no preferred caption language) - ## is not recommended, in order to not penalize people using - ## other languages. + ## Note: When hosting a public instance, overriding the + ## default (english) is not recommended, as it may + ## people using other languages. ## ## Accepted values: ## ar (Arabic) diff --git a/docker-compose.yml b/docker-compose.yml index cc62d6e5..c76c314c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: POSTGRES_PASSWORD: kemal POSTGRES_USER: kemal healthcheck: - test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER $$POSTGRES_DB"] + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] invidious: build: context: . diff --git a/docker/Dockerfile b/docker/Dockerfile index 21d4269c..5f1c0a11 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM crystallang/crystal:1.2.1-alpine AS builder +FROM crystallang/crystal:1.2.2-alpine AS builder RUN apk add --no-cache sqlite-static yaml-static ARG release diff --git a/docker/Dockerfile.arm64 b/docker/Dockerfile.arm64 index 4fe6b1ea..4d5d46bf 100644 --- a/docker/Dockerfile.arm64 +++ b/docker/Dockerfile.arm64 @@ -1,5 +1,5 @@ FROM alpine:edge AS builder -RUN apk add --no-cache 'crystal=1.2.1-r0' shards sqlite-static yaml-static yaml-dev libxml2-dev zlib-static openssl-libs-static openssl-dev musl-dev +RUN apk add --no-cache 'crystal=1.2.2-r0' shards sqlite-static yaml-static yaml-dev libxml2-dev zlib-static openssl-libs-static openssl-dev musl-dev ARG release diff --git a/locales/ar.json b/locales/ar.json index 15cf89bf..f2d457b6 100644 --- a/locales/ar.json +++ b/locales/ar.json @@ -432,5 +432,6 @@ "adminprefs_modified_source_code_url_label": "URL إلى مستودع التعليمات البرمجية المصدرية المعدلة", "footer_documentation": "التوثيق", "footer_donate_page": "تبرّع", - "preferences_region_label": "بلد المحتوى:. " + "preferences_region_label": "بلد المحتوى:. ", + "preferences_quality_dash_label": "جودة الفيديو المفضلة dash: " } diff --git a/locales/eo.json b/locales/eo.json index eafa5928..f8a07c9e 100644 --- a/locales/eo.json +++ b/locales/eo.json @@ -432,5 +432,6 @@ "footer_modfied_source_code": "Modifita Fontkodo", "footer_original_source_code": "Originala fontkodo", "footer_donate_page": "Donaci", - "preferences_region_label": "Lando de enhavo: " + "preferences_region_label": "Lando de la enhavo: ", + "preferences_quality_dash_label": "Preferata DASH-a videkvalito: " } diff --git a/locales/es.json b/locales/es.json index c4cb41d2..1403a731 100644 --- a/locales/es.json +++ b/locales/es.json @@ -386,7 +386,7 @@ "%A %B %-d, %Y": "%A %B %-d, %Y", "(edited)": "(editado)", "YouTube comment permalink": "Enlace permanente de YouTube del comentario", - "permalink": "permalink", + "permalink": "enlace permanente", "`x` marked it with a ❤": "`x` lo ha marcado con un ❤", "Audio mode": "Modo de audio", "Video mode": "Modo de vídeo", @@ -432,5 +432,6 @@ "footer_source_code": "Código fuente", "footer_modfied_source_code": "Código fuente modificado", "footer_donate_page": "Donar", - "preferences_region_label": "País del contenido: " + "preferences_region_label": "País del contenido: ", + "preferences_quality_dash_label": "Calidad de vídeo DASH preferida: " } diff --git a/locales/hr.json b/locales/hr.json index 884bf021..9b5f9250 100644 --- a/locales/hr.json +++ b/locales/hr.json @@ -68,7 +68,7 @@ "preferences_listen_label": "Standardno slušaj: ", "preferences_local_label": "Koristi posrednika videa: ", "preferences_speed_label": "Standardna brzina: ", - "preferences_quality_label": "Primarna kvaliteta videa: ", + "preferences_quality_label": "Preferirana kvaliteta videa: ", "preferences_volume_label": "Glasnoća playera: ", "preferences_comments_label": "Standardni komentari: ", "youtube": "YouTube", @@ -431,5 +431,7 @@ "footer_source_code": "Izvorni kod", "footer_modfied_source_code": "Izmijenjeni izvorni kod", "footer_documentation": "Dokumentacija", - "footer_original_source_code": "Izvoran izvorni kod" + "footer_original_source_code": "Izvoran izvorni kod", + "preferences_region_label": "Zemlja sadržaja: ", + "preferences_quality_dash_label": "Preferirana kvaliteta dash-videa: " } diff --git a/locales/id.json b/locales/id.json index 2623efe4..ca4c1e0f 100644 --- a/locales/id.json +++ b/locales/id.json @@ -12,9 +12,9 @@ "": "`x` daftar putar" }, "LIVE": "SIARAN LANGSUNG", - "Shared `x` ago": "Dibagikan`x` lalu", + "Shared `x` ago": "Dibagikan `x` yang lalu", "Unsubscribe": "Batal Langganan", - "Subscribe": "Langganan", + "Subscribe": "Berangganan", "View channel on YouTube": "Lihat kanal di YouTube", "View playlist on YouTube": "Lihat daftar putar di YouTube", "newest": "terbaru", @@ -44,11 +44,11 @@ "Export data as JSON": "Ekspor data sebagai JSON", "Delete account?": "Hapus akun?", "History": "Riwayat", - "An alternative front-end to YouTube": "Sebuah alternatif front-end untuk YouTube", + "An alternative front-end to YouTube": "Sebuah alternatif layar depan untuk YouTube", "JavaScript license information": "Informasi lisensi JavaScript", "source": "sumber", "Log in": "Masuk", - "Log in/register": "Daftar", + "Log in/register": "Masuk/Daftar", "Log in with Google": "Masuk dengan Google", "User ID": "ID Pengguna", "Password": "Kata Sandi", @@ -62,21 +62,21 @@ "Preferences": "Preferensi", "preferences_category_player": "Preferensi pemutar", "preferences_video_loop_label": "Selalu ulangi: ", - "preferences_autoplay_label": "Putar-Otomatis: ", - "preferences_continue_label": "Putar selanjutnya secara default: ", - "preferences_continue_autoplay_label": "Otomatis-Putar video berikutnya: ", - "preferences_listen_label": "Dengarkan secara default: ", - "preferences_local_label": "Video Proksi: ", - "preferences_speed_label": "Kecepatan default: ", + "preferences_autoplay_label": "Putar Otomatis: ", + "preferences_continue_label": "Putar selanjutnya secara baku: ", + "preferences_continue_autoplay_label": "Putar otomatis video berikutnya: ", + "preferences_listen_label": "Dengarkan secara baku: ", + "preferences_local_label": "Proksi video: ", + "preferences_speed_label": "Kecepatan baku: ", "preferences_quality_label": "Kualitas video yang disukai: ", "preferences_volume_label": "Volume pemutar: ", - "preferences_comments_label": "Komentar default: ", + "preferences_comments_label": "Komentar baku: ", "youtube": "YouTube", "reddit": "Reddit", - "preferences_captions_label": "Subtitel default: ", - "Fallback captions: ": "Subtitel fallback: ", + "preferences_captions_label": "Takarir baku: ", + "Fallback captions: ": "Takarir cadangan: ", "preferences_related_videos_label": "Tampilkan video terkait: ", - "preferences_annotations_label": "Tampilkan anotasi secara default: ", + "preferences_annotations_label": "Tampilkan anotasi secara baku: ", "preferences_extend_desc_label": "Perluas deskripsi video secara otomatis: ", "preferences_vr_mode_label": "Video interaktif 360°: ", "preferences_category_visual": "Preferensi visual", @@ -87,18 +87,18 @@ "light": "terang", "preferences_thin_mode_label": "Mode tipis: ", "preferences_category_misc": "Preferensi lainnya", - "preferences_automatic_instance_redirect_label": "Pengalihan instans otomatis (fallback ke redirect.invidious.io): ", + "preferences_automatic_instance_redirect_label": "Pengalihan peladen otomatis (balik kembali ke redirect.invidious.io): ", "preferences_category_subscription": "Preferensi langganan", - "preferences_annotations_subscribed_label": "Tampilkan anotasi secara default untuk kanal langganan: ", + "preferences_annotations_subscribed_label": "Tampilkan anotasi secara baku untuk kanal yang dilanggan? ", "Redirect homepage to feed: ": "Arahkan kembali laman beranda ke umpan: ", "preferences_max_results_label": "Jumlah video ditampilkan di umpan: ", "preferences_sort_label": "Urutkan video berdasarkan: ", "published": "dipublikasi", - "published - reverse": "dipublikasi - sebaliknya", + "published - reverse": "dipublikasi - terbalik", "alphabetically": "menurut abjad", - "alphabetically - reverse": "menurut abjad - sebaliknya", + "alphabetically - reverse": "menurut abjad - terbalik", "channel name": "nama kanal", - "channel name - reverse": "nama kanal - sebaliknya", + "channel name - reverse": "nama kanal - terbalik", "Only show latest video from channel: ": "Hanya tampilkan video terbaru dari kanal: ", "Only show latest unwatched video from channel: ": "Hanya tampilkan video belum ditonton terbaru dari kanal: ", "preferences_unseen_only_label": "Hanya tampilkan belum ditonton: ", @@ -106,7 +106,7 @@ "Enable web notifications": "Aktifkan pemberitahuan web", "`x` uploaded a video": "`x` mengunggah video", "`x` is live": "`x` sedang siaran langsung", - "preferences_category_data": "Preferensi Data", + "preferences_category_data": "Preferensi data", "Clear watch history": "Bersihkan riwayat tontonan", "Import/export data": "Impor/Ekspor data", "Change password": "Ganti kata sandi", @@ -115,13 +115,13 @@ "Watch history": "Riwayat tontonan", "Delete account": "Hapus akun", "preferences_category_admin": "Preferensi administrator", - "preferences_default_home_label": "Laman beranda default: ", + "preferences_default_home_label": "Laman beranda baku: ", "preferences_feed_menu_label": "Menu umpan: ", "preferences_show_nick_label": "Tampilkan nama panggilan di atas: ", "Top enabled: ": "Teratas diaktifkan: ", "CAPTCHA enabled: ": "CAPTCHA diaktifkan: ", "Login enabled: ": "Masuk diaktifkan: ", - "Registration enabled: ": "Registrasi diaktifkan: ", + "Registration enabled: ": "Pendaftaran diaktifkan: ", "Report statistics: ": "Laporan statistik: ", "Save preferences": "Simpan preferensi", "Subscription manager": "Pengatur langganan", @@ -161,11 +161,11 @@ "Title": "Judul", "Playlist privacy": "Privasi daftar putar", "Editing playlist `x`": "Menyunting daftar putar `x`", - "Show more": "Tampilkan lainnya", + "Show more": "Tampilkan lebih banyak", "Show less": "Tampilkan lebih sedikit", "Watch on YouTube": "Tonton di YouTube", - "Switch Invidious Instance": "Beralih Instance Invidious", - "Broken? Try another Invidious Instance": "Rusak? Coba Instance Invidious lain", + "Switch Invidious Instance": "Ganti peladen Invidious", + "Broken? Try another Invidious Instance": "Rusak? Coba peladen Invidious yang lain", "Hide annotations": "Sembunyikan anotasi", "Show annotations": "Tampilkan anotasi", "Genre: ": "Genre: ", @@ -175,9 +175,9 @@ "Engagement: ": "Keterlibatan: ", "Whitelisted regions: ": "Wilayah daftar-putih: ", "Blacklisted regions: ": "Wilayah daftar-hitam: ", - "Shared `x`": "Berbagi`x`", + "Shared `x`": "Berbagi `x`", "`x` views": { - "([^.,0-9]|^)1([^.,0-9]|$)": "`x` tampilan.([^.,0-9]|^)1([^.,0-9]|$)", + "([^.,0-9]|^)1([^.,0-9]|$)": "`x` tampilan", "": "`x` tampilan" }, "Premieres in `x`": "Tayang dalam `x`", @@ -186,7 +186,7 @@ "View YouTube comments": "Lihat komentar YouTube", "View more comments on Reddit": "Lihat lebih banyak komentar di Reddit", "View `x` comments": { - "([^.,0-9]|^)1([^.,0-9]|$)": "Lihat`x` komentar.([^.,0-9]|^)1([^.,0-9]|$)", + "([^.,0-9]|^)1([^.,0-9]|$)": "Lihat`x` komentar", "": "Lihat`x` komentar" }, "View Reddit comments": "Lihat komentar Reddit", @@ -368,7 +368,7 @@ "([^.,0-9]|^)1([^.,0-9]|$)": "`x` detik", "": "`x` detik" }, - "Fallback comments: ": "Komentar mundur: ", + "Fallback comments: ": "Komentar alternatif: ", "Popular": "Populer", "Search": "Cari", "Top": "Teratas", @@ -376,7 +376,7 @@ "Rating: ": "Peringkat: ", "preferences_locale_label": "Bahasa: ", "View as playlist": "Tampilkan sebagai daftar putar", - "Default": "Asali", + "Default": "Baku", "Music": "Musik", "Gaming": "Permainan", "News": "Berita", @@ -386,7 +386,7 @@ "%A %B %-d, %Y": "%A %B %-d, %Y", "(edited)": "(disunting)", "YouTube comment permalink": "Komentar YouTube permalink", - "permalink": "permalink", + "permalink": "tautan permanen", "`x` marked it with a ❤": "`x` telah ditandai dengan ❤", "Audio mode": "Mode audio", "Video mode": "Mode video", @@ -431,5 +431,7 @@ "short": "Pendek (< 4 menit)", "long": "Panjang (> 20 menit)", "footer_modfied_source_code": "Kode sumber yang dimodifikasi", - "footer_documentation": "Dokumentasi" + "footer_documentation": "Dokumentasi", + "preferences_region_label": "Konten dari negara: ", + "preferences_quality_dash_label": "Kualitas video dash yang disukai: " } diff --git a/locales/ja.json b/locales/ja.json index f67150fe..c7764d33 100644 --- a/locales/ja.json +++ b/locales/ja.json @@ -72,7 +72,7 @@ "preferences_volume_label": "プレイヤーの音量: ", "preferences_comments_label": "デフォルトのコメント: ", "youtube": "YouTube", - "reddit": "reddit", + "reddit": "Reddit", "preferences_captions_label": "デフォルトの字幕: ", "Fallback captions: ": "フォールバック時の字幕: ", "preferences_related_videos_label": "関連動画を表示: ", @@ -145,7 +145,7 @@ }, "search": "検索", "Log out": "ログアウト", - "Released under the AGPLv3 on Github.": "Github 上で AGPLv3 の元で公開されています", + "Released under the AGPLv3 on Github.": "GitHub 上で AGPLv3 の元で公開されています。", "Source available here.": "ソースはここで閲覧可能です。", "View JavaScript license information.": "JavaScript ライセンス情報", "View privacy policy.": "プライバシーポリシー", @@ -430,5 +430,8 @@ "footer_original_source_code": "ソースコード(元)", "footer_modfied_source_code": "ソースコード(編集)", "adminprefs_modified_source_code_url_label": "編集したソースコードのレポジトリーURL", - "long": "20 分以上" + "long": "20 分以上", + "preferences_region_label": "地域: ", + "footer_donate_page": "寄付する", + "preferences_quality_dash_label": "優先するDash画質 : " } diff --git a/locales/lt.json b/locales/lt.json index 6864a178..1881ac0b 100644 --- a/locales/lt.json +++ b/locales/lt.json @@ -432,5 +432,6 @@ "adminprefs_modified_source_code_url_label": "URL į pakeisto pirminio kodo repozitoriją", "footer_modfied_source_code": "Pakeistas pirminis kodas", "footer_donate_page": "Paaukoti", - "preferences_region_label": "Turinio šalis: " + "preferences_region_label": "Turinio šalis: ", + "preferences_quality_dash_label": "Pageidaujama DASH vaizdo kokybė: " } diff --git a/locales/pt.json b/locales/pt.json index b545d098..3665d0b5 100644 --- a/locales/pt.json +++ b/locales/pt.json @@ -432,5 +432,6 @@ "footer_documentation": "Documentação", "footer_modfied_source_code": "Código-fonte alterado", "footer_donate_page": "Doar", - "preferences_region_label": "País do conteúdo: " + "preferences_region_label": "País do conteúdo: ", + "preferences_quality_dash_label": "Qualidade de vídeo DASH preferida: " } diff --git a/locales/sv-SE.json b/locales/sv-SE.json index beacc278..d366aa91 100644 --- a/locales/sv-SE.json +++ b/locales/sv-SE.json @@ -420,5 +420,10 @@ "filter": "Filter", "Current version: ": "Nuvarande version: ", "next_steps_error_message_refresh": "Uppdatera", - "next_steps_error_message_go_to_youtube": "Gå till Youtube" + "next_steps_error_message_go_to_youtube": "Gå till Youtube", + "Released under the AGPLv3 on Github.": "Publicerad under AGPLv3 på Github.", + "footer_source_code": "Källkod", + "long": "Lång (> 20 minuter)", + "footer_documentation": "Dokumentation", + "short": "Kort (< 4 minuter)" } diff --git a/locales/tr.json b/locales/tr.json index c8a0648a..6e753bfc 100644 --- a/locales/tr.json +++ b/locales/tr.json @@ -256,7 +256,7 @@ "Croatian": "Hırvatça", "Czech": "Çekçe", "Danish": "Danca", - "Dutch": "Flemenkçe", + "Dutch": "Felemenkçe", "Esperanto": "Esperanto", "Estonian": "Estonca", "Filipino": "Filipince", @@ -432,5 +432,6 @@ "footer_modfied_source_code": "Değiştirilmiş kaynak kodları", "adminprefs_modified_source_code_url_label": "Değiştirilmiş kaynak kodları deposunun URL'si", "footer_donate_page": "Bağış yap", - "preferences_region_label": "İçerik ülkesi: " + "preferences_region_label": "İçerik ülkesi: ", + "preferences_quality_dash_label": "Tercih edilen dash video kalitesi: " } diff --git a/locales/zh-CN.json b/locales/zh-CN.json index 59287ee8..8821ccf9 100644 --- a/locales/zh-CN.json +++ b/locales/zh-CN.json @@ -432,5 +432,6 @@ "adminprefs_modified_source_code_url_label": "更改的源代码仓库网址", "footer_original_source_code": "原始源代码", "footer_donate_page": "捐赠", - "preferences_region_label": "内容国家: " + "preferences_region_label": "内容国家: ", + "preferences_quality_dash_label": "首选 dash 视频分辨率: " } diff --git a/locales/zh-TW.json b/locales/zh-TW.json index 139b2786..b23e439a 100644 --- a/locales/zh-TW.json +++ b/locales/zh-TW.json @@ -432,5 +432,6 @@ "footer_modfied_source_code": "修改後的原始碼", "adminprefs_modified_source_code_url_label": "修改後的原始碼倉庫 URL", "footer_donate_page": "捐款", - "preferences_region_label": "內容國家: " + "preferences_region_label": "內容國家: ", + "preferences_quality_dash_label": "偏好的 dash 影片品質: " } diff --git a/src/invidious/config.cr b/src/invidious/config.cr index bacdb4ac..578e31fd 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -93,7 +93,7 @@ class Config property port : Int32 = 3000 # Port to listen for connections (overrided by command line argument) property host_binding : String = "0.0.0.0" # Host to bind (overrided by command line argument) property pool_size : Int32 = 100 # Pool size for HTTP requests to youtube.com and ytimg.com (each domain has a separate pool of `pool_size`) - property use_quic : Bool = true # Use quic transport for youtube api + property use_quic : Bool = false # Use quic transport for youtube api @[YAML::Field(converter: Preferences::StringToCookies)] property cookies : HTTP::Cookies = HTTP::Cookies.new # Saved cookies in "name1=value1; name2=value2..." format diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 9c053d74..c3b356a9 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -206,7 +206,7 @@ def create_notification_stream(env, topics, connection_channel) video = get_video(video_id, PG_DB) video.published = published - response = JSON.parse(video.to_json(locale)) + response = JSON.parse(video.to_json(locale, nil)) if fields_text = env.params.query["fields"]? begin @@ -282,7 +282,7 @@ def create_notification_stream(env, topics, connection_channel) video = get_video(video_id, PG_DB) video.published = Time.unix(published) - response = JSON.parse(video.to_json(locale)) + response = JSON.parse(video.to_json(locale, nil)) if fields_text = env.params.query["fields"]? begin diff --git a/src/invidious/helpers/serialized_yt_data.cr b/src/invidious/helpers/serialized_yt_data.cr index 1ba3f20e..f92b7b89 100644 --- a/src/invidious/helpers/serialized_yt_data.cr +++ b/src/invidious/helpers/serialized_yt_data.cr @@ -58,17 +58,13 @@ struct SearchVideo end end - def to_xml(auto_generated, query_params, xml : XML::Builder | Nil = nil) - if xml - to_xml(HOST_URL, auto_generated, query_params, xml) - else - XML.build do |xml| - to_xml(HOST_URL, auto_generated, query_params, xml) - end + def to_xml(auto_generated, query_params, _xml : Nil) + XML.build do |xml| + to_xml(auto_generated, query_params, xml) end end - def to_json(locale : Hash(String, JSON::Any), json : JSON::Builder) + def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) json.object do json.field "type", "video" json.field "title", self.title @@ -99,16 +95,17 @@ struct SearchVideo end end - def to_json(locale, json : JSON::Builder | Nil = nil) - if json + # TODO: remove the locale and follow the crystal convention + def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) + JSON.build do |json| to_json(locale, json) - else - JSON.build do |json| - to_json(locale, json) - end end end + def to_json(json : JSON::Builder) + to_json(nil, json) + end + def is_upcoming premiere_timestamp ? true : false end @@ -133,7 +130,7 @@ struct SearchPlaylist property videos : Array(SearchPlaylistVideo) property thumbnail : String? - def to_json(locale, json : JSON::Builder) + def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) json.object do json.field "type", "playlist" json.field "title", self.title @@ -163,15 +160,16 @@ struct SearchPlaylist end end - def to_json(locale, json : JSON::Builder | Nil = nil) - if json + # TODO: remove the locale and follow the crystal convention + def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) + JSON.build do |json| to_json(locale, json) - else - JSON.build do |json| - to_json(locale, json) - end end end + + def to_json(json : JSON::Builder) + to_json(nil, json) + end end struct SearchChannel @@ -185,7 +183,7 @@ struct SearchChannel property description_html : String property auto_generated : Bool - def to_json(locale, json : JSON::Builder) + def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) json.object do json.field "type", "channel" json.field "author", self.author @@ -215,15 +213,16 @@ struct SearchChannel end end - def to_json(locale, json : JSON::Builder | Nil = nil) - if json + # TODO: remove the locale and follow the crystal convention + def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) + JSON.build do |json| to_json(locale, json) - else - JSON.build do |json| - to_json(locale, json) - end end end + + def to_json(json : JSON::Builder) + to_json(nil, json) + end end class Category @@ -235,7 +234,7 @@ class Category property description_html : String property badges : Array(Tuple(String, String))? - def to_json(locale, json : JSON::Builder) + def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) json.object do json.field "type", "category" json.field "title", self.title @@ -249,15 +248,16 @@ class Category end end - def to_json(locale, json : JSON::Builder | Nil = nil) - if json + # TODO: remove the locale and follow the crystal convention + def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) + JSON.build do |json| to_json(locale, json) - else - JSON.build do |json| - to_json(locale, json) - end end end + + def to_json(json : JSON::Builder) + to_json(nil, json) + end end alias SearchItem = SearchVideo | SearchChannel | SearchPlaylist | Category diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index 443d19d7..f37667b5 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -11,7 +11,7 @@ struct PlaylistVideo property index : Int64 property live_now : Bool - def to_xml(auto_generated, xml : XML::Builder) + def to_xml(xml : XML::Builder) xml.element("entry") do xml.element("id") { xml.text "yt:video:#{self.id}" } xml.element("yt:videoId") { xml.text self.id } @@ -20,13 +20,8 @@ struct PlaylistVideo xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?v=#{self.id}") xml.element("author") do - if auto_generated - xml.element("name") { xml.text self.author } - xml.element("uri") { xml.text "#{HOST_URL}/channel/#{self.ucid}" } - else - xml.element("name") { xml.text author } - xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" } - end + xml.element("name") { xml.text self.author } + xml.element("uri") { xml.text "#{HOST_URL}/channel/#{self.ucid}" } end xml.element("content", type: "xhtml") do @@ -47,17 +42,11 @@ struct PlaylistVideo end end - def to_xml(auto_generated, xml : XML::Builder? = nil) - if xml - to_xml(auto_generated, xml) - else - XML.build do |xml| - to_xml(auto_generated, xml) - end - end + def to_xml(_xml : Nil = nil) + XML.build { |xml| to_xml(xml) } end - def to_json(locale, json : JSON::Builder, index : Int32?) + def to_json(json : JSON::Builder, index : Int32? = nil) json.object do json.field "title", self.title json.field "videoId", self.id @@ -81,14 +70,8 @@ struct PlaylistVideo end end - def to_json(locale, json : JSON::Builder? = nil, index : Int32? = nil) - if json - to_json(locale, json, index: index) - else - JSON.build do |json| - to_json(locale, json, index: index) - end - end + def to_json(_json : Nil, index : Int32? = nil) + JSON.build { |json| to_json(json, index: index) } end end @@ -144,7 +127,7 @@ struct Playlist json.array do videos = get_playlist_videos(PG_DB, self, offset: offset, locale: locale, video_id: video_id) videos.each do |video| - video.to_json(locale, json) + video.to_json(json) end end end @@ -224,7 +207,7 @@ struct InvidiousPlaylist videos = get_playlist_videos(PG_DB, self, offset: offset, locale: locale, video_id: video_id) videos.each_with_index do |video, index| - video.to_json(locale, json, offset + index) + video.to_json(json, offset + index) end end end diff --git a/src/invidious/routes/api/v1/authenticated.cr b/src/invidious/routes/api/v1/authenticated.cr index 7950b302..cdd9e2f6 100644 --- a/src/invidious/routes/api/v1/authenticated.cr +++ b/src/invidious/routes/api/v1/authenticated.cr @@ -274,7 +274,10 @@ module Invidious::Routes::API::V1::Authenticated env.response.headers["Location"] = "#{HOST_URL}/api/v1/auth/playlists/#{plid}/videos/#{playlist_video.index.to_u64.to_s(16).upcase}" env.response.status_code = 201 - playlist_video.to_json(locale, index: playlist.index.size) + + JSON.build do |json| + playlist_video.to_json(json, index: playlist.index.size) + end end def self.delete_video_in_playlist(env) diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.cr index d483bca6..1edee29c 100644 --- a/src/invidious/routes/api/v1/videos.cr +++ b/src/invidious/routes/api/v1/videos.cr @@ -16,7 +16,7 @@ module Invidious::Routes::API::V1::Videos return error_json(500, ex) end - video.to_json(locale) + video.to_json(locale, nil) end def self.captions(env) diff --git a/src/invidious/routes/feeds.cr b/src/invidious/routes/feeds.cr index 40c41dc1..f4a8467b 100644 --- a/src/invidious/routes/feeds.cr +++ b/src/invidious/routes/feeds.cr @@ -281,9 +281,7 @@ module Invidious::Routes::Feeds xml.element("name") { xml.text playlist.author } end - videos.each do |video| - video.to_xml(false, xml) - end + videos.each &.to_xml(xml) end end else diff --git a/src/invidious/routes/images.cr b/src/invidious/routes/images.cr index bb924cdf..594a7869 100644 --- a/src/invidious/routes/images.cr +++ b/src/invidious/routes/images.cr @@ -3,31 +3,61 @@ module Invidious::Routes::Images def self.ggpht(env) url = env.request.path.lchop("/ggpht") - headers = HTTP::Headers{":authority" => "yt3.ggpht.com"} + headers = ( + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + HTTP::Headers{":authority" => "yt3.ggpht.com"} + else + HTTP::Headers.new + end + {% else %} + HTTP::Headers.new + {% end %} + ) + REQUEST_HEADERS_WHITELIST.each do |header| if env.request.headers[header]? headers[header] = env.request.headers[header] end end - begin - YT_POOL.client &.get(url, headers) do |response| - env.response.status_code = response.status_code - response.headers.each do |key, value| - if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) - env.response.headers[key] = value - end + # We're encapsulating this into a proc in order to easily reuse this + # portion of the code for each request block below. + request_proc = ->(response : HTTP::Client::Response) { + env.response.status_code = response.status_code + response.headers.each do |key, value| + if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) + env.response.headers[key] = value end + end - env.response.headers["Access-Control-Allow-Origin"] = "*" - - if response.status_code >= 300 - env.response.headers.delete("Transfer-Encoding") - break - end + env.response.headers["Access-Control-Allow-Origin"] = "*" - proxy_file(response, env) + if response.status_code >= 300 + env.response.headers.delete("Transfer-Encoding") + return end + + proxy_file(response, env) + } + + begin + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + YT_POOL.client &.get(url, headers) do |resp| + return request_proc.call(resp) + end + else + HTTP::Client.get("https://yt3.ggpht.com#{url}") do |resp| + return request_proc.call(resp) + end + end + {% else %} + # This can likely be optimized into a (small) pool sometime in the future. + HTTP::Client.get("https://yt3.ggpht.com#{url}") do |resp| + return request_proc.call(resp) + end + {% end %} rescue ex end end @@ -48,7 +78,9 @@ module Invidious::Routes::Images headers = HTTP::Headers.new - headers[":authority"] = "#{authority}.ytimg.com" + {% unless flag?(:disable_quic) %} + headers[":authority"] = "#{authority}.ytimg.com" + {% end %} REQUEST_HEADERS_WHITELIST.each do |header| if env.request.headers[header]? @@ -56,25 +88,41 @@ module Invidious::Routes::Images end end - begin - YT_POOL.client &.get(url, headers) do |response| - env.response.status_code = response.status_code - response.headers.each do |key, value| - if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) - env.response.headers[key] = value - end + request_proc = ->(response : HTTP::Client::Response) { + env.response.status_code = response.status_code + response.headers.each do |key, value| + if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) + env.response.headers[key] = value end + end - env.response.headers["Connection"] = "close" - env.response.headers["Access-Control-Allow-Origin"] = "*" - - if response.status_code >= 300 - env.response.headers.delete("Transfer-Encoding") - break - end + env.response.headers["Connection"] = "close" + env.response.headers["Access-Control-Allow-Origin"] = "*" - proxy_file(response, env) + if response.status_code >= 300 + return env.response.headers.delete("Transfer-Encoding") end + + proxy_file(response, env) + } + + begin + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + YT_POOL.client &.get(url, headers) do |resp| + return request_proc.call(resp) + end + else + HTTP::Client.get("https://#{authority}.ytimg.com#{url}") do |resp| + return request_proc.call(resp) + end + end + {% else %} + # This can likely be optimized into a (small) pool sometime in the future. + HTTP::Client.get("https://#{authority}.ytimg.com#{url}") do |resp| + return request_proc.call(resp) + end + {% end %} rescue ex end end @@ -83,34 +131,60 @@ module Invidious::Routes::Images def self.s_p_image(env) id = env.params.url["id"] name = env.params.url["name"] - url = env.request.resource - headers = HTTP::Headers{":authority" => "i9.ytimg.com"} + headers = ( + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + HTTP::Headers{":authority" => "i9.ytimg.com"} + else + HTTP::Headers.new + end + {% else %} + HTTP::Headers.new + {% end %} + ) + REQUEST_HEADERS_WHITELIST.each do |header| if env.request.headers[header]? headers[header] = env.request.headers[header] end end - begin - YT_POOL.client &.get(url, headers) do |response| - env.response.status_code = response.status_code - response.headers.each do |key, value| - if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) - env.response.headers[key] = value - end + request_proc = ->(response : HTTP::Client::Response) { + env.response.status_code = response.status_code + response.headers.each do |key, value| + if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) + env.response.headers[key] = value end + end - env.response.headers["Access-Control-Allow-Origin"] = "*" - - if response.status_code >= 300 && response.status_code != 404 - env.response.headers.delete("Transfer-Encoding") - break - end + env.response.headers["Access-Control-Allow-Origin"] = "*" - proxy_file(response, env) + if response.status_code >= 300 && response.status_code != 404 + return env.response.headers.delete("Transfer-Encoding") end + + proxy_file(response, env) + } + + begin + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + YT_POOL.client &.get(url, headers) do |resp| + return request_proc.call(resp) + end + else + HTTP::Client.get("https://i9.ytimg.com#{url}") do |resp| + return request_proc.call(resp) + end + end + {% else %} + # This can likely be optimized into a (small) pool sometime in the future. + HTTP::Client.get("https://i9.ytimg.com#{url}") do |resp| + return request_proc.call(resp) + end + {% end %} rescue ex end end @@ -149,16 +223,44 @@ module Invidious::Routes::Images id = env.params.url["id"] name = env.params.url["name"] - headers = HTTP::Headers{":authority" => "i.ytimg.com"} + headers = ( + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + HTTP::Headers{":authority" => "i.ytimg.com"} + else + HTTP::Headers.new + end + {% else %} + HTTP::Headers.new + {% end %} + ) if name == "maxres.jpg" build_thumbnails(id).each do |thumb| - if YT_POOL.client &.head("/vi/#{id}/#{thumb[:url]}.jpg", headers).status_code == 200 - name = thumb[:url] + ".jpg" - break - end + thumbnail_resource_path = "/vi/#{id}/#{thumb[:url]}.jpg" + # Logic here is short enough that manually typing them out should be fine. + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + if YT_POOL.client &.head(thumbnail_resource_path, headers).status_code == 200 + name = thumb[:url] + ".jpg" + break + end + else + if HTTP::Client.head("https://i.ytimg.com#{thumbnail_resource_path}").status_code == 200 + name = thumb[:url] + ".jpg" + break + end + end + {% else %} + # This can likely be optimized into a (small) pool sometime in the future. + if HTTP::Client.head("https://i.ytimg.com#{thumbnail_resource_path}").status_code == 200 + name = thumb[:url] + ".jpg" + break + end + {% end %} end end + url = "/vi/#{id}/#{name}" REQUEST_HEADERS_WHITELIST.each do |header| @@ -167,24 +269,40 @@ module Invidious::Routes::Images end end - begin - YT_POOL.client &.get(url, headers) do |response| - env.response.status_code = response.status_code - response.headers.each do |key, value| - if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) - env.response.headers[key] = value - end + request_proc = ->(response : HTTP::Client::Response) { + env.response.status_code = response.status_code + response.headers.each do |key, value| + if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) + env.response.headers[key] = value end + end - env.response.headers["Access-Control-Allow-Origin"] = "*" + env.response.headers["Access-Control-Allow-Origin"] = "*" - if response.status_code >= 300 && response.status_code != 404 - env.response.headers.delete("Transfer-Encoding") - break - end - - proxy_file(response, env) + if response.status_code >= 300 && response.status_code != 404 + return env.response.headers.delete("Transfer-Encoding") end + + proxy_file(response, env) + } + + begin + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + YT_POOL.client &.get(url, headers) do |resp| + return request_proc.call(resp) + end + else + HTTP::Client.get("https://i.ytimg.com#{url}") do |resp| + return request_proc.call(resp) + end + end + {% else %} + # This can likely be optimized into a (small) pool sometime in the future. + HTTP::Client.get("https://i.ytimg.com#{url}") do |resp| + return request_proc.call(resp) + end + {% end %} rescue ex end end diff --git a/src/invidious/routes/login.cr b/src/invidious/routes/login.cr index b719b571..562d88e5 100644 --- a/src/invidious/routes/login.cr +++ b/src/invidious/routes/login.cr @@ -53,7 +53,13 @@ module Invidious::Routes::Login # See https://github.com/ytdl-org/youtube-dl/blob/2019.04.07/youtube_dl/extractor/youtube.py#L82 begin - client = QUIC::Client.new(LOGIN_URL) + client = nil # Declare variable + {% unless flag?(:disable_quic) %} + client = CONFIG.use_quic ? QUIC::Client.new(LOGIN_URL) : HTTP::Client.new(LOGIN_URL) + {% else %} + client = HTTP::Client.new(LOGIN_URL) + {% end %} + headers = HTTP::Headers.new login_page = client.get("/ServiceLogin") diff --git a/src/invidious/routes/misc.cr b/src/invidious/routes/misc.cr index 0e6356d0..3ea4c272 100644 --- a/src/invidious/routes/misc.cr +++ b/src/invidious/routes/misc.cr @@ -40,11 +40,6 @@ module Invidious::Routes::Misc def self.cross_instance_redirect(env) referer = get_referer(env) - - if !env.get("preferences").as(Preferences).automatic_instance_redirect - return env.redirect("https://redirect.invidious.io#{referer}") - end - instance_url = fetch_random_instance env.redirect "https://#{instance_url}#{referer}" end diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index d38a66d8..d3e5800c 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -275,7 +275,7 @@ struct Video end end - def to_json(locale : Hash(String, JSON::Any), json : JSON::Builder) + def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) json.object do json.field "type", "video" @@ -474,14 +474,13 @@ struct Video end end - def to_json(locale, json : JSON::Builder | Nil = nil) - if json - to_json(locale, json) - else - JSON.build do |json| - to_json(locale, json) - end - end + # TODO: remove the locale and follow the crystal convention + def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) + JSON.build { |json| to_json(locale, json) } + end + + def to_json(json : JSON::Builder | Nil = nil) + to_json(nil, json) end def title diff --git a/src/invidious/views/channel.ecr b/src/invidious/views/channel.ecr index 7f797e37..40b553a9 100644 --- a/src/invidious/views/channel.ecr +++ b/src/invidious/views/channel.ecr @@ -45,7 +45,11 @@ <div class="pure-u-1-3"> <a href="https://www.youtube.com/channel/<%= ucid %>"><%= translate(locale, "View channel on YouTube") %></a> <div class="pure-u-1 pure-md-1-3"> - <a href="/redirect?referer=<%= env.get?("current_page") %>"><%= translate(locale, "Switch Invidious Instance") %></a> + <% if env.get("preferences").as(Preferences).automatic_instance_redirect%> + <a href="/redirect?referer=<%= env.get?("current_page") %>"><%= translate(locale, "Switch Invidious Instance") %></a> + <% else %> + <a href="https://redirect.invidious.io<%= env.request.path %>"><%= translate(locale, "Switch Invidious Instance") %></a> + <% end %> </div> <% if !channel.auto_generated %> <div class="pure-u-1 pure-md-1-3"> diff --git a/src/invidious/views/community.ecr b/src/invidious/views/community.ecr index 15d8ed1e..f0add06b 100644 --- a/src/invidious/views/community.ecr +++ b/src/invidious/views/community.ecr @@ -44,7 +44,11 @@ <div class="pure-u-1-3"> <a href="https://www.youtube.com/channel/<%= channel.ucid %>/community"><%= translate(locale, "View channel on YouTube") %></a> <div class="pure-u-1 pure-md-1-3"> - <a href="/redirect?referer=<%= env.get?("current_page") %>"><%= translate(locale, "Switch Invidious Instance") %></a> + <% if env.get("preferences").as(Preferences).automatic_instance_redirect%> + <a href="/redirect?referer=<%= env.get?("current_page") %>"><%= translate(locale, "Switch Invidious Instance") %></a> + <% else %> + <a href="https://redirect.invidious.io<%= env.request.resource %>"><%= translate(locale, "Switch Invidious Instance") %></a> + <% end %> </div> <% if !channel.auto_generated %> <div class="pure-u-1 pure-md-1-3"> diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr index 5788bf51..a58571aa 100644 --- a/src/invidious/views/components/item.ecr +++ b/src/invidious/views/components/item.ecr @@ -79,19 +79,8 @@ <div class="flex-left"><a href="/channel/<%= item.ucid %>"> <p class="channel-name" dir="auto"><%= HTML.escape(item.author) %></p> </a></div> - <div class="flex-right"> - <div class="icon-buttons"> - <a title="<%=translate(locale, "Watch on YouTube")%>" href="https://www.youtube.com/watch?v=<%= item.id %>&list=<%= item.plid %>"> - <i class="icon ion-logo-youtube"></i> - </a> - <a title="<%=translate(locale, "Audio mode")%>" href="/watch?v=<%= item.id %>&list=<%= item.plid %>&listen=1"> - <i class="icon ion-md-headset"></i> - </a> - <a title="<%=translate(locale, "Switch Invidious Instance")%>" href="/redirect?referer=<%=URI.encode_www_form("watch?v=#{item.id}&list=#{item.plid}")%>"> - <i class="icon ion-md-jet"></i> - </a> - </div> - </div> + <% endpoint_params = "?v=#{item.id}&list=#{item.plid}" %> + <%= rendered "components/video-context-buttons" %> </div> <div class="video-card-row flexible"> @@ -155,19 +144,9 @@ <div class="flex-left"><a href="/channel/<%= item.ucid %>"> <p class="channel-name" dir="auto"><%= HTML.escape(item.author) %></p> </a></div> - <div class="flex-right"> - <div class="icon-buttons"> - <a title="<%=translate(locale, "Watch on YouTube")%>" href="https://www.youtube.com/watch?v=<%= item.id %>"> - <i class="icon ion-logo-youtube"></i> - </a> - <a title="<%=translate(locale, "Audio mode")%>" href="/watch?v=<%= item.id %>&listen=1"> - <i class="icon ion-md-headset"></i> - </a> - <a title="<%=translate(locale, "Switch Invidious Instance")%>" href="/redirect?referer=<%=URI.encode_www_form("watch?v=#{item.id}")%>"> - <i class="icon ion-md-jet"></i> - </a> - </div> - </div> + + <% endpoint_params = "?v=#{item.id}" %> + <%= rendered "components/video-context-buttons" %> </div> <div class="video-card-row flexible"> diff --git a/src/invidious/views/components/video-context-buttons.ecr b/src/invidious/views/components/video-context-buttons.ecr new file mode 100644 index 00000000..daa107f0 --- /dev/null +++ b/src/invidious/views/components/video-context-buttons.ecr @@ -0,0 +1,21 @@ +<div class="flex-right"> + <div class="icon-buttons"> + <a title="<%=translate(locale, "Watch on YouTube")%>" href="https://www.youtube.com/watch<%=endpoint_params%>"> + <i class="icon ion-logo-youtube"></i> + </a> + <a title="<%=translate(locale, "Audio mode")%>" href="/watch<%=endpoint_params%>&listen=1"> + <i class="icon ion-md-headset"></i> + </a> + + <% if env.get("preferences").as(Preferences).automatic_instance_redirect%> + <a title="<%=translate(locale, "Switch Invidious Instance")%>" href="/redirect?referer=%2Fwatch<%=URI.encode_www_form(endpoint_params)%>"> + <i class="icon ion-md-jet"></i> + </a> + <% else %> + <a title="<%=translate(locale, "Switch Invidious Instance")%>" href="https://redirect.invidious.io/watch<%=endpoint_params%>"> + <i class="icon ion-md-jet"></i> + </a> + <% end %> + + </div> +</div>
\ No newline at end of file diff --git a/src/invidious/views/playlist.ecr b/src/invidious/views/playlist.ecr index 12f93a72..d0518de7 100644 --- a/src/invidious/views/playlist.ecr +++ b/src/invidious/views/playlist.ecr @@ -41,9 +41,16 @@ <%= translate(locale, "View playlist on YouTube") %> </a> <span> | </span> - <a href="/redirect?referer=<%= env.get?("current_page") %>"> - <%= translate(locale, "Switch Invidious Instance") %> - </a> + + <% if env.get("preferences").as(Preferences).automatic_instance_redirect%> + <a href="/redirect?referer=<%= env.get?("current_page") %>"> + <%= translate(locale, "Switch Invidious Instance") %> + </a> + <% else %> + <a href="https://redirect.invidious.io<%= env.request.resource %>"> + <%= translate(locale, "Switch Invidious Instance") %> + </a> + <% end %> </div> <% end %> </div> diff --git a/src/invidious/views/playlists.ecr b/src/invidious/views/playlists.ecr index 1245256f..12dba088 100644 --- a/src/invidious/views/playlists.ecr +++ b/src/invidious/views/playlists.ecr @@ -47,7 +47,11 @@ </div> <div class="pure-u-1 pure-md-1-3"> - <a href="/redirect?referer=<%= env.get?("current_page") %>"><%= translate(locale, "Switch Invidious Instance") %></a> + <% if env.get("preferences").as(Preferences).automatic_instance_redirect%> + <a href="/redirect?referer=<%= env.get?("current_page") %>"><%= translate(locale, "Switch Invidious Instance") %></a> + <% else %> + <a href="https://redirect.invidious.io<%= env.request.resource %>"><%= translate(locale, "Switch Invidious Instance") %></a> + <% end %> </div> <div class="pure-u-1 pure-md-1-3"> diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index cad36e73..9cf00393 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -11,7 +11,7 @@ <meta property="og:url" content="<%= HOST_URL %>/watch?v=<%= video.id %>"> <meta property="og:title" content="<%= title %>"> <meta property="og:image" content="/vi/<%= video.id %>/maxres.jpg"> -<meta property="og:description" content="<%= video.short_description %>"> +<meta property="og:description" content="<%= HTML.escape(video.short_description) %>"> <meta property="og:type" content="video.other"> <meta property="og:video:url" content="<%= HOST_URL %>/embed/<%= video.id %>"> <meta property="og:video:secure_url" content="<%= HOST_URL %>/embed/<%= video.id %>"> @@ -22,7 +22,7 @@ <meta name="twitter:site" content="@omarroth1"> <meta name="twitter:url" content="<%= HOST_URL %>/watch?v=<%= video.id %>"> <meta name="twitter:title" content="<%= title %>"> -<meta name="twitter:description" content="<%= video.short_description %>"> +<meta name="twitter:description" content="<%= HTML.escape(video.short_description) %>"> <meta name="twitter:image" content="<%= HOST_URL %>/vi/<%= video.id %>/maxres.jpg"> <meta name="twitter:player" content="<%= HOST_URL %>/embed/<%= video.id %>"> <meta name="twitter:player:width" content="1280"> @@ -116,7 +116,11 @@ we're going to need to do it here in order to allow for translations. (<a href="https://www.youtube.com/embed/<%= video.id %>"><%= translate(locale, "Embed") %></a>) </span> <p id="watch-on-another-invidious-instance"> + <% if env.get("preferences").as(Preferences).automatic_instance_redirect%> <a href="/redirect?referer=<%= env.get?("current_page") %>"><%= translate(locale, "Switch Invidious Instance") %></a> + <% else %> + <a href="https://redirect.invidious.io<%= env.request.resource %>"><%= translate(locale, "Switch Invidious Instance") %></a> + <% end %> </p> <p id="embed-link"> <a href="<%= embed_link %>"><%= translate(locale, "Embed Link") %></a> diff --git a/src/invidious/yt_backend/connection_pool.cr b/src/invidious/yt_backend/connection_pool.cr index 5ba2d73c..3feb9233 100644 --- a/src/invidious/yt_backend/connection_pool.cr +++ b/src/invidious/yt_backend/connection_pool.cr @@ -1,4 +1,10 @@ -require "lsquic" +{% unless flag?(:disable_quic) %} + require "lsquic" + + alias HTTPClientType = QUIC::Client | HTTP::Client +{% else %} + alias HTTPClientType = HTTP::Client +{% end %} def add_yt_headers(request) request.headers["user-agent"] ||= "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36" @@ -19,7 +25,7 @@ struct YoutubeConnectionPool property! url : URI property! capacity : Int32 property! timeout : Float64 - property pool : DB::Pool(QUIC::Client | HTTP::Client) + property pool : DB::Pool(HTTPClientType) def initialize(url : URI, @capacity = 5, @timeout = 5.0, use_quic = true) @url = url @@ -36,7 +42,12 @@ struct YoutubeConnectionPool response = yield conn rescue ex conn.close - conn = QUIC::Client.new(url) + {% unless flag?(:disable_quic) %} + conn = CONFIG.use_quic ? QUIC::Client.new(url) : HTTP::Client.new(url) + {% else %} + conn = HTTP::Client.new(url) + {% end %} + conn.family = (url.host == "www.youtube.com") ? CONFIG.force_resolve : Socket::Family::INET conn.family = Socket::Family::INET if conn.family == Socket::Family::UNSPEC conn.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com" @@ -50,12 +61,18 @@ struct YoutubeConnectionPool end private def build_pool(use_quic) - DB::Pool(QUIC::Client | HTTP::Client).new(initial_pool_size: 0, max_pool_size: capacity, max_idle_pool_size: capacity, checkout_timeout: timeout) do - if use_quic - conn = QUIC::Client.new(url) - else + DB::Pool(HTTPClientType).new(initial_pool_size: 0, max_pool_size: capacity, max_idle_pool_size: capacity, checkout_timeout: timeout) do + conn = nil # Declare + {% unless flag?(:disable_quic) %} + if use_quic + conn = QUIC::Client.new(url) + else + conn = HTTP::Client.new(url) + end + {% else %} conn = HTTP::Client.new(url) - end + {% end %} + conn.family = (url.host == "www.youtube.com") ? CONFIG.force_resolve : Socket::Family::INET conn.family = Socket::Family::INET if conn.family == Socket::Family::UNSPEC conn.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com" diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr index 8ab2fe46..27f25036 100644 --- a/src/invidious/yt_backend/youtube_api.cr +++ b/src/invidious/yt_backend/youtube_api.cr @@ -404,10 +404,19 @@ module YoutubeAPI url = "#{endpoint}?key=#{client_config.api_key}" headers = HTTP::Headers{ - "Content-Type" => "application/json; charset=UTF-8", - "Accept-Encoding" => "gzip", + "Content-Type" => "application/json; charset=UTF-8", } + # The normal HTTP client automatically applies accept-encoding: gzip, + # and decompresses. However, explicitly applying it will remove this functionality. + # + # https://github.com/crystal-lang/crystal/issues/11252#issuecomment-929594741 + {% unless flag?(:disable_quic) %} + if CONFIG.use_quic + headers["Accept-Encoding"] = "gzip" + end + {% end %} + # Logging LOGGER.debug("YoutubeAPI: Using endpoint: \"#{endpoint}\"") LOGGER.trace("YoutubeAPI: ClientConfig: #{client_config}") |
