Create a gist now

Instantly share code, notes, and snippets.

Embed
Quick, Dirty 'n' Hacky Method to Send Video URL's to Kodi/XBMC
<!DOCTYPE html>
<html lang=”en”>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
Enter URL:
<input type="text" style="width: 300px;" value="http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi">
<button>Send..</button>
</br></br>
<textarea id="kodioutput" cols="150" rows="10"></textarea>
</body>
<script>
// 'Hacky' Way To Send URL's To Kodi/XBMC Using JS/JQuery
// Address And Port For Your Kodi Install
var KodiAddress = 'http://192.168.0.1:80';
// Send URL To Kodi On Button Click
$( 'button' ).click( function() {
var kodioutput = $( '#kodioutput' );
var URL = $( 'input' ).val(); // Grab Input Value
// Proceed On URL Not Being Empty (Validate URL Perhaps)
if ( URL !== '' ) {
kodioutput.val( kodioutput.val() + "Sending " + URL + "........" );
$.ajax({
type: 'GET',
url: KodiAddress + '/jsonrpc',
dataType: 'jsonp',
jsonpCallback: 'jsonCallback',
type: 'GET',
async: true,
timeout: 5000,
data: 'request=' + encodeURIComponent( '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"' + URL + '"}},"id":"1"}' )
})
// If Success, Notify User
.done( function( data, textStatus, jqXHR ) {
if ( jqXHR.status == 200 && data['result'] == 'OK' ) {
kodioutput.val( kodioutput.val() + "done!\n" );
} else {
kodioutput.val( kodioutput.val() + "error!\n" );
}
})
// Older Versions Of Kodi/XBMC Tend To Fail Due To CORS But Typically If A '200' Is Returned Then It Has Worked!
.fail( function( jqXHR, textStatus ) {
if ( jqXHR.status == 200 ) {
kodioutput.val( kodioutput.val() + "done!\n" );
} else {
kodioutput.val( kodioutput.val() + "error - " + textStatus + "!\n" );
}
});
}
});
</script>
</html>
@DomSless

This comment has been minimized.

Show comment
Hide comment
@DomSless

DomSless Aug 8, 2015

Updated for versions that allow CORS.

Owner

DomSless commented Aug 8, 2015

Updated for versions that allow CORS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment