# -*- coding: utf-8 -*-

import re

#簡易正規表達式
def Simple_Regular(RegularStr,String,index=0):
    STR=re.search(RegularStr,String)
    if STR is None:
        return False
    else:
        return STR.group(index)
    
UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("※　　　【免空科學研究所　ｔｉｇｅｒｍａｘ．ｄｙｎｄｎｓ．ｏｒｇ】　　　※")
UI.UpdateLog("※　　　～㊣　　　　　　　　　ＺＫＭ　　製作分享　　　　　　　㊣～　　　※")
UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("【腳本更新】：2013.03.12 panda0305 撰寫腳本",2)
UI.UpdateLog("【上傳空間】：ImageShack.us",2)
UI.UpdateLog("【上傳大小】：未知",2)
UI.UpdateLog("【砍檔時間】：未知",2)
UI.UpdateLog("【腳本功能】：無帳號上傳",2)
UI.UpdateLog("【腳本備註】：支援各32/64位元Windows系列",1)
UI.UpdateLog("=========================================",2)
HTML=HTTP.GetURL("http://www.imageshack.us/")
UI.UpdateLog("正在準備上傳參數")
key=Simple_Regular('hidden" name="key" value="(.+?)"',HTML,1)

UI.UpdateLog("取得key 參數->"+key)
UI.UpdateLog("開始上傳....",4)
HTTP.AddUpParam("Filename",UI.FileName)
HTTP.AddUpParam("swfupload","1")
HTTP.AddUpParam("key",key)
HTTP.AddUpParam("new_flash_uploader","y")
HTTP.AddUpParam("ulevel","null")
HTTP.AddUpParam("rem_bar","null")
HTTP.AddUpParam("rembar","0")
HTTP.AddUpParam("myimages","null")
HTTP.AddUpParam("optsize","resample")
HTTP.AddUpParam("isUSER","null")
HTTP.AddUpParam("always_opt","resample")
HTTP.AddUpParam("Upload","Submit Query")
HTTP.AddFileReference("Filedata","image/pjpeg")
HTML=UI.UpFile("http://iload5.imageshack.us/upload_api.php")
#UI.UpdateLog(HTML)
alink=Simple_Regular('http:\/\/img\d+\.(.+?)<\/image_link>',HTML,1)
if alink!=False:
  blink="http://a."+alink
  UI.UpdateLog("下載連結->"+blink,4)
  UI.AddShareLink(blink)
  UI.ProceSuccess()
else:
  UI.UpdateLog("無法取得網址",3)
  UI.ProceFalse()
    