使用 Python 从 .swf 中提取视频 [英] Extract video from .swf using Python

查看:91
本文介绍了使用 Python 从 .swf 中提取视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了生成视频链接的代码,例如下面的视频.获得后,我尝试以这种方式下载它:

I've written code that generated the links to videos such as the one below. Once obtained, I try to download it in this manner:

import urllib.request
import os

url = 'http://www.videodetective.net/flash/players/?customerid=300120&playerid=351&publishedid=319113&playlistid=0&videokbrate=750&sub=RTO&pversion=5.2%22%20width=%22670%22%20height=%22360%22'
response = urllib.request.urlopen(url).read()
outpath = os.path.join(os.getcwd(), 'video.mp4')
videofile = open(outpath , 'wb')
videofile.write(response)
videofile.close()   

我得到的只是那个目录中一个 58kB 的文件,无法读取.有人能指出我正确的方向吗?

All I get is a 58kB file in that directory that can't be read. Could someone point me in the right direction?

推荐答案

使用您的代码,您不是在此处下载编码的视频文件,而是用于播放视频的 Flash 应用程序(CWS 格式).它在浏览器中执行并动态加载和播放视频.您需要应用一些逆向工程来找出实际的视频源.以下是我的尝试:

With your code, you aren't downloading the encoded video file here, but the flash application (in CWS-format) that is used to play the video. It is executed in the browser and dynamically loads and plays the video. You'd need to apply some reverse-engineering to figure out the actual video source. The following is my attempt at it:

解压 SWF 文件

首先,将您提到的 58K 文件保存在硬盘上,名称为 test.swf(或类似名称).然后,您可以使用小的 Perl 脚本 cws2fws:

First, save the 58K file you mentioned on your hard disk under the name test.swf (or similiar). You can then use the small Perl script cws2fws for that:

perl cws2fws test.swf

这会在同一目录中生成一个名为 test.fws.swf 的新文件

This results in a new file named test.fws.swf in the same directory

在 FWS 文件中搜索配置 URL

我用了一个简单的

strings test.fws.swf | grep http

产生的结果:

...
cookieOhttp://www.videodetective.net/flash/players/flashconfiguration.aspx?customerid=
...

有趣.让我们尝试将我们已知的 customeridplayeridpublishedid 参数放到这个 URL 中:

Interesting. Let's try to put our known customerid, playerid and publishedid arguments to this URL:

http://www.videodetective.net/flash/players/flashconfiguration.aspx?customerid=300120&playerid=351&publishedid=319113

如果我们在浏览器中打开它,我们可以看到播放器配置 XML,这反过来又指向我们

If we open that in a browser, we can see the player configuration XML, which in turn points us to

http://www.videodetective.net/flash/players/playlist.aspx?videokbrate=450&version=4.6&customerid=300120&fmt=3&publishedid=&sub=

现在,如果我们打开它,我们终于可以看到源 URL:

Now if we open that, we can finally see the source URL:

http://cdn.videodetective.net/svideo/mp4/450/6993/293732.mp4?c=300120&r=450&s=293732&d=153&sub=&ref=&fmt=4&e=20111228220329&h=03e5d78201ff0d2f7df9a

现在我们可以下载这个 h264 视频文件,我们就完成了.

Now we can download this h264 video file and we are finished.

在 Python 脚本中自动化整个过程

这是一个完全不同的任务(留给读者作为练习).

This is an entirely different task (left as an exercise to the reader).

这篇关于使用 Python 从 .swf 中提取视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