[wip] show_image(): Introduce struct screen_image with complete but abstract on-scree...
[elinks/images.git] / contrib / smjs / youtube2.js
blob893a9249ff1a94aa6590b03be3ab076b839bcd77
1 /* Play videos at YouTube with minimal niggling. Just load the page for a video,
2 * and the video will automatically be loaded. */
3 function load_youtube(cached, vs) {
4 var par = cached.uri.match(/http:\/\/\w+\.youtube\.com\/watch\?v=([^&]+).*/);
5 if (!par) return true;
7 var t = cached.content.match(/, \"t\": \"([^"]+)\"/);
8 if (!t) return true;
10 var url = 'http://uk.youtube.com/get_video?video_id=' + par[1] + '&t=' + t[1];
12 cached.content = '<a href="' + url + '">View</a>';
14 return true;
16 elinks.preformat_html_hooks.push(load_youtube);
18 /* When one tries to follow a link to <http://www.youtube.com/v/foo>,
19 * redirect to <http://www.youtube.com/watch?v=foo>, which has the information
20 * that is necessary to get the actual video file. */
21 function redirect_embedded_youtube(uri) {
22 var uri_match = uri.match(/http:\/\/\w+\.youtube\.com\/v\/([^&]+).*/);
23 if (!uri_match) {
24 return true;
26 return 'http://uk.youtube.com/watch?v=' + uri_match[1];
28 elinks.follow_url_hooks.push(redirect_embedded_youtube);