# -*- coding: utf-8 -*- import re from urllib import unquote from pyload.utils import json_loads from pyload.plugin.Hoster import Hoster 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" __version = "0.12" __pattern = r'http://(?:www\.)?xhamster\.com/movies/.+' __config = [("type", ".mp4;.flv", "Preferred type", ".mp4")] __description = """XHamster.com hoster plugin""" __license = "GPLv3" __authors = [] def process(self, pyfile): self.pyfile = pyfile if not self.file_exists(): self.offline() if self.getConfig('type'): self.desired_fmt = self.getConfig('type') 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 not self.html: self.download_html() flashvar_pattern = re.compile('flashvars = ({.*?});', re.S) json_flashvar = flashvar_pattern.search(self.html) if not json_flashvar: self.error(_("flashvar not found")) j = clean_json(json_flashvar.group(1)) flashvars = json_loads(j) if flashvars['srv']: srv_url = flashvars['srv'] + '/' else: self.error(_("srv_url not found")) if flashvars['url_mode']: url_mode = flashvars['url_mode'] else: self.error(_("url_mode not found")) if self.desired_fmt == ".mp4": file_url = re.search(r"(.*)' name = re.search(pattern, self.html) if name is None: return "Unknown" return name.group(1) def file_exists(self): """ returns True or False """ if not self.html: self.download_html() if re.search(r"(.*Video not found.*)", self.html): return False else: return True