使用 Python 从直接 URL 下载视频

Download video from a direct URL with Python

我想用 python 下载视频。我尝试使用 youtube-dl,但不支持我希望从中下载视频的站点。如何下载 Python 中的视频。首先,我尝试获取我想从 keepvid.com 下载的视频的直接 link 之后 link http://www.kmcgraphics.com/bits-of-code/how-to-get-the-direct-url-path-to-flv-video-files-on-youtube-for-free/. I got the following link http://www.animefun.com/dl/googDev.php?url=/108994262975881368074/Po270 当我尝试运行以下代码时,我是出现错误。

import urllib
test=urllib.URLopener()
test.retrieve("http://www.animefun.com/dl/googDev.php?url=/108994262975881368074/Po270.flv","testout.flv")

错误:

Traceback (most recent call last):
File "downl.py", line 14, in <module>
test.retrieve("http://www.animefun.com/dl/googDev.php?url=/108994262975881368074/Po270.flv","testout.flv")
File "/usr/lib/python2.7/urllib.py", line 240, in retrieve
fp = self.open(url, data)
File "/usr/lib/python2.7/urllib.py", line 208, in open
return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py", line 359, in open_http
return self.http_error(url, fp, errcode, errmsg, headers)
File "/usr/lib/python2.7/urllib.py", line 376, in http_error
return self.http_error_default(url, fp, errcode, errmsg, headers)
File "/usr/lib/python2.7/urllib.py", line 381, in http_error_default
raise IOError, ('http error', errcode, errmsg, headers)
IOError: ('http error', 301, 'Moved Permanently', <httplib.HTTPMessage instance at 0x7f094d5d5290>)

我是 Python 的新手。所以请帮帮我。

urllib.URLopener 默认不处理重定向

改用urllib.FancyURLopener

import urllib
test=urllib.FancyURLopener()
test.retrieve("http://www.animefun.com/dl/googDev.php?url=/108994262975881368074/Po270.flv","testout.flv")