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

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

from EasyScript import *
zkm = EasyScript()

def Simple_Regular(RegularStr,String,index=0):
    STR=re.search(RegularStr,String)
    if STR is None:
        return False
    else:
        return STR.group(index)

def Matches(*s):
    html=s[0]
    sstr=s[1]
    lens=re.findall(sstr,html)
    ss=[]
    if s[len(s)-1]!=False:
        for i, v in enumerate(lens):
            ss.append(v)
    return lens

def sum(a, b, c = 0):
    return a + b + c

def suma(x):       
              setlink=zkm.ReplaceVariable(linka[x],'http://adf.ly/658999/','')
              UI.UpdateLog(setlink)


UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("※　　　【免空科學研究所　ｔｉｇｅｒｍａｘ．ｄｙｎｄｎｓ．ｏｒｇ】　  ※")
UI.UpdateLog("※　　　～㊣　　　　　　　　　ＺＫＭ　　製作分享　　　　　　　㊣～      ※")
UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("【腳本更新】：2013.03.27 panda0305 撰寫",2)
UI.UpdateLog("【上傳空間】：http://www.filebox.bg",2)
UI.UpdateLog("【上傳大小】：200 MB",2)
UI.UpdateLog("【砍檔時間】：未知",2)
UI.UpdateLog("【腳本功能】：無帳號上傳",2)
UI.UpdateLog("【腳本備註】：分流空上傳",1)
UI.UpdateLog("=========================================",2)
time=str(zkm.GetTime())
html=HTTP.GetURL("http://www.filebox.bg/ubr_link_upload.php?rnd_id="+time)
upid=Simple_Regular('startUpload\("(.+?)"',html,1)
upurl="http://www.filebox.bg/cgi-bin/ubr_upload.pl?upload_id="+upid
getlink="http://www.filebox.bg/process.php?upload_id="+upid
UI.UpdateLog("上傳網址 為"+upurl,1)
UI.UpdateLog("轉頁網址 為"+getlink,1)
UI.UpdateLog("取得當前任務檔名："+UI.FileName)
UI.UpdateLog("開始上傳....",4)
HTTP.ClearProcedureData()
HTTP.AddUpParam("mail","")
#HTTP.AddUpParam("rapidshare","on")
HTTP.AddUpParam("zippyshare","on")
#HTTP.AddUpParam("mediafire","on")
HTTP.AddUpParam("depositfiles","on")
#HTTP.AddUpParam("_2shared","on")
#HTTP.AddUpParam("hotfile","on")
HTTP.AddUpParam("netload","on")
HTTP.AddUpParam("easyshare","on")
HTTP.AddFileReference("upfile_0")
status=UI.UpFile(upurl)
#UI.UpdateLog(status)
html1=HTTP.GetURL(getlink)
#UI.UpdateLog(html)
if html1!=False:
            Link=zkm.GetstrToVariable(html1,'Your download link is: <a href="files/','/',1)
            check="http://www.filebox.bg/status.php?uid="+Link
            UI.UpdateLog('上傳成功',1)
            UI.UpdateLog('分流連結：'+check,4)
            UI.AddShareLink(check)
            UI.UpdateLog('60秒後進行取連結',1)
            UI.Sleep(60,False)
            UI.UpdateLog('開始取分流連結',1)
            html=HTTP.GetURL(check)
            #UI.UpdateLog(html,1)
            linka=Matches(html,'src=\/images\/.+?<a href=([^ ]+)')
            UI.UpdateLog(linka)
            x=-1
            for v in linka:  
                  x=sum(x,1)
                  suma(x)                  
            UI.ProceSuccess()
else:
            UI.UpdateLog("上傳失敗",3)