Skip to content

Commit

Permalink
Fixed problems with ampersand and quote characters. Changed the menu …
Browse files Browse the repository at this point in the history
…to show more info and the thumbnail as a big image when a menu item is selected. The thumbnail is also shown in the menu when the recording is played.
  • Loading branch information
tizmon committed Oct 23, 2015
1 parent 44fa624 commit 8a49147
Showing 1 changed file with 55 additions and 28 deletions.
83 changes: 55 additions & 28 deletions addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# Note pydevd module need to be copied in XBMC\system\python\Lib\pysrc
try:
import pysrc.pydevd as pydevd
# stdoutToServer and stderrToServer redirect stdout and stderr to eclipse console
# stdoutToServer and stderrToServer redirect stdout and stderr to
# eclipse console
pydevd.settrace('localhost', stdoutToServer=True, stderrToServer=True)
except ImportError:
sys.stderr.write("Error: " +
Expand All @@ -42,6 +43,7 @@
# Init Elisa
elisa = elisaviihde.elisaviihde(False)


def get_params():
param = []
paramstring = sys.argv[2]
Expand All @@ -56,92 +58,115 @@ def get_params():
splitparams = {}
splitparams = pairsofparams[i].split('=')
if (len(splitparams)) == 2:
param[splitparams[0]] = splitparams[1]
param[splitparams[0]] = splitparams[1].replace('_ampersand_', '&').replace(
'_lessthan_', '<').replace('_greaterthan_', '>')
return param


def create_name(prog_data):
time_raw = prog_data["startTimeUTC"]/1000
parsed_time = datetime.datetime.fromtimestamp(time_raw).strftime("%d.%m.%Y %H:%M:%S")
weekday_number = int(datetime.datetime.fromtimestamp(time_raw).strftime("%w"))
time_raw = prog_data["startTimeUTC"] / 1000
parsed_time = datetime.datetime.fromtimestamp(
time_raw).strftime("%d.%m.%Y %H:%M:%S")
weekday_number = int(
datetime.datetime.fromtimestamp(time_raw).strftime("%w"))
prog_date = datetime.date.fromtimestamp(time_raw)
today = datetime.date.today()
diff = today - prog_date
if diff.days == 0:
date_name = __language__(30013) + " " + datetime.datetime.fromtimestamp(time_raw).strftime("%H:%M")
date_name = __language__(
30013) + " " + datetime.datetime.fromtimestamp(time_raw).strftime("%H:%M")
elif diff.days == 1:
date_name = __language__(30014) + " " + datetime.datetime.fromtimestamp(time_raw).strftime("%H:%M")
date_name = __language__(
30014) + " " + datetime.datetime.fromtimestamp(time_raw).strftime("%H:%M")
else:
date_name = str(weekdays[weekday_number]) + " " + datetime.datetime.fromtimestamp(time_raw).strftime("%d.%m.%Y %H:%M")
date_name = str(weekdays[weekday_number]) + " " + \
datetime.datetime.fromtimestamp(
time_raw).strftime("%d.%m.%Y %H:%M")
return prog_data['name'] + " (" + prog_data['serviceName'] + ", " + date_name + ")"


def show_dir(dirid=0):
# List folders
for row in elisa.getfolders(dirid):
add_dir_link(row['name'] + "/", row['id'])

data = elisa.getrecordings(dirid)
totalItems = len(data)

# List recordings
for row in data:
name = create_name(row)
add_watch_link(name,
row['programId'],
totalItems,
kwargs = {
"title": name,
"date": datetime.datetime.fromtimestamp(row["startTimeUTC"]/1000).strftime("%d.%m.%Y"),
"duration": ((row["endTimeUTC"]/1000/60) - (row["startTimeUTC"]/1000/60)),
"plotoutline": (row['description'] if "description" in row else "N/a").encode('utf8'),
"playcount": (1 if row['isWatched'] else 0),
"iconimage": (row['thumbnail'] if "thumbnail" in row else "DefaultVideo.png")
kwargs={
"title": name.replace('"', '\'\'').replace('&', '_ampersand_').replace('<', '_lessthan_').replace('>', '_greaterthan_'),
"date": datetime.datetime.fromtimestamp(row["startTimeUTC"] / 1000).strftime("%d.%m.%Y"),
"aired": datetime.datetime.fromtimestamp(row["startTimeUTC"] / 1000).strftime("%d.%m.%Y"),
"duration": ((row["endTimeUTC"] / 1000 / 60) - (row["startTimeUTC"] / 1000 / 60)),
"plotoutline": (row['description'] if "description" in row else "N/a").encode('utf8').replace('"', '\'\'').replace('&', '_ampersand_').replace('<',
'_lessthan_').replace('>', '_greaterthan_'),
"plot": str((row['serviceName'] if "serviceName" in row else "N/a").encode('utf8') + '\n' +
datetime.datetime.fromtimestamp(row["startTimeUTC"] / 1000).strftime("%d.%m.%Y") + ' ' + str((row["endTimeUTC"] / 1000 / 60) - (row["startTimeUTC"] / 1000 / 60)) + ' min\n' +
(row['description'] if "description" in row else "N/a").encode('utf8')).replace('"', '\'\'').replace('&', '_ampersand_').replace('<', '_lessthan_').replace('>', '_greaterthan_'),
"playcount": (1 if row['isWatched'] else 0),
"iconimage": (row['thumbnail'] if "thumbnail" in row else "DefaultVideo.png"),
})


def add_dir_link(name, dirid):
u = sys.argv[0] + "?dirid=" + str(dirid)
liz = xbmcgui.ListItem(label=name, iconImage="DefaultFolder.png")
liz.setInfo('video', {"Title": name})
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=True)
xbmcplugin.addDirectoryItem(handle=int(
sys.argv[1]), url=u, listitem=liz, isFolder=True)
return liz


def add_watch_link(name, progid, totalItems=None, kwargs={}):
u = sys.argv[0] + "?progid=" + str(progid) + "&watch=" + json.dumps(kwargs).replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
liz = xbmcgui.ListItem(name, iconImage=kwargs["iconimage"])
u = sys.argv[0] + "?progid=" + str(progid) + "&watch=" + json.dumps(kwargs)
liz = xbmcgui.ListItem(name, iconImage=kwargs[
"iconimage"], thumbnailImage=kwargs["iconimage"])
liz.setProperty('fanart_image', kwargs["iconimage"])
liz.setInfo('video', kwargs)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, totalItems=totalItems)
xbmcplugin.addDirectoryItem(handle=int(
sys.argv[1]), url=u, listitem=liz, totalItems=totalItems)
return liz


