Help with Screenshots filepaths
#1
Hi everyone,

I'm relatively new to Kodi, having recently transitioned from an MPV setup after getting a Xiaomi box.
I've set up Kodi to share files using SMB, and everything is working smoothly so far. However, I'm finding the screenshot feature to be a bit limited.
I've successfully configured a folder where all my screenshots are saved, but the problem is that they're all being dumped into the same directory with generic filenames.

Is there a way to replicate MPV's functionality in Kodi? Specifically, I'd like Kodi to create a separate folder for each show, with the episode title as the filename for each screenshot.

For reference, in MPV, I used the following syntax:
Code:
screenshot-template="%xscreenshots\%F%02n
Reply
#2
(2024-09-03, 22:52)fistchu Wrote: Specifically, I'd like Kodi to create a separate folder for each show, with the episode title as the filename for each screenshot.
Unfortunately not. There are no adjustments for the screenshot functionality and all images are saved into a single folder.
If you are a coder, maybe you could consider a feature improvement...
https://github.com/grubernd/xbmc/blob/ma...enshot.cpp
My Signature
Links to : Official:Forum rules (wiki) | Official:Forum rules/Banned add-ons (wiki) | Debug Log (wiki)
Links to : HOW-TO:Create Music Library (wiki) | HOW-TO:Create_Video_Library (wiki)  ||  Artwork (wiki) | Basic controls (wiki) | Import-export library (wiki) | Movie sets (wiki) | Movie universe (wiki) | NFO files (wiki) | Quick start guide (wiki)
Reply
#3
(2024-09-03, 23:17)Karellen Wrote:
(2024-09-03, 22:52)fistchu Wrote: Specifically, I'd like Kodi to create a separate folder for each show, with the episode title as the filename for each screenshot.
Unfortunately not. There are no adjustments for the screenshot functionality and all images are saved into a single folder.
If you are a coder, maybe you could consider a feature improvement...
https://github.com/grubernd/xbmc/blob/ma...enshot.cpp
I see, thank you for your answer. I don't feel comfortable enough working on the source itself, but with GPT's help I managed to create a workaround based on a script from another forum post.

I don't know the first thing about Kodi programming but it's working well so far at least. It's only the .jpg conversion that never worked in the end.

Script:
python:
import xbmc
import xbmcgui
import xbmcvfs
import re
import time

# Function to wait until the new screenshot is detected
def wait_for_screenshot(folder, pattern, timeout=10, check_interval=0.5):
"""
Waits for a new screenshot file to appear in the folder that matches the given pattern.

Args:
folder (str): The directory where screenshots are saved.
pattern (Pattern): The compiled regex pattern to match screenshot filenames.
timeout (int): Maximum time to wait in seconds (default is 10 seconds).
check_interval (float): Time between each check in seconds (default is 0.5 seconds).

Returns:
str: The latest screenshot filename if found, None otherwise.
"""
elapsed_time = 0
while elapsed_time < timeout:
# List all files in the folder and check if any match the pattern
screenshot_files = [file for file in xbmcvfs.listdir(folder)[1] if pattern.fullmatch(file)]
if screenshot_files:
return screenshot_files[-1] # Return the latest screenshot if found
time.sleep(check_interval) # Wait before checking again
elapsed_time += check_interval
return None # Return None if no screenshot is found within the timeout

# Main function to capture and rename screenshots
def get_screenshot() -> None:
"""
Captures a screenshot, saves it to the appropriate folder, and renames it with an incremented number.
"""
# Retrieve the current folder path (applies to episodes and files)
current_folder = xbmc.getInfoLabel('Player.Folderpath')

# Validate if media is being played, skip if not
if (not xbmc.getCondVisibility('Player.HasMedia')
or xbmc.getCondVisibility('Player.IsInternetStream')):
return

# Normalize folder path to use forward slashes
current_folder = current_folder.replace('\\', '/')
shot_folder = current_folder + 'screenshot/'

# Create the screenshot folder if it doesn't exist
if not xbmcvfs.exists(shot_folder):
xbmcvfs.mkdir(shot_folder)

# Set the screenshot folder in Kodi
str_shot_folder = f'"{shot_folder}"'
response = xbmc.executeJSONRPC(
'{"jsonrpc":"2.0", "method":"Settings.SetSettingValue",'
'"params": {"setting": "debug.screenshotpath", "value": %s}, "id":1}' % str_shot_folder
)

# Take the screenshot if the setting change was successful
if 'result' in response:
xbmc.executebuiltin('TakeScreenshot')
notify_dialog = xbmcgui.Dialog()
notify_dialog.notification('Screenshot taken', '', '', 1000)

# Get the current media filename
full_path = xbmc.getInfoLabel('Player.Filenameandpath')
filename = full_path.split('/')[-1] # Extract filename from the path

xbmc.sleep(500) # Ensure the screenshot is saved

# Patterns to match screenshots and incremented filenames
shot_pattern = re.compile(r'screenshot(\d+)\.png')
increment_pattern = re.compile(rf'{re.escape(filename)}_(\d+)\.png')

# Wait for the new screenshot to appear in the folder
latest_screenshot = wait_for_screenshot(shot_folder, shot_pattern)

# If a screenshot was found, proceed with renaming
if latest_screenshot:
# Get list of existing files that match the increment pattern
existing_files = [file for file in xbmcvfs.listdir(shot_folder)[1] if increment_pattern.fullmatch(file)]
max_number = 0

# Find the highest number among the existing incremented files
for existing_file in existing_files:
match = increment_pattern.search(existing_file)
if match:
number = int(match.group(1))
if number > max_number:
max_number = number

# Increment the file number for the new screenshot
new_number = max_number + 1
new_file_path = shot_folder + f"{filename}_{str(new_number).zfill(2)}.png"

try:
# Rename the latest screenshot to the new incremented filename
xbmcvfs.rename(shot_folder + latest_screenshot, new_file_path)
except IOError as ioerror:
xbmc.log(f"Unable to rename {latest_screenshot} due to {ioerror}", xbmc.LOGERROR)
else:
xbmc.log("Screenshot not found within the timeout period.", xbmc.LOGERROR)

# Entry point for the script
if __name__ == '__main__':
get_screenshot()
Reply

Logout Mark Read Team Forum Stats Members Help
Help with Screenshots filepaths0