start working on smart playlist parser

This commit is contained in:
Ron Pedde 2005-06-20 03:18:16 +00:00
parent d18acd2f9e
commit 95e20a41d5
4 changed files with 131 additions and 3 deletions

View File

@ -6,10 +6,11 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="mt-daapd.css" /> <link rel="stylesheet" type="text/css" href="mt-daapd.css" />
@ispage status.html:<meta http-equiv="refresh" content="10" />:@ @ispage status.html:<meta http-equiv="refresh" content="10" />:@
@ispage smart.html:<script type="text/javascript" src="smart.js" />:@
@ispage playlist.html:<script type="text/javascript" src="playlist.js" />:@ @ispage playlist.html:<script type="text/javascript" src="playlist.js" />:@
</head> </head>
<body @ispage playlist.html:onload="init()":@> <body @ispage playlist.html:onload="init()":@ @ispage smart.html:onload="init()":@>
@ispage playlist.html:<!--:@ @ispage playlist.html:<!--:@
<div> <div>
<table border="0" width="100%"> <table border="0" width="100%">
@ -24,7 +25,9 @@
<a href="config.html" class="@ispage config.html:selected:plain@">Config</a> <a href="config.html" class="@ispage config.html:selected:plain@">Config</a>
<a href="status.html" class="@ispage status.html:selected:plain@">Status</a> <a href="status.html" class="@ispage status.html:selected:plain@">Status</a>
<a href="playlist.html" class="@ispage playlist.html:selected:plain@">Playlist</a> <a href="playlist.html" class="@ispage playlist.html:selected:plain@">Playlist</a>
<a href="feedback.html" class="@ispage feedback.html:selected:plain@">Feedback</a> <a href="feedback.html" class="@ispage
feedback.html:selected:plain@">Feedback</a>
<a href="smart.html" class="@ispage smart.html:selected:plain@">Smart</a>
<a href="thanks.html" class="@ispage thanks.html:selected:plain@">Thanks</a> <a href="thanks.html" class="@ispage thanks.html:selected:plain@">Thanks</a>
</div> </div>

View File

@ -28,7 +28,10 @@
/* */ /* */
table.hovertable tr:hover {
background-color: #8CACBB;
}
body { body {
font: 0.7em Verdana, Helvetica, Arial, sans-serif; font: 0.7em Verdana, Helvetica, Arial, sans-serif;
background: White; background: White;
@ -45,6 +48,7 @@ body {
scrollbar-arrow-color: #436976; scrollbar-arrow-color: #436976;
} }
table { table {
font-size: 100%; font-size: 100%;
} }

16
admin-root/smart.html Normal file
View File

@ -0,0 +1,16 @@
@include hdr.html@
<div class="stx">
<table class="hovertable" width="400">
<thead><th>ID</th><th>Playlist Name</th><th>Type</th></thead>
<tbody id="playlists">
</tbody>
</table>
<div id="pl_data">
</div>
</div>
@include ftr.html@

105
admin-root/smart.js Normal file
View File

@ -0,0 +1,105 @@
var req;
var playlist_info={};
function selectPlaylist(e) {
var targ;
if(!e) var e=window.event;
if(e.target) targ=e.target;
else if (e.srcElement) targ=e.srcElement;
if(targ.nodeType == 3)
targ = targ.parentNode;
while(targ.previousSibling)
targ=targ.previousSibling;
pl_id = targ.firstChild.nodeValue;
alert(playlist_info[pl_id]['name']);
}
function processPlaylists() {
var xmldoc = req.responseXML;
var playlists = xmldoc.getElementsByTagName("dmap.listingitem");
var pl_table = document.getElementById("playlists");
playlist_info = {};
while(pl_table.childNodes.length > 0) {
pl_table.removeChild(pl_table.lastChild);
}
for(var x=0; x < playlists.length; x++) {
var pl_id=playlists[x].getElementsByTagName("dmap.itemid")[0].firstChild.nodeValue;
var pl_name=playlists[x].getElementsByTagName("dmap.itemname")[0].firstChild.nodeValue;
var pl_type=playlists[x].getElementsByTagName("org.mt-daapd.playlist-type")[0].firstChild.nodeValue;
playlist_info[String(pl_id)] = { 'name': pl_name, 'type': pl_type };
if(pl_type == 1) {
var pl_spec=playlists[x].getElementsByTagName("org.mt-daapd.smart-playlist-spec")[0].firstChild.nodeValue;
playlist_info[String(pl_id)]['spec'] = pl_spec;
}
switch(pl_type) {
case "0":
pl_type = "Static&nbsp;(Web&nbsp;Edited)";
break;
case "1":
pl_type = "Smart";
break;
case "2":
pl_type = "Static&nbsp;(File)";
break;
case "3":
pl_type = "Static&nbsp;(iTunes)";
break;
}
var row = document.createElement("tr");
row.onclick=selectPlaylist;
if(row.captureEvents) row.captureEvents(Event.CLICK);
var td1 = document.createElement("td");
var td2 = document.createElement("td");
var td3 = document.createElement("td");
td1.innerHTML=pl_id;
td2.innerHTML=pl_name + "\n";
td3.innerHTML=pl_type + "\n";
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
pl_table.appendChild(row);
}
}
function processReqChange() {
if(req.readyState == 4) {
if(req.status == 200) {
processPlaylists();
}
}
}
function init() {
loadXMLDoc("/databases/1/containers?output=xml&meta=dmap.itemid,dmap.itemname,org.mt-daapd.playlist-type,org.mt-daapd.smart-playlist-spec","playlists");
}
function loadXMLDoc(url) {
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}