july 2009年08月21日 星期五 22:06 | 1801次浏览 | 2条评论
FLV download flvcd.com
#this is a Python wrapper of flvcd.com to facilitate FLV video download
from urllib import FancyURLopener, urlopen, urlencode
import os, re, threading, time
def get(url, fdir):
'''down one file'''
#print '---', url, fdir
os.system('wget -t 0 -c -O "%s" -U ie %s'%(fdir,url))
def getall(lst_url, dir, num_threads=3):
'''down all that belong to one video in to dir;
@param n: number of threads;
'''
try:
os.makedirs(dir)
except:
pass
for i,url in enumerate(lst_url):
fdir = os.path.join(dir, '%02d.flv'%i)
if num_threads:
t = threading.Thread(target=get, args=(url, fdir))
t.start()
while threading.activeCount() > num_threads:
time.sleep(1)
else:
get(url, fdir)
def down(url, dir, n=3):
'''download the video with given one url and dir to save'''
data = {'kw': url,
'flag': '',
'format': ''
}
f = urlopen('http://www.flvcd.com/parse.php?' + urlencode(data))
lst_all = re.findall('> (
http://.*?)</a>'
, f.read())
f.close()
getall(lst_all, dir, n)
def GetClipboardUrl():
try:
import win32con, ctypes
except:
return ''
OpenClipboard = ctypes.windll.user32.OpenClipboard
GetClipboardData = ctypes.windll.user32.GetClipboardData
CloseClipboard = ctypes.windll.user32.CloseClipboard
GlobalLock = ctypes.windll.kernel32.GlobalLock
GlobalUnlock = ctypes.windll.kernel32.GlobalUnlock
url=''
if OpenClipboard(0):
hClipMem = GetClipboardData(win32con.CF_TEXT)
GlobalLock.restype = ctypes.c_char_p
url = GlobalLock(hClipMem)
GlobalUnlock(hClipMem)
CloseClipboard()
return url
if __name__ == '__main__':
url = GetClipboardUrl()
print '---', url
dir = raw_input('dir:')
print '===', dir
os.system('title %s'%dir)
down(url, dir, 5)
Zeuux © 2024
京ICP备05028076号
回复 july 2009年08月22日 星期六 08:46