From e3a8c32c6b5e5f45a63bd74b7261f818e0ab2663 Mon Sep 17 00:00:00 2001 From: nsteel Date: Tue, 16 Feb 2016 17:36:11 +0000 Subject: [PATCH] Handle pls playlist parsing exception --- mopidy_tunein/tunein.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mopidy_tunein/tunein.py b/mopidy_tunein/tunein.py index bc2793d..1925712 100644 --- a/mopidy_tunein/tunein.py +++ b/mopidy_tunein/tunein.py @@ -88,11 +88,14 @@ def parse_pls(data): continue for i in xrange(cp.getint(section, 'numberofentries')): try: - # TODO: Remove this horrible hack - if cp.get(section, 'length%d' % (i+1)) == '-1': - yield cp.get(section, 'file%d' % (i+1)) + # TODO: Remove this horrible hack to avoid adverts + if cp.has_option(section, 'length%d' % (i+1)): + if cp.get(section, 'length%d' % (i+1)) == '-1': + yield cp.get(section, 'file%d' % (i+1)) + else: + yield cp.get(section, 'file%d' % (i+1)) except configparser.NoOptionError: - yield cp.get(section, 'file%d' % (i+1)) + return def fix_asf_uri(uri): @@ -305,8 +308,11 @@ def parse_stream_url(self, url): parser = find_playlist_parser(extension, content_type) if parser: playlist_data = StringIO.StringIO(playlist) - results = [u for u in parser(playlist_data) - if u and u != url] + try: + results = [u for u in parser(playlist_data) + if u and u != url] + except Exception as e: + logger.error('TuneIn playlist parsing failed %s' % e) if not results: logger.debug('Parsing failure, ' 'malformed playlist: %s' % playlist)