home *** CD-ROM | disk | FTP | other *** search
-
- #name: gaogao libraly
- #author: Wolfy
- #homepage: http://gaogao.tripod.co.jp/
-
- import sys,httplib,re,urlparse,string,os.path
-
- #const
- TRUE = 1
- FALSE = 0
-
- ERROR = 0 #Ä╕ös
- SUCCESS = 1 #É│ÅφÅIù╣
- TERMINATE = 2 #âXâîâbâhé≡ÆΓÄ~é╡é▄é╖
- IGNORE = 3 #îïë╩é═û│Äïé│éΩé▄é╖
- TERMINATE_SUCCESS = 4 #âXâîâbâhé≡ï¡ÉºôIé╔ɼî≈ÅIù╣é╡é▄é╖
- EXIT = 5 #ûóÄ└ìsé╠âXâNâèâvâgé¬éáé┴é─éαâCâxâôâgé≡ÅIù╣
- SUCCESS_EXIT = 6 #ûóÄ└ìsé╠âXâNâèâvâgé¬éáé┴é─éαâCâxâôâgé≡É│ÅφÅIù╣
-
- def parse_url(url,protocol = ''):
- r'''ò╘Ælé═urlÅεò±é╠ôⁿé┴é╜Ľſ protocol://user:pass@host:port/path?query'''
- u = {'protocol':'http','host':'','port':'','user':'','password':'','path':'/','dir':'/','filename':'index.html','query':''}
- u['url'] = url
- tmp = url
- protocol = string.lower(protocol)
- #protocolé≡ĵéΦÅoé╖
- idx = string.find(tmp,'://')
- if idx == -1:
- u['protocol'] = protocol
- else:
- u['protocol'] = tmp[0:idx]
- tmp = tmp[idx + 3:]
- #host
- idx = string.find(tmp,'/')
- #pathé¬û│é»éΩé╬
- if idx == -1:
- host = tmp[0:]
- tmp = '/'
- else: #pathé¬éáéΩé╬
- host = tmp[0:idx]
- tmp = tmp[idx:]
-
- u['path'] = tmp
- #dir
- u['dir'] = os.path.dirname(tmp)
- #filename
- u['filename'] = os.path.basename(tmp)
- #query
- idx = string.find(u['filename'],'?')
- if idx > -1:
- u['query'] = u['filename'][idx + 1:]
-
- #user&pass
- idx = string.find(host,'@')
- #user&passé╚é╡
- if idx == -1:
- idx = string.find(host,':')
- #porté╚é╡
- if idx == -1:
- u['host'] = host
- else: #portéáéΦ
- u['host'] = host[0:idx]
- u['port'] = host[idx + 1:]
- else: #user&passéáéΦ
- tmp2 = host[0:idx]
- tmp3 = host[idx + 1:]
- idx = string.find(tmp2,':')
- if idx > -1:
- u['user'] = tmp2[0:idx]
- u['password'] = tmp2[idx + 1:]
- #host&port
- idx = string.find(tmp3,':')
- #porté╚é╡
- if idx == -1:
- u['host'] = tmp3
- else: #portéáéΦ
- u['host'] = tmp3[0:idx]
- u['port'] = tmp3[idx + 1:]
-
- return u
- #end parse_url
-
- def extract_url(url,proxy = ''):
- r'''ò╘Ælé═ host,port,pathé╠â^âvâï'''
- url_info = parse_url(url,'http')
- #proxyé¬éáéΘé╚éτé╬
- if proxy:
- #pathé═URL
- if url_info['port']:
- path = url_info['protocol'] + '://' + url_info['host'] + ':' + url_info['port'] + url_info['path']
- else:
- path = url_info['protocol'] + '://' + url_info['host'] + url_info['path']
-
- #porté≡â`âFâbâN
- proxy_info = parse_url(proxy)
- host = proxy_info['host']
- try:
- port = string.atoi(proxy_info['port'])
- except:
- port = 8080
- else: #proxyé╚é╡
- #pathé═é╗é╠é▄é▄path
- path = url_info['path']
- host = url_info['host']
- try:
- port = string.atoi(url_info['port'])
- except:
- port = 80
-
- return (host,port,path)
- #end extract_url
-
- def restore_webjump(url):
- r'''ò╘Ælé═ webjumpé╠î│é╠Url
- http://freehosting1.at.webjump.com/0919a3cc8/ac/acount-webjump/filename.jpg'''
-
- m = re.search(r'freehosting[0-9]*\.at\.webjump\.com',url,re.IGNORECASE)
- #â}âbâ`é╡é╜
- if m:
- #âAâJâEâôâgé≡ÆTé╖
- m = re.search(r'/[^/]+-webjump/',url,re.IGNORECASE)
- if m:
- acount = url[m.start(0) + 1:m.end(0) - 9]
- path = url[m.end(0) - 1:]
- #ɼî≈
- return 'http://' + acount + '.webjump.com' + path
-
- return url
- #end restore_webjump
-
- def restore_homestead(url):
- r'''ò╘Ælé═homesteadé╠î│é╠url
- http://freeload.homestead.com/_ksi0701961600708147/acount/files/filename'''
-
- m = re.search(r'freeload.*\.homestead\.com/',url,re.IGNORECASE)
- if m:
- path = url[m.end(0) - 1:]
- m = re.search(r'/[^/]*/files/.*',path,re.IGNORECASE)
- if m:
- return 'http://www.homestead.com' + path[m.start(0):]
-
- return url
- #end restore_homestead
-
- def replace_renren(url):
- r'''ò╘Ælé═Æuè╖é╡é╜renrené╠Url'''
-
- m = re.search(r'renren\.com/.+/',url,re.IGNORECASE)
- if m:
- user = url[m.start(0) + 11: m.end(0) - 1]
- path = url[m.end(0) - 1:]
- return 'http://www.renren.com/js/download.DPage?user=' + user + '&path=' + path
- else:
- return url
- #end replace_renren
-
-
-