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

UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("※　　　【免空科學研究所　ｔｉｇｅｒｍａｘ．ｄｙｎｄｎｓ．ｏｒｇ】　  ※")
UI.UpdateLog("※　　　～㊣　　　　　　　　　Ｚ８９　　製作分享　　　　　　　㊣～      ※")
UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("【腳本更新】：2013.03.15 z89 撰寫",2)
UI.UpdateLog("【上傳空間】：http://www.embedupload.com/",2)
UI.UpdateLog("【上傳大小】：4 MB",2)
UI.UpdateLog("【砍檔時間】：未知",2)
UI.UpdateLog("【腳本功能】：無帳號上傳",2)
UI.UpdateLog("【腳本備註】：分流空上傳",1)
UI.UpdateLog("=========================================",2)

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):       
              html=HTTP.GetURL(linka[x])
              link=Simple_Regular("target='_blank'>([^\s]+)<\/a>",html,1)
              UI.UpdateLog(link)

html=HTTP.GetURL("http://www.embedupload.com/")
upload_url=Simple_Regular('upload_url: "([^\s]+)"',html,1)
UI.UpdateLog("開始上傳....",4)
HTTP.ClearProcedureData()
HTTP.AddUpParam("Filename",UI.FileName)
HTTP.AddUpParam("Fichier",1)
HTTP.AddUpParam("Filerio",1)
HTTP.AddUpParam("do","upload")
HTTP.AddUpParam("Hipfile","1")
HTTP.AddUpParam("Zshare","1")
HTTP.AddUpParam("Crocko","1")
HTTP.AddUpParam("Zippyshare","1")
HTTP.AddUpParam("Uptobox","1")
HTTP.AddUpParam("site","http://")
HTTP.AddUpParam("Netload","1")
HTTP.AddUpParam("2shared","1")
HTTP.AddUpParam("Upload","Submit Query")
HTTP.AddUpParam("upload_id","")
HTTP.AddFileReference("file_1")
HTML=UI.UpFile(upload_url)
embedupload=("http://www.embedupload.com/?d="+HTML)
html=HTTP.GetURL(embedupload)
oov=Simple_Regular('(You can download from these site)',html,1)
if oov!=False:
            UI.UpdateLog('上傳成功',1)
            UI.UpdateLog('em連結：'+embedupload,4)
            UI.AddShareLink(embedupload)
            UI.UpdateLog('30秒後進行取連結',1)
            UI.Sleep(30,False)
            UI.UpdateLog('開始取分流連結',1)
            html=HTTP.GetURL(embedupload)
            linka=Matches(html,'<a href="([^\s]+)" target="_blank" class="DownloadNow">')
            x=-1
            for v in linka:  
                  x=sum(x,1)
                  suma(x)                  
            UI.ProceSuccess()
else:
            UI.UpdateLog("上傳失敗",3)