2006-10-22, 18:09
A user of hhtpapi can use other commands to screw up xbmc such as the Config ones or even just haphazard deletion of files. There has to be a level of trust. I will place a warning in the online manual.
<script type="text/javascript">
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function PlayMedia(mediapath){
var url = '/xbmcCmds/xbmcHttp?command=playfile¶meter='+mediapath;
http.open("get",url);
http.send(null);
}
function QueryMusicDatabase(query){
alert("searching for: "+query);
document.getElementById("results").innerHTML = "";
var sqlquery = "SELECT strPath, strFileName, strTitle, strAlbum, strArtist from songview WHERE strTitle LIKE '%%"+query+"%%';";
var url = "/xbmcCmds/xbmcHttp?command=QueryMusicDatabase¶meter="+sqlquery;
resultsHTML = "<b>"+unescape(sqlquery)+"</b><br><br>";
http.open("get",url);
http.onreadystatechange = function(){
if(http.readyState == 4){
responseArr = http.responseText.split("<li>");
while(responseArr.length>1){
//We know that we pulled 5 columns,
//so we can pop off 5 at a time for each song
strArtist = responseArr.pop();
strAlbum = responseArr.pop();
strTitle = responseArr.pop();
strFileName = responseArr.pop();
strPath = responseArr.pop();
//document.write("strPath:"+strPath+"<br>");
//document.write("strAlbum:"+strAlbum+"<br>");
//document.write("strTitle:"+strTitle+"<br>");
//document.write("strFileName:"+strFileName+"<br>");
//document.write("strArtist:"+strArtist+"<br>");
//document.write("fullpath:"+strPath+"/"+strFileName+"<br>");
//document.write("<br><br>"+"<br>");
resultsHTML += "<a href='javascript:PlayMedia(\""+escape(strPath)+"/"+escape(strFileName)+"\");'><img src='http://liquidice629.googlepages.com/play.gif' border=0> "+strTitle+"</a><br><b>Album:</b> "+strAlbum+"<br><b>Artist:</b> "+strArtist+"<br><br>";
}
document.getElementById("results").innerHTML = resultsHTML;
}
}
http.send(null);
}
</script>
<input type="text" name="query" id="query">
<a href="javascript:QueryMusicDatabase(document.getElementById('query').value);">Search</a><br><br>
<div id="results">
</div>
KingJames Wrote:I think I got the ajax beta 3 versin of this but the album art doesnt show , is there a simple fix, is there people still using this program?
<%
import xbmc, base64
response.setContentType('image/jpeg')
thumbfile = 'q:\\userdata\\Thumbnails\\Music\\d1fa1e1b.tbn'
file = open(thumbfile, 'r+b').read()
print base64.decodestring(file)
%>
<%
import xbmc
response.setContentType('image/jpeg')
thumbfile = 'q:\\userdata\\Thumbnails\\Music\\d1fa1e1b.tbn'
file = open(thumbfile, 'r+').read()
print file
%>
print request.get("myvariable1") //outputs 123
<body topmargin=0 leftmargin=0 style="overflow:hidden">
<a href="javascript:PlayMedia('<%print request.get("strPath")[0]%>')"><img border=0 width="100" height="100" src="data:image/jpg;base64,
<%
import xbmc, base64
thumbfile = 'q:\\userdata\\Thumbnails\\Music\\'+request.get("thumb")[0]
file = open(thumbfile, 'r+b').read()
print base64.encodestring(file)
%>
">
</body>
<ul id="musiclibrary" align="left" class="musiclibrary">
<%
var itemCount; // number of items in list
var data; // tmp var used in for loop
var tmpType; // holds isDir value
var i; // iterator
navigatorstate = xbmcCommand("navigatorstate");
if (navigatorstate == "pictures") {
ItemIconPath = "images/image.png";
ItemPlayIcon = "images/view.png";
ItemAddIcon = "images/addtoplaylist.gif";
CurrentPlayList = 0;
}
else if (navigatorstate == "music") {
ItemIconPath = "images/music.png";
ItemPlayIcon = "images/play.png";
ItemAddIcon = "images/addtoplaylist.gif";
CurrentPlayList = 0;
}
else if (navigatorstate == "videos") {
ItemIconPath = "images/movie.png";
ItemPlayIcon = "images/video.png";
ItemAddIcon = "images/addtoplaylist.gif";
CurrentPlayList = 2;
}
else {
xbmcCommand("navigate", "music");
ItemIconPath = "images/music.png";
ItemPlayIcon = "images/play.png";
ItemAddIcon = "images/addtoplaylist.gif";
CurrentPlayList = 0;
}
if (isset("Action")) { xbmcCommand("navigate", Action); }
if (isset("command")) {
if (command == "select") { xbmcCommand("catalog", "select," + item); }
}
itemCount = xbmcCommand("catalog","items");
file = xbmcCommand("catalog","first");
for (i = 0; i < itemCount; i = i + 1) {
tmpType = xbmcCommand("catalog","type,"+i);
if (tmpType == "directory") { data = ' <li class="row' + (i % 2) + '" mediapath="'+ i + '" id="musiclibrary'+ i + '"> <span style="height:40px">'; }
else { data = ' <li class="row' + (i % 2) + '" mediapath="'+ i + '" id="musiclibrary'+ i + '" > <span style="height:40px">'; }
if (tmpType == "directory") { data = data + '<span valign="center" align="left" id="musiclibArt'+ i +'"><img hspace="20" align="left" onclick="javascript:navigateToLocation(\''+ i +'\');" src="images/folder_small.png"/></span><div style="overflow: hidden; width: 60%;" id="musiclibSongInfo'+ i +'">'+ file +'</div>'; }
else { data = data + '<span valign="center" align="left" id="musiclibArt'+ i +'"><img hspace="20" align="left" onclick="javascript:PlayMedia('+ i + ');" src="'+ ItemIconPath +'"/></span><div style="overflow: hidden; width: 60%;" id="musiclibSongInfo'+ i +'">'+ file +'</div>'; }
data = data + "</span>";
data = data + '<div style="position: absolute; right: 0pt; top: 0px; width: 100px; vertical-align: top;" id="itemControls'+ i +'">';
if (tmpType == "directory") { data = data + '<a href="javascript:navigateToLocation('+ i + ')" ><img border="0" src="images/openfolder.png" /></a>'; }
else { data = data + '<a href="javascript:PlayId('+ i + ');" ><img border="0" src="'+ ItemPlayIcon +'" /></a>'; }
if (file != "..") data = data + '<img border="0" onclick="javascript:SetCurrentPlaylist('+CurrentPlayList+');AddIdToPlayList('+ i + ')" src="'+ ItemAddIcon +'"/>';
data = data + '</div></li>';
write(data+"\n");
file = xbmcCommand("catalog","next");
}
%>
</ul>
<%
import sys
thumbfile = 'q:\\userdata\\Thumbnails\\Music\\d1fa1e1b.tbn'
file = open(thumbfile, 'rwb').read()
response.setContentType('image/jpeg')
sys.stdout.write(file)
%>
<%
import string
thumbfile = 'q:\\userdata\\Thumbnails\\Music\\d1fa1e1b.tbn'
file = open(thumbfile, 'rwb').readlines()
response.setContentType('image/jpeg')
print string.join(file, '')
print "more" #this never runs, the entire script is halted after it hits a NULL
%>
This text outside the main code will not be displayed either
[[.import name=include ]]
[[\
response.setContentType('image/jpeg')
path = "10888eaf.tbn"
response.write(include.dump(path, 1))
]]