Petter Holt Juliussen • Mail | Mastodon | GitHub | Letterboxd

for later reference.

Scripting

2019-04-04

Resources

Scripts

# Modules
import xbmc, xbmcgui

# Notification
n = xbmcgui.Dialog().notification('Header', 'Message') #, icon, time, sound)
del n
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Imports
import requests
import xbmc
import xbmcgui
from dateutil import parser

from sys_info import *
from watchlist import show_watchlist


# Notification
def notify(heading, message, icon=xbmcgui.NOTIFICATION_INFO, time=5000):
    # xbmcgui.NOTIFICATION_INFO | xbmcgui.NOTIFICATION_WARNING | xbmcgui.NOTIFICATION_ERROR
    notification = xbmcgui.Dialog().notification(heading, message, icon, time)
    del notification


control = xbmc.getInfoLabel('System.CurrentControl')
control_id = xbmc.getInfoLabel('System.CurrentControlID')
window = xbmc.getInfoLabel('System.CurrentWindow')
plugin = xbmc.getInfoLabel('Container.PluginName')
listitem_label = xbmc.getInfoLabel('ListItem.Label')
listitem_title = xbmc.getInfoLabel('ListItem.Title')
listitem_year = xbmc.getInfoLabel('ListItem.Year')
player_title = xbmc.getInfoLabel('VideoPlayer.Title')
player_year = xbmc.getInfoLabel('VideoPlayer.Year')
player_imdb = xbmc.getInfoLabel('VideoPlayer.IMDBNumber')
# gpu_temperature = xbmc.getInfoLabel('System.GPUTemperature')

print '-'*50
print 'Control: %r' % (control)
print 'Control ID: %r' % (control_id)
print 'Window: %r' % (window)
print 'Plugin: %r' % (plugin)
print 'ListItem.Label: %r' % (listitem_label)
print 'ListItem.Title: %r' % (listitem_title)
print 'ListItem.Year: %r' % (listitem_year)
print 'Player.Title: %r' % (player_title)
print 'Player.Year: %r' % (player_year)
print 'Player.IMDb: %r' % (player_imdb)
print '-'*50



# Window: Fullscreen video
if window == 'Fullscreen video':
    # NRK live stream
    if player_title in ['NRK1', 'NRK2', 'NRK3']:
        # EPG
        try:
            epg = requests.get('/path/to/api/nrk/epg/%s/' % (player_title.lower())).json()

            text = ' '*5

            for i in [0, 1, 2]:
                if str(i) in epg['response']['result']:
                    program = epg['response']['result'][str(i)]
                    title = program['title']
                    start = parser.parse(program['start']).strftime('%H:%M')

                    time = 'NÅ' if i == 0 else start
                    text += '[COLOR 40FFFFFF]%s[/COLOR]  %s%s' % (time, title, ' '*10)

            current_title = epg['response']['result']['0']['title']
            current_description = epg['response']['result']['0']['description']
            current_text = ' '*5 + '[COLOR 40FFFFFF]NÅ[/COLOR]  ' + current_title + ': ' + current_description
        except:
            raise
        else:
            notify(player_title, text, time=6000)
            xbmc.sleep(6000)
            notify(player_title, current_text, time=15000)
            quit()

    # Unknown
    else:
        notify('Unknown media', 'No action defined for currently playing media (title=%s)' % (
            player_title
        ), time=1500)

else:
    # Display menu
    # li = xbmcgui.ListItem(label='Watchlist', thumbnailImage='/storage/downloads/eminence/icons/nrk.png')
    functions = ['Watchlist', 'System info', 'Toggle debug']
    dialog = xbmcgui.Dialog().select('Blue button', functions)
    print 'Selected: %d' % (dialog)

    if dialog == 0:
        # Watchlist
        show_watchlist()

    if dialog == 1:
        # System info
        nuc = get_nuc_info()
        nuc_info = '[COLOR 40FFFFFF]NUC[/COLOR]  CPU=%s°C, GPU=%s°C' % (nuc['cpu'], nuc['gpu'])
        nas = get_synology_info()
        disks = ['disk%d=%s°C' % ((i+1), str(t)) for i, t in enumerate(nas['disks_temp'])]
        nas_info = '[COLOR 40FFFFFF]NAS[/COLOR]  %s' % (', '.join(disks))
        sys_info = ' '*5 + nuc_info + '   |   ' + nas_info
        notify('System', sys_info, time=15000)

    if dialog == 2:
        # Toggle debug
        xbmc.executebuiltin('ToggleDebug')



# WINDOW_DIALOG_FAVOURITES
# dia = xbmcgui.Dialog()
# seleccion = dia.select("Listar desde el Av±o: ", ['hei', 'foo', 'bar'])

'''
xbmc.executebuiltin('ActivateWindow(10106)')
xbmc.sleep(100)
dialog = xbmcgui.Window(10106)
xbmc.sleep(10)
controllist = dialog.getControl(996)
print controllist
# dialog.getControl(1).setLabel('HEISANN')
'''

'''

item = xbmcgui.ListItem('Trivia')
item.setPath('https://www.youtube.com/watch?v=J9d9UrK0Jsw')
item.setProperty('IsPlayable' , 'true')

controllist.addItem(item)
'''