diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-03-24 17:16:34 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-03-24 17:16:34 +0100 |
commit | 3ae2fbb170ad0f2bfe1ebf7f59e76d3645861f0a (patch) | |
tree | b01e2c881aaf744aaab0af613a7a26e7129f2028 /module/plugins/hoster/XHamsterCom.py | |
parent | enter captchas on webui (diff) | |
parent | Rapidgator: fixed bug #47 (diff) | |
download | pyload-3ae2fbb170ad0f2bfe1ebf7f59e76d3645861f0a.tar.xz |
Merge remote-tracking branch 'origin/stable'
Conflicts:
module/plugins/accounts/FilesonicCom.py
module/plugins/accounts/OronCom.py
module/plugins/accounts/ShareonlineBiz.py
module/plugins/addons/UpdateManager.py
module/plugins/crypter/FilesonicComFolder.py
module/plugins/hoster/BezvadataCz.py
module/plugins/hoster/EuroshareEu.py
module/plugins/hoster/FilesonicCom.py
module/plugins/hoster/MegauploadCom.py
module/plugins/hoster/Premium4Me.py
module/plugins/hoster/YoutubeCom.py
module/plugins/internal/MultiHoster.py
module/utils.py
Diffstat (limited to 'module/plugins/hoster/XHamsterCom.py')
-rw-r--r-- | module/plugins/hoster/XHamsterCom.py | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/module/plugins/hoster/XHamsterCom.py b/module/plugins/hoster/XHamsterCom.py new file mode 100644 index 000000000..0779a78e6 --- /dev/null +++ b/module/plugins/hoster/XHamsterCom.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import re +from module.plugins.Hoster import Hoster +from urllib import unquote +from module.common.json_layer import json_loads + +def clean_json(json_expr): + json_expr = re.sub('[\n\r]', '', json_expr) + json_expr = re.sub(' +', '', json_expr) + json_expr = re.sub('\'','"', json_expr) + + return json_expr + +class XHamsterCom(Hoster): + __name__ = "XHamsterCom" + __type__ = "hoster" + __pattern__ = r"http://(www\.)?xhamster\.com/movies/.+" + __version__ = "0.1" + __config__ = [("type", ".mp4;.flv", "Preferred type", ".mp4")] + __description__ = """XHamster.com Video Download Hoster""" + + def setup(self): + self.html = None + + def process(self, pyfile): + self.pyfile = pyfile + + if not self.file_exists(): + self.offline() + + if self.getConfig("type"): + self.desired_fmt = self.getConf("type") + + self.pyfile.name = self.get_file_name() + self.desired_fmt + self.download(self.get_file_url()) + + def download_html(self): + url = self.pyfile.url + self.html = self.load(url) + + def get_file_url(self): + """ returns the absolute downloadable filepath + """ + if self.html is None: + self.download_html() + + flashvar_pattern = re.compile('flashvars = ({.*?});', re.DOTALL) + json_flashvar=flashvar_pattern.search(self.html) + + if json_flashvar is None: + self.fail("Parse error (flashvars)") + + j = clean_json(json_flashvar.group(1)) + flashvars = json_loads(j) + + if flashvars["srv"]: + srv_url = flashvars["srv"] + '/' + else: + self.fail("Parse error (srv_url)") + + if flashvars["url_mode"]: + url_mode = flashvars["url_mode"] + else: + self.fail("Parse error (url_mode)") + + + if self.desired_fmt == ".mp4": + file_url = re.search(r"<a href=\"" + srv_url + "(.+?)\"", self.html) + if file_url is None: + self.fail("Parse error (file_url)") + file_url=file_url.group(1) + long_url = srv_url + file_url + self.logDebug(_("long_url: %s") % long_url) + else: + if flashvars["file"]: + file_url = unquote(flashvars["file"]) + else: + self.fail("Parse error (file_url)") + + if url_mode=='3': + long_url = file_url + self.logDebug(_("long_url: %s") % long_url) + else: + long_url = srv_url + "key=" + file_url + self.logDebug(_("long_url: %s") % long_url) + + return long_url + + + def get_file_name(self): + if self.html is None: + self.download_html() + + file_name_pattern = r"<title>(.*?) - xHamster\.com</title>" + file_name = re.search(file_name_pattern, self.html) + if file_name is None: + file_name_pattern = r"<h1 >(.*)</h1>" + file_name = re.search(file_name_pattern, self.html) + if file_name is None: + file_name_pattern = r"http://[www.]+xhamster\.com/movies/.*/(.*?)\.html?" + file_name = re.search(file_name_pattern, self.pyfile.url) + if file_name is None: + file_name_pattern = r"<div id=\"element_str_id\" style=\"display:none;\">(.*)</div>" + file_name = re.search(file_name_pattern, self.html) + if file_name is None: + return "Unknown" + + return file_name.group(1) + + def file_exists(self): + """ returns True or False + """ + if self.html is None: + self.download_html() + if re.search(r"(.*Video not found.*)", self.html) is not None: + return False + else: + return True |