diff --git a/etiquette/constants.py b/etiquette/constants.py index efb094f..066f02a 100644 --- a/etiquette/constants.py +++ b/etiquette/constants.py @@ -109,17 +109,18 @@ WARNING_ORDERBY_BADDIRECTION = 'You can\'t order "{column}" by "{direction}". De # Operational info EXPRESSION_OPERATORS = {'(', ')', 'OR', 'AND', 'NOT'} ADDITIONAL_MIMETYPES = { - 'srt': 'text', - - 'mkv': 'video', - - 'm4a': 'audio', - '7z': 'archive', 'gz': 'archive', 'rar': 'archive', - 'tar': 'archive', - 'zip': 'archive', + + 'aac': 'audio/aac', + 'ac3': 'audio/ac3', + 'dts': 'audio/dts', + 'm4a': 'audio/mp4', + + 'mkv': 'video/x-matroska', + + 'srt': 'text/plain', } DEFAULT_DATADIR = '.\\_etiquette' diff --git a/etiquette/helpers.py b/etiquette/helpers.py index 28f0ccd..fa1e9bc 100644 --- a/etiquette/helpers.py +++ b/etiquette/helpers.py @@ -138,8 +138,6 @@ def get_mimetype(filepath): if extension in constants.ADDITIONAL_MIMETYPES: return constants.ADDITIONAL_MIMETYPES[extension] mimetype = mimetypes.guess_type(filepath)[0] - if mimetype is not None: - mimetype = mimetype.split('/')[0] return mimetype def hyphen_range(s): diff --git a/etiquette/objects.py b/etiquette/objects.py index 461856e..b28725f 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -369,6 +369,10 @@ class Photo(ObjectBase): self.thumbnail = row_tuple['thumbnail'] self.mimetype = helpers.get_mimetype(self.real_filepath) + if self.mimetype is None: + self.simple_mimetype = None + else: + self.simple_mimetype = self.mimetype.split('/')[0] def __reinit__(self): ''' @@ -457,7 +461,7 @@ class Photo(ObjectBase): return None return helpers.seconds_to_hms(self.duration) - @decorators.time_me + #@decorators.time_me def generate_thumbnail(self, *, commit=True, **special): ''' special: @@ -468,7 +472,7 @@ class Photo(ObjectBase): #print(hopeful_filepath) return_filepath = None - if self.mimetype == 'image': + if self.simple_mimetype == 'image': self.photodb.log.debug('Thumbnailing %s' % self.real_filepath) try: image = PIL.Image.open(self.real_filepath) @@ -488,7 +492,7 @@ class Photo(ObjectBase): image.save(hopeful_filepath, quality=50) return_filepath = hopeful_filepath - elif self.mimetype == 'video' and constants.ffmpeg: + elif self.simple_mimetype == 'video' and constants.ffmpeg: #print('video') probe = constants.ffmpeg.probe(self.real_filepath) try: @@ -572,7 +576,7 @@ class Photo(ObjectBase): hopeful_filepath = folder.with_child(basename + '.jpg') return hopeful_filepath - @decorators.time_me + #@decorators.time_me def reload_metadata(self, *, commit=True): ''' Load the file's height, width, etc as appropriate for this type of file. @@ -586,7 +590,7 @@ class Photo(ObjectBase): self.photodb.log.debug('Reloading metadata for {photo:r}'.format(photo=self)) - if self.mimetype == 'image': + if self.simple_mimetype == 'image': try: image = PIL.Image.open(self.real_filepath) except (OSError, ValueError): @@ -594,9 +598,9 @@ class Photo(ObjectBase): else: (self.width, self.height) = image.size image.close() - self.photodb.log.debug('Loaded image data for {photo:r}'.format(photo=self)) + #self.photodb.log.debug('Loaded image data for {photo:r}'.format(photo=self)) - elif self.mimetype == 'video' and constants.ffmpeg: + elif self.simple_mimetype == 'video' and constants.ffmpeg: try: probe = constants.ffmpeg.probe(self.real_filepath) if probe and probe.video: @@ -606,7 +610,7 @@ class Photo(ObjectBase): except: traceback.print_exc() - elif self.mimetype == 'audio' and constants.ffmpeg: + elif self.simple_mimetype == 'audio' and constants.ffmpeg: try: probe = constants.ffmpeg.probe(self.real_filepath) if probe and probe.audio: diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 8e695d9..ae65f15 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -421,7 +421,7 @@ class PDBPhotoMixin: Returns the Photo object. ''' filename = os.path.abspath(filename) - safeprint.safeprint('Processing %s' % filename) + self.log.debug('New Photo: %s' % filename) if not os.path.isfile(filename): raise FileNotFoundError(filename) @@ -754,7 +754,7 @@ class PDBPhotoMixin: #print('Failed extension_not') continue - if mimetype and photo.mimetype not in mimetype: + if mimetype and photo.simple_mimetype not in mimetype: #print('Failed mimetype') continue @@ -1204,11 +1204,13 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs albums = {directory.absolute_path: album} for (current_location, directories, files) in generator: + new_photos = [] for filepath in files: try: photo = self.new_photo(filepath.absolute_path, commit=False) except exceptions.PhotoExists as e: photo = e.photo + new_photos.append(photo) if not make_albums: continue @@ -1223,17 +1225,19 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs commit=False, title=current_location.basename, ) - safeprint.safeprint('Created %s' % current_album.title) + self.log.debug('Created %s' % current_album.title) albums[current_location.absolute_path] = current_album parent = albums.get(current_location.parent.absolute_path, None) if parent is not None: try: parent.add(current_album, commit=False) - #safeprint.safeprint('Added to %s' % parent.title) + self.log.debug('Added child album to %s' % parent.title) except exceptions.GroupExists: pass - current_album.add_photo(photo, commit=False) + self.log.debug('Added photo to %s' % current_album) + for photo in new_photos: + current_album.add_photo(photo, commit=False) if commit: self.log.debug('Committing - digest') diff --git a/etiquette_site.py b/etiquette_site.py index b47d262..8ec8cd3 100644 --- a/etiquette_site.py +++ b/etiquette_site.py @@ -122,10 +122,12 @@ def send_file(filepath, override_mimetype=None): flask.abort(404) outgoing_headers = {} + print(override_mimetype) if override_mimetype is not None: mimetype = override_mimetype else: mimetype = mimetypes.guess_type(filepath)[0] + if mimetype is not None: if 'text/' in mimetype: mimetype += '; charset=utf-8' diff --git a/templates/photo.html b/templates/photo.html index 0a85175..2491708 100644 --- a/templates/photo.html +++ b/templates/photo.html @@ -169,7 +169,7 @@