diff options
Diffstat (limited to 'pyload')
-rw-r--r-- | pyload/database/FileDatabase.py | 14 | ||||
-rw-r--r-- | pyload/datatypes/PyFile.py | 7 | ||||
-rw-r--r-- | pyload/remote/apitypes.py | 1 | ||||
-rw-r--r-- | pyload/remote/apitypes_debug.py | 2 | ||||
-rw-r--r-- | pyload/remote/create_apitypes.py | 2 | ||||
-rw-r--r-- | pyload/remote/pyload.thrift | 1 | ||||
-rw-r--r-- | pyload/utils/filetypes.py | 24 | ||||
-rw-r--r-- | pyload/web/app/scripts/helpers/fileHelper.js | 18 | ||||
-rw-r--r-- | pyload/web/app/scripts/utils/apitypes.js | 2 |
9 files changed, 61 insertions, 10 deletions
diff --git a/pyload/database/FileDatabase.py b/pyload/database/FileDatabase.py index 7b39cfa47..7765cd744 100644 --- a/pyload/database/FileDatabase.py +++ b/pyload/database/FileDatabase.py @@ -19,12 +19,12 @@ from new_collections import OrderedDict from pyload.Api import DownloadInfo, FileInfo, PackageInfo, PackageStats, DownloadState as DS, state_string from pyload.database import DatabaseMethods, queue, async, inner +from pyload.utils.filetypes import guess_type zero_stats = PackageStats(0, 0, 0, 0) class FileMethods(DatabaseMethods): - @queue def filecount(self): """returns number of files, currently only used for debugging""" @@ -309,13 +309,19 @@ class FileMethods(DatabaseMethods): @async def updateLinkInfo(self, data): """ data is list of tuples (name, size, status,[ hash,] url)""" + + # inserts media type as n-1th arguments + data = [t[:-1] + (guess_type(t[0]),) + t[-1] for t in data] + # status in (NA, Offline, Online, Queued, TempOffline) if data and len(data[0]) == 4: - self.c.executemany('UPDATE files SET name=?, size=?, dlstatus=? WHERE url=? AND dlstatus IN (0,1,2,3,11)', - data) + self.c.executemany( + 'UPDATE files SET name=?, size=?, dlstatus=?, media=? WHERE url=? AND dlstatus IN (0,1,2,3,11)', + data) else: self.c.executemany( - 'UPDATE files SET name=?, size=?, dlstatus=?, hash=? WHERE url=? AND dlstatus IN (0,1,2,3,11)', data) + 'UPDATE files SET name=?, size=?, dlstatus=?, hash=?, media=? WHERE url=? AND dlstatus IN (0,1,2,3,11)', + data) @async def updateFile(self, f): diff --git a/pyload/datatypes/PyFile.py b/pyload/datatypes/PyFile.py index 7bb3a4e31..f15ad7ee0 100644 --- a/pyload/datatypes/PyFile.py +++ b/pyload/datatypes/PyFile.py @@ -21,6 +21,7 @@ from ReadWriteLock import ReadWriteLock from pyload.Api import ProgressInfo, DownloadProgress, FileInfo, DownloadInfo, DownloadStatus from pyload.utils import lock, read_lock +from pyload.utils.filetypes import guess_type statusMap = { "none": 0, @@ -123,7 +124,11 @@ class PyFile(object): if type(name) == str: name = name.decode("utf8") - self._name = name + # media type is updated if needed + if self._name != name: + self.media = guess_type(name) + self._name = name + name = property(getName, setName) diff --git a/pyload/remote/apitypes.py b/pyload/remote/apitypes.py index 6cf7529fd..0d9e35963 100644 --- a/pyload/remote/apitypes.py +++ b/pyload/remote/apitypes.py @@ -74,6 +74,7 @@ class MediaType: Video = 8 Document = 16 Archive = 32 + Executable = 64 class PackageStatus: Ok = 0 diff --git a/pyload/remote/apitypes_debug.py b/pyload/remote/apitypes_debug.py index 7c62a6277..0d04a8225 100644 --- a/pyload/remote/apitypes_debug.py +++ b/pyload/remote/apitypes_debug.py @@ -3,7 +3,7 @@ # Autogenerated by pyload # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -from ttypes import * +from apitypes import * enums = [ "DownloadState", diff --git a/pyload/remote/create_apitypes.py b/pyload/remote/create_apitypes.py index d596f07ac..61063fa3b 100644 --- a/pyload/remote/create_apitypes.py +++ b/pyload/remote/create_apitypes.py @@ -95,7 +95,7 @@ class ExceptionObject(Exception): # -*- coding: utf-8 -*- # Autogenerated by pyload # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n -from ttypes import *\n +from apitypes import *\n """) dev.write("enums = [\n") diff --git a/pyload/remote/pyload.thrift b/pyload/remote/pyload.thrift index 309c972cd..9f2cfc8ee 100644 --- a/pyload/remote/pyload.thrift +++ b/pyload/remote/pyload.thrift @@ -50,6 +50,7 @@ enum MediaType { Video = 8, Document = 16, Archive = 32, + Executable = 64 } enum FileStatus { 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 + + + diff --git a/pyload/web/app/scripts/helpers/fileHelper.js b/pyload/web/app/scripts/helpers/fileHelper.js index 156be58f0..044887eea 100644 --- a/pyload/web/app/scripts/helpers/fileHelper.js +++ b/pyload/web/app/scripts/helpers/fileHelper.js @@ -20,9 +20,23 @@ define('helpers/fileHelper', ['handlebars', 'utils/apitypes', 'helpers/formatTim return ''; } - // TODO function fileIcon(media, options) { - return 'icon-music'; + switch (media) { + case Api.MediaType.Audio: + return 'icon-music'; + case Api.MediaType.Image: + return 'icon-picture'; + case Api.MediaType.Video: + return 'icon-film'; + case Api.MediaType.Document: + return 'icon-file-text'; + case Api.MediaType.Archive: + return 'icon-archive'; + case Api.MediaType.Executable: + return 'icon-cog'; + default: + return 'icon-file-alt'; + } } // TODO rest of the states diff --git a/pyload/web/app/scripts/utils/apitypes.js b/pyload/web/app/scripts/utils/apitypes.js index 342f61f68..23d87def0 100644 --- a/pyload/web/app/scripts/utils/apitypes.js +++ b/pyload/web/app/scripts/utils/apitypes.js @@ -8,7 +8,7 @@ define([], function() { FileStatus: {'Remote': 2, 'Ok': 0, 'Missing': 1}, InputType: {'PluginList': 13, 'Multiple': 11, 'Int': 2, 'NA': 0, 'Time': 7, 'List': 12, 'Bool': 8, 'File': 3, 'Text': 1, 'Table': 14, 'Folder': 4, 'Password': 6, 'Click': 9, 'Select': 10, 'Textbox': 5}, Interaction: {'Captcha': 2, 'All': 0, 'Query': 4, 'Notification': 1}, - MediaType: {'All': 0, 'Audio': 2, 'Image': 4, 'Other': 1, 'Video': 8, 'Document': 16, 'Archive': 32}, + MediaType: {'All': 0, 'Audio': 2, 'Image': 4, 'Executable': 64, 'Other': 1, 'Video': 8, 'Document': 16, 'Archive': 32}, PackageStatus: {'Paused': 1, 'Remote': 3, 'Folder': 2, 'Ok': 0}, Permission: {'All': 0, 'Interaction': 32, 'Modify': 4, 'Add': 1, 'Accounts': 16, 'Plugins': 64, 'Download': 8, 'Delete': 2}, Role: {'Admin': 0, 'User': 1}, |