Stream youtube videos on XBMC via rss [php script]
#1
Thumbs Up 
Maybe a bit off topic (not a python script but php) but this will allow to directly stream youtube flv videos on XBMC via RSS.

Tested and working 100% on latest build: T3CH XBMC 2007-07-01 SVN rev9489

Enjoy.

PHP Code:
<?php

// Youtube RSS Feed Converter v0.1 - youtube_rss.php
// Stream youtube videos directly on your XBMC via rss feed
// Adds enclosure tags to youtube rss feeds
// Links to the flv videos directly from google cache servers (get video directly from id)

// Usage:
// youtube_rss.php?rss=[recently_added|recently_featured|top_favorites|top_rated|top_viewed_today | top_viewed_week|top_viewed_month|top_viewed]
// youtube_rss.php?user=[username]
// youtube_rss.php?tag=[tag]

// Requirements:
// - Web server running php where to host this file.
// - Snoopy php class: http://sourceforge.net/projects/snoopy/
// - An XBMC script that can stream media from RSS feeds like:
// Xbox Podcast Script - http://www.xbmcscripts.com/?option=com_docman&task=search_result&Itemid=Array&search_mode=phrase&search_phrase=XBox%20Podcast%20Script%20v0.5
// or
// Navi-X - http://www.xbmcscripts.com/?option=com_docman&task=search_result&Itemid=Array&search_mode=phrase&search_phrase=Navi-X%20v1.2

if(isset($_GET['rss'])){
    
$rss $_GET['rss'];
    if(
$rss == 'recently_added'$rss == 'recently_featured' $rss == 'top_favorites' $rss == 'top_rated' $rss == 'top_viewed_today' $rss == 'top_viewed_week' $rss == 'top_viewed_month'$rss == 'top_viewed'){
        
$URL 'http://www.youtube.com/rss/global/'.$rss.'.rss';
    }
} else if(isset(
$_GET['user'])){
    
$user $_GET['user'];
    
$URL 'http://www.youtube.com/rss/user/'.$user.'/videos.rss';
} else if(isset(
$_GET['tag'])){
    
$tag $_GET['tag'];
    
$URL 'http://www.youtube.com/rss/tag/'.$tag.'.rss';
}

include 
"Snoopy-1.2.3/Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->rawheaders["Pragma"] = "no-cache";
$snoopy->expandlinks false;
$snoopy->fetch($URL);

$rss=str_replace('.swf'''$snoopy->results); // get rid of enclosure extension
$rss=str_replace('http://youtube.com/v/''http://cache.googlevideo.com/get_video?video_id='$rss); // enclosure is flv
$rss=str_replace('application/x-shockwave-flash''video/flv'$rss); // adjust mime type
$rss=str_replace('http://youtube.com/?v=''http://cache.googlevideo.com/get_video?video_id='$rss); // make urls link to flv too

echo $rss;

?>
Reply
#2
This kicks ass. It totally makes up for the crappy RSS support in Youtube!
Reply
#3
Thanks for the feedback.
In my opinion this beats having to open the xbmc youtube script all the time.
Reply
#4
deadelvis Wrote:Maybe a bit off topic (not a python script but php) but this will allow to directly stream youtube flv videos on XBMC via RSS.

Tested and working 100% on latest build: T3CH XBMC 2007-07-01 SVN rev9489

Enjoy.

PHP Code:
<?php

// Youtube RSS Feed Converter v0.1 - youtube_rss.php
// Stream youtube videos directly on your XBMC via rss feed
// Adds enclosure tags to youtube rss feeds
// Links to the flv videos directly from google cache servers (get video directly from id)

// Usage:
// youtube_rss.php?rss=[recently_added|recently_featured|top_favorites|top_rated|top_viewed_today | top_viewed_week|top_viewed_month|top_viewed]
// youtube_rss.php?user=[username]
// youtube_rss.php?tag=[tag]

