machine learning公开课的字幕获取脚本


话说10月10日斯坦福开始的machine learning很有意思,网站在这,而且视频可以下载,观看起来非常方便,但是有个问题就是下载下来的视频没有字幕,而从网上的视频有字幕,于是可以写个程序将字幕搞下来。

感谢scturtle提供的最初的脚本程序

下面是我经过修改的精简版,只要输入视频的文件名(名字中不要有后缀名)就可以下载字幕了

# coding: utf-8
import urllib2,os
import sys,re,codecs

limit=[60,60,60,1000]
def xml2srt(fi,fo):
    data=''.join((fi.split('\n')[9:-4])).strip().split('

') for i in range(0,len(data)-1): if data[i]: st_st=data[i].index('"') st_ed=data[i].index('"',st_st+1) if i+1')+1:].replace('\n',' ')+' \n\n\n' for i,stamp in enumerate(stamps): stamp=stamp.split('.') stamps[i]=map(int,stamp[0].split(':')) stamps[i].append(int(stamp[1])) stamps=map(lambda s:"%02d:%02d:%02d,%03d" % tuple(s),stamps) fo.write("%s --> %s \n" % tuple(stamps)) fo.write(word) print 'OK!' baseurl='http://s3.amazonaws.com/stanford_videos/cs229/subtitles/%s-subtitles.xml' fn=raw_input('file name:') if os.path.exists(fn+'.srt'): print 'file exit!' exit(0) fi=urllib2.urlopen(baseurl % fn).read() fo=file(fn+'.srt','w') xml2srt(fi,fo) fo.close() print 'Done'

为了方便使用,我还制作了windows下可执行的exe的程序,直接运行run.exe输入视频名就可以了,这里下载

您可能喜欢:
我猜您可能还喜欢:
, ,

有 12 条《machine learning公开课的字幕获取脚本》的回复

  1. sth | #1

    请问文件名是指什么,machine learning?

  2. Mrl | #2

    thanks a lot!!!

  3. Dean | #3

    使用说明能不能提供下?我输入了 但是机器没有反应,下载下来的位置是哪里?

  4. Yatao Bian | #4

    但是现在视频文件的名字好像改了,原来视频文件的名字你知道吗?

  5. 🌈一元VPS優惠!站群服務器如雲,穩定如山!http://csplat888.net🌈1 Yuan VPS Deals! Site-cluster servers plentiful as clouds, stable as mountains! http://csplat888.net

Trackbacks/Pingbacks:

  1. gevent初步 | 吃杂烩
  2. 查找第K小的元素 | 吃杂烩
  3. Thought this was cool: 查找第K小的元素 « CWYAlpha
  4. Recommended Online Courses for Computer Science Students | Science Matrix

发表回复