helgeerbe / picframe

Picture frame viewer for raspi, controlled via mqtt and automatticly integrated as mqtt device in homeassistant.
MIT License
91 stars 27 forks source link

Potential problem with pictureframe.db3 updating #347

Closed GitRayc closed 6 months ago

GitRayc commented 7 months ago

Paddy:

What triggers the pictureframe.db3 file to refresh/update?

I think there my be a problem here. I have set my "yaml" file line "reshuffle_num" parameter to 1. So as I understand it, a new shuffle will happen once all images have been displayed once. I did this because I have been a having an ongoing problem with new images added to my usb thumbdrive not showing up. I thought perhaps that once the previous images had run through once, that perhaps this database would be rebuilt to recognize new images, a new shuffle would take place and I would see them then. Maybe it doesn't work that way.

However I have added new images that never show up after hours of running through the images. Several restarts do not seem to fix the problem but eventually a reboot will solve the problem.

I have found that if I delete the pictureframe.db3 file and reboot; that new images added will be recognized and they show up immediately as one would expect.

So perhaps there is a problem with this file refreshing on a consistent basis? Just wondered what triggers it to rebuild.

Hope I am not being a bother. But I love this package!

Ray

paddywwoof commented 7 months ago

There is a process running in its own thread see here that checks for any changes in directories and files every two seconds. It relies on the OS giving the modified time for the directory here which seems to be pretty robust, but maybe it waits until the external process writing the files has completely "let go" of the resource before updating the modified time for the directory?

The re-fetching of the image list happens here but I can't see where __reload_files gets set to True apart from a) you select a folder with no images b) you are showing in random order and have completed the number of run-throughs you set c) you restart picframe d) you set a subdirectory (using MQTT or HTTP say) e) you set shuffle on or off (by MQTT, HTTP) f) force reload (MQTT, HTTP)

i.e. running through in date, file name, title, location etc order will never reload the image list. I suppose that might seem logical if the picture order will remain the same - apart from the circumstances where files have been added or removed from the disk. However this explanation would only apply if you were not showing the images in random order.

GitRayc commented 7 months ago

Thanks for the update mate! I run my slideshow from a images that I store on a USB Thumbdrive which of course mounts automatically when the pi boots up.

But the only way I can get new images to be recognized as I add them is to delete the pictureframe_db3 file and reboot. Not a huge deal but just noting such.

Ray

paddywwoof commented 7 months ago

Just to clarify. If you stop the picframe app and restart it (or reboot the whole Raspberry Pi) the added pictures don't show? That definitelyshouldn't be the case. See point c above.

GitRayc commented 7 months ago

That is correct. The only way I can get new pictures to show up is to delete the db3 file. Then all is fine until I add a new pic. Reboots dont help, stopping and starting picframe doesnt help.

GitRayc commented 7 months ago

Could it be that db3 is looking at the pictures directory and not the USB Thumbdrive where my pics are stored? Maybe I need to edit a line to point to my thumbdrive rather than looking at the pictures directory,

Of course my yaml file has been edited to look at the thumbdrive rather than the pictures directory
Generally things are finally running beautifully.

paddywwoof commented 6 months ago

It sounds more like the part of image_cache that checks if anything has changed in a directory isn't registering a change when files are added, and not putting the new images onto the db. Maybe this is some quirk of USB Thumbdrives (though it does seem very unlikely to me). You could test it by running something like this in your terminal before and after adding a new image to the drive

import os
for (dir, _, _) in os.walk('/media/pi/my_thumb_drive/'): # use wherever the USB is mounted, whatever you use to look at files from the RPi terminal
    print(dir, os.stat(dir).st_mtime)

The number representing the time should change after altering the directory

jgodfrey commented 6 months ago

It sounds more like the part of image_cache that checks if anything has changed in a directory isn't registering a change when files are added

Agreed. We first ask the OS for any directories that have been modified. Then, in those directories only, we look for update or new files. If that initial "modified directories" check is failing for some reason, we won't find any changes. IIRC, updating an existing file in a folder won't mark the folder as modified, so that change is missed by default. I wonder if your updates get picked up if you touch the containing folder?

paddywwoof commented 6 months ago

I thought it might be something to do with symbolic links but can't find any way to not get a change in st_mtime. I tried touching the directories, adding, editing and renaming (mving) files in a directory and via a symbolic link to the directory. All change the datetime! PS on this ubuntu laptop. I will try SSHing RPi later.