Last active
September 15, 2021 20:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated for versions that allow CORS.