aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Yakushev <yakushev.alex@gmail.com>2011-06-10 22:36:19 +0300
committerAlexander Yakushev <yakushev.alex@gmail.com>2011-06-10 22:36:19 +0300
commit0066060ea80221ee843b080d1efbed1f9ee36ab1 (patch)
tree5b74b5a3dac487f8865add2e820a98968b75e530
parent4b3250ca24938afe4f3bf2707c929abbbd759c5b (diff)
downloadawesompd-0066060ea80221ee843b080d1efbed1f9ee36ab1.tar.gz
awesompd-0066060ea80221ee843b080d1efbed1f9ee36ab1.tar.bz2
Fixed bug with widget crashing after restarting awesome
-rw-r--r--awesompd.lua40
1 files changed, 36 insertions, 4 deletions
diff --git a/awesompd.lua b/awesompd.lua
index e0b4025..6a452ce 100644
--- a/awesompd.lua
+++ b/awesompd.lua
@@ -65,6 +65,8 @@ function awesompd:create()
instance.status_text = "Stopped"
instance.to_notify = false
instance.connected = true
+ instance.jamendo_list = {}
+
-- instance.promptbox = {}
-- for s = 1, screen.count() do
-- instance.promptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
@@ -102,6 +104,7 @@ function awesompd:run()
-- self:update_state()
self:check_playlists()
self.load_icons(self.path_to_icons)
+ self:retrieve_cache()
self.update_widget_timer = timer({ timeout = 1 })
self.update_widget_timer:add_signal("timeout", function () self:update_widget() end)
self.update_widget_timer:start()
@@ -285,14 +288,14 @@ function awesompd:add_jamendo_top(prefix,format)
track = (_track or ""),
artist = (_artist or "")})
end)
- self.jamendo_list = {}
for i = 1,table.getn(parse_table) do
track_link = "http://stream"..prefix..".jamendo.com/stream/" .. parse_table[i].id .."/".. format .."/"
self:command("add " .. track_link)
- self.jamendo_list[track_link] = parse_table[i].artist .. " - " .. parse_table[i].track
+ self.jamendo_list[parse_table[i].id] = parse_table[i].artist .. " - " .. parse_table[i].track
end
self.recreate_menu = true
self.recreate_list = true
+ self:save_cache()
end
end
@@ -333,7 +336,7 @@ function awesompd:get_list_menu()
for i = start_num, end_num do
print(self.list_array[i])
if (string.find(self.list_array[i],"jamendo.com")) then
- table.insert(new_menu, { self.jamendo_list[(self.list_array[i])],
+ table.insert(new_menu, { self.jamendo_list[awesompd.get_id_from_link(self.list_array[i])],
self:command_play_specific(i),
self.current_number == i and
(self.status == "Playing" and self.ICONS.PLAY or self.ICONS.PAUSE)
@@ -497,6 +500,35 @@ function awesompd:wrap_output(text)
return '<span font="' .. self.font .. '">| ' .. text .. ' |</span>'
end
+function awesompd:retrieve_cache()
+ if self.path_to_icons == "" then
+ self.filename = "jamendo_cache"
+ else
+ self.filename = self.path_to_icons .. "/jamendo_cache"
+ end
+ local bus = io.open(self.filename)
+ if bus then
+ for l in bus:lines() do
+ local _, _, id, track = string.find(l,"(%d+)-(.+)")
+ self.jamendo_list[id] = track
+ end
+ end
+end
+
+function awesompd:save_cache()
+ local bus = io.open(self.filename, "w")
+ for id,name in pairs(self.jamendo_list) do
+ bus:write(id.."-"..name.."\n")
+ end
+ bus:flush()
+ bus:close()
+end
+
+function awesompd.get_id_from_link(link)
+ local _, _, id = string.find(link,"stream/(%d+)")
+ return id
+end
+
function awesompd.split (s,t)
local l = {n=0}
local f = function (s)
@@ -598,7 +630,7 @@ function awesompd:update_track()
local new_track = awesompd.protect_string(info_ar[1])
if new_track ~= self.unique_text then
if (string.find(new_track,"jamendo.com")) then
- self.text = self.jamendo_list[new_track]
+ self.text = self.jamendo_list[awesompd.get_id_from_link(new_track)]
else
self.text = new_track
end