Python script to generate thumbnails (via keystrokes)
#1
My situation: I have all my pictures in folders (year-month) on an external hdd (Tvix/Photos) on a rpi3b+
If I auto-generate thumbnails, when I navigate the 1st time in the folder, it can take a very big amount of time to display these (and I remember vaguely about non-responding interface).
So, I decided to prepare these thumbnails while not using my pi: it's hacky, but I couldn't find another way to do it: the idea is to send keystrokes via json.
I don't think any tool exists, for now, to do this.

You need the kodijson.py file in the same folder as this script (it comes from:
https://github.com/jcsaaddupuy/python-kodijson
)

Adapt to your own configuration. I wished I could find an easy way to get the number of files per folder, but I don't think it is exposed via json queries.

I'm launching this with Spyder3 which is my Ide for python things.
I repeat: it seems very hacky, but it does the job for me, so I share it.

It works on my transparency skin, with the pictures folders in the "list" view, descending sorting.
python:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Aug  6 10:54:49 2019

@author:
tested on libreelec 9.0 (kodi 18)
tested in transparency, with the folder as a favorite in pictures
In the pictures: view: list, sort:descending
"""
from kodijson import Kodi, PLAYER_VIDEO
import time
import datetime


#estimated maxi number of pictures in each folder
#(100 should be sufficient to force caching most of pictures)
nb_pict=60
#if we don't want to start at the 1st folder:
offset_start=140
#waiting time between 2 clicks
wait_time=0.5

kodi = Kodi("http://192.168.1.3/jsonrpc")
#get the nb of folders to explore
dict1=kodi.Files.GetDirectory(directory="/var/media/Tvix/Photos",media="video")
#for directories:media="video" and for dir+files: media="files"
#dict1=kodi.Files.GetDirectory(directory="/var/media/Tvix/Games",media="video")
#dict1=kodi.Files.GetDirectory(directory="/var/media/Tvix/Games",media="files")
#print(dict1)
answer1=dict1.get('result')
answer2=answer1.get('limits')
answer3=answer2.get('total')
print(str(answer3)+" folders with pictures")
#wake up (there's probably a screensaver in action: so 1st stroke is just to bring back the interface)
kodi.Input.Down()
time.sleep(5)

#go to the pictures menu
#new_boot is for debugging purposes
new_boot=1
    
if new_boot:
    for i in range(4):
        kodi.Input.Down()
        time.sleep(wait_time)
    kodi.Input.Right()
    time.sleep(wait_time)
    kodi.Input.Select()
    time.sleep(5)

#We're now in the correct picture folder
#move down and select (to avoid the [..] folder)
#you must be in list view
if offset_start:
    for i in range(offset_start):
        kodi.Input.Down()

offset_range=answer3-offset_start
for i in range(offset_range):
    print("Treated folders: "+str(offset_start+i)+"/"+str(answer3)+" time="+
          str(datetime.timedelta(seconds=wait_time*nb_pict*(answer3-i))))
    kodi.Input.Down()
    time.sleep(wait_time)
    kodi.Input.Select()
    time.sleep(wait_time)
    for j in range(nb_pict):
        kodi.Input.Down()
        time.sleep(wait_time)
    kodi.Input.Back()
    time.sleep(2)
Reply
#2
Isn't texturecache.py (https://github.com/MilhouseVH/texturecache.py) able to solve this?
Reply
#3
(2019-08-07, 15:46)Uatschitchun Wrote: Isn't texturecache.py (https://github.com/MilhouseVH/texturecache.py) able to solve this?
Was going to recommend this great script!
Image Image
Reply
#4
Unfortunately texturecache.py doesn't generate thumbnails for your pictures collection (as far as I know). Maybe there's an option somewhere that I overlooked ?
Reply

Logout Mark Read Team Forum Stats Members Help
Python script to generate thumbnails (via keystrokes)0