// Requirements:
// - Web server running php where to host this file.
// - Snoopy php class: http://sourceforge.net/projects/snoopy/
// - An XBMC script that can stream media from RSS feeds like:
// Xbox Podcast Script - http://www.xbmcscripts.com/?option=com_docman&task=search_result&Itemid=Array&search_mode=phrase&search_phrase=XBox%20Podcast%20Script%20v0.5
// or
// Navi-X - http://www.xbmcscripts.com/?option=com_docman&task=search_result&Itemid=Array&search_mode=phrase&search_phrase=Navi-X%20v1.2

if(isset($_GET['rss'])){
    
$rss $_GET['rss'];
    if(
$rss == 'recently_added'$rss == 'recently_featured' $rss == 'top_favorites' $rss == 'top_rated' $rss == 'top_viewed_today' $rss == 'top_viewed_week' $rss == 'top_viewed_month'$rss == 'top_viewed'){
        
$URL 'http://www.youtube.com/rss/global/'.$rss.'.rss';
    }
} else if(isset(
$_GET['user'])){
    
$user $_GET['user'];
    
$URL 'http://www.youtube.com/rss/user/'.$user.'/videos.rss';
} else if(isset(
$_GET['tag'])){
    
$tag $_GET['tag'];
    
$URL 'http://www.youtube.com/rss/tag/'.$tag.'.rss';
}

include 
"Snoopy-1.2.3/Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->rawheaders["Pragma"] = "no-cache";
$snoopy->expandlinks false;
$snoopy->fetch($URL);

$rss=str_replace('.swf'''$snoopy->results); // get rid of enclosure extension
$rss=str_replace('http://youtube.com/v/''http://cache.googlevideo.com/get_video?video_id='$rss); // enclosure is flv
$rss=str_replace('application/x-shockwave-flash''video/flv'$rss); // adjust mime type
$rss=str_replace('http://youtube.com/?v=''http://cache.googlevideo.com/get_video?video_id='$rss); // make urls link to flv too

echo $rss;

?>

Tnx..

But how to I install this so I can use it?
Reply
#5
Step1:
Save file as youtube_rss.php on a webserver with PHP support, together with Snoopy class - http://sourceforge.net/projects/snoopy/

Step2:
If necessary in youtube_rss.php edit the line - include "Snoopy-1.2.3/Snoopy.class.php" - to point to the snoopy class.

Step3:
Get an XBMC RSS script that supports enclosures and put it on your xbox. These work for me:
Xbox Podcast Script - http://www.xbmcscripts.com/?option=com_d...ipt%20v0.5
Navi-X - http://www.xbmcscripts.com/?option=com_d...i-X%20v1.2

Step4:
Add desired links pointing to your webserver's youtube_rss.php in the XBMC RSS script. Check "usage" for possible options. Examples:

http://www.yourdomain.com/youtube_rss.php?user=Bob
Will show links to Bob's latest clips.

http://www.yourdomain.com/youtube_rss.php?tag=cool
Will show links to clips tagged "cool".


Hope this helps...
Reply
#6
kk il try it now tnx 4 the fast reply..
will it work with the latest version of xbmc?
Reply
#7
yes. should work with any XBMC version that supports flv (flash video) playback.
Reply
#8
It recently stopped working for me... is there something about cache.google.com not working anymore? It seems to timeout trying to connect...
Reply
#9
Yeah ... this method is no longer possible due to some changes google implemented (links now return a bad request error instead of the flv). Sad

Working on a new solution.
Reply
#10
Quick and dirty solution. Wink
Tested and working 100% on this side.

Although the rss the script outputs seems to be correctly formatted, firefox does not seem to like it for some reason, displaying a blank "subscribe to this feed" page. Shows fine on safari though. If anyone has an idea why... please let me know.

About how the script gets the flv links now... please read the warning below and check the code.

cheers


PHP Code:
<?php

