33from typing import Any , Dict , List , Optional , Tuple
44from wand .image import Image
55from wand .color import Color
6+ import rawpy
67
78from gallery .util import DEFAULT_THUMBNAIL_NAME
89from gallery .util import hash_file
@@ -65,6 +66,10 @@ def generate_thumbnail(self):
6566from gallery .file_modules .txt import TXTFile
6667from gallery .file_modules .mp3 import MP3File
6768from gallery .file_modules .wav import WAVFile
69+ from gallery .file_modules .heic import HEICFile
70+ from gallery .file_modules .nef import NEFFile
71+ from gallery .file_modules .mov import MOVFile
72+ from gallery .file_modules .m4a import M4AFile
6873
6974file_mimetype_relation = {
7075 "image/jpeg" : JPEGFile ,
@@ -76,20 +81,36 @@ def generate_thumbnail(self):
7681 "image/x-windows-bmp" : BMPFile ,
7782 "image/tiff" : TIFFFile ,
7883 "image/x-tiff" : TIFFFile ,
84+ "image/heic" : HEICFile ,
85+ "image/x-nikon-nef" : NEFFile ,
7986 "video/mp4" : MP4File ,
8087 "video/webm" : WebMFile ,
8188 "video/ogg" : OggFile ,
89+ "video/quicktime" : MOVFile ,
8290 "application/pdf" : PDFFile ,
8391 "text/plain" : TXTFile ,
8492 "audio/mpeg" : MP3File ,
85- "audio/x-wav" : WAVFile
93+ "audio/x-wav" : WAVFile ,
94+ "audio/mp4" : M4AFile ,
95+ "audio/x-m4a" : M4AFile ,
8696}
8797
8898
8999# classism
90100def parse_file_info (file_path : str , dir_path : str ) -> Tuple [str , Optional [FileModule ]]:
91101 print ("entering parse_file_info" )
102+
92103 mime_type = magic .from_file (file_path , mime = True )
104+
105+ if "tif" in mime_type : # .nef is a special case, magic reads it as .tiff, but it is not processed correctly by the tiff module
106+ # check if it is a raw file
107+ try :
108+ with rawpy .imread (file_path ): # this may cause issues for other raw files
109+ mime_type = "image/x-nikon-nef"
110+ except rawpy .LibRawFileUnsupportedError :
111+ pass
112+ except rawpy .LibRawIOError :
113+ pass
93114 print (mime_type )
94115 print (file_path )
95116
0 commit comments