Skip to content

Instantly share code, notes, and snippets.

@DomSless
Last active September 15, 2021 20:48
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DomSless/5cd5e5dd64603a8548a6 to your computer and use it in GitHub Desktop.
Save DomSless/5cd5e5dd64603a8548a6 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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