2013-06-19, 07:58
Can someone with some scripting/programming experience please help me edit this py script to suit my needs?
It is a script that scans through your TV DB, and plays random episodes, but the first unwatched episode of that season.
Thanks to Roman_V_M that gave me the script, in this thread http://forum.xbmc.org/showthread.php?tid=166925
My only problem with the script is, that I dont want sitcoms included, and also not any of my daughters shows, I watch enough Dora The Explorer when she is awake
So I thought that I would be able to open and make some changes, but boy, was I wrong! Some common sense would say that just adding a if statement somewhere to filter out any episodes shorter than say 30mins will work fine, or if anyone has any ideas?
Here is the download to the script:
https://disk.yandex.com/public/?hash=s9b...lAE4dT4%3D
And here is the code
It is a script that scans through your TV DB, and plays random episodes, but the first unwatched episode of that season.
Thanks to Roman_V_M that gave me the script, in this thread http://forum.xbmc.org/showthread.php?tid=166925
My only problem with the script is, that I dont want sitcoms included, and also not any of my daughters shows, I watch enough Dora The Explorer when she is awake
So I thought that I would be able to open and make some changes, but boy, was I wrong! Some common sense would say that just adding a if statement somewhere to filter out any episodes shorter than say 30mins will work fine, or if anyone has any ideas?
Here is the download to the script:
https://disk.yandex.com/public/?hash=s9b...lAE4dT4%3D
And here is the code
Code:
# -*- coding: utf-8 -*-
import json, random, datetime
import xbmc, xbmcgui
IGNORE = []
def json_query(query):
xbmc_request = json.dumps(query)
result = xbmc.executeJSONRPC(xbmc_request)
return json.loads(result)
def main():
dt = datetime.datetime.now()
seed_value = dt.day * 1000 + dt.hour * 100 + dt.minute * 10 + dt.second + dt.microsecond
random.seed(seed_value)
shows_query = {
'jsonrpc': '2.0',
'method': 'VideoLibrary.GetTVShows',
'params': { 'properties': ['episode', 'watchedepisodes'],
'sort': {'order': 'ascending', 'method': 'label'}},
'id': '1'}
shows_list = json_query(shows_query)['result']['tvshows']
for item in shows_list:
if item['watchedepisodes'] < item['episode']:
unwatched = True
break
else:
unwatched = False
while unwatched:
show = shows_list[random.randint(0, len(shows_list) - 1)]
if show['watchedepisodes'] < show['episode'] and show['tvshowid'] not in IGNORE:
seasons_query = {
'jsonrpc': '2.0',
'method': 'VideoLibrary.GetSeasons',
'params': { 'tvshowid': show['tvshowid'],
'properties': ['episode', 'watchedepisodes', 'season'],
'sort': {'order': 'ascending', 'method': 'season'}},
'id': '1'}
seasons = json_query(seasons_query)['result']['seasons']
for season in seasons:
if season['watchedepisodes'] < season['episode']:
episodes_query = {
'jsonrpc': '2.0',
'method': 'VideoLibrary.GetEpisodes',
'params': { 'tvshowid': show['tvshowid'],
'season': season['season'],
'properties': ['file']},
'id': '1'}
episodes = json_query(episodes_query)['result']['episodes']
break
play_command = {
'jsonrpc': '2.0',
'method': 'Player.Open',
'params': {'item': {'file': episodes[season['watchedepisodes']]['file']},
'options':{'resume': True}},
'id': '1'}
json_query(play_command)
subtitles_on = {
'jsonrpc': '2.0',
'method': 'Player.SetSubtitle',
'params': {'subtitle': 'on'},
'id': '1'}
json_query(subtitles_on)
break
else:
dialog = xbmcgui.Dialog()
dialog.ok('Oops!', 'No unwatched episodes\nto play.')
if __name__ == '__main__':
main()