VuGen Scripting for YouTube Video
Video has seen a massive surgance on the internet with the launch of YouTube and other video sharing web sites. This raises some interesting challenges beyond simple scripting in VuGen; with a combination of Javascript, Adobe Flash and HTTP partial download support.
This article will show you how to play a video, and save it to your hard drive.
Okay, first step. Old style web video basically streams web video to the user on a “best-effort” basis…this sort of video can be recorded using the Media Player (MMS) protocol in VuGen. However Flash Video is comprised of an embedded flash SWF file which downloads a FLV video file over standard HTTP.
The steps within this example script for this tech tip are:
- Go to the video page (e.g. http://www.youtube.com/watch?v=J—aiyznGQ)
- Play the Video. Capturing the FLV file to your local disk.
For obvious reasons, we are removing any advertisting requests. The aim is to capture the YouTube video and save it to the local hard drive.
Getting Started
The first step is to create a new script using the standard Web (HTTP/HTML) protocol. After doing that, add the following three lines to your script.
web_set_max_html_param_len("50000000"); web_set_timeout("RECEIVE", "300"); web_set_timeout("STEP", "300");
These lines increase the parameter length limit to 50MB (for storing our video data), and increase the download timeout to 5 minutes (you may need to increase this further if you’re running on a slow connection.
The next step is to navigate to the Video. I’ve included the famous “Keyboard Cat” video, but I suggest that you parameterize this and navigate to any YouTube video.
web_reg_save_param("videoid", "LB=\"video_id\": \"", "RB=\"", "Ord=1", LAST); web_reg_save_param("t", "LB=\"t\": \"", "RB=%3D\"", "Ord=1", LAST); web_reg_save_param("fmt", "LB=fmt_url_map\": \"", "RB=%7", "Ord=1", LAST); web_reg_save_param("swfplayer", "LB=canPlayV9Swf() ? \"", "RB=.swf", "Ord=1", "NotFound=Error", LAST); web_reg_save_param("playbackhost", "LB=%7Chttp%3A%2F%2F", "RB=%", "Ord=1", "NotFound=Error", LAST); web_reg_save_param("itag", "LB=itag%3D", "RB=%", "Ord=1", "NotFound=Error", LAST); web_reg_save_param("ipbits", "LB=ipbits%3D", "RB=%", "Ord=1", "NotFound=Error", LAST); web_reg_save_param("signature", "LB=signature%3D", "RB=%", "Ord=1", "NotFound=Error", LAST); web_reg_save_param("sver", "LB=sver%3D", "RB=%", "Ord=1", "NotFound=Error", LAST); web_reg_save_param("expire", "LB=expire%3D", "RB=%", "Ord=1", "NotFound=Error", LAST); web_reg_save_param("key", "LB=key%3D", "RB=%", "Ord=1", "NotFound=Error", LAST); web_reg_save_param("factor", "LB=factor%3D", "RB=%", "Ord=1", "NotFound=Error", LAST); web_reg_save_param("burst", "LB=burst%3D", "RB=%", "Ord=1", "NotFound=Error", LAST); web_reg_save_param("id", "LB=%26id%3D", "RB=%", "Ord=1", "NotFound=Error", LAST); web_url("watch", "URL=http://www.youtube.com/watch?v=J---aiyznGQ", "Resource=0", "RecContentType=text/html", "Mode=HTML", LAST);
Next we download the Flash player file and send a get_video request. The get_video request doesn’t actually return any content, but is part of how YouTube operates.
web_url("LoadPlayer", "URL={swfplayer}.swf", "TargetFrame=", "Resource=0", "Mode=HTML", LAST); web_url("get_video", "URL=http://www.youtube.com/get_video?video_id={videoid}&t={t}=&el=detailpage&ps=&fmt={fmt}&noflv=1", "TargetFrame=", "Resource=0", "Referer={swfplayer}.swf", "Mode=HTML", LAST);
The last step is to download the FLV file.
We use the code snippet from http://www.jds.net.au/tech-tips/vugen-code-snippets to save the downloaded FLV to our local disk.
web_add_header("x-flash-version", "10,0,32,18"); web_add_header("UA-CPU", "x86"); web_reg_save_param("FLVContents", "LB=", "RB=", "Search=Body", LAST); web_url("videoplayback", "URL=http://{playbackhost}/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Cburst%2Cfactor&fexp=900018&itag={itag}&ipbits={ipbits}&signature={signature}&sver={sver}&expire={expire}&key={key}&factor={factor}&burst={burst}&id={id}&redirect_counter=1", "TargetFrame=", "Resource=0", "Referer={swfplayer}.swf" "Mode=HTML", LAST); size = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE); jds_save_file(lr_eval_string("Keyboard Cat.flv"), lr_eval_string("{FLVContents}"), size);
That’s it !!!!
Just a word of caution. I don’t provide this script with the intention that you actually run Load Tests against YouTube…that would be a very bad idea. This is technical example for interest purposes only.
Related posts:
- WDiff Replacement for VuGen One of the quick ways to identify those areas in...
- Parameterising Unix/Posix timestamps in VuGen A common question from people creating web-based VuGen scripts is...
- DNS-based load balancing for virtual users In DNS-based load balancing, a website visitor will request a...
- VuGen Code Snippets This is a repository of code snippets. Please send me...
- VuGen Feature Requests VuGen is a great tool for developing scripts to emulate...
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply