/module/plugins/accounts/FshareVn.py

https://bitbucket.org/kase/my-pyload · Python · 59 lines · 30 code · 11 blank · 18 comment · 5 complexity · b10476d4b4c933285eb8abe3bb04aed4 MD5 · raw file

  1. # -*- coding: utf-8 -*-
  2. """
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License,
  6. or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. @author: zoidberg
  14. """
  15. from module.plugins.Account import Account
  16. from time import mktime, strptime
  17. from pycurl import REFERER
  18. import re
  19. class FshareVn(Account):
  20. __name__ = "FshareVn"
  21. __version__ = "0.01"
  22. __type__ = "account"
  23. __description__ = """fshare.vn account plugin"""
  24. __author_name__ = ("zoidberg")
  25. __author_mail__ = ("zoidberg@mujmail.cz")
  26. VALID_UNTIL_PATTERN = ur'<dt>Thời hạn dùng:</dt>\s*<dd>([^<]+)</dd>'
  27. TRAFFIC_LEFT_PATTERN = ur'<dt>Bandwidth Còn Lại</dt>\s*<dd[^>]*>([0-9.]+) ([kKMG])B</dd>'
  28. DIRECT_DOWNLOAD_PATTERN = ur'<input type="checkbox"\s*([^=>]*)[^>]*/>Kích hoạt download trực tiếp</dt>'
  29. def loadAccountInfo(self, user, req):
  30. #self.relogin(user)
  31. html = req.load("http://www.fshare.vn/account_info.php", decode = True)
  32. found = re.search(self.VALID_UNTIL_PATTERN, html)
  33. validuntil = mktime(strptime(found.group(1), '%I:%M:%S %p %d-%m-%Y')) if found else 0
  34. found = re.search(self.TRAFFIC_LEFT_PATTERN, html)
  35. trafficleft = float(found.group(1)) * 1024 ** {'k': 0, 'K': 0, 'M': 1, 'G': 2}[found.group(2)] if found else 0
  36. return {"validuntil": validuntil, "trafficleft": trafficleft}
  37. def login(self, user, data, req):
  38. req.http.c.setopt(REFERER, "http://www.fshare.vn/login.php")
  39. html = req.load('http://www.fshare.vn/login.php', post = {
  40. "login_password" : data['password'],
  41. "login_useremail" : user,
  42. "url_refe" : "http://www.fshare.vn/login.php"
  43. }, referer = True, decode = True)
  44. if not '<img alt="VIP"' in html:
  45. self.wrongPassword()