Page 1 of 1

need help with conky .lua script please [SOLVED]

Posted: Tue May 14, 2024 7:46 pm
by Logansfury
Hello everyone,

I am trying to use conky to display a random image and play a corresponding .mp3 file with mpg123.

I have a directory with .png files numbered 1-51.png and a directory of .mp3 files named 1-51.mp3

Here is the conf:

Code: Select all

 
 --[[
Bleys 2024 

]]
conky.config = {
-- — Conky settings

	background = false,
	total_run_times = 0,
	no_buffers = true,	

-- — Window specifications with Background

	own_window = true,
	own_window_type = dock,
    own_window_hints = 'skip_taskbar,skip_pager,undecorated,above',
    own_window_transparent = false,
	own_window_argb_visual = true,
	own_window_argb_value = 0,
	own_window_colour = '000000', 
	
	double_buffer = true,
	minimum_width = 324, minimum_height = 214,
	alignment = 'middle_middle',
	
	gap_x = 20,
	gap_y = 20,

    update_interval = 3600,

-- Lua Load
	lua_load = '/home/logansfury/.conky/Biohazzard/test.lua',
	lua_draw_hook_post = 'main',		
};
conky.text = [[

]];
and here is the .lua

Code: Select all

require 'cairo'
require "imlib2"
home_path = os.getenv ('HOME')

function fDrawImage(cr,path,xx,yy,ww,hh,arc)
    cairo_save (cr)
    local img =  cairo_image_surface_create_from_png(path)
    local w_img, h_img = cairo_image_surface_get_width(img), cairo_image_surface_get_height(img)
    cairo_translate (cr, xx, yy)
    if arc then
        cairo_rotate (cr, arc)
    end
    cairo_scale (cr, ww/w_img, hh/h_img)
    cairo_set_source_surface (cr, img, -w_img/2, -h_img/2)
    cairo_paint (cr)
    cairo_surface_destroy (img)
    collectgarbage ()
    cairo_restore (cr)
end

function conky_main()
    if conky_window == nil then
        return
    end
    local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
    local cr = cairo_create(cs)
        math.randomseed(os.time())
        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
       --end
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end
Currently what I have works. It randomizes a different number every time, and is showing the .png file.
Now I need an edit for mpg123 to navigate to /home/logansfury/Music/eyegor/ and play the $random_number .mp3

Can anyone provide code to help?

Thanks for reading,

Logan

Re: need help with conky .lua script please

Posted: Wed May 15, 2024 5:55 pm
by zcot
look at the last 6 lines of the .lua file:

Code: Select all

        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
       --end
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end
but it should look like these 5 lines instead:

Code: Select all

        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end
now make it look like that:

Code: Select all

        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
        local dangler = io.popen('some bash command goes here')
        dangler:close()
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end

Re: need help with conky .lua script please

Posted: Wed May 15, 2024 6:28 pm
by Logansfury
zcot wrote: Wed May 15, 2024 5:55 pm look at the last 6 lines of the .lua file:

Code: Select all

        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
       --end
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end
but it should look like these 5 lines instead:

Code: Select all

        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end
now make it look like that:

Code: Select all

        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
        local dangler = io.popen('some bash command goes here')
        dangler:close()
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end
Partial success :)

It looks like a good starting point. What happened was:

- it played an mp3 (7.mp3)
- it then played a 2nd mp3 (22.mp3)
- after 2nd mp3 completed, it showed the image corresponding to 2nd mp3 played.

What I am looking for is

- display the .png image first
- immediately play corresponding mp3
- code to wait while mpg123 plays
- code to wait 2 seconds after mpg123 stops playing
- code to stop showing the .png

Here is the terminal output from the launch:

Code: Select all

conky: desktop window (2400010) is subwindow of root window (6cc)
conky: window type - normal
conky: drawing to created window (0x7000002)
conky: drawing to double buffer
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2, and 3.
Version 0.3.2-1 (2012/03/25). Written and copyrights by Joe Drew,
now maintained by Nanakos Chrysostomos and others.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!

Directory: /home/logansfury/Music/eyegor
Playing MPEG stream from 7.mp3 ...
MPEG 2.0 layer III, 48 kbit/s, 24000 Hz mono
                                                                            
[0:07] Decoding of 7.mp3 finished.
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2, and 3.
Version 0.3.2-1 (2012/03/25). Written and copyrights by Joe Drew,
now maintained by Nanakos Chrysostomos and others.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!

Directory: /home/logansfury/Music/eyegor
Playing MPEG stream from 22.mp3 ...
MPEG 2.0 layer III, 48 kbit/s, 24000 Hz mono
                                                                            
[0:06] Decoding of 22.mp3 finished.