Flash and ubuntu part 2

A few days after my first part on flash on ubuntu, I  made a greasemonkey script, that works on youtube, and (via a httprequest to a php page) downloads the video and converts it to a ogg theora. Then the embed tag is replaced by a html 5 video tag.

Script (JS):

// ==UserScript==
// @name Youtube OGGER
// @namespace userscripts.org
// @description Converts youtube's FLV files to OGG Theora files
// @version 0.1
// @include http://youtube.com/watch?*
// @include http://www.youtube.com/watch?*
// @include http://*.youtube.com/watch?*
// ==/UserScript==
var video_id = null;
var video_hash = null;
var video_player = document.getElementById('movie_player');
if (video_player) {var flash_variables=video_player.attributes.getNamedItem('flashvars');
if (flash_variables) {var flash_values=flash_variables.value; }
}
document.getElementById('watch-player-div').innerHTML='Even geduld...';
GM_xmlhttpRequest({
method: "GET",
url: "http://localhost/youtubeoggs/youtubeogger.php?fv="+flash_values+"&url="+location.href,
headers: {
"User-Agent": "Mozilla/5.0", // Recommend using navigator.userAgent when possible
},
onload: function(response) {
if (response.status == 200) {
var div_embed=document.getElementById('watch-player-div');
if (div_embed) {
div_embed.innerHTML='your browser does not support the video tag';
}
}
}
});

Script (PHP) :

$fv=$_GET['fv'];
$url=$_GET['url'];
$urlmap=$_GET['fmt_url_map'];
preg_match("/v\=([A-Za-z0-9]+)/",$url,$videoIDarr);
$videoID=$videoIDarr[1];
if (!file_exists("/var/www/youtubeoggs/ogg/y-".$videoID.".ogg")) {
$urlMapArr=explode("http",$urlmap);
$stanQual="http".$urlMapArr[count($urlMapArr)-1];
exec("wget -O flv/y-".$videoID.".flv \"".$stanQual."\"");
exec("ffmpeg -i flv/y-".$videoID.".flv -vcodec libtheora -sameq -acodec libvorbis -ac 2 -sameq ogg/y-".$videoID.".ogg");
}
echo "http://localhost/youtubeoggs/ogg/y-".$videoID.".ogg";

However, you need ffmpeg for it. Any room for improvement? Any idea’s on how to make it faster? (it is quite slow)

Advertisement
Published in: on 26/08/2009 at 20:09  Leave a Comment  
Tags: , , , , , ,

The URI to TrackBack this entry is: http://wimweb.wordpress.com/2009/08/26/flash-and-ubuntu-part-2/trackback/

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.