From a044870e905853dfdcd13e7d4b6edf0a129bdbc1 Mon Sep 17 00:00:00 2001 From: fragonib Date: Tue, 28 Sep 2010 23:59:53 +0200 Subject: NEW: 1fichier.com hoster plugin, not info API support yet. --- module/plugins/hoster/OneFichierCom.py | 94 ++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 module/plugins/hoster/OneFichierCom.py (limited to 'module/plugins/hoster/OneFichierCom.py') diff --git a/module/plugins/hoster/OneFichierCom.py b/module/plugins/hoster/OneFichierCom.py new file mode 100644 index 000000000..8461482ad --- /dev/null +++ b/module/plugins/hoster/OneFichierCom.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import re + +from module.plugins.Hoster import Hoster + +class OneFichierCom(Hoster): + __name__ = "OneFichierCom" + __type__ = "hoster" + __pattern__ = r"http://[a-z0-9]+\.1fichier\.com/(.*)" + __version__ = "0.1" + __description__ = """1fichier.com download hoster""" + __author_name__ = ("fragonib") + __author_mail__ = ("fragonib AT yahoo DOT es") + + def setup(self): + self.html = None + self.multiDL = False + + def process(self, pyfile): + self.pyfile = pyfile + self.download_html() + + if not self.file_exists(): + self.log.debug("OneFichierCom: File not yet available.") + self.offline() + + pyfile.name = self.get_file_name() + pyfile.size = self.get_file_size() + + url = self.get_file_url() + self.pyfile.setStatus("downloading") + self.download(url) + + def download_html(self): + self.html = self.load(self.pyfile.url, cookies=False) + + def file_exists(self): + warnings = (r"The requested file could not be found", + r"The file may has been deleted by its owner", + r"Le fichier demandé n'existe pas\.", + r"Il a pu être supprimé par son propriétaire\.") + expr = '(' + '|'.join(warnings) + ')' + + if re.search(expr, self.html) is not None: + return False + return True + + def get_file_url(self): + self.log.debug("OneFichierCom: Getting file URL") + file_url_pattern = r"


\ [\t\n\r ]+", + r"(>Cliquez ici pour télécharger|>Click here to download) (.*?)", + r"\">(Nom du fichier :|File name :)[\t\r\n ]+(.*?)", + r"Download of (.*?)" + ) + + for pattern in file_name_patterns: + m = re.search(pattern, self.html) + if m is not None: + name = m.group(1).strip() + self.log.debug("OneFichierCom: File name [%s]" % name) + return name + + def get_file_size(self): + self.log.debug("OneFichierCom: Getting file size") + file_size_pattern = r"(Taille :|File size :)[\t\n\r ]+(\d*)\s+(.*?)" + + m = re.search(file_size_pattern, self.html) + if m is not None: + size = m.group(2) + units = m.group(3) + multiplier = 1 + if units in ("Go", "Gb"): + multiplier = 1024 ** 3 + if units in ("Mo", "Mb"): + multiplier = 1024 ** 2 + if units in ("Ko", "Kb"): + multiplier = 1024 ** 1 + bytes = int(size) * multiplier + self.log.debug("OneFichierCom: File size [%s] bytes" % bytes) + return bytes + \ No newline at end of file -- cgit v1.2.3