// Youtube RSS Feed Converter v0.2 - youtube_rss.php
// Stream youtube videos directly on your XBMC via rss feed
// Alters youtube rss feeds and links to the flv videos directly

// WARNING:
// Previous approach of linking to google cache servers stopped working.
// To find the link to each .flv this script now does one GET request to youtube per video listed on the RSS!
// This means it is considerably slower, and that every time you load it your server will be doing at least 15 requests 
// to youtube (implementing local caching might be something to consider)... so please be aware of timeouts and be
// patient while waiting for it to load.

// Usage:
// youtube_rss.php?rss=[recently_added|recently_featured|top_favorites|top_rated|top_viewed_today | top_viewed_week|top_viewed_month|top_viewed]
// youtube_rss.php?user=[username]
// youtube_rss.php?tag=[tag]

// Requirements:
// Snoopy php class: [url]http://sourceforge.net/projects/snoopy/[/url]
// An XBMC script that can stream media from rss feeds like:
// Xbox Podcast Script - [url]http://www.xbmcscripts.com/?option=com_docman&task=search_result&Itemid=Array&search_mode=phrase&search_phrase=XBox%20Podcast%20Script%20v0.5[/url]
// or
// Navi-X - [url]http://www.xbmcscripts.com/?option=com_docman&task=search_result&Itemid=Array&search_mode=phrase&search_phrase=Navi-X%20v1.2[/url]

if(isset($_GET['rss'])){
    
$rss $_GET['rss'];
    if(
$rss == 'recently_added'$rss == 'recently_featured' $rss == 'top_favorites' $rss == 'top_rated' $rss == 'top_viewed_today' $rss == 'top_viewed_week' $rss == 'top_viewed_month'$rss == 'top_viewed'){
        
$URL 'http://www.youtube.com/rss/global/'.$rss.'.rss';
    }
} else if(isset(
$_GET['user'])){
    
$user $_GET['user'];
    
$URL 'http://www.youtube.com/rss/user/'.$user.'/videos.rss';
} else if(isset(
$_GET['tag'])){
    
$tag $_GET['tag'];
    
$URL 'http://www.youtube.com/rss/tag/'.$tag.'.rss';
}

include 
"Snoopy-1.2.3/Snoopy.class.php";

function 
flvurl ($URL) {
    
$snoopy = new Snoopy;
    
$snoopy->rawheaders["Pragma"] = "no-cache";
    
$snoopy->expandlinks false;
    
$snoopy->fetch($URL);
    
$page $snoopy->results;
    
preg_match('/watch_fullscreen\?video_id=(.*?)&l=(.*?)+&t=(.*?)&/'$page$match);
    
$URL "http://www.youtube.com/get_video?video_id=".$match[1]."&t=".$match[3];
    return 
$URL;
}

$snoopy = new Snoopy;
$snoopy->rawheaders["Pragma"] = "no-cache";
$snoopy->expandlinks false;
$snoopy->fetch($URL);
$rss $snoopy->results;

preg_match_all('/<media:player url="(.*?)" \/>/'$rss$matches);
preg_match_all('/<enclosure url="(.*?)"/'$rss$matches2);

for(
$i=0$i<sizeof($matches[1]); $i++){
    
$match $matches[1][$i];
    
$match2 $matches2[1][$i];
    
$URL flvurl($match);
    
$rss str_replace($match$URL$rss);
    
$rss str_replace($match2$URL$rss);
    
$rss str_replace("application/x-shockwave-flash""video/x-flv"$rss);
}

echo 
$rss;

?>
Reply
#11
hi all

is this script still the best solution for the problem at hand? last update end of 2007, does it really work so well it doesnt need any updates or can xbmc handle this natively now?
xbmc-pvr-ppa-odk68, Gentoo x86 3.0.7-pf, xorg-server-1.11.2, mesa-7.11, nvidia-drivers-290.10
Reply

Logout Mark Read Team Forum Stats Members Help
Stream youtube videos on XBMC via rss [php script]0