Created
October 27, 2023 09:23
-
-
Save evinjaff/db051ed2926fbd9a30dcfe255998c94f to your computer and use it in GitHub Desktop.
Random Startup Movie Hack for Arctic Zephyr Kodi Skin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<addon id="service.autoexec" name="Autoexec Service" version="1.0.0" provider-name="evinjaff"> | |
<requires> | |
<import addon="xbmc.python" version="3.0.0"/> | |
</requires> | |
<extension point="xbmc.service" library="autoexec.py"> | |
</extension> | |
<extension point="xbmc.addon.metadata"> | |
<summary lang="en_GB">Automatically run python code when Kodi starts.</summary> | |
<description lang="en_GB">The Autoexec Service will automatically be run on Kodi startup.</description> | |
<platform>all</platform> | |
<license>GNU GENERAL PUBLIC LICENSE Version 2</license> | |
</extension> | |
</addon> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a super basic Python Script that extends the option to play a movie upon starting Kodi to play a random movie. | |
# The rough way this works is that Arctic Zephyr lets you point at a video file to play on startup (this is very | |
# similar to say, the Steam Deck). Since Artic Zephyr's XML language has minimal scripting, all we need to do is just | |
# treat that file as if its a symlink and drop in a different file each time. Since autoexec runs sometimes before/during | |
# loading the skin, it's better to actually replace the startup movie for the next run and let the cycle perpetuate. | |
# | |
# Python isn't great at handling symlinks, so I just decided to use shutils and copy to overwrite the file. I did need to | |
# add a delay, but I might look in the future about using atomics or formalizing this as an add-on instead of just a gist. | |
# No external Python dependencies are needed! Should be supported on any relatively modern Python Version. To install this, | |
# You need to put these files in a folder inside your .kodi folder under the addons folder. In Linux, that should look like | |
# ~/.kodi/addons/service.autoexec | |
# ├── service.autoexec | |
# │ ├── addon.xml | |
# │ └── autoexec.py | |
# Fill in your dest_directory and source_directory at the bottom where source_directory should contain the set of video files | |
# you want to pull from, and the dest_directory is the directory you want to hold the .mp4 file that will act as the | |
# pointer/symlink for Artic Zephyr to load. Point Artic Zephyr at that file for the video intro and download some MP4s to be | |
# your intro! | |
import os | |
import random | |
import shutil | |
import time | |
# I first ran this script without any delays, but then found that sometimes there were issues where only half the video played | |
# and then it just cut to a green screen. If that happens, increase this number, but 3 should be ok. | |
OS_TIME_DELAY = 3 | |
def get_random_mp4(directory): | |
# List all files in the directory | |
files = os.listdir(directory) | |
# Filter out only .mp4 files | |
mp4_files = [f for f in files if f.endswith('.mp4')] | |
# Return a random .mp4 file | |
return random.choice(mp4_files) | |
def copy_to_destination(src_directory, dest_directory, dest_filename="1.mp4"): | |
# Get a random .mp4 file from the source directory | |
random_mp4 = get_random_mp4(src_directory) | |
# Construct full paths for source and destination | |
src_path = os.path.join(src_directory, random_mp4) | |
dest_path = os.path.join(dest_directory, dest_filename) | |
# print("Copying from", src_path) | |
# print("Copying to", dest_path) | |
time.sleep(OS_TIME_DELAY) | |
# Copy the file (overwriting if necessary) | |
shutil.copy2(src_path, dest_path) | |
# print(f"Copied {random_webm} to {dest_path}") | |
# Example usage | |
src_directory = "~/.kodi/Intros/Candidates" | |
dest_directory = "~/.kodi/Intros" | |
copy_to_destination(src_directory, dest_directory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment