mirror of
https://github.com/k4yt3x/video2x.git
synced 2025-01-30 23:58:11 +00:00
using mimetypes as a backup mime detection method, fixed typo
This commit is contained in:
parent
676e70f088
commit
89740f01dc
@ -4,7 +4,7 @@
|
|||||||
Name: Video2X Upscaler
|
Name: Video2X Upscaler
|
||||||
Author: K4YT3X
|
Author: K4YT3X
|
||||||
Date Created: December 10, 2018
|
Date Created: December 10, 2018
|
||||||
Last Modified: May 17, 2020
|
Last Modified: May 22, 2020
|
||||||
|
|
||||||
Description: This file contains the Upscaler class. Each
|
Description: This file contains the Upscaler class. Each
|
||||||
instance of the Upscaler class is an upscaler on an image or
|
instance of the Upscaler class is an upscaler on an image or
|
||||||
@ -25,6 +25,7 @@ import copy
|
|||||||
import gettext
|
import gettext
|
||||||
import importlib
|
import importlib
|
||||||
import locale
|
import locale
|
||||||
|
import mimetypes
|
||||||
import pathlib
|
import pathlib
|
||||||
import queue
|
import queue
|
||||||
import re
|
import re
|
||||||
@ -457,6 +458,13 @@ class Upscaler:
|
|||||||
input_file_type = input_file_mime_type.split('/')[0]
|
input_file_type = input_file_mime_type.split('/')[0]
|
||||||
input_file_subtype = input_file_mime_type.split('/')[1]
|
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(self.current_input_file.name)[0]
|
||||||
|
input_file_type = input_file_mime_type.split('/')[0]
|
||||||
|
input_file_subtype = input_file_mime_type.split('/')[1]
|
||||||
|
|
||||||
# start handling input
|
# start handling input
|
||||||
# if input file is a static image
|
# if input file is a static image
|
||||||
if input_file_type == 'image' and input_file_subtype != 'gif':
|
if input_file_type == 'image' and input_file_subtype != 'gif':
|
||||||
@ -530,7 +538,7 @@ class Upscaler:
|
|||||||
# if file is none of: image, image/gif, video
|
# if file is none of: image, image/gif, video
|
||||||
# skip to the next task
|
# skip to the next task
|
||||||
else:
|
else:
|
||||||
Avalon.error(_('File {} ({}) neither an image of a video').format(self.current_input_file, input_file_mime_type))
|
Avalon.error(_('File {} ({}) neither an image nor a video').format(self.current_input_file, input_file_mime_type))
|
||||||
Avalon.warning(_('Skipping this file'))
|
Avalon.warning(_('Skipping this file'))
|
||||||
self.processing_queue.task_done()
|
self.processing_queue.task_done()
|
||||||
self.total_processed += 1
|
self.total_processed += 1
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
Creator: Video2X GUI
|
Creator: Video2X GUI
|
||||||
Author: K4YT3X
|
Author: K4YT3X
|
||||||
Date Created: May 5, 2020
|
Date Created: May 5, 2020
|
||||||
Last Modified: May 17, 2020
|
Last Modified: May 22, 2020
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
@ -15,6 +15,7 @@ from wrappers.ffmpeg import Ffmpeg
|
|||||||
# built-in imports
|
# built-in imports
|
||||||
import contextlib
|
import contextlib
|
||||||
import json
|
import json
|
||||||
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import sys
|
import sys
|
||||||
@ -131,6 +132,14 @@ class InputTableModel(QAbstractTableModel):
|
|||||||
input_file_mime_type = magic.from_file(str(file_path.absolute()), mime=True)
|
input_file_mime_type = magic.from_file(str(file_path.absolute()), mime=True)
|
||||||
input_file_type = input_file_mime_type.split('/')[0]
|
input_file_type = input_file_mime_type.split('/')[0]
|
||||||
input_file_subtype = input_file_mime_type.split('/')[1]
|
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_type == 'image':
|
||||||
if input_file_subtype == 'gif':
|
if input_file_subtype == 'gif':
|
||||||
return 'GIF'
|
return 'GIF'
|
||||||
@ -838,6 +847,13 @@ class Video2XMainWindow(QMainWindow):
|
|||||||
input_file_type = input_file_mime_type.split('/')[0]
|
input_file_type = input_file_mime_type.split('/')[0]
|
||||||
input_file_subtype = input_file_mime_type.split('/')[1]
|
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 is an image
|
||||||
if input_file_type == 'image':
|
if input_file_type == 'image':
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user