using mimetypes as a backup mime detection method, fixed typo

This commit is contained in:
k4yt3x
2020-05-22 16:29:51 -04:00
parent 676e70f088
commit 89740f01dc
2 changed files with 27 additions and 3 deletions

View File

@@ -4,7 +4,7 @@
Creator: Video2X GUI
Author: K4YT3X
Date Created: May 5, 2020
Last Modified: May 17, 2020
Last Modified: May 22, 2020
"""
# local imports
@@ -15,6 +15,7 @@ from wrappers.ffmpeg import Ffmpeg
# built-in imports
import contextlib
import json
import mimetypes
import os
import pathlib
import sys
@@ -131,6 +132,14 @@ class InputTableModel(QAbstractTableModel):
input_file_mime_type = magic.from_file(str(file_path.absolute()), mime=True)
input_file_type = input_file_mime_type.split('/')[0]
input_file_subtype = input_file_mime_type.split('/')[1]
# in case python-magic fails to detect file type
# try guessing file mime type with mimetypes
if input_file_type not in ['image', 'video']:
input_file_mime_type = mimetypes.guess_type(file_path.name)[0]
input_file_type = input_file_mime_type.split('/')[0]
input_file_subtype = input_file_mime_type.split('/')[1]
if input_file_type == 'image':
if input_file_subtype == 'gif':
return 'GIF'
@@ -838,6 +847,13 @@ class Video2XMainWindow(QMainWindow):
input_file_type = input_file_mime_type.split('/')[0]
input_file_subtype = input_file_mime_type.split('/')[1]
# in case python-magic fails to detect file type
# try guessing file mime type with mimetypes
if input_file_type not in ['image', 'video']:
input_file_mime_type = mimetypes.guess_type(input_path.name)[0]
input_file_type = input_file_mime_type.split('/')[0]
input_file_subtype = input_file_mime_type.split('/')[1]
# if input file is an image
if input_file_type == 'image':