summaryrefslogtreecommitdiffstats
path: root/pyload/utils/filetypes.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-07-21 21:42:43 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-07-21 21:42:43 +0200
commit6172180c95695cae84e71484b4c60af4166ebf89 (patch)
tree17f4d63cca0b8407bb556911929725532bcede26 /pyload/utils/filetypes.py
parentReplace rule Hook -> Addon (diff)
downloadpyload-6172180c95695cae84e71484b4c60af4166ebf89.tar.xz
guess media types by name
Diffstat (limited to 'pyload/utils/filetypes.py')
-rw-r--r--pyload/utils/filetypes.py24
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
+
+
+