Can I configure variety to give priority to pictures which are new?

Asked by Peeyush on 2018-07-23

I've configured sources such as bing picture of the day and reddit. And my rate of changing is slow (once a day).

I was wondering if I could configure this behavior - If there is a new picture available that has never been shown before, show that instead of choosing one from the already shown ones.

If there is no new picture then I guess it's alright to show an existing picture, though I think this should rarely happen.

From what I've explored in preferences, I don't think this is possible. If it isn't, I'd like to submit this as a feature request please.

Question information

Language:
English Edit question
Status:
Solved
For:
Variety Edit question
Assignee:
No assignee Edit question
Solved by:
Peter Levi
Solved:
2018-07-23
Last query:
2018-07-23
Last reply:
2018-07-23
Peter Levi (peterlevi) said : #1

By default Variety does prefer newly downloaded pictures when choosing what to show as a wallpaper.
However the downloads themselves are not "prioritized" - we'll just download a random picture of those returned by the image source, so we will not for example prioritize downloading the wallpaper that was just now uploaded to Bing POTD over the older ones.

Peeyush (peey) said : #2

Oh, I was thinking that Bing POTD is like the actual POTD (i.e. whatever was selected as a POTD "today")

Which is why I had set download frequency to 1 / day since I thought you can't get more than 1 POTD from Bing.

> By default Variety does prefer newly downloaded pictures when choosing what to show as a wallpaper.

But even with the priority, I still see one of the old images being chosen over the new ones available. I guess right now this is because there is only _one_ new picture whenever it's time to choose?

When you say "prefer" do you mean that it will absolutely not show an old picture if a new one is available or do you mean that there is a higher weight assigned to probability of choosing a new one over an old one?

If it's the latter, then it doesn't solve my issue. My issue is the former.

Since my change rate is slow, I can't really stay with the same image which I've seen for a whole day before, so I often manually have to change it to one of the newer pictures.

Peter Levi (peterlevi) said : #3

The code is literally this:

        file = downloader.download_one()
        if file:
            self.register_downloaded_file(file)

            if downloader.is_refresher or self.image_ok(file, 0):
                # give priority to newly-downloaded images - prepared_from_downloads are later prepended to self.prepared
                logger.info(lambda: "Adding downloaded file %s to prepared_from_downloads queue" % file)
                with self.prepared_lock:
                    self.prepared_from_downloads.append(file)

So, in short - as soon as Variety downloads a new image, it goes to the top of the queue, and next time you change the wallpaper, it should choose one image of those downloaded since the last change. But if you then keep on changing images, it will start selecting images at random and once the new ones are "consumed", they will no more have any priority over old ones. You can see what happens if you reduce the downloading interval, and also show "Recent downloads", and change the wallpaper to "Next" immediately after you see a new downloaded image appear - you should see it immediately as the new wallpaper.

The changing interval and the downloading interval are more or less independent "timers".

Bing's POTD stream actually returns a list of, I think, 10 images. Variety will randomly download one of them when the time to download comes. But afterwards, on next change, you should see it.

Since most of this logic is governed by state kept in RAM and not persisted, if you restart Variety or the PC on a regular basis, with the long download interval you use, this prioritizing logic may not work, depends on the scheduling.

Peeyush (peey) said : #4

I understand this now. So variety should behave exactly as I'm expecting if I have a decent buffer of recently downloaded images, so that whenever it's time for changing - it most definitely has a new image to change to.

I could do this by setting the download period to a minute for a few minutes and setting it back to once a day.

But at the same time, since all the state is kept in RAM, the buffer I've created above would be useless because the information about all the new images in the buffer will be lost.

So what I also need is to ensure that after rebooting, my download timer is such that it has downloaded something - at least one thing - before it's time to change the wallpaper.

I'm thinking if I could do this by having a very minor change in the download period (say download once per 23 hours, change once per day)

But I'm not sure what happens to the timers once you reboot. Do they start again on boot? Do they take care of the "elapsed time" while the computer was off and do pending operations? (so if my machine was off for 3 days, would variety try to download 3 times?)

Or do they ignore what was scheduled to happen while the PC was off? -- this might cause problems (perhaps rarely) - if my computer was off 23.5 hours since last time variety downloaded a pic, the scheduled time to download a new one was 30 minutes ago, so it won't be downloaded. Whereas the wallpaper will be changed 30 minutes after the boot - to something random since there is nothing in the queue

I guess I can use the minutes unit to queue download cycle to be as close to the change cycle as possible - i.e. 23 hours, 58 minutes etc to make this very unlikely, so this shouldn't be a problem.

I'd just like to know which of the above is variety's behavior on boot

Best Peter Levi (peterlevi) said : #5

Digging into this old piece of code again, there is this logic and comment:

    def load_last_change_time(self):
        now = time.time()
        self.last_change_time = now

        # take persisted last_change_time into consideration only if the change interval is more than 6 hours:
        # thus users who change often won't have the wallpaper changed practically on every start,
        # and users who change rarely will still have their wallpaper changed sometimes even if Variety or the computer
        # does not run all the time
        if self.options.change_interval >= 6 * 60 * 60:
            try:
                with open(os.path.join(self.config_folder, ".last_change_time")) as f:
                    self.last_change_time = float(f.read().strip())

So, in your case, the last change time will be persisted and taken into account.
However, there is no similar logic for the download timer - it is always reset on start and Variety waits for a full interval before it downloads anything.

In general, I think if you use a shorter download interval, e.g. 5-6 hours, and keep the once-per-day changing, you should be seeing a fairly good selection of mostly "fresh" images with pretty rare cases of older images. And you'll also build up faster some buffer of downloads for the cases when you just want to scroll manually around the images.

Peeyush (peey) said : #6

Thanks for digging in and giving me the detailed information!

And I love this software, thanks for taking the time to maintain it.