@@ -53,28 +53,27 @@ def _process_item(self, item):
5353 try :
5454 from gdrive import gcache
5555 cache_path = gcache .get_cache_path_for_file (item )
56-
57- if self .is_cancelled (): return
58-
59- if cache_path and cache_path .exists ():
56+ if not cache_path :
57+ return
58+ thumb_path = thumbnail_path_for_file (cache_path , shared = True , size = 'normal' )
59+ if thumb_path .exists ():
60+ img = QImage (str (thumb_path ))
61+ elif cache_path .exists ():
62+ if self .is_cancelled (): return
6063 if mime == 'application/pdf' :
61- thumbnail_bytes = pdfutils .get_cached_pdf_thumbnail (cache_path , size = 'large ' )
64+ thumbnail_bytes = pdfutils .get_cached_pdf_thumbnail (cache_path , size = 'normal ' )
6265 img = QImage ()
6366 img .loadFromData (thumbnail_bytes )
6467 else :
65- thumb_path = thumbnail_path_for_file (f"gdrive_{ file_id } " , size = 'large' )
66- if thumb_path .exists ():
67- img = QImage (str (thumb_path ))
68- else :
69- if mime == 'application/pdf' :
70- if self .is_cancelled (): return
71- thumbnail_bytes = gdrive_base .fetch_preview_image (file_id , size = 256 )
72- if thumbnail_bytes :
73- if self .is_cancelled (): return
74- img = QImage ()
75- img .loadFromData (thumbnail_bytes )
76- thumb_path .parent .mkdir (parents = True , exist_ok = True )
77- thumb_path .write_bytes (thumbnail_bytes )
68+ if mime == 'application/pdf' :
69+ if self .is_cancelled (): return
70+ thumbnail_bytes = gdrive_base .fetch_preview_image (file_id , size = 128 )
71+ if thumbnail_bytes :
72+ img = QImage ()
73+ img .loadFromData (thumbnail_bytes )
74+ thumb_path .parent .mkdir (parents = True , exist_ok = True )
75+ # Yes, the thumb_path and the gdrive preview_image are both PNG
76+ thumb_path .write_bytes (thumbnail_bytes )
7877 except Exception as e :
7978 if not self .is_cancelled ():
8079 print (f"Error fetching thumbnail for { file_id } : { e } " )
0 commit comments