X-Git-Url: http://git.hcoop.net/clinton/unknownlamer-kodi-addons.git/blobdiff_plain/fffe2166e5b9d471823c3c8b96ece2175ba18062..7517b9d5e1e376ef2d9ba98fab21a19e8f11fe07:/party-upload/admin.cgi diff --git a/party-upload/admin.cgi b/party-upload/admin.cgi dissimilarity index 79% index 4c67bb9..c1be02e 100755 --- a/party-upload/admin.cgi +++ b/party-upload/admin.cgi @@ -1,175 +1,143 @@ -#!/usr/bin/python - -# ADD COMMAND TO RESTART PARTY MODE -# (probably should require confirmation) -# also add undelete link to post-del link just in case (reinsert at old pos) - -# Trivial xbmc admin script to view active playlist, control volume, -# etc. - -# I would not recommend putting this online, no attempt is made at -# being even trivially secure (e.g. form values are passed directly to -# kodi with zero verification) - -# todo -# any kind of error checking - -from __future__ import unicode_literals - -# Python is being obnoxious as hell and refusing to .format() utf-8 -# strings. I have no idea. Just hack around it and deal with the -# actual problem later instead of scattering the code with .encode -# calls. - -import sys -reload(sys) -sys.setdefaultencoding ('utf-8') - -import cgi, cgitb -import os -import subprocess -import random -from xbmcjson import XBMC - -cgitb.enable() - -print ("content-type: text/html; charset=utf-8\n\n") - -print (u''' - - -
-''') - -music_dir = "/srv/archive/incoming/stolen-moosic" -form = cgi.FieldStorage () - -xbmc = XBMC ("http://localhost:8080/jsonrpc") - -def show_quick_search (term="",thereal=False): - print (u''' - - ''').format(term, 'id="quicksearch"' if thereal else '') - -def show_search_results (songs): - print (u"Deleted {}
".format(name['label'])) - print (xbmc.Playlist.Remove (playlistid=0, position=pos)) -elif 'songup' in form: - songid = int(form['songup'].value) - print (songid) - (pos,name) = next ((i,s) for i,s in enumerate(xbmc.Playlist.GetItems (playlistid=0)['result']['items']) if s['id'] == songid) - print (u"Promoted {}
".format(name['label'])) - print (xbmc.Playlist.Swap (playlistid=0, position1=pos, position2=pos-1)) -elif 'songdown' in form: - songid = int(form['songdown'].value) - print (songid) - (pos,name) = next ((i,s) for i,s in enumerate(xbmc.Playlist.GetItems (playlistid=0)['result']['items']) if s['id'] == songid) - print (u"Demoted {}
".format(name['label'])) - print (xbmc.Playlist.Swap (playlistid=0, position1=pos, position2=pos+1)) -elif 'volchange' in form: - curvolume = xbmc.Application.GetProperties (properties=['volume'])['result']['volume'] - newvolume = max (0, min (int (form['volchange'].value) + curvolume, 100)) - print (xbmc.Application.SetVolume (volume=newvolume)) -elif 'volmute' in form: - print (xbmc.Application.SetMute (mute="toggle")) -elif 'navigate' in form: - action = form['navigate'].value - if action == 'prev': - print xbmc.Player.GoTo (to="previous", playerid=0) - elif action == 'next': - print xbmc.Player.GoTo (to="next", playerid=0) - elif action == 'playpause': - print xbmc.Player.PlayPause (play="toggle", playerid=0) -elif 'searchgo' in form: - term = form['searchterm'].value - field = form['searchfield'].value - results = xbmc.AudioLibrary.GetSongs (filter={'operator': "contains", 'field': field, 'value': term}, properties=['album', 'albumartist'], sort={'order': 'ascending', 'method': 'artist'})['result']['songs'] - show_quick_search (term) - show_search_results (results) -elif 'randomqueue' in form: - songid = int(form['randomqueue'].value) - totalitems = xbmc.Playlist.GetItems (playlistid=0)['result']['limits']['total'] - playpos = random.randint (1, totalitems / 3 + 1) - print xbmc.Playlist.Insert (playlistid=0, item={"songid": songid}, position=playpos) - print 'Your song is number {0} in the queue ({1} songs in playlist).
'.format (playpos, totalitems+1) - - - - - -playlist = xbmc.Playlist.GetItems (playlistid=0, properties=['album', 'albumartist'])['result']['items'] -#playpos = random.randint (1, totalitems / (1 if 'asap' not in form else 3)) - -print ('') -print ('Volume: {}%
'.format(xbmc.Application.GetProperties (properties=['volume'])['result']['volume'])) -print (''' - -''') - -print (''' - -''') - - -print ('{}
".format (html.escape (u"{}".format (item)))) + +show_menu () + +manager = PartyManager (cgi.FieldStorage ()) +manager.process () + +playlist = Playlist() +#playpos = random.randint (1, totalitems / (1 if 'asap' not in form else 3)) + +class PlayerControls: + def __init__ (self, name='controls'): + self.name = name + + def info (self): + doc, tag, text = Doc().tagtext() + _playtime = xbmc.Player.GetProperties (playerid=0, properties = ['position', 'percentage', 'time', 'totaltime']) + pt = _playtime['result'] if 'result' in _playtime else None + with tag ('ul', klass = 'horiz-menu'): + for infotext in ['Volume {}%'.format(xbmc.Application.GetProperties (properties=['volume'])['result']['volume']), + 'Time {:02d}:{:02d} / {:02d}:{:02d} ({:.2f}%) @ {:%H:%M:%S}'.format (pt['time']['hours'] * 60 + pt['time']['minutes'], pt['time']['seconds'], pt['totaltime']['hours'] * 60 + pt['totaltime']['minutes'], pt['totaltime']['seconds'], pt['percentage'], datetime.now())]: + with tag ('li'): + text (infotext) + + return doc.getvalue () + + + +controls = PlayerControls () +print (controls.info ()) + +print ('') +print (''' + +'''.format (html.escape (PAGE_SELF))) + +print (''' + +'''.format (html.escape (PAGE_SELF))) + +print ('