Skip to content

Commit

Permalink
Version 2.1.3
Browse files Browse the repository at this point in the history
* Better unicode error handling (#122)
* Localization fixes and optimisation
  • Loading branch information
Cigaras committed May 22, 2017
1 parent 6a246b1 commit d189122
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
25 changes: 17 additions & 8 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def ListGroups(page = 1):

use_groups = False
for group in groups_list:
if group['title'] not in [unicode(L('All')), unicode(L('No category'))]:
if group['title'] not in [unicode('All'), unicode('No category')]:
use_groups = True
break

Expand All @@ -126,12 +126,12 @@ def ListGroups(page = 1):
oc = ObjectContainer(title1 = unicode(L('View playlist')))
oc.add(
DirectoryObject(
key = Callback(ListItems, group = unicode(L('All'))),
key = Callback(ListItems, group = unicode('All')),
title = unicode(L('All'))
)
)
for group in groups_list:
if group['title'] not in [unicode(L('All')), unicode(L('No category'))]:
if group['title'] not in [unicode('All'), unicode('No category')]:
thumb = GetImage(group['thumb'], default = 'icon-folder.png', title = group['title'])
art = GetImage(group['art'], default = 'art-default.png')
oc.add(
Expand All @@ -142,10 +142,10 @@ def ListGroups(page = 1):
art = art
)
)
if unicode(L('No category')) in groups.keys():
if unicode('No category') in groups.keys():
oc.add(
DirectoryObject(
key = Callback(ListItems, group = unicode(L('No category'))),
key = Callback(ListItems, group = unicode('No category')),
title = unicode(L('No category'))
)
)
Expand All @@ -155,7 +155,7 @@ def ListGroups(page = 1):

####################################################################################################
@route(PREFIX + '/listitems', page = int)
def ListItems(group = unicode(L('All')), query = '', page = 1):
def ListItems(group = unicode('All'), query = '', page = 1):

if not Dict['streams']:
LoadPlaylist()
Expand Down Expand Up @@ -220,6 +220,7 @@ def ListItems(group = unicode(L('All')), query = '', page = 1):
return oc
else:
return ObjectContainer(
title1 = unicode(L('Search')),
header = unicode(L('Search')),
message = unicode(L('No items were found'))
)
Expand Down Expand Up @@ -281,7 +282,11 @@ def PlayVideo(url):
def ReloadPlaylist():

if Dict['playlist_loading_in_progress']:
return ObjectContainer(header = unicode(L('Warning')), message = unicode(L('Playlist is reloading in the background, please wait')))
return ObjectContainer(
title1 = unicode(L('Warning')),
header = unicode(L('Warning')),
message = unicode(L('Playlist is reloading in the background, please wait'))
)

LoadPlaylist()

Expand All @@ -303,7 +308,11 @@ def ReloadPlaylist():
def ReloadGuide():

if Dict['guide_loading_in_progress']:
return ObjectContainer(header = unicode(L('Warning')), message = unicode(L('Program guide is reloading in the background, please wait')))
return ObjectContainer(
title1 = unicode(L('Warning')),
header = unicode(L('Warning')),
message = unicode(L('Program guide is reloading in the background, please wait'))
)

LoadGuide()

Expand Down
24 changes: 9 additions & 15 deletions Contents/Code/m3u_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def LoadM3UFile(m3u_file, groups = {}, streams = {}, cust_m3u_name = None):
for i in range(line_count - 1):
line_1 = lines[i].strip()
if line_1.startswith('#EXTINF'):
title = unicode(line_1[line_1.rfind(',') + 1:len(line_1)].strip())
title = unicode(line_1[line_1.rfind(',') + 1:len(line_1)].strip(), errors = 'replace')
id = GetAttribute(line_1, 'tvg-id')
name = GetAttribute(line_1, 'tvg-name')
thumb = GetAttribute(line_1, 'tvg-logo')
Expand Down Expand Up @@ -102,12 +102,12 @@ def LoadM3UFile(m3u_file, groups = {}, streams = {}, cust_m3u_name = None):
'order': stream_count
}
if not streams:
streams.setdefault(unicode(L('All')), {})[stream_count] = stream
streams.setdefault(unicode('All'), {})[stream_count] = stream
if streams:
if not any(item['url'] == stream['url'] for item in streams[unicode(L('All'))].values()):
streams.setdefault(unicode(L('All')), {})[stream_count] = stream
if not any(item['url'] == stream['url'] for item in streams[unicode('All')].values()):
streams.setdefault(unicode('All'), {})[stream_count] = stream
if not group_title:
group_title = unicode(L('No category') if not m3u_name else m3u_name)
group_title = unicode('No category' if not m3u_name else m3u_name)
if group_title not in groups.keys():
group_thumb = GetAttribute(line_1, 'group-logo')
group_art = GetAttribute(line_1, 'group-art')
Expand All @@ -124,7 +124,7 @@ def LoadM3UFile(m3u_file, groups = {}, streams = {}, cust_m3u_name = None):
else:
streams.setdefault(group_title, {})[stream_count] = stream
elif line_1.startswith('#EXTIMPORT'):
group_title = unicode(line_1[line_1.rfind(',') + 1:len(line_1)].strip()) if line_1.rfind(',') > -1 else None
group_title = unicode(line_1[line_1.rfind(',') + 1:len(line_1)].strip(), errors = 'replace') if line_1.rfind(',') > -1 else None
url = None
for j in range(i + 1, line_count):
line_2 = lines[j].strip()
Expand All @@ -151,21 +151,15 @@ def DecodeURIComponent(uri):
####################################################################################################
def GetAttribute(text, attribute, delimiter1 = '=', delimiter2 = '"', default = ''):

try:
value = unicode(default)
except:
value = unicode(L('Unicode decode error'))
x = text.lower().find(attribute.lower() + delimiter1 + delimiter2)
if x > -1:
y = x + len(attribute) + len(delimiter1) + len(delimiter2)
z = text.lower().find(delimiter2.lower(), y) if delimiter2 else len(text)
if z == -1:
z = len(text)
try:
value = unicode(text[y:z].strip())
except:
value = unicode(L('Unicode decode error'))
return value
return unicode(text[y:z].strip(), errors = 'replace')
else:
return unicode(default, errors = 'replace')

####################################################################################################
def PlaylistReloader():
Expand Down
6 changes: 3 additions & 3 deletions Contents/Code/xmltv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ def LoadGuide():
id = channel.get('id')
if id:
for name in channel.findall('display-name'):
key = unicode(name.text)
key = unicode(name.text, errors = 'replace')
if key:
channels[key] = id
count = 0
current_datetime = Datetime.Now()
for programme in root.findall('./programme'):
channel = unicode(programme.get('channel'))
channel = unicode(programme.get('channel'), errors = 'replace')
start = StringToLocalDatetime(programme.get('start'))
stop = StringToLocalDatetime(programme.get('stop'))
if stop >= current_datetime:
title = programme.find('title').text
desc_node = programme.find('desc')
try:
desc = unicode(programme.find('desc').text)
desc = unicode(programme.find('desc').text, errors = 'replace')
except:
desc = None
count = count + 1
Expand Down
1 change: 0 additions & 1 deletion Contents/Strings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"Reload program guide": "Reload program guide",
"Search": "Search",
"Success": "Success",
"Unicode decode error": "Unicode decode error",
"View playlist": "View playlist",
"Warning": "Warning"
}
1 change: 0 additions & 1 deletion Contents/Strings/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"Reload program guide": "Recharger le guide des programmes",
"Search": "Rechercher",
"Success": "Succès",
"Unicode decode error": "Unicode decode error",
"View playlist": "Visualiser la playlist",
"Warning": "Attention"
}
1 change: 0 additions & 1 deletion Contents/Strings/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"Reload program guide": "Обновить программу передач",
"Search": "Поиск",
"Success": "Готово",
"Unicode decode error": "Unicode decode error",
"View playlist": "Показать плейлист",
"Warning": "Внимание"
}

0 comments on commit d189122

Please sign in to comment.