Author: titmuss
Date: Fri Mar 28 05:19:21 2008
New Revision: 2153
URL: http://svn.slimdevices.com?rev=2153&root=Jive&view=rev
Log:
Bug: N/A
Description:
Refactor to remove _artworkThumbUri. This function had been copied to three
different places, and is better processed in SlimServer.lua.
Refactor to combine common code in SlimServer:fetchArtworkThumb and
SlimServer:fetchArtworkURL.
Modified:
trunk/squeezeplay/src/squeezeplay/share/applets/NowPlaying/NowPlayingApplet.lua
trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
trunk/squeezeplay/src/squeezeplay/share/jive/slim/Player.lua
trunk/squeezeplay/src/squeezeplay/share/jive/slim/SlimServer.lua
Modified:
trunk/squeezeplay/src/squeezeplay/share/applets/NowPlaying/NowPlayingApplet.lua
URL:
http://svn.slimdevices.com/trunk/squeezeplay/src/squeezeplay/share/applets/NowPlaying/NowPlayingApplet.lua?rev=2153&root=Jive&r1=2152&r2=2153&view=diff
==============================================================================
---
trunk/squeezeplay/src/squeezeplay/share/applets/NowPlaying/NowPlayingApplet.lua
(original)
+++
trunk/squeezeplay/src/squeezeplay/share/applets/NowPlaying/NowPlayingApplet.lua
Fri Mar 28 05:19:21 2008
@@ -103,28 +103,6 @@
return style
end
-local function _nowPlayingArtworkThumbUri(iconId)
- return '/music/' .. iconId .. '/cover_' .. ARTWORK_SIZE .. 'x' ..
ARTWORK_SIZE .. '_p.png'
-end
-
-local function _staticArtworkThumbUri(path)
- local resizedImg = path
- -- 'p' is for padded, png gives us transparency
- local resizeFrag = '_' .. ARTWORK_SIZE .. 'x' .. ARTWORK_SIZE ..
'_p.png'
- local artworkUri = path
- -- replace .png with the resize params
- if string.match(path, '.png') then
- artworkUri = string.gsub(path, '.png', resizeFrag)
- end
-
- -- Bug 7123, Add a leading slash if needed
- if not string.find(artworkUri, "^/") then
- artworkUri = "/" .. artworkUri
- end
-
- return artworkUri
-end
-
local function _secondsToString(seconds)
local hrs = math.floor(seconds / 3600)
local min = math.floor((seconds / 60) - (hrs*60))
@@ -151,7 +129,7 @@
if item and item["icon-id"] then
-- Fetch an image from SlimServer
- server:fetchArtworkThumb(item["icon-id"], icon,
_nowPlayingArtworkThumbUri, ARTWORK_SIZE)
+ server:fetchArtworkThumb(item["icon-id"], icon, ARTWORK_SIZE)
elseif item and item["icon"] then
-- Fetch a remote image URL, sized to ARTWORK_SIZE x
ARTWORK_SIZE
local remoteContent = string.find(item['icon'], 'http://')
@@ -171,12 +149,12 @@
item["icon"] = 'http://' .. ip .. ':' .. port
.. item["icon"]
server:fetchArtworkURL(item["icon"], icon,
ARTWORK_SIZE)
else
- server:fetchArtworkThumb(item["icon"], icon,
_staticArtworkThumbUri, ARTWORK_SIZE)
+ server:fetchArtworkThumb(item["icon"], icon,
ARTWORK_SIZE)
end
end
elseif item and item["params"] and item["params"]["track_id"] then
-- this is for the radio image-- remote URLs with no icon (Bug
6087)
- server:fetchArtworkThumb(item["params"]["track_id"], icon,
_nowPlayingArtworkThumbUri, ARTWORK_SIZE)
+ server:fetchArtworkThumb(item["params"]["track_id"], icon,
ARTWORK_SIZE)
elseif icon then
icon:setValue(nil)
end
Modified:
trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
URL:
http://svn.slimdevices.com/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua?rev=2153&root=Jive&r1=2152&r2=2153&view=diff
==============================================================================
---
trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
(original)
+++
trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
Fri Mar 28 05:19:21 2008
@@ -102,7 +102,6 @@
-- defaults for thumbnail images
local THUMB_SIZE = 56
-local THUMB_FORMAT = 'jpg'
--==============================================================================
-- Local variables (globals)
@@ -188,41 +187,6 @@
end
--- artworkThumbUri
--- returns a URI to fetch artwork on the server
--- FIXME: should this be styled?
-local function _artworkThumbUri(iconId, size, imgFormat)
- -- we want THUMB_FORMAT if it wasn't specified
- if not imgFormat then
- imgFormat = THUMB_FORMAT
- end
-
- -- we want a THUMB_SIZE pixel thumbnail if it wasn't specified
- if not size then
- size = THUMB_SIZE
- end
-
- -- request SqueezeCenter resizes the thumbnail, use 'o' for
- -- original aspect ratio
- local resizeFrag = '_' .. size .. 'x' .. size .. '_o'
-
- local artworkUri
- if string.match(iconId, "^%d+$") then
- -- if the iconId is a number, this is cover art
- artworkUri = '/music/' .. iconId .. '/cover' .. resizeFrag ..
"." .. imgFormat
- else
- artworkUri = string.gsub(iconId, "(%a+)(%.%a+)", "%1" ..
resizeFrag .. "%2")
-
- if not string.find(artworkUri, "^/") then
- -- Bug 7123, Add a leading slash if needed
- artworkUri = "/" .. artworkUri
- end
- end
-
- return artworkUri
-end
-
-
local function _pushToNewWindow(step)
if not step then
return
@@ -286,7 +250,7 @@
_server:cancelArtwork(icon)
else
-- Fetch an image from SlimServer
- _server:fetchArtworkThumb(item["icon-id"], icon,
_artworkThumbUri, THUMB_SIZE)
+ _server:fetchArtworkThumb(item["icon-id"], icon,
THUMB_SIZE)
end
elseif item["icon"] then
@@ -301,7 +265,7 @@
-- Fetch a remote image URL, sized to
THUMB_SIZExTHUMB_SIZE (artwork from a streamed source)
_server:fetchArtworkURL(item["icon"], icon,
THUMB_SIZE)
else
- _server:fetchArtworkThumb(item["icon"], icon,
_artworkThumbUri, THUMB_SIZE)
+ _server:fetchArtworkThumb(item["icon"], icon,
THUMB_SIZE)
end
end
elseif item["trackType"] == 'radio' and item["params"] and
item["params"]["track_id"] then
@@ -311,7 +275,7 @@
else
-- workaround: this needs to be png not jpg to allow
for transparencies
-- XXXX is this workaround needed now?
- _server:fetchArtworkThumb(item["params"]["track_id"],
icon, _artworkThumbUri, THUMB_SIZE, 'png')
+ _server:fetchArtworkThumb(item["params"]["track_id"],
icon, THUMB_SIZE, 'png')
end
else
_server:cancelArtwork(icon)
@@ -652,7 +616,7 @@
end
log:debug("Artwork width/height will be ", shortDimension)
- _server:fetchArtworkThumb(chunk.data.artworkId, icon, _artworkThumbUri,
shortDimension)
+ _server:fetchArtworkThumb(chunk.data.artworkId, icon, shortDimension)
popup:addWidget(icon)
popup:show()
return popup
Modified: trunk/squeezeplay/src/squeezeplay/share/jive/slim/Player.lua
URL:
http://svn.slimdevices.com/trunk/squeezeplay/src/squeezeplay/share/jive/slim/Player.lua?rev=2153&root=Jive&r1=2152&r2=2153&view=diff
==============================================================================
--- trunk/squeezeplay/src/squeezeplay/share/jive/slim/Player.lua (original)
+++ trunk/squeezeplay/src/squeezeplay/share/jive/slim/Player.lua Fri Mar 28
05:19:21 2008
@@ -760,41 +760,6 @@
self:updateIconbar()
end
-function artworkThumbUri (iconId, size)
-
-
- assert(iconId)
- assert(size)
-
- -- sometimes we get a path to a static image rather than an iconId
- -- if the iconId is a number, this is cover art, otherwise it's static
content
- -- do some extra checking instead of just looking for type = number
- local thisIsAnId = true
- if type(iconId) == "number" then -- iconId is a number
- thisIsAnId = true
- elseif string.find(iconId, "%a") then -- iconID string contains a letter
- thisIsAnId = false
- else -- a string with no letters must be an id
- thisIsAnId = true
- end
-
- -- if this is a number, construct the path for a sizexsize cover art
thumbnail
- local artworkUri
- local resizeFrag = '_' .. size .. 'x' .. size .. '_p' -- 'p' is for
padded
- if thisIsAnId then
- artworkUri = '/music/' .. iconId .. '/cover' .. resizeFrag ..
'.gd'
- elseif string.match(iconId, '.png') then
- -- if this isn't a number, then we just want the path
- -- with server-side resizing
- artworkUri = string.gsub(iconId, '.png', resizeFrag .. '.png')
- -- otherwise punt and just send back the iconId path
- else
- return iconId
- end
- log:info(artworkUri)
- return artworkUri
-end
-
-- _process_displaystatus
-- receives the display status data
@@ -816,7 +781,7 @@
if display['icon'] then
self.slimServer:fetchArtworkURL(display['icon'], s.artIcon, 56)
else
-
self.slimServer:fetchArtworkThumb(display["icon-id"], s.artIcon,
artworkThumbUri, 56)
+
self.slimServer:fetchArtworkThumb(display["icon-id"], s.artIcon, 56)
end
else
s.text:setValue(table.concat(display["text"], "\n"))
Modified: trunk/squeezeplay/src/squeezeplay/share/jive/slim/SlimServer.lua
URL:
http://svn.slimdevices.com/trunk/squeezeplay/src/squeezeplay/share/jive/slim/SlimServer.lua?rev=2153&root=Jive&r1=2152&r2=2153&view=diff
==============================================================================
--- trunk/squeezeplay/src/squeezeplay/share/jive/slim/SlimServer.lua (original)
+++ trunk/squeezeplay/src/squeezeplay/share/jive/slim/SlimServer.lua Fri Mar 28
05:19:21 2008
@@ -36,6 +36,7 @@
local os = require("os")
local table = require("jive.utils.table")
+local string = require("string")
local debug = require("jive.utils.debug")
local oo = require("loop.base")
@@ -460,12 +461,10 @@
-- _getArworkThumbSink
-- returns a sink for artwork so we can cache it as Surface before sending it
forward
-local function _getArtworkThumbSink(self, iconId, size)
+local function _getArtworkThumbSink(self, cacheKey, size)
assert(size)
- local cacheKey = iconId .. "@" .. size
-
return function(chunk, err)
if err or chunk then
@@ -535,7 +534,7 @@
self.artworkFetchCount = self.artworkFetchCount + 1
- if entry.thumb then
+ if entry.id then
-- slimserver icon id
self.artworkPool:queue(req)
else
@@ -628,25 +627,68 @@
--[[
-=head2 jive.slim.SlimServer:fetchArtworkThumb(iconId, icon, uriGenerator,
size, imgFormat)
+=head2 jive.slim.SlimServer:fetchArtworkThumb(iconId, icon, size, imgFormat)
The SlimServer object maintains an artwork cache. This function either loads
from the cache or
gets from the network the thumb for I<iconId>. A L<jive.ui.Surface> is used to
perform
-I<icon>:setValue(). I<uriGenerator> must be a function that
-computes the URI to request the artwork from the server from I<iconId> (i.e.
if needed, this
-method will call uriGenerator(iconId) and use the result as URI). I<imgFormat>
is an optional
-argument sent to the uriGenerator. See applets.SlimBrowser._artworkThumbUri as
an example.
-
-
-=cut
---]]
-function fetchArtworkThumb(self, iconId, icon, uriGenerator, size, imgFormat)
+I<icon>:setValue(). This function computes the URI to request the artwork from
the server from I<iconId>. I<imgFormat> is an optional
+argument to control the image format.
+
+=cut
+--]]
+function fetchArtworkThumb(self, iconId, icon, size, imgFormat)
logcache:debug(self, ":fetchArtworkThumb(", iconId, ")")
assert(size)
-
+
+ -- we want jpg if it wasn't specified
+ if not imgFormat then
+ imgFormat = 'jpg'
+ end
+
local cacheKey = iconId .. "@" .. size
+ -- request SqueezeCenter resizes the thumbnail, use 'o' for
+ -- original aspect ratio
+ local resizeFrag = '_' .. size .. 'x' .. size .. '_o'
+
+ local url
+ if string.match(iconId, "^%d+$") then
+ -- if the iconId is a number, this is cover art
+ url = '/music/' .. iconId .. '/cover' .. resizeFrag .. "." ..
imgFormat
+ else
+ url = string.gsub(iconId, "(%a+)(%.%a+)", "%1" .. resizeFrag ..
"%2")
+
+ if not string.find(url, "^/") then
+ -- Bug 7123, Add a leading slash if needed
+ url = "/" .. url
+ end
+ end
+
+ return _fetchArtworkURL(self, icon, iconId, size, cacheKey, url)
+end
+
+--[[
+
+=head2 jive.slim.SlimServer:fetchArtworkURL(url, icon, size)
+
+Same as fetchArtworkThumb except it fetches the artwork from a remote URL.
+This method is in the SlimServer class so it can reuse the other artwork code.
+
+=cut
+--]]
+function fetchArtworkURL(self, url, icon, size)
+ logcache:debug(self, ":fetchArtworkURL(", url, ")")
+
+ assert(size)
+ local cacheKey = url .. "@" .. size
+
+ return _fetchArtworkURL(self, icon, nil, size, cacheKey, url)
+end
+
+
+-- common parts of fetchArtworkThumb and fetchArtworkURL
+function _fetchArtworkURL(self, icon, iconId, size, cacheKey, url)
-- do we have the artwork in the cache
local artwork = self.artworkCache:get(cacheKey)
if artwork then
@@ -671,72 +713,17 @@
-- no luck, generate a request for the artwork
self.artworkCache:set(cacheKey, true)
if icon then
+ icon:setValue(nil)
self.artworkThumbIcons[icon] = cacheKey
- icon:setValue(nil)
end
logcache:debug("..fetching artwork")
-- queue up the request on a lifo
table.insert(self.artworkFetchQueue, {
- key = iconId,
- url = uriGenerator(iconId, size, imgFormat),
- size = size,
- thumb = true
- })
- self.artworkFetchTask:addTask()
-end
-
---[[
-
-=head2 jive.slim.SlimServer:fetchArtworkURL(url, icon, size)
-
-Same as fetchArtworkThumb except it fetches the artwork from a remote URL.
-This method is in the SlimServer class so it can reuse the other artwork code.
-
-=cut
---]]
-function fetchArtworkURL(self, url, icon, size)
- logcache:debug(self, ":fetchArtworkURL(", url, ")")
-
- assert(size)
-
- local cacheKey = url .. "@" .. size
-
- -- do we have the artwork in the cache
- local artwork = self.artworkCache:get(cacheKey)
- if artwork then
- -- are we requesting it already?
- if artwork == true then
- logcache:debug("..artwork already requested")
- if icon then
- icon:setValue(nil)
- self.artworkThumbIcons[icon] = cacheKey
- end
- return
- else
- logcache:debug("..artwork in cache")
- if icon then
- icon:setValue(artwork)
- self.artworkThumbIcons[icon] = nil
- end
- return
- end
- end
-
- -- no luck, generate a request for the artwork
- self.artworkCache:set(cacheKey, true)
- if icon then
- icon:setValue(nil)
- self.artworkThumbIcons[icon] = cacheKey
- end
- logcache:debug("..fetching artwork")
-
- -- queue up the request on a lifo
- table.insert(self.artworkFetchQueue, {
- key = url,
+ key = cacheKey,
+ id = iconId,
url = url,
size = size,
- thumb = false
})
self.artworkFetchTask:addTask()
end
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins