# -*- coding: utf-8 -*-
import re
import sys
import System
import clr

#簡易正規表達式
def Simple_Regular(RegularStr,String,index=0):
    STR=re.search(RegularStr,String)
    if STR is None:
        return False
    else:
        return STR.group(index)

sys.path.append(UI.StartupPath+'\Script\Module\dll')
clr.AddReferenceToFile("EasyScript.dll")

from EasyScript import *
zkm = EasyScript()

UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("※　　　【免空科學研究所　ｔｉｇｅｒｍａｘ．ｄｙｎｄｎｓ．ｏｒｇ】　  ※")
UI.UpdateLog("※　　　～㊣　　　　　　　　　ＺＫＭ　　製作分享　　　　　　　㊣～      ※")
UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("【腳本更新】：2013.03.26 panda0305 撰寫",2)
UI.UpdateLog("【上傳空間】：http://wikisend.com",2)
UI.UpdateLog("【上傳大小】：100 MB",2)
UI.UpdateLog("【砍檔時間】：未知",2)
UI.UpdateLog("【腳本功能】：一般下載",2)
UI.UpdateLog("【腳本備註】：免費用戶下載僅可以開3線",1)
UI.UpdateLog("=========================================",2)
HTML=HTTP.GetURL(UI.Link)
name=zkm.GetstrToVariable(HTML,'<span id="filetitle">','</span>',1) 

if name!=False:
    UI.UpdateLog("準備開始下載檔案"+ name,4)
    UI.UpdateLog("開始下載....",4)
    HTTP.ClearProcedureData()
    HTTP.AddPostParam("act","download")
    HTTP.AddPostParam("confpassw","")
    HTTP.AddPostParam("ffName","")
    HTTP.AddPostParam("fileDesc","")
    HTTP.AddPostParam("passw","")
    HTTP.AddPostParam("storageDays","90")
    HTTP.AddPostParam("x","56")
    HTTP.AddPostParam("y","23")
    #HTTP.Referer=UI.Link
    HTTP.AllowAutoRedirect=False
    HTML1=HTTP.PostURL(UI.Link,HTTP.PostData)
    #UI.UpdateLog(HTML1)
    dllink1=zkm.GetstrToVariable(HTML1,'http://','/',1) 
    dllink2=zkm.GetstrToVariable(HTML1,'node-fs/download/','/',1) 
    dllink="http://"+dllink1+"/node-fs/download/"+dllink2+"/"+name
    UI.UpdateLog(dllink)
    #HTTP.AllowAutoRedirect=True
    UI.FileName=name
    Staus=UI.DownloadURL(dllink)
    if Status==True:
        UI.UpdateLog("下載成功",3)
        UI.ProceSuccess()
    else:
        UI.UpdateLog("錯誤",3)
        UI.ProceFalse()

else:
    UI.UpdateLog("發生錯誤!無法取得必要參數值",3)
    UI.ProceFalse()