diff options
35 files changed, 557 insertions, 243 deletions
@@ -89,28 +89,28 @@ distclean: clean # ----------------------- help: - echo "Targets available in this Makefile:" - echo "" - echo "get-libs Fetch Crystal libraries" - echo "invidious Build Invidious" - echo "run Launch Invidious" - echo "" - echo "format Run the Crystal formatter" - echo "test Run tests" - echo "verify Just make sure that the code compiles, but without" - echo " generating any binaries. Useful to search for errors" - echo "" - echo "clean Remove build artifacts" - echo "distclean Remove build artifacts and libraries" - echo "" - echo "" - echo "Build options available for this Makefile:" - echo "" - echo "RELEASE Make a release build (Default: 1)" - echo "STATIC Link libraries statically (Default: 0)" - echo "" - echo "DISABLE_QUIC Disable support for QUIC (Default: 0)" - echo "NO_DBG_SYMBOLS Strip debug symbols (Default: 0)" + @echo "Targets available in this Makefile:" + @echo "" + @echo " get-libs Fetch Crystal libraries" + @echo " invidious Build Invidious" + @echo " run Launch Invidious" + @echo "" + @echo " format Run the Crystal formatter" + @echo " test Run tests" + @echo " verify Just make sure that the code compiles, but without" + @echo " generating any binaries. Useful to search for errors" + @echo "" + @echo " clean Remove build artifacts" + @echo " distclean Remove build artifacts and libraries" + @echo "" + @echo "" + @echo "Build options available for this Makefile:" + @echo "" + @echo " RELEASE Make a release build (Default: 1)" + @echo " STATIC Link libraries statically (Default: 0)" + @echo "" + @echo " DISABLE_QUIC Disable support for QUIC (Default: 0)" + @echo " NO_DBG_SYMBOLS Strip debug symbols (Default: 0)" @@ -51,8 +51,8 @@ <img alt="Mastodon: @invidious@social.tchncs.de" src="https://img.shields.io/badge/Mastodon-%40invidious%40social.tchncs.de-darkgreen"> </a> <br> - <a href="#contact-the-team-directly"> - <img alt="Contact the team directly" src="https://img.shields.io/badge/E%2d%2dmail-darkgreen"> + <a href="https://invidious.io/contact/"> + <img alt="E-mail" src="https://img.shields.io/badge/E%2d%2dmail-darkgreen"> </a> </div> @@ -152,19 +152,6 @@ Weblate also allows you to log-in with major SSO providers like Github, Gitlab, - [HoloPlay](https://github.com/stephane-r/HoloPlay): Funny Android application connecting on Invidious API's with search, playlists and favorites. -## Contact the team directly - -Every team member is available through GitHub or through the Matrix room (bridged to IRC), however, if you need/have to, you can contact the team directly via e-mail (remove `+SPAMGUARD` from the addresses): - -- General Inquiries (forwarded to all team members): `contact +SPAMGUARD [at] invidious [dot] io` - -Note: before sending a bug report please check that it hasn't already be reported on GitHub - bug reports sent to this address will be copied to GitHub - -- Security issues (forwarded to the two project owners, <a href="https://github.com/TheFrenchGhosty">@TheFrenchGhosty</a> and <a href="https://github.com/Perflyst">@Perflyst</a>): `security +SPAMGUARD [at] invidious [dot] io` - -Note: the creation of a PGP key for this address is planned - - ## Liability We take no responsibility for the use of our tool, or external instances diff --git a/assets/js/player.js b/assets/js/player.js index 81a27009..a1a2cd16 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -35,21 +35,11 @@ if (player_data.aspect_ratio) { var embed_url = new URL(location); embed_url.searchParams.delete('v'); -short_url = location.origin + '/' + video_data.id + embed_url.search; +var short_url = location.origin + '/' + video_data.id + embed_url.search; embed_url = location.origin + '/embed/' + video_data.id + embed_url.search; var save_player_pos_key = "save_player_pos"; -var shareOptions = { - socials: ['fbFeed', 'tw', 'reddit', 'email'], - - url: short_url, - title: player_data.title, - description: player_data.description, - image: player_data.thumbnail, - embedCode: "<iframe id='ivplayer' width='640' height='360' src='" + embed_url + "' style='border:none;'></iframe>" -} - videojs.Vhs.xhr.beforeRequest = function(options) { if (options.uri.indexOf('videoplayback') === -1 && options.uri.indexOf('local=true') === -1) { options.uri = options.uri + '?local=true'; @@ -59,6 +49,37 @@ videojs.Vhs.xhr.beforeRequest = function(options) { var player = videojs('player', options); +/** + * Function for add time argument to url + * @param {String} url + * @returns urlWithTimeArg + */ +function addCurrentTimeToURL(url) { + var urlUsed = new URL(url); + urlUsed.searchParams.delete('start'); + var currentTime = Math.ceil(player.currentTime()); + if (currentTime > 0) + urlUsed.searchParams.set('t', currentTime); + else if (urlUsed.searchParams.has('t')) + urlUsed.searchParams.delete('t'); + return urlUsed; +} + +var shareOptions = { + socials: ['fbFeed', 'tw', 'reddit', 'email'], + + get url() { + return addCurrentTimeToURL(short_url); + }, + title: player_data.title, + description: player_data.description, + image: player_data.thumbnail, + get embedCode() { + return "<iframe id='ivplayer' width='640' height='360' src='" + + addCurrentTimeToURL(embed_url) + "' style='border:none;'></iframe>"; + } +}; + const storage = (() => { try { if (localStorage.length !== -1) return localStorage; } catch (e) { console.info('No storage available: ' + e); } diff --git a/config/config.example.yml b/config/config.example.yml index 866e8944..ae9509d2 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -856,3 +856,13 @@ default_user_preferences: ## Default: false ## #automatic_instance_redirect: false + + ## + ## Show the entire video description by default (when set to 'false', + ## only the first few lines of the description are shown and a + ## "show more" button allows to expand it). + ## + ## Accepted values: true, false + ## Default: false + ## + #extend_desc: false diff --git a/docker-compose.yml b/docker-compose.yml index c76c314c..cd1df4ff 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,18 +1,12 @@ -version: '3' +# Warning: This docker-compose file is made for development purposes. +# Using it will build an image from the locally cloned repository. +# +# If you want to use Invidious in production, see the docker-compose.yml file provided +# in the installation documentation: https://docs.invidious.io/Installation.md + +version: "3" services: - postgres: - image: postgres:10 - restart: unless-stopped - volumes: - - postgresdata:/var/lib/postgresql/data - - ./config/sql:/config/sql - - ./docker/init-invidious-db.sh:/docker-entrypoint-initdb.d/init-invidious-db.sh - environment: - POSTGRES_DB: invidious - POSTGRES_PASSWORD: kemal - POSTGRES_USER: kemal - healthcheck: - test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] + invidious: build: context: . @@ -21,27 +15,42 @@ services: ports: - "127.0.0.1:3000:3000" environment: - # Adapted from ./config/config.yml + # Please read the following file for a comprehensive list of all available + # configuration options and their associated syntax: + # https://github.com/iv-org/invidious/blob/master/config/config.example.yml INVIDIOUS_CONFIG: | - channel_threads: 1 - check_tables: true - feed_threads: 1 db: + dbname: invidious user: kemal password: kemal - host: postgres + host: invidious-db port: 5432 - dbname: invidious - full_refresh: false - https_only: false - domain: + check_tables: true + # external_port: + # domain: + # https_only: false + # statistics_enabled: false healthcheck: test: wget -nv --tries=1 --spider http://127.0.0.1:3000/api/v1/comments/jNQXAC9IVRw || exit 1 interval: 30s timeout: 5s retries: 2 depends_on: - - postgres + - invidious-db + + invidious-db: + image: docker.io/library/postgres:14 + restart: unless-stopped + volumes: + - postgresdata:/var/lib/postgresql/data + - ./config/sql:/config/sql + - ./docker/init-invidious-db.sh:/docker-entrypoint-initdb.d/init-invidious-db.sh + environment: + POSTGRES_DB: invidious + POSTGRES_USER: kemal + POSTGRES_PASSWORD: kemal + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] volumes: postgresdata: diff --git a/locales/el.json b/locales/el.json index b33fc02f..36fc695b 100644 --- a/locales/el.json +++ b/locales/el.json @@ -21,15 +21,15 @@ "No": "Όχι", "Import and Export Data": "Εισαγωγή και Εξαγωγή Δεδομένων", "Import": "Εισαγωγή", - "Import Invidious data": "Εισαγωγή δεδομένων Invidious", - "Import YouTube subscriptions": "Εισαγωγή συνδρομών YouTube", + "Import Invidious data": "Εsαγωγή δεδομένων Invidious JSON", + "Import YouTube subscriptions": "Εισαγωγή συνδρομών YouTube/OPML", "Import FreeTube subscriptions (.db)": "Εισαγωγή συνδρομών FreeTube (.db)", "Import NewPipe subscriptions (.json)": "Εισαγωγή συνδρομών NewPipe (.json)", "Import NewPipe data (.zip)": "Εισαγωγή δεδομένων NewPipe (.zip)", "Export": "Εξαγωγή", "Export subscriptions as OPML": "Εξαγωγή συνδρομών ως OPML", "Export subscriptions as OPML (for NewPipe & FreeTube)": "Εξαγωγή συνδρομών ως OPML (για NewPipe & FreeTube)", - "Export data as JSON": "Εξαγωγή δεδομένων ως JSON", + "Export data as JSON": "Εξαγωγή δεδομένων Invidious ως JSON", "Delete account?": "Διαγραφή λογαριασμού;", "History": "Ιστορικό", "An alternative front-end to YouTube": "Μία εναλλακτική πλατφόρμα για το YouTube", @@ -419,7 +419,34 @@ "Search": "Αναζήτηση", "hdr": "HDR", "preferences_extend_desc_label": "Αυτόματη επέκταση της περιγραφής του βίντεο: ", - "preferences_vr_mode_label": "Διαδραστικά βίντεο 360 μοιρών: ", + "preferences_vr_mode_label": "Διαδραστικά βίντεο 360 μοιρών (απαιτεί WebGL): ", "Show less": "Εμφάνιση λιγότερων", - "footer_source_code": "Πηγαίος κώδικας" + "footer_source_code": "Πηγαίος κώδικας", + "Chinese (Taiwan)": "Κινέζικα (Ταϊβάν)", + "Portuguese (Brazil)": "Πορτογαλικά (Βραζιλία)", + "German (auto-generated)": "Γερμανικά (αυτόματη παραγωγή)", + "Korean (auto-generated)": "Κορεάτικα (αυτόματη παραγωγή)", + "Russian (auto-generated)": "Ρωσικά (αυτόματη παραγωγή)", + "Spanish (auto-generated)": "Ισπανικά (αυτόματη παραγωγή)", + "Vietnamese (auto-generated)": "Βιετναμέζικα (αυτόματη παραγωγή)", + "English (United Kingdom)": "Αγγλικά (Ηνωμένο Βασίλειο)", + "English (United States)": "Αγγλικά (Ηνωμένων Πολιτειών)", + "Cantonese (Hong Kong)": "Καντονέζικα (Χονγκ Κονγκ)", + "Chinese": "Κινεζικά", + "Chinese (China)": "Κινέζικα (Κίνα)", + "Chinese (Hong Kong)": "Κινεζικά (Χονγκ Κονγκ)", + "Dutch (auto-generated)": "Ολαμδικά (αυτόματη παραγωγή)", + "French (auto-generated)": "Γαλλικά (αυτόματη παραγωγή)", + "Interlingue": "Ιντερλίνγκουα", + "Indonesian (auto-generated)": "Ινδονησιακά (αυτόματη παραγωγή)", + "Italian (auto-generated)": "Ιταλικά (αυτόματη παραγωγή)", + "Japanese (auto-generated)": "Ιαπωνικά (αυτόματη παραγωγή)", + "Portuguese (auto-generated)": "Πορτογαλικά (αυτόματη παραγωγή)", + "Spanish (Mexico)": "Ισπανικά (Μεξικό)", + "Spanish (Spain)": "Ισπανικά (Ισπανία)", + "Turkish (auto-generated)": "Τούρκικα (αυτόματη παραγωγή)", + "none": "κανένα", + "videoinfo_youTube_embed_link": "Ενσωμάτωση", + "videoinfo_invidious_embed_link": "Σύνδεσμος Ενσωμάτωσης", + "show": "Μπάρα προόδου διαβάσματος" } diff --git a/locales/en-US.json b/locales/en-US.json index c924c8aa..1335d384 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -65,6 +65,7 @@ "preferences_continue_autoplay_label": "Autoplay next video: ", "preferences_listen_label": "Listen by default: ", "preferences_local_label": "Proxy videos: ", + "preferences_watch_history_label": "Enable watch history: ", "preferences_speed_label": "Default speed: ", "preferences_quality_label": "Preferred video quality: ", "preferences_quality_option_dash": "DASH (adaptative quality)", diff --git a/locales/es.json b/locales/es.json index 24f8dbdf..fbdb13ac 100644 --- a/locales/es.json +++ b/locales/es.json @@ -458,5 +458,6 @@ "Chinese (China)": "Chino (China)", "Korean (auto-generated)": "Coreano (generados automáticamente)", "Spanish (Mexico)": "Español (Méjico)", - "Spanish (auto-generated)": "Español (generados automáticamente)" + "Spanish (auto-generated)": "Español (generados automáticamente)", + "preferences_watch_history_label": "Habilitar historial de reproducciones: " } diff --git a/locales/fr.json b/locales/fr.json index b9732345..96103580 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -31,15 +31,15 @@ "No": "Non", "Import and Export Data": "Importer et exporter des données", "Import": "Importer", - "Import Invidious data": "Importer des données Invidious", - "Import YouTube subscriptions": "Importer des abonnements YouTube", + "Import Invidious data": "Importer des données Invidious au format JSON", + "Import YouTube subscriptions": "Importer des abonnements YouTube/OPML", "Import FreeTube subscriptions (.db)": "Importer des abonnements FreeTube (.db)", "Import NewPipe subscriptions (.json)": "Importer des abonnements NewPipe (.json)", "Import NewPipe data (.zip)": "Importer des données NewPipe (.zip)", "Export": "Exporter", "Export subscriptions as OPML": "Exporter les abonnements au format OPML", "Export subscriptions as OPML (for NewPipe & FreeTube)": "Exporter les abonnements au format OPML (pour NewPipe & FreeTube)", - "Export data as JSON": "Exporter les données au format JSON", + "Export data as JSON": "Exporter les données Invidious au format JSON", "Delete account?": "Êtes-vous sûr de vouloir supprimer votre compte ?", "History": "Historique", "An alternative front-end to YouTube": "Un front-end alternatif à YouTube", @@ -460,5 +460,6 @@ "Italian (auto-generated)": "Italien (auto-généré)", "Vietnamese (auto-generated)": "Vietnamien (auto-généré)", "Russian (auto-generated)": "Russe (auto-généré)", - "Spanish (Spain)": "Espagnol (Espagne)" + "Spanish (Spain)": "Espagnol (Espagne)", + "preferences_watch_history_label": "Activer l'historique de visionnage : " } diff --git a/locales/hr.json b/locales/hr.json index 2f5d3bcf..1de3fa79 100644 --- a/locales/hr.json +++ b/locales/hr.json @@ -21,15 +21,15 @@ "No": "Ne", "Import and Export Data": "Uvezi i izvezi podatke", "Import": "Uvezi", - "Import Invidious data": "Uvezi Invidious podatke", - "Import YouTube subscriptions": "Uvezi YouTube pretplate", + "Import Invidious data": "Uvezi Invidious JSON podatke", + "Import YouTube subscriptions": "Uvezi YouTube/OPML pretplate", "Import FreeTube subscriptions (.db)": "Uvezi FreeTube pretplate (.db)", "Import NewPipe subscriptions (.json)": "Uvezi NewPipe pretplate (.json)", "Import NewPipe data (.zip)": "Uvezi NewPipe podatke (.zip)", "Export": "Izvezi", "Export subscriptions as OPML": "Izvezi pretplate kao OPML", "Export subscriptions as OPML (for NewPipe & FreeTube)": "Izvezi pretplate kao OPML (za NewPipe i FreeTube)", - "Export data as JSON": "Izvezi podatke kao JSON", + "Export data as JSON": "Izvezi Invidious podatke kao JSON", "Delete account?": "Izbrisati račun?", "History": "Povijest", "An alternative front-end to YouTube": "Alternativa za YouTube", @@ -66,7 +66,7 @@ "preferences_related_videos_label": "Prikaži povezana videa: ", "preferences_annotations_label": "Standardno prikaži napomene: ", "preferences_extend_desc_label": "Automatski proširi opis videa: ", - "preferences_vr_mode_label": "Interaktivna videa od 360 stupnjeva: ", + "preferences_vr_mode_label": "Interaktivna videa od 360 stupnjeva (zahtijeva WebGL): ", "preferences_category_visual": "Postavke prikaza", "preferences_player_style_label": "Stil playera: ", "Dark mode: ": "Tamni modus: ", @@ -453,5 +453,28 @@ "crash_page_switch_instance": "pokušaj <a href=\"`x`\">koristiti jednu drugu instancu</a>", "crash_page_read_the_faq": "pročitaj <a href=\"`x`\">Često postavljena pitanja (ČPP)</a>", "crash_page_search_issue": "pretraži <a href=\"`x`\">postojeće probleme na Github-u</a>", - "crash_page_report_issue": "Ako ništa od gore navedenog ne pomaže, <a href=\"`x`\">prijavi novi problem na GitHub-u</a> (po mogućnosti na engleskom) i uključi sljedeći tekst u poruku (NEMOJ prevoditi taj tekst):" + "crash_page_report_issue": "Ako ništa od gore navedenog ne pomaže, <a href=\"`x`\">prijavi novi problem na GitHub-u</a> (po mogućnosti na engleskom) i uključi sljedeći tekst u poruku (NEMOJ prevoditi taj tekst):", + "English (United Kingdom)": "Engleski (Ujedinjeno Kraljevstvo)", + "English (United States)": "Engleski (Sjedinjene Američke Države)", + "Cantonese (Hong Kong)": "Kantonski (Hong Kong)", + "Chinese": "Kineski", + "Chinese (Taiwan)": "Kineski (Tajvan)", + "Dutch (auto-generated)": "Nizozemski (automatski generiran)", + "French (auto-generated)": "Francuski (automatski generiran)", + "Indonesian (auto-generated)": "Indonezijski (automatski generiran)", + "Interlingue": "Interlingua", + "Japanese (auto-generated)": "Japanski (automatski generiran)", + "Russian (auto-generated)": "Ruski (automatski generiran)", + "Turkish (auto-generated)": "Turski (automatski generiran)", + "Vietnamese (auto-generated)": "Vijetnamski (automatski generiran)", + "Spanish (Spain)": "Španjolski (Španjolska)", + "Italian (auto-generated)": "Talijanski (automatski generiran)", + "Portuguese (Brazil)": "Portugalski (Brazil)", + "Spanish (Mexico)": "Španjolski (Meksiko)", + "German (auto-generated)": "Njemački (automatski generiran)", + "Chinese (China)": "Kineski (Kina)", + "Chinese (Hong Kong)": "Kineski (Hong Kong)", + "Korean (auto-generated)": "Korejski (automatski generiran)", + "Portuguese (auto-generated)": "Portugalski (automatski generiran)", + "Spanish (auto-generated)": "Španjolski (automatski generiran)" } diff --git a/locales/is.json b/locales/is.json index 9258154e..99bd6574 100644 --- a/locales/is.json +++ b/locales/is.json @@ -318,5 +318,6 @@ "Videos": "Myndbönd", "Playlists": "Spilunarlistar", "Community": "Samfélag", - "Current version: ": "Núverandi útgáfa: " + "Current version: ": "Núverandi útgáfa: ", + "preferences_watch_history_label": "Virkja áhorfssögu: " } diff --git a/locales/pl.json b/locales/pl.json index 5c4667f0..0f4e0927 100644 --- a/locales/pl.json +++ b/locales/pl.json @@ -21,15 +21,15 @@ "No": "Nie", "Import and Export Data": "Import i eksport danych", "Import": "Import", - "Import Invidious data": "Importuj dane Invidious", - "Import YouTube subscriptions": "Importuj subskrybcje z YouTube", + "Import Invidious data": "Importuj dane JSON Invidious", + "Import YouTube subscriptions": "Importuj subskrybcje z YouTube/OPML", "Import FreeTube subscriptions (.db)": "Importuj subskrybcje z FreeTube (.db)", "Import NewPipe subscriptions (.json)": "Importuj subskrybcje z NewPipe (.json)", "Import NewPipe data (.zip)": "Importuj dane NewPipe (.zip)", "Export": "Eksport", "Export subscriptions as OPML": "Eksportuj subskrybcje jako OPML", "Export subscriptions as OPML (for NewPipe & FreeTube)": "Eksportuj subskrybcje jako OPML (dla NewPipe i FreeTube)", - "Export data as JSON": "Eksportuj dane jako JSON", + "Export data as JSON": "Eksportuj dane Invidious jako JSON", "Delete account?": "Usunąć konto?", "History": "Historia", "An alternative front-end to YouTube": "Alternatywny front-end dla YouTube", @@ -66,7 +66,7 @@ "preferences_related_videos_label": "Pokaż powiązane filmy? ", "preferences_annotations_label": "Domyślnie pokazuj adnotacje: ", "preferences_extend_desc_label": "Automatycznie rozwijaj opisy filmów: ", - "preferences_vr_mode_label": "Interaktywne filmy 360 stopni: ", + "preferences_vr_mode_label": "Interaktywne filmy 360 stopni (wymaga WebGL): ", "preferences_category_visual": "Preferencje Wizualne", "preferences_player_style_label": "Styl odtwarzacza: ", "Dark mode: ": "Ciemny motyw: ", @@ -446,12 +446,35 @@ "Video unavailable": "Film niedostępny", "preferences_save_player_pos_label": "Zapisz pozycję odtwarzania: ", "preferences_region_label": "Region zawartości: ", - "Released under the AGPLv3 on Github.": "Wydane na licencji AGPLv3 na Github'ie.", + "Released under the AGPLv3 on Github.": "Wydany na licencji AGPLv3 na Github.", "short": "Krótkie (< 4 minutes)", "long": "Długie (> 20 minutes)", "footer_documentation": "Dokumentacja", "footer_source_code": "Kod źródłowy", "footer_modfied_source_code": "Zmodyfikowany Kod źródłowy", "footer_original_source_code": "Oryginalny kod źródłowy", - "adminprefs_modified_source_code_url_label": "Adres URL do repozytorium z zmodyfikowanym kodem źródłowym" + "adminprefs_modified_source_code_url_label": "Adres URL do repozytorium z zmodyfikowanym kodem źródłowym", + "English (United Kingdom)": "angielski (Wielka Brytania)", + "English (United States)": "angielski (Stany Zjednoczone)", + "Cantonese (Hong Kong)": "kantoński (Hong Kong)", + "Chinese": "chiński", + "Chinese (China)": "chiński (Chiny)", + "Chinese (Hong Kong)": "chiński (Hong Kong)", + "Chinese (Taiwan)": "chiński (Tajwan)", + "Dutch (auto-generated)": "niderlandzki (wygenerowany automatycznie)", + "French (auto-generated)": "francuski (wygenerowany automatycznie)", + "German (auto-generated)": "niemiecki (wygenerowany automatycznie)", + "Indonesian (auto-generated)": "indonezyjski (wygenerowany automatycznie)", + "Interlingue": "interlingue", + "Italian (auto-generated)": "włoski (wygenerowany automatycznie)", + "Korean (auto-generated)": "koreański (wygenerowany automatycznie)", + "Spanish (auto-generated)": "hiszpański (wygenerowany automatycznie)", + "Spanish (Mexico)": "hiszpański (Meksyk)", + "Spanish (Spain)": "hiszpański (Hiszpania)", + "Turkish (auto-generated)": "turecki (wygenerowany automatycznie)", + "Vietnamese (auto-generated)": "wietnamski (wygenerowany automatycznie)", + "Japanese (auto-generated)": "japoński (wygenerowany automatycznie)", + "Russian (auto-generated)": "rosyjski (wygenerowany automatycznie)", + "Portuguese (auto-generated)": "portugalski (wygenerowany automatycznie)", + "Portuguese (Brazil)": "portugalski (Brazylia)" } diff --git a/locales/ru.json b/locales/ru.json index 6d370b80..88f81395 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -374,7 +374,7 @@ "German (auto-generated)": "Немецкий (автоматический)", "Indonesian (auto-generated)": "Индонезийский (автоматический)", "Italian (auto-generated)": "Итальянский (автоматический)", - "Interlingue": "Интерлингва", + "Interlingue": "Окциденталь", "Russian (auto-generated)": "Русский (автоматический)", "Spanish (auto-generated)": "Испанский (автоматический)", "Spanish (Spain)": "Испанский (Испания)", diff --git a/locales/sq.json b/locales/sq.json index 6b3b8daa..3e2a3fb1 100644 --- a/locales/sq.json +++ b/locales/sq.json @@ -379,5 +379,74 @@ "footer_donate_page": "Dhuroni", "footer_documentation": "Dokumentim", "footer_source_code": "Kod burim", - "footer_original_source_code": "Kodim burim origjinal" + "footer_original_source_code": "Kodim burim origjinal", + "generic_count_hours": "{{count}} orë", + "generic_count_hours_plural": "{{count}} orë", + "generic_videos_count": "{{count}} video", + "generic_videos_count_plural": "{{count}} video", + "generic_playlists_count": "{{count}} luajlistë", + "generic_playlists_count_plural": "{{count}} luajlista", + "generic_subscribers_count": "{{count}} pajtimtar", + "generic_subscribers_count_plural": "{{count}} pajtimtarë", + "subscriptions_unseen_notifs_count": "{{count}} njoftim që s’është parë", + "subscriptions_unseen_notifs_count_plural": "{{count}} njoftime që s’janë parë", + "comments_view_x_replies": "Shihni {{count}} përgjigje", + "comments_view_x_replies_plural": "Shihni {{count}} përgjigje", + "comments_points_count": "{{count}} pikë", + "comments_points_count_plural": "{{count}} pikë", + "generic_count_years": "{{count}} vit", + "generic_count_years_plural": "{{count}} vjet", + "generic_count_months": "{{count}} muaj", + "generic_count_months_plural": "{{count}} muaj", + "generic_count_weeks": "{{count}} javë", + "generic_count_weeks_plural": "{{count}} javë", + "generic_count_days": "{{count}} ditë", + "generic_count_days_plural": "{{count}} ditë", + "generic_count_minutes": "{{count}} minutë", + "generic_count_minutes_plural": "{{count}} minuta", + "generic_count_seconds": "{{count}} sekondë", + "generic_count_seconds_plural": "{{count}} sekonda", + "crash_page_you_found_a_bug": "Duket sikur gjetët një të metë në Invidious!", + "crash_page_before_reporting": "Para se të njoftoni një të metë, sigurohuni se keni:", + "crash_page_refresh": "provuar të <a href=\"`x`\">rifreskoni faqen</a>", + "crash_page_switch_instance": "provuar të <a href=\"`x`\">përdorni tjetër instancë</a>", + "crash_page_read_the_faq": "lexuar <a href=\"`x`\">Pyetje të Bëra Rëndom (PBR)</a>", + "generic_views_count": "{{count}} parje", + "generic_views_count_plural": "{{count}} parje", + "English (United Kingdom)": "Anglisht (Mbretëri e Bashkuar)", + "English (United States)": "Anglisht (Shtetet e Bashkuara)", + "Cantonese (Hong Kong)": "Kantoneze (Hong Kong)", + "Chinese": "Kinezçe", + "Chinese (China)": "Kinezçe (Kinë)", + "Chinese (Hong Kong)": "Kinezçe (Hong-Kong)", + "Chinese (Taiwan)": "Kinezçe (Tajvan)", + "Dutch (auto-generated)": "Holandisht (e prodhuar automatikisht)", + "French (auto-generated)": "Anglisht (të prodhuara automatikisht)", + "German (auto-generated)": "Gjermanisht (të prodhuara automatikisht)", + "Hmong": "Hmong", + "Indonesian (auto-generated)": "Indonezisht (të prodhuara automatikisht)", + "Interlingue": "Interlingue", + "Italian (auto-generated)": "Italisht (të prodhuara automatikisht)", + "Japanese (auto-generated)": "Japonisht (të prodhuara automatikisht)", + "Korean (auto-generated)": "Koreane (të prodhuara automatikisht)", + "Portuguese (auto-generated)": "Portugalisht (të prodhuara automatikisht)", + "Portuguese (Brazil)": "Portugeze (Brazil)", + "Russian (auto-generated)": "Rusisht (të prodhuara automatikisht)", + "Spanish (auto-generated)": "Spanjisht (të prodhuara automatikisht)", + "Spanish (Mexico)": "Spanjisht (Meksikë)", + "Spanish (Spain)": "Spanjisht (Spanjë)", + "Turkish (auto-generated)": "Turqisht (të prodhuara automatikisht)", + "Vietnamese (auto-generated)": "Vietnamisht (të prodhuara automatikisht)", + "crash_page_search_issue": "kërkuar për <a href=\"`x`\">çështje ekzistuese në Github</a>", + "crash_page_report_issue": "Nëse asnjë nga sa më sipër s’ndihmoi, ju lutemi, <a href=\"`x`\">hapni një çështje në GitHub</a> (mundësisht në anglisht) dhe përfshini në mesazhin tuaj tekstin vijues (MOS e përktheni këtë tekst):", + "generic_subscriptions_count": "{{count}} pajtim", + "generic_subscriptions_count_plural": "{{count}} pajtime", + "tokens_count": "{{count}} token", + "tokens_count_plural": "{{count}} tokenë", + "preferences_save_player_pos_label": "Mba mend pozicionin e luajtjes: ", + "Import Invidious data": "Importoni të dhëna JSON Invidious", + "Import YouTube subscriptions": "Importoni pajtime YouTube/OPML", + "Export data as JSON": "Eksportoji të dhënat Invidious si JSON", + "preferences_vr_mode_label": "Video me ndërveprim 360 gradë (lyp WebGL): ", + "Shared `x`": "Ndau me të tjerë `x`" } diff --git a/locales/tr.json b/locales/tr.json index 65648fd7..094728fa 100644 --- a/locales/tr.json +++ b/locales/tr.json @@ -460,5 +460,6 @@ "German (auto-generated)": "Almanca (otomatik oluşturuldu)", "Portuguese (auto-generated)": "Portekizce (otomatik oluşturuldu)", "Spanish (Spain)": "İspanyolca (İspanya)", - "Vietnamese (auto-generated)": "Vietnamca (otomatik oluşturuldu)" + "Vietnamese (auto-generated)": "Vietnamca (otomatik oluşturuldu)", + "preferences_watch_history_label": "İzleme geçmişini etkinleştir: " } diff --git a/locales/zh-CN.json b/locales/zh-CN.json index f21fe8da..4b760dd3 100644 --- a/locales/zh-CN.json +++ b/locales/zh-CN.json @@ -444,5 +444,6 @@ "Dutch (auto-generated)": "荷兰语 (自动生成)", "French (auto-generated)": "法语 (自动生成)", "Turkish (auto-generated)": "土耳其语 (自动生成)", - "Spanish (Spain)": "西班牙语 (西班牙)" + "Spanish (Spain)": "西班牙语 (西班牙)", + "preferences_watch_history_label": "启用观看历史: " } diff --git a/locales/zh-TW.json b/locales/zh-TW.json index 2fdb2036..84bd1dae 100644 --- a/locales/zh-TW.json +++ b/locales/zh-TW.json @@ -444,5 +444,6 @@ "Indonesian (auto-generated)": "印尼語(自動產生)", "Portuguese (Brazil)": "葡萄牙語(巴西)", "Japanese (auto-generated)": "日語(自動產生)", - "Portuguese (auto-generated)": "葡萄牙語(自動產生)" + "Portuguese (auto-generated)": "葡萄牙語(自動產生)", + "preferences_watch_history_label": "啟用觀看紀錄: " } 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> |
