From 13186dc697de71c3ee7be5068650946fadc3bbea Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 27 Apr 2021 20:24:24 +0000 Subject: [PATCH] Improve the settings layout and translation * Turn the name of the main category of the settings into a localized string * Add separators to group settings per theme * Make some settings name more explicit * Translate the possible values of the settings video_filter and video_sort_method See merge request StCyr/plugin.video.peertube!20 for more information --- README.md | 22 ++++++---- .../resource.language.en_gb/strings.po | 34 ++++++++++++-- .../resource.language.fr_fr/strings.po | 42 +++++++++++++++--- resources/lib/addon.py | 4 +- resources/lib/peertube.py | 44 ++++++++++++++----- resources/settings.xml | 18 ++++---- 6 files changed, 123 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 4f3fbf8..1eb474a 100644 --- a/README.md +++ b/README.md @@ -24,15 +24,19 @@ If you want to contribute, please start with the # User settings * Preferred PeerTube instance -* Preferred video resolution -* Number of items to display per page -* Value used to sort items when listing/searching videos: - * `views`: sort by number of views (ascending only) - * `likes`: sort by number of likes (ascending only) -* Select the filter to use when browsing the videos on an instance: - * local will only display the videos which are local to the selected instance - * all-local will only display the videos which are local to the selected - instance plus the private and unlisted videos **(requires admin privileges)** +* Browsing/Searching: + * Number of items to show per page (max 100) + * Field used to sort items when listing/searching videos: + * `views`: sort by number of views (ascending only) + * `likes`: sort by number of likes (ascending only) + * Select the filter to use when browsing and searching the videos on an instance: + * `local` will only display the videos which are local to the selected + instance + * `all-local` will only display the videos which are local to the selected + instance **plus** the private and unlisted videos + **(requires admin privileges)** +* Video playback: + * Preferred video resolution # API diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index e5fa4d9..11539f0 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -21,11 +21,11 @@ msgid "Preferred instance" msgstr "" msgctxt "#30001" -msgid "Number of videos to show per page" +msgid "Number of items to show per page" msgstr "" msgctxt "#30002" -msgid "Sort method to be used when listing videos" +msgid "Sort videos by" msgstr "" msgctxt "#30003" @@ -37,5 +37,33 @@ msgstr "" #msgstr "" msgctxt "#30005" -msgid "Filter local or all videos (for browsing only)" +msgid "List only videos with scope" +msgstr "" + +msgctxt "#30006" +msgid "General" +msgstr "" + +msgctxt "#30007" +msgid "Browsing/Searching" +msgstr "" + +msgctxt "#30008" +msgid "Video playback" +msgstr "" + +msgctxt "#30009" +msgid "local" +msgstr "" + +msgctxt "#30010" +msgid "all-local (admins only)" +msgstr "" + +msgctxt "#30011" +msgid "likes" +msgstr "" + +msgctxt "#30012" +msgid "views" msgstr "" diff --git a/resources/language/resource.language.fr_fr/strings.po b/resources/language/resource.language.fr_fr/strings.po index ecb2ec1..291fa87 100644 --- a/resources/language/resource.language.fr_fr/strings.po +++ b/resources/language/resource.language.fr_fr/strings.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Kodi Addons\n" "Report-Msgid-Bugs-To: https://framagit.org/StCyr/plugin.video.peertube\n" -"Last-Translator: DavidHenryThoreau\n" +"Last-Translator: Thomas B.\n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -21,12 +21,12 @@ msgid "Preferred instance" msgstr "Instance préférée" msgctxt "#30001" -msgid "Number of videos to show per page" -msgstr "Nombre de vidéos à afficher par page" +msgid "Number of items to show per page" +msgstr "Nombre d'éléments à afficher par page" msgctxt "#30002" -msgid "Sort method to be used when listing videos" -msgstr "Méthode de tri pour lister les vidéos" +msgid "Sort videos by" +msgstr "Trier les vidéos par" msgctxt "#30003" msgid "Preferred video resolution" @@ -37,5 +37,33 @@ msgstr "Résolution vidéo préférée" #msgstr "Supprimer les vidéos téléchargées à la fermeture de Kodi" msgctxt "#30005" -msgid "Filter local or all videos (for browsing only)" -msgstr "Filtre local ou toutes les vidéos (pour la navigation seulement)" +msgid "List only videos with scope" +msgstr "Afficher uniquement les vidéos de type" + +msgctxt "#30006" +msgid "General" +msgstr "Général" + +msgctxt "#30007" +msgid "Browsing/Searching" +msgstr "Navigation/Recherche" + +msgctxt "#30008" +msgid "Video playback" +msgstr "Lecture" + +msgctxt "#30009" +msgid "local" +msgstr "local" + +msgctxt "#30010" +msgid "all-local (admins only)" +msgstr "all-local (admins seulement)" + +msgctxt "#30011" +msgid "likes" +msgstr "nombre de j'aime" + +msgctxt "#30012" +msgid "views" +msgstr "nombre de vues" diff --git a/resources/lib/addon.py b/resources/lib/addon.py index ed71327..a3cefe9 100644 --- a/resources/lib/addon.py +++ b/resources/lib/addon.py @@ -49,9 +49,7 @@ class PeerTubeAddon(): # only by this object are directly retrieved from the settings self.peertube = PeerTube( instance=kodi.get_setting("preferred_instance"), - count=self.items_per_page, - sort=kodi.get_setting("video_sort_method"), - video_filter=kodi.get_setting("video_filter")) + count=self.items_per_page) def _browse_videos(self, start): """Display the list of all the videos published on a PeerTube instance diff --git a/resources/lib/peertube.py b/resources/lib/peertube.py index 5b4265d..af88411 100644 --- a/resources/lib/peertube.py +++ b/resources/lib/peertube.py @@ -17,27 +17,23 @@ from resources.lib.kodi_utils import kodi class PeerTube: """A class to interact easily with PeerTube instances using REST APIs""" - def __init__(self, instance, sort, count, video_filter): - """Constructor + def __init__(self, instance, count): + """Initialize the parameters that will be used in the requests + + Some values are retrieved directly from the settings, others come as + arguments because they are used somewhere else in the add-on. :param str instance: URL of the PeerTube instance - :param str sort: sort method to use when listing items :param int count: number of items to display - :param str video_filter: filter to apply when listing/searching videos """ self.set_instance(instance) self.list_settings = { - "sort": sort, + "sort": self._get_sort_method(), "count": count } - # The value "video_filter" is directly retrieved from the settings so - # it must be converted into one of the expected values by the REST APIs - if "all-local" in video_filter: - self.filter = "all-local" - else: - self.filter = "local" + self.filter = self._get_video_filter() def _request(self, method, url, params=None, data=None, instance=None): """Call a REST API on the instance @@ -117,6 +113,32 @@ class PeerTube: return params + def _get_video_filter(self): + """Get the video filter from the settings + + The value of the associated setting is localized so a list is used to + get the value expected by the API based on the index of the value used. + + :return: value of the video_filter setting + :rtype: str + """ + + filters = ["local", "all-local"] + return filters[int(kodi.get_setting("video_filter"))] + + def _get_sort_method(self): + """Get the sort method from the settings + + The value of the associated setting is localized so a list is used to + get the value expected by the API based on the index of the value used. + + :return: value of the video_sort_method setting + :rtype: str + """ + + sort_methods = ["likes", "views"] + return sort_methods[int(kodi.get_setting("video_sort_method"))] + def get_video_urls(self, video_id, instance=None): """Return the URLs of a video diff --git a/resources/settings.xml b/resources/settings.xml index 6b38426..65d978f 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -1,11 +1,13 @@ - - - - - - - - + + + + + + + + + +