diff options
author | jcass <john.cass77@gmail.com> | 2015-12-24 21:53:32 +0200 |
---|---|---|
committer | jcass <john.cass77@gmail.com> | 2015-12-24 21:53:32 +0200 |
commit | 79245f34a8abdc296157b78b879994a2738f02e3 (patch) | |
tree | 7699afed6e69609b1c9a1eceef65af94275b4cdb /pydora | |
parent | 1ed6b260da26597034c41681cb4f7c1933988d96 (diff) | |
download | pydora-79245f34a8abdc296157b78b879994a2738f02e3.tar.bz2 pydora-79245f34a8abdc296157b78b879994a2738f02e3.tar.xz pydora-79245f34a8abdc296157b78b879994a2738f02e3.zip |
Handle ParameterMissing exceptions due to missing ad tokens.
Diffstat (limited to 'pydora')
-rw-r--r-- | pydora/utils.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/pydora/utils.py b/pydora/utils.py index 71d736a..c2a5323 100644 --- a/pydora/utils.py +++ b/pydora/utils.py | |||
@@ -5,6 +5,8 @@ import sys | |||
5 | import termios | 5 | import termios |
6 | import getpass | 6 | import getpass |
7 | import subprocess | 7 | import subprocess |
8 | from pandora.models.pandora import AdItem | ||
9 | from pandora import errors | ||
8 | 10 | ||
9 | 11 | ||
10 | def input(prompt): | 12 | def input(prompt): |
@@ -118,9 +120,18 @@ def iterate_forever(func, *args, **kwargs): | |||
118 | 120 | ||
119 | while True: | 121 | while True: |
120 | try: | 122 | try: |
121 | yield next(output).prepare_playback() | 123 | playlistItem = next(output) |
124 | playlistItem.prepare_playback() | ||
125 | yield playlistItem | ||
122 | except StopIteration: | 126 | except StopIteration: |
123 | output = func(*args, **kwargs) | 127 | output = func(*args, **kwargs) |
128 | except errors.ParameterMissing as e: | ||
129 | if isinstance(playlistItem, AdItem): | ||
130 | if not playlistItem.tracking_tokens or len(playlistItem.tracking_tokens) == 0: | ||
131 | # Ad item does not contain any tracking tokens, yield without registering | ||
132 | yield playlistItem | ||
133 | # Something else went wrong, re-raise | ||
134 | raise e | ||
124 | 135 | ||
125 | 136 | ||
126 | class SilentPopen(subprocess.Popen): | 137 | class SilentPopen(subprocess.Popen): |