Guest - Testers are needed for the reworked CDateTime core component. See... https://forum.kodi.tv/showthread.php?tid=378981 (September 29) x
v19 Play random videos from genre with overlay, switch genres using input
#1
I was trying to make a Kodi 19.1 Add-on which plays random videos within a genre and display a Genre Icon in the corner of the screen, disable player controls and use left/right/up/down to switch genres, finally return to main menu when the back/b button is pressed.
It was supposed to choose shows tagged with "morning" "midday" and "night" depending on the time of day.
I managed to find documentation to play a video but I couldn't understand how to define the paths without giving an explicit path like "E:/Kodi/Video/ExampleShow/ExampleSeason/S01E01.mp4"
One example which didn't work was "videodb://tvshows/genres/comedy/exampleshow/exampleseason/s01e01.mp4"

I ended up trying to run a playRandomVideo script using smart playlists but this caused an error message "can not play from non-permanent video source" and I couldn't add the playlist location as a source because it's in the hidden folder AppData ("special://profile/playlists/video/test.xsp"). Sometimes my addon would start the playlist and other times nothing would happen other than the error message.. I had no luck displaying an image using xbmcgui.ControlImage(10, 10, 200, 200, genre_icon_path).

I asked OpenAI to write some example code and spent 14 hours trying to fix it, discovering that most of the functionality was non-existent after fixing indentation and attempting some of the syntax errors..
This is the output from OpenAI
 
Code:
import xbmc
import xbmcgui
import random
import datetime

# Connect to the Kodi JSON-RPC API
kodi = xbmc.Kodi()

# Get the list of TV shows from the video library
shows = kodi.VideoLibrary.GetTVShows()

# Create a function to play random episodes
def play_random_episode(show_list, genre_filter):
    filtered_shows = []
    # Filter shows by genre
    for show in show_list:
        for genre in show["genre"]:
            if genre["label"] == genre_filter:
                filtered_shows.append(show)
                break
    # Get a random show from the filtered list
    random_show = random.choice(filtered_shows)
    # Get the seasons of the show
    seasons = kodi.VideoLibrary.GetSeasons(tvshowid=random_show["tvshowid"])
    # Get a random season from the list
    random_season = random.choice(seasons["result"]["seasons"])
    # Get the episodes of the season
    episodes = kodi.VideoLibrary.GetEpisodes(tvshowid=random_show["tvshowid"], season=random_season["season"])
        # Get a random number of episodes between 1 and 3
        random_number = random.randint(1,3)
    # Get a random episode from the list
    random_episodes = random.sample(episodes["result"]["episodes"], random_number)
    # Play the episodes
    for episode in random_episodes:
        kodi.Player.Open(item={"episodeid": episode["episodeid"]})
        if genre_filter != current_genre:
            # start playing the video from a random point
            kodi.Player.Seek(value=random.randint(0, episode["runtime"]))
            current_genre = genre_filter
        else:
        # Show the genre icon in the corner of the screen
        genre_icon_path = "special://userdata/addon_data/plugin.video.kodi/Genre Icons/" + genre_filter + ".png"
        genre_icon = xbmcgui.ControlImage(10, 10, 200, 200, genre_icon_path)
        xbmc.getCurrentWindowDialogId()
        genre_icon.setVisible(True)
        # Wait for the episode to end
        while not xbmc.abortRequested:
            xbmc.sleep(100)
            if xbmc.Player().isPlaying() == False:
                genre_icon.setVisible(False)
                break

# Get current time
now = datetime.datetime.now()

# loop to play random episodes depending on the time of day
while not xbmc.abortRequested:
    if now.hour >= 6 and now.hour < 12:
        # Morning, play comedy
        play_random_episode(shows["result"]["tvshows"], "Comedy")
    elif now.hour >= 12 and now.hour < 18:
        # Afternoon, play drama
        play_random_episode(shows["result"]["tvshows"], "Drama")
    elif now.hour >= 18 and now.hour < 22:
        # Evening, play Action
        play_random_episode(shows["result"]["tvshows"], "Action")
    else:
        # Night, play horror
        play_random_episode(shows["result"]["tvshows"], "Horror")
    now = datetime.datetime.now()
    # Disable player controls
    kodi.Player.SetPlayerControls(enable=False)
    # Wait for the back button to be pressed
    while not xbmc.abortRequested:
        xbmc.sleep(100)
        if xbmc.getCondVisibility("Input.IsButtonPressed(9)"):
            # Stop playback
            kodi.Player.Stop()
            break
