diff options
author | Alexander Yakushev <yakushev.alex@gmail.com> | 2011-06-23 00:38:50 +0300 |
---|---|---|
committer | Alexander Yakushev <yakushev.alex@gmail.com> | 2011-06-23 00:38:50 +0300 |
commit | ad48622a9703c553619fc67bd18ba16ff168a576 (patch) | |
tree | 4dcb3f4f09e7f4a14a385880a1ba654ac555c937 | |
parent | 93fa2b685ca9de49766ef8bc8909ba0efd8b55a2 (diff) | |
download | awesompd-ad48622a9703c553619fc67bd18ba16ff168a576.tar.gz awesompd-ad48622a9703c553619fc67bd18ba16ff168a576.tar.bz2 |
Now using API to get stream number (hardcoded before)
-rw-r--r-- | awesompd.lua | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/awesompd.lua b/awesompd.lua index e178b89..9af3778 100644 --- a/awesompd.lua +++ b/awesompd.lua @@ -1,6 +1,5 @@ --------------------------------------------------------------------------- --- @author Alexander Yakushev <yakushev.alex@gmail.com> --- @copyright 2010 Alexander Yakushev +-- @author Alexander Yakushev <yakushev.alex@gmail.com>-- @copyright 2010 Alexander Yakushev -- @release v0.5b --------------------------------------------------------------------------- @@ -277,29 +276,44 @@ function awesompd:command_show_menu() return function() -- end --end -function awesompd:add_jamendo_top(prefix,format) - return function () - top_list = "curl -A 'Mozilla/4.0' -fsm 5 \"http://api.jamendo.com/get2/id+name+url+stream+album_name+album_url+album_id+artist_id+artist_name/track/jsonpretty/track_album+album_artist/?n=100&order=ratingweek_desc\"" - bus = io.popen(top_list) - r = bus:read("*all") - parse_table = {} - string.gsub(r, "\"id\":(%d+),%s+\"name\":\"([^\"]+)[^%}]*\"artist_name\":\"([^\"]+)\"",function(_id,_track,_artist) - table.insert(parse_table, - { id = _id, - track = (_track or ""), - artist = (_artist or "")}) - end) +function awesompd:add_tracks_from_jamendo(parse_table,format) + if (table.getn(parse_table) > 0) then + local trygetlink = + assert(io.popen("echo $(curl -w %{redirect_url} " .. + "'http://api.jamendo.com/get2/stream/track/redirect/" .. + "?streamencoding="..format.."&id="..parse_table[1].id.."')"),'r'):read("*lines") + + local _, _, prefix = string.find(trygetlink,"stream(%d+)\.jamendo\.com") 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[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 +function awesompd:add_jamendo_top(prefix,format) + return function () + local top_list = "curl -A 'Mozilla/4.0' -fsm 5 \"http://api.jamendo.com/get2/" .. + "id+name+url+stream+album_name+album_url+album_id+artist_id+artist_name" .. + "/track/jsonpretty/track_album+album_artist/?n=100&order=ratingweek_desc\"" + local bus = assert(io.popen(top_list, 'r')) + local r = bus:read("*all") + local parse_table = {} + string.gsub(r, "\"id\":(%d+),%s+\"name\":\"([^\"]+)[^%}]*\"artist_name\":\"([^\"]+)\"", + function(_id,_track,_artist) + table.insert(parse_table, + { id = _id, + track = (_track or ""), + artist = (_artist or "")}) + end) + self:add_tracks_from_jamendo(parse_table,format) + self.recreate_menu = true + self.recreate_list = true + self:save_cache() + end +end + -- Returns the playback menu. Menu contains of: -- Play\Pause - always -- Previous - if the current track is not the first in the list and playback is not stopped |