More optimized check against supported extensions

This commit is contained in:
Fabio Manganiello 2019-01-20 10:01:07 +01:00
parent 297d1114e7
commit 56b6e6a899
1 changed files with 13 additions and 25 deletions

View File

@ -22,21 +22,21 @@ class MediaPlugin(Plugin):
# Supported audio extensions # Supported audio extensions
audio_extensions = { audio_extensions = {
'.3gp', '.aa', '.aac', '.aax', '.act', '.aiff', '.amr', '.ape', '.au', '3gp', 'aa', 'aac', 'aax', 'act', 'aiff', 'amr', 'ape', 'au',
'.awb', '.dct', '.dss', '.dvf', '.flac', '.gsm', '.iklax', '.ivs', 'awb', 'dct', 'dss', 'dvf', 'flac', 'gsm', 'iklax', 'ivs',
'.m4a', '.m4b', '.m4p', '.mmf', '.mp3', '.mpc', '.msv', '.nmf', '.nsf', 'm4a', 'm4b', 'm4p', 'mmf', 'mp3', 'mpc', 'msv', 'nmf', 'nsf',
'.ogg,', '.opus', '.ra,', '.raw', '.sln', '.tta', '.vox', '.wav', 'ogg,', 'opus', 'ra,', 'raw', 'sln', 'tta', 'vox', 'wav',
'.wma', '.wv', '.webm', '.8svx', 'wma', 'wv', 'webm', '8svx',
} }
# Supported video extensions # Supported video extensions
video_extensions = { video_extensions = {
'.webm', '.mkv', '.flv', '.flv', '.vob', '.ogv', '.ogg', '.drc', '.gif', 'webm', 'mkv', 'flv', 'flv', 'vob', 'ogv', 'ogg', 'drc', 'gif',
'.gifv', '.mng', '.avi', '.mts', '.m2ts', '.mov', '.qt', '.wmv', '.yuv', 'gifv', 'mng', 'avi', 'mts', 'm2ts', 'mov', 'qt', 'wmv', 'yuv',
'.rm', '.rmvb', '.asf', '.amv', '.mp4', '.m4p', '.m4v', '.mpg', '.mp2', 'rm', 'rmvb', 'asf', 'amv', 'mp4', 'm4p', 'm4v', 'mpg', 'mp2',
'.mpeg', '.mpe', '.mpv', '.mpg', '.mpeg', '.m2v', '.m4v', '.svi', 'mpeg', 'mpe', 'mpv', 'mpg', 'mpeg', 'm2v', 'm4v', 'svi',
'.3gp', '.3g2', '.mxf', '.roq', '.nsv', '.flv', '.f4v', '.f4p', '.f4a', '3gp', '3g2', 'mxf', 'roq', 'nsv', 'flv', 'f4v', 'f4p', 'f4a',
'.f4b', 'f4b',
} }
def __init__(self, player, media_dirs=[], download_dir=None, *args, **kwargs): def __init__(self, player, media_dirs=[], download_dir=None, *args, **kwargs):
@ -219,23 +219,11 @@ class MediaPlugin(Plugin):
@classmethod @classmethod
def _is_video_file(cls, filename): def _is_video_file(cls, filename):
is_video = False return filename.lower().split('.') in cls.video_extensions
for ext in cls.video_extensions:
if filename.lower().endswith(ext):
is_video = True
break
return is_video
@classmethod @classmethod
def _is_audio_file(cls, filename): def _is_audio_file(cls, filename):
is_audio = False return filename.lower().split('.') in cls.audio_extensions
for ext in cls.audio_extensions:
if filename.lower().endswith(ext):
is_audio = True
break
return is_audio
@action @action
def file_search(self, query): def file_search(self, query):