]> gitweb.fluxo.info Git - awesompd.git/commitdiff
coverart.sh simply rewritten in Lua
authorAlexander Yakushev <yakushev.alex@gmail.com>
Fri, 19 Aug 2011 07:30:25 +0000 (10:30 +0300)
committerAlexander Yakushev <yakushev.alex@gmail.com>
Fri, 19 Aug 2011 09:41:21 +0000 (12:41 +0300)
README
awesompd.lua
icons/default_album_cover.png [new file with mode: 0644]
jamendo.lua
rcsample.lua

diff --git a/README b/README
index a5e52c65b1b67da675809d85cc33d8fc3edf9a87..2a2e3bc6a4a7967f3af7b328bc0b5aedc57bf5ba 100644 (file)
--- a/README
+++ b/README
@@ -1,3 +1,3 @@
 This is a MPD widget for AwesomeWM.
 
-For the detailed installation guide see https://awesome.naquadah.org/wiki/Awesompd_widget .
+For the detailed installation guide see http://awesome.naquadah.org/wiki/Awesompd_widget .
index 4e7625851e34ac435266c1f956dc08b00ae8c7fa..2731f396b6102f6e27892d80b554cae816204923 100644 (file)
@@ -1,7 +1,7 @@
 ---------------------------------------------------------------------------
 -- @author Alexander Yakushev &lt;yakushev.alex@gmail.com&gt;
 -- @copyright 2010-2011 Alexander Yakushev
--- @release v1.0
+-- @release v1.0.2
 ---------------------------------------------------------------------------
 
 require('utf8')
@@ -66,6 +66,8 @@ function awesompd.load_icons(path)
    awesompd.ICONS.PREV = awesompd.try_load(path .. "/prev_icon.png")
    awesompd.ICONS.CHECK = awesompd.try_load(path .. "/check_icon.png")
    awesompd.ICONS.RADIO = awesompd.try_load(path .. "/radio_icon.png")
+   awesompd.ICONS.DEFAULT_ALBUM_COVER = 
+      awesompd.try_load(path .. "/default_album_cover.png")
 end
 
 -- Function that returns a new awesompd object.
@@ -93,7 +95,7 @@ function awesompd:create()
    instance.recreate_jamendo_formats = true
    instance.recreate_jamendo_order = true
    instance.current_number = 0
-   instance.menu_shown = false 
+   instance.menu_shown = false
 
 -- Default user options
    instance.servers = { { server = "localhost", port = 6600 } }
@@ -106,7 +108,8 @@ function awesompd:create()
    instance.rdecorator = " "
    instance.show_jamendo_album_covers = true
    instance.album_cover_size = 50
