summaryrefslogtreecommitdiffstats
path: root/module/plugins/internal/SimpleHoster.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/internal/SimpleHoster.py')
-rw-r--r--module/plugins/internal/SimpleHoster.py76
1 files changed, 40 insertions, 36 deletions
diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py
index 4a03ec60a..14cb8a15e 100644
--- a/module/plugins/internal/SimpleHoster.py
+++ b/module/plugins/internal/SimpleHoster.py
@@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
-
+
@author: zoidberg
"""
from urlparse import urlparse
@@ -29,10 +29,11 @@ def reSub(string, ruleslist):
string = sub(rf, rt, string)
return string
-def parseFileInfo(self, url = '', html = ''):
+def parseFileInfo(self, url = '', html = '', infomode = False):
if not html and hasattr(self, "html"): html = self.html
info = {"name" : url, "size" : 0, "status" : 3}
-
+ online = False
+
if hasattr(self, "FILE_OFFLINE_PATTERN") and search(self.FILE_OFFLINE_PATTERN, html):
# File offline
info['status'] = 1
@@ -40,28 +41,31 @@ def parseFileInfo(self, url = '', html = ''):
for pattern in ("FILE_INFO_PATTERN", "FILE_NAME_PATTERN", "FILE_SIZE_PATTERN"):
try:
info = dict(info, **search(getattr(self, pattern), html).groupdict())
+ online = True
except AttributeError:
continue
-
- if len(info) > 3:
- # File online, return name and size
- info['status'] = 2
- if 'N' in info: info['name'] = reSub(info['N'], self.FILE_NAME_REPLACEMENTS)
- if 'S' in info:
- size = info['S'] + info['U'] if 'U' in info else info['S']
- print repr(size)
- size = parseFileSize(reSub(size, self.FILE_SIZE_REPLACEMENTS))
- print repr(self.FILE_SIZE_REPLACEMENTS), repr(size)
- info['size'] = size
-
- print info
- return info
+
+ if online:
+ # File online, return name and size
+ info['status'] = 2
+ if 'N' in info: info['name'] = reSub(info['N'], self.FILE_NAME_REPLACEMENTS)
+ if 'S' in info:
+ size = reSub(info['S'] + info['U'] if 'U' in info else info['S'], self.FILE_SIZE_REPLACEMENTS)
+ info['size'] = parseFileSize(size)
+ elif isinstance(info['size'], (str, unicode)):
+ if 'units' in info: info['size'] += info['units']
+ info['size'] = parseFileSize(info['size'])
+
+ if infomode:
+ return info
+ else:
+ return info['name'], info['size'], info['status'], url
def create_getInfo(plugin):
def getInfo(urls):
for url in urls:
file_info = parseFileInfo(plugin, url, getURL(reSub(url, plugin.FILE_URL_REPLACEMENTS), decode=True))
- yield file_info['name'], file_info['size'], file_info['status'], url
+ yield file_info
return getInfo
class PluginParseError(Exception):
@@ -73,7 +77,7 @@ class PluginParseError(Exception):
class SimpleHoster(Hoster):
__name__ = "SimpleHoster"
- __version__ = "0.13"
+ __version__ = "0.14"
__pattern__ = None
__type__ = "hoster"
__description__ = """Base hoster plugin"""
@@ -81,8 +85,8 @@ class SimpleHoster(Hoster):
__author_mail__ = ("zoidberg@mujmail.cz")
"""
These patterns should be defined by each hoster:
- FILE_INFO_PATTERN = r'(?P<N>file_name) (?P<S>file_size) (?P<U>units)'
- or FILE_NAME_INFO = r'(?P<N>file_name)'
+ FILE_INFO_PATTERN = r'(?P<N>file_name) (?P<S>file_size) (?P<U>units)'
+ or FILE_NAME_INFO = r'(?P<N>file_name)'
and FILE_SIZE_INFO = r'(?P<S>file_size) (?P<U>units)'
FILE_OFFLINE_PATTERN = r'File (deleted|not found)'
TEMP_OFFLINE_PATTERN = r'Server maintainance'
@@ -93,12 +97,12 @@ class SimpleHoster(Hoster):
FILE_URL_REPLACEMENTS = []
def setup(self):
- self.resumeDownload = self.multiDL = True if self.account else False
+ self.resumeDownload = self.multiDL = True if self.account else False
def process(self, pyfile):
- pyfile.url = reSub(pyfile.url, self.FILE_URL_REPLACEMENTS)
+ pyfile.url = reSub(pyfile.url, self.FILE_URL_REPLACEMENTS)
self.html = self.load(pyfile.url, decode = True)
- self.file_info = self.getFileInfo()
+ self.file_info = self.getFileInfo()
if self.account:
self.handlePremium()
else:
@@ -106,34 +110,34 @@ class SimpleHoster(Hoster):
def getFileInfo(self):
self.logDebug("URL: %s" % self.pyfile.url)
- if hasattr(self, "TEMP_OFFLINE_PATTERN") and search(self.TEMP_OFFLINE_PATTERN, html):
+ if hasattr(self, "TEMP_OFFLINE_PATTERN") and search(self.TEMP_OFFLINE_PATTERN, self.html):
self.tempOffline()
-
- file_info = parseFileInfo(self)
- if file_info['status'] == 1:
+
+ file_info = parseFileInfo(self, infomode = True)
+ if file_info['status'] == 1:
self.offline()
elif file_info['status'] != 2:
- self.logDebug(file_info)
+ self.logDebug(file_info)
self.parseError('File info')
-
+
if file_info['name']:
self.pyfile.name = file_info['name']
else:
self.pyfile.name = html_unescape(urlparse(self.pyfile.url).path.split("/")[-1])
-
+
if file_info['size']:
self.pyfile.size = file_info['size']
else:
self.logError("File size not parsed")
self.logDebug("FILE NAME: %s FILE SIZE: %s" % (self.pyfile.name, self.pyfile.size))
- return file_info
-
+ return file_info
+
def handleFree(self):
self.fail("Free download not implemented")
-
+
def handlePremium(self):
self.fail("Premium download not implemented")
-
+
def parseError(self, msg):
- raise PluginParseError(msg) \ No newline at end of file
+ raise PluginParseError(msg) \ No newline at end of file