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

import re

UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("※　　　【免空科學研究所　ｔｉｇｅｒｍａｘ．ｄｙｎｄｎｓ．ｏｒｇ】　　　※")
UI.UpdateLog("※　　　～㊣　　　　　　　　　　影楓　　製作分享　　　　　　　㊣～　　　※")
UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("【腳本更新】：2013.03.13",2)
UI.UpdateLog("【上傳空間】：[ES上傳] herosh.com (免空)",2)
UI.UpdateLog("【上傳大小】：200 MB",2)
UI.UpdateLog("【砍檔時間】：未知",2)
UI.UpdateLog("【腳本功能】：無帳號上傳",2)

UI.UpdateLog("※連結至『herosh.com』頁面，請稍候...",4)
URL = "http://herosh.com"
HTML = HTTP.GetURL(URL)
Match = re.search("APC\_UPLOAD\_PROGRESS\" value\=\"([^\"]+)",HTML)
if Match == None:
        UI.UpdateLog("※無法擷取圖片連結網址..." + HTML,3)
        UI.ProceFalse()
        exit()
else:
        APC_UPLOAD_PROGRESS = Match.group(1)
        UI.UpdateLog("※APC_UPLOAD_PROGRESS → " + APC_UPLOAD_PROGRESS,3)
        UI.UpdateLog("※上傳所需參數值擷取成功...",4)
        UI.UpdateLog("=================================================================")
HTTP.ClearProcedureData()
HTTP.AddUpParam("APC_UPLOAD_PROGRESS",APC_UPLOAD_PROGRESS)
HTTP.AddFileReference("file2up[]","application/octet-stream")
UI.UpdateLog("※開始上傳...",4)
HTML=UI.UpFile("http://herosh.com/index.php?page=upload")
Match = re.search("File URL",HTML)
if Match == None:
        UI.UpdateLog("※上傳失敗，網站改版或檔案超過上限值..." + HTML,3)
        UI.ProceFalse()
        exit()
else:
        UI.UpdateLog("※檔案：【" + UI.FileName + "】，上傳成功。",4)
        UI.UpdateLog("=================================================================")
Match = re.search("File URL\: \<a target\=\"\_blank\" href\=\"([^\"]+)",HTML)
if Match == None:
        UI.UpdateLog("※無法擷取下載連結網址..." + HTML,3)
        UI.ProceFalse()
        exit()
else:
        DownloadLink = Match.group(1)
UI.AddShareLink(DownloadLink)
UI.UpdateLog("※下載連結網址：" + DownloadLink,4)
UI.UpdateLog("=================================================================")
UI.ProceSuccess()
exit()