2424
2525from collections import OrderedDict
2626from functools import lru_cache
27- import pdfutils as pdfutils
28- import gdrive_base as gdrive_base
29- from strutils import thumbnail_path_for_file
27+ import pdfutils
28+ import videoutils
29+ import gdrive_base
30+ from strutils import thumbnail_path_for_file , THUMBNAIL_SIZES
3031
3132
3233class ThumbnailWorker (QRunnable ):
@@ -35,6 +36,7 @@ def __init__(self, item, cancel_flag, emit_callback):
3536 self .item = item
3637 self .cancel_flag = cancel_flag
3738 self .emit_callback = emit_callback
39+ self .size = 'normal'
3840
3941 def is_cancelled (self ):
4042 return self .cancel_flag [0 ]
@@ -55,19 +57,24 @@ def _process_item(self, item):
5557 cache_path = gcache .get_cache_path_for_file (item )
5658 if not cache_path :
5759 return
58- thumb_path = thumbnail_path_for_file (cache_path , shared = True , size = 'normal' )
60+ size = THUMBNAIL_SIZES [self .size ]
61+ thumb_path = thumbnail_path_for_file (cache_path , shared = True , size = self .size )
5962 if thumb_path .exists ():
6063 img = QImage (str (thumb_path ))
6164 elif cache_path .exists ():
6265 if self .is_cancelled (): return
6366 if mime == 'application/pdf' :
64- thumbnail_bytes = pdfutils .get_cached_pdf_thumbnail (cache_path , size = 'normal' )
67+ thumbnail_bytes = pdfutils .get_cached_pdf_thumbnail (cache_path , size = self .size )
68+ img = QImage ()
69+ img .loadFromData (thumbnail_bytes )
70+ elif mime .startswith ('video/' ):
71+ thumbnail_bytes = videoutils .get_cached_video_thumbnail (cache_path , size = self .size )
6572 img = QImage ()
6673 img .loadFromData (thumbnail_bytes )
6774 else :
68- if mime == 'application/pdf' :
75+ if mime == 'application/pdf' or mime . startswith ( 'video/' ) :
6976 if self .is_cancelled (): return
70- thumbnail_bytes = gdrive_base .fetch_preview_image (file_id , size = 128 )
77+ thumbnail_bytes = gdrive_base .fetch_preview_image (file_id , size = size )
7178 if thumbnail_bytes :
7279 img = QImage ()
7380 img .loadFromData (thumbnail_bytes )
@@ -374,7 +381,7 @@ def populate_files(self, items: List[Dict[str, Any]]):
374381 list_item .setIcon (QIcon (cached_pixmap ))
375382 else :
376383 list_item .setIcon (get_mime_icon (mime ))
377- if mime == 'application/pdf' :
384+ if mime == 'application/pdf' or mime . startswith ( 'video/' ) :
378385 items_needing_thumbnails .append (item )
379386
380387 list_item .setData (Qt .UserRole , item )
@@ -395,7 +402,7 @@ def update_visible_thumbnails(self):
395402 mime = file_data .get ('mimeType' , '' )
396403 file_id = file_data .get ('id' , '' )
397404
398- if mime == 'application/pdf' and file_id not in self .queued_thumbnails :
405+ if ( mime == 'application/pdf' or mime . startswith ( 'video/' )) and file_id not in self .queued_thumbnails :
399406 if not self .thumbnail_cache .get (file_id ):
400407 item_rect = self .file_view .visualItemRect (item )
401408 if expanded_rect .intersects (item_rect ):
0 commit comments