Kodi Community Forum
Information Browse movies like tv channels - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: Video Support (https://forum.kodi.tv/forumdisplay.php?fid=264)
+--- Thread: Information Browse movies like tv channels (/showthread.php?tid=378373)



Browse movies like tv channels - Dvrhax - 2024-07-30

So this may sound like an odd request but I have watched more movies that I own on tv than I care to admit. There is something about channel surfing and stopping on an in progress movie that you just don't get from selecting a title from a list.

So I would like to write an addon that Everytime I push the up or down arrow randomly selects a movie and a random starting position in the first say 10 minutes of a movie.

I'm just not sure how to go about doing this. I've written add-ons before and am quite proficient with python I'm just struggling where to start with this. So if someone could help with the framework of adding a button on the main selection, ie movies tv, music, etc that then opens a random movie from the collection plays it and rebinds the up down keys to play a different movie, I would greatly appreciate it.

Thank you


RE: Browse movies like tv channels - Lunatixz - 2024-07-30

https://forum.kodi.tv/showthread.php?tid=355549

https://forum.kodi.tv/showthread.php?tid=170975


RE: Browse movies like tv channels - Dvrhax - 2024-07-30

Maybe I'm not that weird. Thanks for the resources. I'll test them out to see if they offer what I'm looking for, if not use the code to start something new. Thanks again


RE: Browse movies like tv channels - Dvrhax - 2024-08-11

So this is what I came up with still needs some tweaking here and there to get at original intent, but functions well, just needs a little code cleanup.
Quote:import xbmc, xbmcaddon, xbmcgui
import random, json, time


class MyPlayer(xbmc.Player):#None of these callbacks work and need this functionality to do a seek at the beginning of new media.
    def __init__(self):
        #xbmc.Player.__init__(self)
        xbmc.log('ChannelSurfer - Instantiating Player', xbmc.LOGWARNING)
        pass

    def onPlayBackEnded(self):
        xbmc.log('ChannelSurfer - PlayBackEnded', xbmc.LOGWARNING)

    def onPlayBackStarted(self):
        xbmc.log('ChannelSurfer - PlayBackStarted', xbmc.LOGWARNING)

    def onPlaybackStopped(self):
        xbmc.log('ChannelSurfer - PlayBackStopped', xbmc.LOGWARNING)

    def onAVStarted(self):
        xbmc.log('ChannelSurfer - AVStarted', xbmc.LOGWARNING)

    def onAVChange(self):
        xbmc.log('ChannelSurfer - AVChange', xbmc.LOGWARNING)

    def onQueueNextItem(self):
        xbmc.log('ChannelSurfer - QueueNextItem', xbmc.LOGWARNING)

#query_AllMovies = '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties" : ["file"]}, "id": "libMovies"}'
query_AllMovies = '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties" : ["playcount", "genre", "file"]}, "id": "libMovies"}' #Include Watched and genre data

ret = xbmc.executeJSONRPC(query_AllMovies)
movies = json.loads(ret)['result']['movies']

def getGenres(movies, exclude=[]):
    genres = set()
    for movie in movies:
        genres.update(movie['genre'])
    for e in exclude:
        try:
            genres.remove(e)
        except KeyError:
            pass
    return sorted(genres)

def filterMovies(movies, genre):
    ret = []

    for movie in movies:
        if genre == 'Watched':
            if movie['playcount']:
                ret.append(movie)
        elif genre == 'Unwatched':
            if not movie['playcount']:
                ret.append(movie)
        elif genre in movie['genre']:
            ret.append(movie)
    return ret

genres = getGenres(movies)

selected = None
genreSelectPrepend = ['Play', 'Watched', 'Unwatched']
selectedList = []
while True:
    selectionList = genreSelectPrepend + genres
    selected = selectionList[xbmcgui.Dialog().select('Genre Select', selectionList)]
    selectedList.append(selected)
    if selected == 'Play': break
    elif selected in ('Watched', 'Unwatched'):
        genreSelectPrepend = ['Play']
    movies = filterMovies(movies, selected)
    genres = getGenres(movies, selectedList)

playList = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
for movie in movies:
    playList.add(movie['file'])

playList.shuffle()

player = MyPlayer()
#player.PlayMedia(movie['file'], noresume=True) #Need to figure out the noresume functionality to keep from litering continue watching
player.play(playList)
while not player.isPlaying():#Seek fails if called too early
    time.sleep(2)
player.seekTime(random.randint(0, 300))#Doesn't work reliably and doesn't seem to work at all on Android

while player.isPlaying():#Keeps script alive while media is playing
    time.sleep(2)
xbmc.log('ChannelSurfer Out', xbmc.LOGWARNING)