Mercurial > libervia-web
comparison libervia/pages/photos/album/_browser/__init__.py @ 1346:cda5537c71d6
browser (photos/album): videos integrations:
videos can now be added to an album, the alternative media player is then used to display
them. Slides options are used to remove pagination and slidebar from slideshow (they don't
play well with media player), and video are reset when its slide is exited.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 25 Aug 2020 08:31:56 +0200 |
parents | ce1217e3a9c0 |
children | 2c3bc7284992 |
comparison
equal
deleted
inserted
replaced
1345:ce1217e3a9c0 | 1346:cda5537c71d6 |
---|---|
3 from bridge import Bridge | 3 from bridge import Bridge |
4 from template import Template | 4 from template import Template |
5 import dialog | 5 import dialog |
6 from slideshow import SlideShow | 6 from slideshow import SlideShow |
7 from invitation import InvitationManager | 7 from invitation import InvitationManager |
8 import alt_media_player | |
8 | 9 |
9 cache_path = window.cache_path | 10 cache_path = window.cache_path |
10 files_service = window.files_service | 11 files_service = window.files_service |
11 files_path = window.files_path | 12 files_path = window.files_path |
12 try: | 13 try: |
13 affiliations = window.affiliations.to_dict() | 14 affiliations = window.affiliations.to_dict() |
14 except AttributeError: | 15 except AttributeError: |
15 pass | 16 pass |
16 bridge = Bridge() | 17 bridge = Bridge() |
18 | |
19 alt_media_player.install_if_needed() | |
20 | |
21 photo_tpl = Template('photo/item.html') | |
22 player_tpl = Template('components/media_player.html') | |
17 | 23 |
18 # file upload | 24 # file upload |
19 | 25 |
20 def on_progress(ev, photo_elt): | 26 def on_progress(ev, photo_elt): |
21 if ev.lengthComputable: | 27 if ev.lengthComputable: |
63 ) | 69 ) |
64 | 70 |
65 | 71 |
66 def upload_files(files): | 72 def upload_files(files): |
67 print(f"uploading {len(files)} files") | 73 print(f"uploading {len(files)} files") |
68 photo_tpl = Template('photo/item.html') | |
69 album_items = document['album_items'] | 74 album_items = document['album_items'] |
70 for file_ in files: | 75 for file_ in files: |
71 url = window.URL.createObjectURL(file_) | 76 url = window.URL.createObjectURL(file_) |
72 photo_elt = photo_tpl.get_elt({ | 77 photo_elt = photo_tpl.get_elt({ |
73 "file": { | 78 "file": { |
178 try: | 183 try: |
179 biggest_thumb = item['extra']['thumbnails'][-1] | 184 biggest_thumb = item['extra']['thumbnails'][-1] |
180 thumb_url = f"{cache_path}{biggest_thumb['filename']}" | 185 thumb_url = f"{cache_path}{biggest_thumb['filename']}" |
181 except (KeyError, IndexError) as e: | 186 except (KeyError, IndexError) as e: |
182 print(f"Can't get full screen thumbnail URL: {e}") | 187 print(f"Can't get full screen thumbnail URL: {e}") |
183 thumb_url = item['url'] | 188 thumb_url = None |
184 slideshow.add_slide(html.IMG(src=thumb_url, Class="slide_img"), item) | 189 if item.get("mime_type", "")[:5] == "video": |
190 player = alt_media_player.MediaPlayer( | |
191 [item['url']], | |
192 poster = thumb_url, | |
193 reduce_click_area = True | |
194 ) | |
195 elt = player.elt | |
196 elt.classList.add("slide_video", "no_fullscreen") | |
197 slideshow.add_slide( | |
198 elt, | |
199 item, | |
200 options={ | |
201 "flags": (alt_media_player.NO_PAGINATION, alt_media_player.NO_SCROLLBAR), | |
202 "exit_callback": player.reset, | |
203 } | |
204 ) | |
205 else: | |
206 slideshow.add_slide(html.IMG(src=thumb_url or item['url'], Class="slide_img"), item) | |
185 if item_elt == clicked_item_elt: | 207 if item_elt == clicked_item_elt: |
186 slideshow.index = idx | 208 slideshow.index = idx |
187 | 209 |
188 | 210 |
189 for elt in document.select('.action_delete'): | 211 for elt in document.select('.action_delete'): |