From 3a6d4d6e584b1680440e26769bce6267c8f6cfd6 Mon Sep 17 00:00:00 2001 From: Mook Date: Fri, 20 Mar 2009 12:06:24 -0700 Subject: [PATCH 2/2] playlist stuff --- extensions/httpserv/components/src/sbhttpserv.js | 75 +++++++++++++++++---- 1 files changed, 60 insertions(+), 15 deletions(-) diff --git extensions/httpserv/components/src/sbhttpserv.js extensions/httpserv/components/src/sbhttpserv.js index 7127e52..31a21ad 100644 --- extensions/httpserv/components/src/sbhttpserv.js +++ extensions/httpserv/components/src/sbhttpserv.js @@ -110,17 +110,17 @@ SBHttpServ.prototype.handle = function SBHttpServ_handle(aMetadata, aResponse) for (let idx = 0; idx < pathParts.length; idx += 2) { let dirName = decodeURIComponent(pathParts[idx]); let dirValue = decodeURIComponent(pathParts[idx + 1]); if (dirName === "") { break; } if (["albums", "artists", "genres", "playlists"].indexOf(dirName) != -1) { if (typeof(dirValue) == "undefined" || dirValue === "") { - this.generateFilterListing(aMetadata, context, dirName, aResponse); + this._generateFilterListing(aMetadata, context, dirName, aResponse); context = null; break; } else { context = context[dirName][dirValue]; if (!context) { dd(<>can't find {dirName} / {dirValue}); throw new HttpError(404, "Not Found"); } @@ -130,96 +130,141 @@ SBHttpServ.prototype.handle = function SBHttpServ_handle(aMetadata, aResponse) break; } else { context = context[dirName][dirValue]; if (!context) { dd(<>can't find {dirName} / {dirValue}); throw new HttpError(404, "Not Found"); } } + } else if (dirName == "pls") { + if (!("items" in context)) { + dd(<>context {context} is not a media list); + throw new HttpError(404, "Playlist not found"); + } + this._generatePlaylistListing(aMetadata, context, aResponse); + context = null; + break; } else { dd(<>ignoring unknown directory [{dirName}]); throw new HttpError(404, "Not Found");; } } if ((context instanceof Ci.sbIMediaItem) && !(context instanceof Ci.sbIMediaList)) { const BUFFER_SIZE = 0x80000; aResponse.setHeader("Content-Type", this._getContentType(context.contentSrc)); let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); let channel = ios.newChannelFromURI(context.contentSrc); aResponse.bodyOutputStream.writeFrom(channel.open(), -1); } else if (context && ("items" in context)) { - this.generateItemListing(aMetadata, context, aResponse); + this._generateItemListing(aMetadata, context, aResponse); } } catch (e) { Components.utils.reportError(e); throw e; } }; -SBHttpServ.prototype.generateFilterListing = -function SBHttpServ_generateFilterListing(aMetadata, aContext, aType, aResponse) { - aResponse.setHeader("Content-Type", "text/html"); +SBHttpServ.prototype._generateFilterListing = +function SBHttpServ__generateFilterListing(aMetadata, aContext, aType, aResponse) { + aResponse.setHeader("Content-Type", "text/html; charset=utf-8"); aResponse.write(String(<> - Directory listing for {aMetadata.path} + Directory listing for {aMetadata.path.split('/').map(unescape).join('/')} -

Directory listing for {aMetadata.path}

+

Directory listing for {aMetadata.path.split('/').map(unescape).join('/')}