Skip to content

Commit

Permalink
Merge pull request #182 from zsprackett/master
Browse files Browse the repository at this point in the history
add episode number to summary and fix issues with invalid title / desc
  • Loading branch information
Cigaras authored Feb 26, 2018
2 parents 58295db + 2c8596e commit 26556e5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
8 changes: 6 additions & 2 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,13 @@ def GetSummary(id, name, title, default = ''):

start = (item['start'] + Datetime.Delta(seconds = guide_offset_seconds)).strftime(guide_format_string)
if summary:
summary = summary + '\n' + start + ' ' + item['title']
summary = summary + '\n' + start
else:
summary = start + ' ' + item['title']
summary = start
if item['title']:
summary = summary + ' ' + item['title']
if item['episode']:
summary = summary + ' (' + item['episode'] + ')'
if item['desc']:
summary = summary + ' - ' + item['desc']

Expand Down
44 changes: 28 additions & 16 deletions Contents/Code/xmltv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,43 @@ def LoadGuide():
start = StringToLocalDatetime(programme_elem.get('start'))
stop = StringToLocalDatetime(programme_elem.get('stop'))
if stop >= current_datetime:
title_text = programme_elem.find('title').text
if title_text:
title_text = programme_elem.findtext("title", default="")
try:
title = unicode(title_text, errors = 'replace')
except TypeError:
title = title_text.decode('utf-8')

desc_text = programme_elem.findtext("desc", default="")
try:
desc = unicode(desc_text, errors = 'replace')
except TypeError:
desc = desc_text.decode('utf-8')

ep = programme_elem.find('episode-num')
if ep != None:
if ep.get('system') == 'xmltv_ns':
fields = ep.text.split('.')
episode_text = "%s%s%s" % (
'S' + fields[0] if len(fields) >= 1 and len(fields[0]) > 0 else '',
'E' + fields[1] if len(fields) >= 2 and len(fields[1]) > 0 else '',
'P' + fields[2] if len(fields) >= 3 and len(fields[2]) > 0 else '')
else:
episode_text = ep.text

try:
title = unicode(title_text, errors = 'replace')
episode = unicode(episode_text, errors = 'replace')
except TypeError:
title = title_text.decode('utf-8')
episode = episode_text.decode('utf-8')
else:
title = None
if programme_elem.find('desc'):
desc_text = programme_elem.find('desc').text
if dest_text:
try:
desc = unicode(desc_text, errors = 'replace')
except TypeError:
desc = desc_text.decode('utf-8')
else:
desc = None
else:
desc = None
episode = None

count = count + 1
item = {
'start': start,
'stop': stop,
'title': title,
'desc': desc,
'episode': episode,
'channel_id': channel,
'order': count
}
Expand Down

0 comments on commit 26556e5

Please sign in to comment.