def watch_program(progid=0, watch=""):
url = elisa.getstreamuri(progid)
kwargs = json.loads(watch.replace('&amp;', '&').replace('&lt;', '<').replace('&gt;', '>'))
listitem = xbmcgui.ListItem(kwargs["title"])
kwargs = json.loads(watch)
listitem = xbmcgui.ListItem(kwargs["title"], iconImage=kwargs[
"iconimage"], thumbnailImage=kwargs["iconimage"])
listitem.setInfo('video', kwargs)
xbmc.Player().play(url, listitem)
return True


def mainloop():
try:
elisa.setsession(json.loads(__settings__.getSetting("session")))
except ValueError as ve:
__settings__.setSetting("session", "{}")

if not elisa.islogged():
dialog = xbmcgui.Dialog()
ok = dialog.ok('XBMC', __language__(30003), __language__(30004))
if ok == True:
__settings__.openSettings(url=sys.argv[0])

username = __settings__.getSetting("username")
password = __settings__.getSetting("password")
elisa.login(username, password)
__settings__.setSetting("session", json.dumps(elisa.getsession()))

params = get_params()

dirid = None
progid = None
watch = None

try:
dirid = int(params["dirid"])
except:
Expand All @@ -166,6 +191,8 @@ def mainloop():
else:
show_dir(0)

xbmcplugin.setContent(handle=int(sys.argv[1]), content="movies")
xbmc.executebuiltin('Container.SetViewMode(504)')
xbmcplugin.endOfDirectory(int(sys.argv[1]))

if __name__ == '__main__':
Expand Down

0 comments on commit 8a49147

Please sign in to comment.