# -*- coding: utf-8 -*-
"""
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License,
    or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program; if not, see .
    @author: zoidberg
"""
import re
from module.plugins.internal.SimpleHoster import SimpleHoster, parseFileInfo
from module.network.RequestFactory import getURL
def getInfo(urls):
    result = []
    for url in urls:
        file_info = parseFileInfo(StahnuTo, url, getURL("http://stahnu.to/?file=" + re.search(StahnuTo.__pattern__, url).group(3), decode=True)) 
        result.append(file_info)
            
    yield result
class StahnuTo(SimpleHoster):
    __name__ = "StahnuTo"
    __type__ = "hoster"
    __pattern__ = r"http://(\w*\.)?stahnu.to/(files/get/|.*\?file=)([^/]+).*"
    __version__ = "0.12"
    __description__ = """stahnu.to"""
    __author_name__ = ("zoidberg")
    FILE_NAME_PATTERN = r"
(?[^<]+)
"
    FILE_SIZE_PATTERN = r'Velikost souboru '
    FILE_OFFLINE_PATTERN = r'\s*'
    #FILE_OFFLINE_PATTERN = r'(?
 [^<]+)\s*(?[kKMG])i?[Bb] | Tento soubor neexistuje  nebo byl odstraněn! 
'
    CAPTCHA_PATTERN = r' '
    def setup(self):
        self.multiDL = True
    def process(self, pyfile):
        found = re.search(self.__pattern__, pyfile.url)
        file_id = found.group(3)
        self.html = self.load("http://stahnu.to/?file=" + file_id, decode=True)
        self.getFileInfo()
        self.download("http://stahnu.to/files/gen/" + file_id, post={
            "file": file_id,
            "user": "Anonym",
            "commenttext": ""
        })
'
    def setup(self):
        self.multiDL = True
    def process(self, pyfile):
        found = re.search(self.__pattern__, pyfile.url)
        file_id = found.group(3)
        self.html = self.load("http://stahnu.to/?file=" + file_id, decode=True)
        self.getFileInfo()
        self.download("http://stahnu.to/files/gen/" + file_id, post={
            "file": file_id,
            "user": "Anonym",
            "commenttext": ""
        })