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

import re
import clr
import sys
import System
import random
import string
from os import urandom
from random import choice

#調用EasyScript.dll指令
sys.path.append(UI.StartupPath+'\Script\Module\dll')
clr.AddReferenceToFile("EasyScript.dll")
from EasyScript import *
EasyScript = EasyScript()

UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("※　　　【免空科學研究所　ｔｉｇｅｒｍａｘ．ｄｙｎｄｎｓ．ｏｒｇ】　　　※")
UI.UpdateLog("※　　　～㊣　　　　　　　　　楓　　　痕　　製作分享　　　　　㊣～　　　※")
UI.UpdateLog("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※")
UI.UpdateLog("【腳本更新】：2013.03.28 楓痕 修正原始冏rz內附腳本",2)
UI.UpdateLog("【下載空間】：2shared.com",2)
UI.UpdateLog("【腳本備註】：支援各32/64位元Windows系列",1)
HTTP.ClearProcedureData()
UI.UpdateLog("※連結至 2shared.com 下載網址...",4)
ReResault = re.search("fadmin",UI.Link)
if ReResault != None:
    HTML=HTTP.GetURL(UI.Link)
    DownLink=EasyScript.GetstrToVariable(HTML,'downloadLink" value="','" readonly',1)
    HTML=HTTP.GetURL(DownLink)
    ReResault = re.search("The file link that you requested is not valid",HTML)
    if ReResault != None:
        UI.UpdateLog("檔案不存在...",3)
        UI.ProceFalse()
    else:
        UI.UpdateLog("檔案存在，繼續下載")

    fname=EasyScript.GetstrToVariable(HTML,'width:468px">',' download',1)
    if fname == None:
        UI.UpdateLog("無法取得檔案名稱...",3)
        UI.ProceFalse()
    else:
        UI.UpdateLog("檔案名稱->"+fname)
        UI.FileName = (fname)
        DownloadLink=EasyScript.GetstrToVariable(HTML,'d3link" value="','"',1)
        UI.UpdateLog("開始下載...",4)
        Staus=UI.DownloadURL(DownloadLink)
        if Staus==True:
            UI.UpdateLog("下載成功...!!",3)
        else:
            UI.ProceFalse()
else:
    HTML=HTTP.GetURL(UI.Link)
    ReResault = re.search("The file link that you requested is not valid",HTML)
    if ReResault != None:
        UI.UpdateLog("檔案不存在...",3)
        UI.ProceFalse()
    else:
        fname=EasyScript.GetstrToVariable(HTML,'width:468px">',' download',1)
        UI.UpdateLog("檔案名稱->"+fname)
        UI.FileName = (fname)
        DownloadLink=EasyScript.GetstrToVariable(HTML,'d3link" value="','"',1)
        UI.UpdateLog("開始下載...",4)
        Staus=UI.DownloadURL(DownloadLink)
        if Staus==True:
            UI.UpdateLog("下載成功...!!",3)
        else:
            UI.ProceFalse()