playlist = grab_xml(playlist_url)
for video_desc in playlist.xpath("//video"):
video_desc_url = video_desc.xpath("@src")[0]
- title = video_desc.xpath("title/text()")[0]
+ title = video_desc.xpath("title/text()")[0].strip()
video_list[title] = (title, video_desc_url)
return video_list
def download_urllib(filename, url):
print "Downloading: %s -> %s" % (url, filename)
- src = urllib.urlopen(url)
- dst = open(filename, "w")
- shutil.copyfileobj(src, dst)
- src.close()
- dst.close()
+ try:
+ src = urllib.urlopen(url)
+ dst = open(filename, "w")
+ shutil.copyfileobj(src, dst)
+ except KeyboardInterrupt:
+ print "\nCancelled", url
+ finally:
+ src.close()
+ dst.close()
def main():
while True: