Skip to content

Commit

Permalink
escape html codes
Browse files Browse the repository at this point in the history
  • Loading branch information
lrusak committed Sep 27, 2016
1 parent ad4fc0d commit 6c48f72
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import urllib
import urlparse
from HTMLParser import HTMLParser

import xbmc
import xbmcgui
Expand Down Expand Up @@ -81,7 +82,7 @@ def add_track(self, track, show_artist=False):
title = track.get("title", "<Unknown>")

# Create item
li = xbmcgui.ListItem(title)
li = xbmcgui.ListItem(self._encode(title))

# Handle cover art
if "coverArt" in track:
Expand All @@ -95,8 +96,8 @@ def add_track(self, track, show_artist=False):
li.setProperty("IsPlayable", "true")
li.setMimeType(track.get("contentType"))
li.setInfo(type="Music", infoLabels={
"Artist": track.get("artist"),
"Title": track.get("title"),
"Artist": self._encode(track.get("artist")),
"Title": self._encode(track.get("title")),
"Year": track.get("year"),
"Duration": track.get("duration"),
"Genre": track.get("genre"),
Expand Down Expand Up @@ -128,7 +129,7 @@ def add_album(self, album, show_artist=False):

# Create item
li = xbmcgui.ListItem()
li.setLabel(title)
li.setLabel(self._encode(title))

# Handle cover art
if "coverArt" in album:
Expand All @@ -140,8 +141,8 @@ def add_album(self, album, show_artist=False):

# Handle metadata
li.setInfo(type="music", infoLabels={
"Artist": album.get("artist"),
"Album": album.get("name"),
"Artist": self._encode(album.get("artist")),
"Album": self._encode(album.get("name")),
"Year": album.get("year")})

xbmcplugin.addDirectoryItem(
Expand Down Expand Up @@ -254,7 +255,7 @@ def artist_list(self):
"mode": "album_list",
"artist_id": artist["id"]})

li = xbmcgui.ListItem(artist["name"])
li = xbmcgui.ListItem(self._encode(artist["name"]))
li.setIconImage(cover_art_url)
li.setThumbnailImage(cover_art_url)
li.setProperty("fanart_image", cover_art_url)
Expand Down Expand Up @@ -368,6 +369,13 @@ def random_by_year_list(self):
xbmcplugin.endOfDirectory(self.addon_handle)


def _encode(self, name):
"""
Converts html encoding into unicode
"""

return HTMLParser().unescape(str(name)).encode('utf-8')

def main():
"""
Entry point for this plugin. Instantiates a new plugin object and runs the
Expand Down

0 comments on commit 6c48f72

Please sign in to comment.