and this is my add-on code which sometimes plays the playlist, never shows any picture and randomly gives an error message
 
Code:
import xbmc
import xbmcgui
import os

player = xbmc.Player()

genre_filter = "Comedy"
# Show the genre icon in the corner of the screen
genre_icon_path = "special://home/Genre Icons/" + genre_filter + ".jpg"
genre_icon = xbmcgui.ControlImage(10, 10, 200, 200, genre_icon_path)
genre_icon.setVisible(True)
runscript = 'RunScript(script.playrandomvideos, "special://profile/playlists/video/testcomedy.xsp")'
xbmc.executebuiltin(runscript)
# Wait for the videos to end
while not xbmc.Monitor().abortRequested:
    xbmc.sleep(100)
    if player.isPlaying() == False:
        genre_icon.setVisible(False)
        break
Please help me someone, I will pay for your time
Reply
#2
I spent a long time looking for tutorials to play videos from the local filesystem (in my case a windows PC) or to access the kodi database for pathinfo from added video sources and I'm beginning to think people just aren't able to do this...
Every tutorial skips from Hello World -> Your first online video or the odd tutorial to create a menu... There is so little documentation on this it's not even funny, who in their right mind thinks "ok i'll make ANOTHER tutorial to play a video online" and every single addon I saw for the first 30 pages was just "streaming app X for kodi addon"
I found people trying to do similar things to me with a different application and their posts were condescended to and ignored for years, often they solved their own problems.. I wouldn't be surprised if everyone who sees this post has no clue how to do something like this, especially with the tutorials available..
Reply
#3
Most of that AI code is garbage and missing specifics that are necessary for a functioning script.

What you are trying to accomplish is definitely achievable.

I'd suggest since you are new to programming break the project into smaller goals and learn as you go. For example; Start with a program that can play a single video, and display a single logo. Work your way to parsing your Kodi library for specific content.

If you are trying to cut corners you can avoid parsing Kodi's library by using playable paths via node filters (library://video/tvshows/genres.xml). Playable URL Ex.: "videodb://tvshows/genres/Action".

Good luck; if you need specific help with code please post here and I can help out.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#4
(2023-01-15, 19:22)Lunatixz Wrote: Most of that AI code is garbage and missing specifics that are necessary for a functioning script.

What you are trying to accomplish is definitely achievable.

I'd suggest since you are new to programming break the project into smaller goals and learn as you go. For example; Start with a program that can play a single video, and display a single logo. Work your way to parsing your Kodi library for specific content.

If you are trying to cut corners you can avoid parsing Kodi's library by using playable paths via node filters (library://video/tvshows/genres.xml). Playable URL Ex.: "videodb://tvshows/genres/Action".

Good luck; if you need specific help with code please post here and I can help out.

Thanks Lunatixz, I stumbled onto the PseudoTV Live beta yesterday and it has a lot of the features I was trying to make.

Is there a way to Refresh the library info for PseudoTV? I tried all the options in the utility menu and also reinstalled. The new genre of a show doesn't appear in the autotune list. Some deleted library content also got added to the guide.

I found a bug with some of my custom videos that were 5 mins long being given an hour slot in the guide and crashing the PVR client when playing (using Kodi or metadata is the same result). I will try to post the log to your thread this afternoon if it helps.

I would love to see an option to allow some shows to populate the guide at certain hours of the day.

I'm donating for your efforts creating this cool add-on, thanks again
Reply

Logout Mark Read Team Forum Stats Members Help
Play random videos from genre with overlay, switch genres using input0