# -*- coding: utf-8 -*- import re import urllib from module.plugins.internal.utils import json from module.plugins.internal.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.16" __status__ = "testing" __pattern__ = r'http://(?:www\.)?xhamster\.com/movies/.+' __config__ = [("activated", "bool", "Activated", True), ("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.get_config('type'): self.desired_fmt = self.get_config('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.data = self.load(url) def get_file_url(self): """ Returns the absolute downloadable filepath """ if not self.data: self.download_html() flashvar_pattern = re.compile('flashvars = ({.*?});', re.S) json_flashvar = flashvar_pattern.search(self.data) 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.data) if name is None: return "Unknown" return name.group(1) def file_exists(self): """ Returns True or False """ if not self.data: self.download_html() if re.search(r"(.*Video not found.*)", self.data): return False else: return True