# -*- 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="http://www.1filesharing.com"+linka[x]
              #UI.UpdateLog(setlink)
              HTTP.Referer=check
              html1=HTTP.GetURL(setlink)
              #UI.UpdateLog(html1)
              Links=zkm.GetstrToVariable(html1,'<iframe id="download" src="','"',1)
              UI.UpdateLog(Links)

UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("※　　　【免空科學研究所　ｔｉｇｅｒｍａｘ．ｄｙｎｄｎｓ．ｏｒｇ】　  ※")
UI.UpdateLog("※　　　～㊣　　　　　　　　　ＺＫＭ　　製作分享　　　　　　　㊣～      ※")
UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("【腳本更新】：2013.03.26 panda0305 撰寫",2)
UI.UpdateLog("【上傳空間】：http://www.1filesharing.com",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.1filesharing.com/ubr_link_upload.php?rnd_id="+time)
upid=Simple_Regular('startUpload\("(.+?)"',html,1)
upurl="http://www.1filesharing.com/cgi-bin/ubr_upload.pl?upload_id="+upid
gelink="http://www.1filesharing.com/process.php?upload_id="+upid
UI.UpdateLog("上傳網址 為"+upurl,1)
UI.UpdateLog("轉頁網址 為"+gelink,1)
UI.UpdateLog("取得當前任務檔名："+UI.FileName)
UI.UpdateLog("開始上傳....",4)
HTTP.ClearProcedureData()
HTTP.AddUpParam("rapidshare","on")
HTTP.AddUpParam("abcdownload","on")
HTTP.AddUpParam("sendspace","on")
HTTP.AddUpParam("zippyshare","on")
HTTP.AddUpParam("uploadedto","on")
HTTP.AddUpParam("jumbofiles","on")
HTTP.AddUpParam("queenshare","on")
HTTP.AddUpParam("davvas","on")
HTTP.AddUpParam("freestorage","on")
HTTP.AddUpParam("uptobox","on")
HTTP.AddFileReference("upfile_0")
status=UI.UpFile(upurl)
html=HTTP.GetURL(gelink)
if html!=False:
            Link=zkm.GetstrToVariable(html,'http://www.1filesharing.com/mirror/','/',1)
            check="http://www.1filesharing.com/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\/\S+\.jpg.+?<a href=([^ ]+) target=_blank>')
            UI.UpdateLog(linka)
            x=-1
            for v in linka:  
                  x=sum(x,1)
                  suma(x)                  
            UI.ProceSuccess()
else:
            UI.UpdateLog("上傳失敗",3)