Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0264.py @ 3329:15612c0fb421
plugin XEP-0264: updated size to get values closest to standard one:
- sizes used for thumbnails are now matching common resolutions.
- added BIG and FULL_SCREEN sizes
- sort thumbnails by sizes when parsing them.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 13 Aug 2020 23:45:59 +0200 |
parents | 5887fb414758 |
children | 7b47f48d31f3 |
comparison
equal
deleted
inserted
replaced
3328:d49607e3a066 | 3329:15612c0fb421 |
---|---|
68 C.PI_DESCRIPTION: _("""Thumbnails handling"""), | 68 C.PI_DESCRIPTION: _("""Thumbnails handling"""), |
69 } | 69 } |
70 | 70 |
71 | 71 |
72 class XEP_0264(object): | 72 class XEP_0264(object): |
73 SIZE_SMALL = (250, 250) | 73 SIZE_SMALL = (320, 320) |
74 SIZE_MEDIUM = (1024, 1024) | 74 SIZE_MEDIUM = (640, 640) |
75 SIZE_BIG = (1280, 1280) | |
76 SIZE_FULL_SCREEN = (2560, 2560) | |
77 SIZES = (SIZE_SMALL, SIZE_MEDIUM, SIZE_FULL_SCREEN) | |
75 | 78 |
76 def __init__(self, host): | 79 def __init__(self, host): |
77 log.info(_("Plugin XEP_0264 initialization")) | 80 log.info(_("Plugin XEP_0264 initialization")) |
78 self.host = host | 81 self.host = host |
79 host.trigger.add("XEP-0234_buildFileElement", self._addFileThumbnails) | 82 host.trigger.add("XEP-0234_buildFileElement", self._addFileThumbnails) |
106 thumbnail = {"id": uri[4:]} | 109 thumbnail = {"id": uri[4:]} |
107 width = thumbnail_elt.getAttribute("width") | 110 width = thumbnail_elt.getAttribute("width") |
108 height = thumbnail_elt.getAttribute("height") | 111 height = thumbnail_elt.getAttribute("height") |
109 if width and height: | 112 if width and height: |
110 try: | 113 try: |
111 thumbnail["size"] = int(width), int(height) | 114 thumbnail["size"] = (int(width), int(height)) |
112 except ValueError: | 115 except ValueError: |
113 pass | 116 pass |
114 try: | 117 try: |
115 thumbnail["mime_type"] = thumbnail_elt["media-type"] | 118 thumbnail["mime_type"] = thumbnail_elt["media-type"] |
116 except KeyError: | 119 except KeyError: |
117 pass | 120 pass |
118 thumbnails.append(thumbnail) | 121 thumbnails.append(thumbnail) |
119 | 122 |
120 if thumbnails: | 123 if thumbnails: |
124 # we want thumbnails ordered from smallest to biggest | |
125 thumbnails.sort(key=lambda t: t.get('size', (0, 0))) | |
121 file_data.setdefault("extra", {})[C.KEY_THUMBNAILS] = thumbnails | 126 file_data.setdefault("extra", {})[C.KEY_THUMBNAILS] = thumbnails |
122 return True | 127 return True |
123 | 128 |
124 ## thumbnails generation ## | 129 ## thumbnails generation ## |
125 | 130 |