# -*- coding: utf-8 -*-

import re

from os import path
from urlparse import urljoin

from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo


class ZippyshareCom(SimpleHoster):
    __name__    = "ZippyshareCom"
    __type__    = "hoster"
    __version__ = "0.56"

    __pattern__ = r'(?P<HOST>http://www\d{0,2}\.zippyshare\.com)/v(?:/|iew\.jsp.*key=)(?P<KEY>\d+)'

    __description__ = """Zippyshare.com hoster plugin"""
    __license__     = "GPLv3"
    __authors__     = [("Walter Purcaro", "vuolter@gmail.com")]


    NAME_PATTERN = r'<title>Zippyshare.com - (?P<N>.+)</title>'
    SIZE_PATTERN = r'>Size:.+?">(?P<S>[\d.,]+) (?P<U>[\w^_]+)'

    OFFLINE_PATTERN = r'>File does not exist on this server<'

    COOKIES = [(".zippyshare.com", "ziplocale", "en")]


    def setup(self):
        self.multiDL = True
        self.chunkLimit = -1
        self.resumeDownload = True


    def handleFree(self):
        url = self.get_link()
        self.download(url)


    def get_checksum(self):
        m = re.search(r'var ab? = (\d+)\%(\d+)', self.html)
        if m:
            return int(m.group(1)) % int(m.group(2))
        else:
            self.error(_("Unable to calculate checksum"))


    def get_link(self):
        checksum = self.get_checksum()
        p_url = path.join("d", self.info['KEY'], str(checksum), self.pyfile.name)
        dl_link = urljoin(self.info['HOST'], p_url)
        return dl_link


getInfo = create_getInfo(ZippyshareCom)

@@ -49,16 +49,43 @@
 rt path%0A
+from urllib import unquote%0A
 from url
@@ -308,9 +308,9 @@
 %220.5
-6
+7
 %22%0A%0A 
@@ -587,32 +587,22 @@
 = r'
-%3Ctitle%3EZippyshare.com - 
+var linkz =.*/
 (?P%3C
@@ -610,16 +610,10 @@
 %3E.+)
-%3C/title%3E
+%22;
 '%0A  
@@ -1009,37 +1009,227 @@
  get
-_checksum(self):%0A        m = 
+FileInfo(self):%0A        info = super(ZippyshareCom, self).getFileInfo()%0A        self.pyfile.name = info%5B'name'%5D = unquote(info%5B'name'%5D)%0A        return info%0A%0A%0A    def get_checksum(self):%0A        try:%0A            a = int(
 re.s
@@ -1245,20 +1245,11 @@
 ar a
-b?
  = 
-(%5Cd+)%5C%25
 (%5Cd+
@@ -1266,73 +1266,89 @@
 tml)
-%0A        if m:%0A            return int(m.group(1)) %25 int(m
+.group(1))%0A            b = int(re.search(r'var ab = a%5C%25(%5Cd+)', self.html)
 .group(
-2
+1
 ))%0A 
@@ -1359,11 +1359,13 @@
    e
-lse
+xcept
 :%0A  
@@ -1420,16 +1420,55 @@
 ksum%22))%0A
+        else:%0A            return a %25 b%0A
 %0A%0A    de

Update plugin