-
+   instance.show_local_album_covers = true
+   
 -- Widget configuration
    instance.widget:add_signal("mouse::enter", function(c)
                                                  instance:notify_track()
@@ -174,6 +177,8 @@ end
 
 -- /// Group of mpc command functions ///
 
+-- Takes a command to mpc and a hook that is provided with awesompd
+-- instance and the result of command execution.
 function awesompd:command(com,hook)
    local file = io.popen(self:mpcquery() .. com)
    if hook then
@@ -182,6 +187,14 @@ function awesompd:command(com,hook)
    file:close()
 end
 
+-- Takes a command to mpc and read mode and returns the result.
+function awesompd:command_read(com, mode)
+   self:command(com, function(_, f)
+                        result = f:read(mode)
+                     end)
+   return result
+end
+
 function awesompd:command_toggle()
    return function()
              self:command("toggle",self.update_track)
@@ -586,7 +599,8 @@ end
 
 function awesompd:add_hint(hint_title, hint_text, hint_image)
    self:remove_hint()
-   hint_image = self.show_jamendo_album_covers and hint_image or nil
+   hint_image = self.show_jamendo_album_covers and hint_image or
+      self.show_local_album_covers and self:try_get_local_cover() or nil
    self.notification = naughty.notify({ title      =  hint_title
                                        , text       = awesompd.protect_string(hint_text)
                                        , timeout    = 5
@@ -813,7 +827,7 @@ function awesompd.protect_string(str, for_menu)
    end
 end
 
--- Displays a inputbox on the screen (looks like naughty with prompt).
+-- Displays an inputbox on the screen (looks like naughty with prompt).
 -- title_text - bold text on the first line
 -- prompt_text - preceding text on the second line
 -- hook - function that will be called with input data
@@ -853,3 +867,49 @@ function awesompd:display_inputbox(title_text, prompt_text, hook)
    awful.prompt.run( { prompt = " " .. prompt_text .. ": " }, wprompt.widget, 
                      exe_callback, nil, nil, nil, done_callback)
 end
+
+-- Tries to find an album cover for the track that is currently
+-- playing.
+function awesompd:try_get_local_cover()
+   local result = self.ICONS.DEFAULT_ALBUM_COVER
+   if self.show_local_album_covers and self.mpd_config then
+      -- First find the music directory in MPD configuration file
+      local _, _, music_folder = string.find(
+         io.popen('cat ' .. self.mpd_config .. ' | grep -v "#" | grep music_directory'):read("*line"),
+         'music_directory%s+"(.+)"')
+      music_folder = music_folder .. "/"
+      dbg("musfolder", music_folder)
+
+      -- Get the path to the file currently playing.
+      local _, _, current_file_folder = 
+         string.find(self:command_read('current -f "%file%"', "*line"), '(.+%/).*')
+
+      local folder = music_folder .. current_file_folder
+      dbg("folder", folder)
+      -- Get all images in the folder
+      local covers_bus = io.popen('ls "' .. folder .. '" | grep -P "\.jpg\|\.png\|\.gif"')
+      dbg('wtf', 'ls "' .. folder .. '" | grep "\.jpg\|\.png\|\.gif"')
+      local covers = {}
+      for l in covers_bus:lines() do
+         dbg('here')
+         table.insert(covers, l)
+      end
+      dbg('first', covers[1])
+
+      if table.getn(covers) > 0 then
+         result = folder .. covers[1]
+         for i = 2, table.getn(covers) do
+            -- Searching for front cover with grep because Lua regular
+            -- expressions suck:[
+            local front_cover = 
+               io.popen('echo "' .. covers[i] .. 
+                        '" | grep -i "cover\|front\|folder\|albumart" | head -n 1')
+            if front_cover then
+               result = folder .. front_cover
+               break
+            end
+         end
+      end
+   end   
+   return result
+end
diff --git a/icons/default_album_cover.png b/icons/default_album_cover.png
new file mode 100644 (file)
index 0000000..b952ba4
Binary files /dev/null and b/icons/default_album_cover.png differ
index f805f2fdcae41c9fd057faaf84a61fd219615c86..1dd421c1eed87679dcafe9d7e496a0e50420c85c 100644 (file)
@@ -1,3 +1,9 @@
+---------------------------------------------------------------------------
+-- @author Alexander Yakushev &lt;yakushev.alex@gmail.com&gt;
+-- @copyright 2011 Alexander Yakushev
+-- @release v1.0.2
+---------------------------------------------------------------------------
+
 module('jamendo', package.seeall)
 
 -- Grab environment
index 71d934977911b03abf4d8160814dc7fdd4674798..2cf593875251e2d47fb1550d506f41ac97669260 100644 (file)
@@ -99,11 +99,11 @@ mysystray = widget({ type = "systray" })
 
   -- If true, song notifications for Jamendo tracks will also contain
   -- album cover image.
-  instance.show_jamendo_album_covers = true
+  musicwidget.show_jamendo_album_covers = true
 
   -- Specify how big in pixels should an album cover be. Maximum value
   -- is 100.
-  instance.album_cover_size = 50
+  musicwidget.album_cover_size = 50
 
   -- Specify decorators on the left and the right side of the
   -- widget. Or just leave empty strings if you decorate the widget