diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-07-21 21:42:43 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-07-21 21:42:43 +0200 |
commit | 6172180c95695cae84e71484b4c60af4166ebf89 (patch) | |
tree | 17f4d63cca0b8407bb556911929725532bcede26 /pyload/utils/filetypes.py | |
parent | Replace rule Hook -> Addon (diff) | |
download | pyload-6172180c95695cae84e71484b4c60af4166ebf89.tar.xz |
guess media types by name
Diffstat (limited to 'pyload/utils/filetypes.py')
-rw-r--r-- | pyload/utils/filetypes.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pyload/utils/filetypes.py b/pyload/utils/filetypes.py new file mode 100644 index 000000000..ce5c8a0c5 --- /dev/null +++ b/pyload/utils/filetypes.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +import re +from pyload.Api import MediaType + +filetypes = { + MediaType.Audio: re.compile("\.(m3u|m4a|mp3|wav|wma|aac?|flac|midi|m4b)$", re.I), + MediaType.Image: re.compile("\.(jpe?g|bmp|png|gif|ico|tiff?|svg|psd)$", re.I), + MediaType.Video: re.compile("\.(3gp|flv|m4v|avi|mp4|mov|swf|vob|wmv|divx|mpe?g|rm|mkv)$", re.I), + MediaType.Document: re.compile("\.(epub|mobi|acsm|azw[0-9]|pdf|txt|md|abw|docx?|tex|odt|rtf||log)$", re.I), + MediaType.Archive: re.compile("\.(rar|r[0-9]+|7z|7z.[0-9]+|zip|gz|bzip2?|tar|lzma)$", re.I), + MediaType.Executable: re.compile("\.(jar|exe|dmg|sh|apk)$", re.I), +} + + +def guess_type(name): + for mt, regex in filetypes.iteritems(): + if regex.search(name) is not None: + return mt + + return MediaType.Other + + + |