开发者

python wmv stream download

开发者_如何学PythonGiven a wmv file that is streaming online. The file is around 10kb as it does not have any video. If i click on the file it opens windows media player which then connects to the net. Windows media player starts to cache the file and then play the video for me.

Instead I would like my python program to open the file. Grab the content from the net and then download it for me. How would can I do this?


I was facing the same issue and looked into the Python VLC bindings but because I was pressed for time and there was a lack of examples using the bindings, I went for another approach.

The vlc command line is extremely powerful. Using subprocess.call i did direct calls to the vlc command line.

This is the format I used and it worked beautifully.

subprocess.call([path_to_vlc, 
                 mms_url, 
                 '--sout', 
                 'file/avi:'+target_file,
                 'vlc://quit'])

In the part of the list of parameters you send to call, here is a description of each:

  • path_to_vlc -- As the name suggests. You don't have to use " to encapsulate spaces as with os.system for Program Files, etc. subprocess.call does that for you.
  • mms_url -- is the url to the stream. Since in my case it was a mms stream the param name stuck. You can use any of the supported vlc stream prefixes.
  • '--sout' -- since call encapsulate spaces for you, you need to explicitly separate each param where a space is needed. The actual param here is --sout file/avi:.... but we have to split them into two.
  • 'file/avi:'+target_file -- The uri (and muxer) pointing to the target file. I used no path to the file since I was standing in the target directory when calling the python script. The target file should
  • 'vlc://quit' -- Last we tell vlc to quit after playback. This way you get rid of the zombie vlc windows that stick around after.

If you wish to see the full code i used to first find the it here.


You could use the VLC Python bindings to handle the actual downloading and saving.

You'll need to get vlc.py from their Git repo.

Look at Instance.media_new_location.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