From b51fd7fc1325ed0008c5aa7043585013ef62c86a Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sun, 14 Apr 2019 17:43:44 -0500 Subject: [PATCH] Add view count to video items --- locales/ar.json | 2 +- locales/de.json | 2 +- locales/en-US.json | 6 +++--- locales/es.json | 2 +- locales/eu.json | 2 +- locales/fr.json | 2 +- locales/it.json | 2 +- locales/nb_NO.json | 2 +- locales/nl.json | 2 +- locales/pl.json | 2 +- locales/ru.json | 2 +- src/invidious/helpers/utils.cr | 4 +++- src/invidious/views/components/item.ecr | 14 ++++++++++++-- 13 files changed, 28 insertions(+), 16 deletions(-) diff --git a/locales/ar.json b/locales/ar.json index e41ab16f9..907479822 100644 --- a/locales/ar.json +++ b/locales/ar.json @@ -5,7 +5,6 @@ "Shared `x` ago": "تم رفع الفيديو منذ `x`", "Unsubscribe": "إلغاء الإشتراك", "Subscribe": "إشتراك", - "View channel on YouTube": "زيارة القناة على موقع يوتيوب", "newest": "الأجدد", "oldest": "الأقدم", @@ -115,6 +114,7 @@ "Whitelisted regions: ": "الدول المسموح فيها هذا الفيديو: ", "Blacklisted regions: ": "الدول الحظور فيها هذا الفيديو: ", "Shared `x`": "شارك منذ `x`", + "`x` views": "", "Premieres in `x`": "يعرض فى 'x'", "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.": "اهلا! يبدو ان الجافاسكريبت معطلة. اضغط هنا لعرض التعليقات, ضع فى إعتبارك انها ستأخذ وقت اطول للعرض.", "View YouTube comments": "عرض تعليقات اليوتيوب", diff --git a/locales/de.json b/locales/de.json index 6b3609e03..275e44e33 100644 --- a/locales/de.json +++ b/locales/de.json @@ -5,7 +5,6 @@ "Shared `x` ago": "Vor `x` geteilt", "Unsubscribe": "Abbestellen", "Subscribe": "Abonnieren", - "View channel on YouTube": "Kanal auf YouTube anzeigen", "newest": "neueste", "oldest": "älteste", @@ -115,6 +114,7 @@ "Whitelisted regions: ": "Erlaubte Regionen: ", "Blacklisted regions: ": "Unerlaubte Regionen: ", "Shared `x`": "Geteilt `x`", + "`x` views": "", "Premieres in `x`": "", "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.": "Hallo! Anscheinend haben Sie JavaScript deaktiviert. Klicken Sie hier um Kommentare anzuzeigen, beachten sie dass es etwas länger dauern kann um sie zu laden.", "View YouTube comments": "YouTube Kommentare anzeigen", diff --git a/locales/en-US.json b/locales/en-US.json index 95012c364..7f5e3d3ba 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -5,7 +5,6 @@ "Shared `x` ago": "Shared `x` ago", "Unsubscribe": "Unsubscribe", "Subscribe": "Subscribe", - "View channel on YouTube": "View channel on YouTube", "newest": "newest", "oldest": "oldest", @@ -103,7 +102,7 @@ "View JavaScript license information.": "View JavaScript license information.", "View privacy policy.": "View privacy policy.", "Trending": "Trending", - "Unlisted": "", + "Unlisted": "Unlisted", "Watch video on Youtube": "Watch video on Youtube", "Genre: ": "Genre: ", "License: ": "License: ", @@ -113,7 +112,8 @@ "Whitelisted regions: ": "Whitelisted regions: ", "Blacklisted regions: ": "Blacklisted regions: ", "Shared `x`": "Shared `x`", - "Premieres in `x`": "", + "`x` views": "", + "Premieres in `x`": "Premieres in `x`", "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.": "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.", "View YouTube comments": "View YouTube comments", "View more comments on Reddit": "View more comments on Reddit", diff --git a/locales/es.json b/locales/es.json index 7ad32336a..6c9cc7d58 100644 --- a/locales/es.json +++ b/locales/es.json @@ -5,7 +5,6 @@ "Shared `x` ago": "Compartido hace `x`", "Unsubscribe": "Desuscribirse", "Subscribe": "Suscribirse", - "View channel on YouTube": "Ver el canal en YouTube", "newest": "más nuevos", "oldest": "más viejos", @@ -113,6 +112,7 @@ "Whitelisted regions: ": "Regiones permitidas: ", "Blacklisted regions: ": "Regiones bloqueadas: ", "Shared `x`": "Compartido `x`", + "`x` views": "", "Premieres in `x`": "", "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.": "¡Hola! Parece que tiene JavaScript desactivado. Haga clic aquí para ver los comentarios, pero tenga en cuenta que pueden tardar un poco más en cargarse.", "View YouTube comments": "Ver los comentarios de YouTube", diff --git a/locales/eu.json b/locales/eu.json index 28dabd1af..5f9d5c09a 100644 --- a/locales/eu.json +++ b/locales/eu.json @@ -5,7 +5,6 @@ "Shared `x` ago": "Duela `x` partekatua", "Unsubscribe": "Harpidetza kendu", "Subscribe": "Harpidetu", - "View channel on YouTube": "Ikusi kanala YouTuben", "newest": "berrienak", "oldest": "zaharrenak", @@ -113,6 +112,7 @@ "Whitelisted regions: ": "", "Blacklisted regions: ": "", "Shared `x`": "", + "`x` views": "", "Premieres in `x`": "", "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.": "", "View YouTube comments": "", diff --git a/locales/fr.json b/locales/fr.json index 6bbc6ff8f..162ebe389 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -5,7 +5,6 @@ "Shared `x` ago": "Ajoutée il y a `x`", "Unsubscribe": "Se désabonner", "Subscribe": "S'abonner", - "View channel on YouTube": "Voir la chaîne sur YouTube", "newest": "Date d'ajout (la plus récente)", "oldest": "Date d'ajout (la plus ancienne)", @@ -113,6 +112,7 @@ "Whitelisted regions: ": "Régions en liste blanche : ", "Blacklisted regions: ": "Régions sur liste noire : ", "Shared `x`": "Ajoutée le `x`", + "`x` views": "", "Premieres in `x`": "Première dans `x`", "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.": "Il semblerait que JavaScript soit désactivé. Cliquez ici pour voir les commentaires sans. Gardez à l'esprit que le chargement peut prendre plus de temps.", "View YouTube comments": "Voir les commentaires YouTube", diff --git a/locales/it.json b/locales/it.json index c6706d6b2..d67df287e 100644 --- a/locales/it.json +++ b/locales/it.json @@ -5,7 +5,6 @@ "Shared `x` ago": "Condiviso `x` fa", "Unsubscribe": "Disiscriviti", "Subscribe": "Iscriviti", - "View channel on YouTube": "Vedi canale su YouTube", "newest": "Data di aggiunta (più recente)", "oldest": "Data di aggiunta (più vecchia)", @@ -113,6 +112,7 @@ "Whitelisted regions: ": "Regioni nella lista bianca: ", "Blacklisted regions: ": "Regioni nella lista nera: ", "Shared `x`": "Condiviso `x`", + "`x` views": "", "Premieres in `x`": "", "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.": "Ciao! Sembra che tu abbia disattivato JavaScript. Clicca qui per visualizzare i commenti. Considera che potrebbe volerci più tempo.", "View YouTube comments": "Visualizza i commenti da YouTube", diff --git a/locales/nb_NO.json b/locales/nb_NO.json index 9078bffdf..926f3f91a 100644 --- a/locales/nb_NO.json +++ b/locales/nb_NO.json @@ -5,7 +5,6 @@ "Shared `x` ago": "Delt for `x` siden", "Unsubscribe": "Opphev abonnement", "Subscribe": "Abonner", - "View channel on YouTube": "Vis kanal på YouTube", "newest": "nyeste", "oldest": "eldste", @@ -113,6 +112,7 @@ "Whitelisted regions: ": "Hvitlistede regioner: ", "Blacklisted regions: ": "Svartelistede regioner: ", "Shared `x`": "Delt `x`", + "`x` views": "", "Premieres in `x`": "Premiere om `x`", "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.": "Hei. Det ser ut til at du har JavaScript avslått. Klikk her for å vise kommentarer, ha i minnet at innlasting tar lengre tid.", "View YouTube comments": "Vis YouTube-kommentarer", diff --git a/locales/nl.json b/locales/nl.json index 8e0dd3de3..4129f378f 100644 --- a/locales/nl.json +++ b/locales/nl.json @@ -5,7 +5,6 @@ "Shared `x` ago": "Gedeeld `x` geleden", "Unsubscribe": "Abonnement opzeggen", "Subscribe": "Abonneren", - "View channel on YouTube": "Bekijk kanaal op Youtube", "newest": "nieuwste", "oldest": "oudste", @@ -113,6 +112,7 @@ "Whitelisted regions: ": "Toegestane regio's: ", "Blacklisted regions: ": "Geblokkeerde regio's: ", "Shared `x`": "`x` gedeeld", + "`x` views": "", "Premieres in `x`": "", "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.": "Hoi! Het lijkt erop dat je JavaScript uit hebt staan. Klik hier om de reacties te bekijken, hou er rekening mee dat het wat langer duurt om te laden.", "View YouTube comments": "Bekijk YouTube reacties", diff --git a/locales/pl.json b/locales/pl.json index 4fa8d5d76..ee8832591 100644 --- a/locales/pl.json +++ b/locales/pl.json @@ -5,7 +5,6 @@ "Shared `x` ago": "Udostępniono `x` temu", "Unsubscribe": "Odsubskrybuj", "Subscribe": "Subskrybuj", - "View channel on YouTube": "Wyświetl kanał na YouTube", "newest": "najnowsze", "oldest": "najstarsze", @@ -113,6 +112,7 @@ "Whitelisted regions: ": "Dostępny na obszarach: ", "Blacklisted regions: ": "Niedostępny na obszarach: ", "Shared `x`": "Udostępniono `x`", + "`x` views": "", "Premieres in `x`": "", "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.": "Cześć! Wygląda na to, że masz wyłączoną obsługę JavaScriptu. Kliknij tutaj, żeby zobaczyć komentarze. Pamiętaj, że wczytywanie może potrwać dłużej.", "View YouTube comments": "Wyświetl komentarze z YouTube", diff --git a/locales/ru.json b/locales/ru.json index ce2355d7a..811c01de1 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -5,7 +5,6 @@ "Shared `x` ago": "Опубликовано `x` назад", "Unsubscribe": "Отписаться", "Subscribe": "Подписаться", - "View channel on YouTube": "Канал на YouTube", "newest": "новые", "oldest": "старые", @@ -115,6 +114,7 @@ "Whitelisted regions: ": "Доступно для: ", "Blacklisted regions: ": "Недоступно для: ", "Shared `x`": "Опубликовано `x`", + "`x` views": "", "Premieres in `x`": "Премьера через `x`", "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.": "Похоже, что у Вас отключен JavaScript. Нажмите сюда, чтобы увидеть комментарии (учтите, что они могут загружаться дольше).", "View YouTube comments": "Смотреть комментарии с YouTube", diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index eb8fa80a7..eb304d8d9 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -189,7 +189,9 @@ def number_to_short_text(number) text = text.rchop(".0") - if number / 1000000 != 0 + if number / 1_000_000_000 != 0 + text += "B" + elsif number / 1_000_000 != 0 text += "M" elsif number / 1000 != 0 text += "K" diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr index e2a5195cd..2dc0bea46 100644 --- a/src/invidious/views/components/item.ecr +++ b/src/invidious/views/components/item.ecr @@ -71,7 +71,12 @@ <% if item.responds_to?(:premiere_timestamp) && item.premiere_timestamp && item.premiere_timestamp.not_nil! > Time.now %>
<%= translate(locale, "Premieres in `x`", recode_date((item.premiere_timestamp.as(Time) - Time.now).ago, locale)) %>
<% elsif Time.now - item.published > 1.minute %> -
<%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %>
+
+
<%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %>
+
+ <%= item.responds_to?(:views) ? translate(locale, "`x` views", number_to_short_text(item.views)) : "" %> +
+
<% end %> <% else %> <% if env.get("preferences").as(Preferences).thin_mode %> @@ -108,7 +113,12 @@ <% if item.responds_to?(:premiere_timestamp) && item.premiere_timestamp && item.premiere_timestamp.not_nil! > Time.now %>
<%= translate(locale, "Premieres in `x`", recode_date((item.premiere_timestamp.as(Time) - Time.now).ago, locale)) %>
<% elsif Time.now - item.published > 1.minute %> -
<%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %>
+
+
<%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %>
+
+ <%= item.responds_to?(:views) ? translate(locale, "`x` views", number_to_short_text(item.views)) : "" %> +
+
<% end %> <% end %>