diff options
author | jcass <john.cass77@gmail.com> | 2015-11-22 11:12:00 +0200 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2015-12-05 18:51:30 -0800 |
commit | a2173c1adde2d4acd351117a5820f79297473e3b (patch) | |
tree | bc624f70620d8a62ef23effb9bffad52f8f1d905 /pydora | |
parent | 6d007190e995fca4bf87699fe9468eb0e0644542 (diff) | |
download | pydora-a2173c1adde2d4acd351117a5820f79297473e3b.tar.bz2 pydora-a2173c1adde2d4acd351117a5820f79297473e3b.tar.xz pydora-a2173c1adde2d4acd351117a5820f79297473e3b.zip |
Encapsulate ad processing: API consumers no longer need to be ad-aware.
Diffstat (limited to 'pydora')
-rw-r--r-- | pydora/configure.py | 1 | ||||
-rwxr-xr-x | pydora/player.py | 61 | ||||
-rw-r--r-- | pydora/utils.py | 2 |
3 files changed, 48 insertions, 16 deletions
diff --git a/pydora/configure.py b/pydora/configure.py index 21ea3c3..7eb3bbb 100644 --- a/pydora/configure.py +++ b/pydora/configure.py | |||
@@ -155,6 +155,7 @@ class Configurator(object): | |||
155 | self.get_password("user", "password", "Pandora Password: ") | 155 | self.get_password("user", "password", "Pandora Password: ") |
156 | self.set_static_value("api", "default_audio_quality", | 156 | self.set_static_value("api", "default_audio_quality", |
157 | APIClient.HIGH_AUDIO_QUALITY) | 157 | APIClient.HIGH_AUDIO_QUALITY) |
158 | self.set_static_value("api", "ad_support_enabled", "true") | ||
158 | 159 | ||
159 | self.write_config() | 160 | self.write_config() |
160 | 161 | ||
diff --git a/pydora/player.py b/pydora/player.py index 8cbd7d2..4561442 100755 --- a/pydora/player.py +++ b/pydora/player.py | |||
@@ -91,11 +91,17 @@ class PlayerApp(object): | |||
91 | def play(self, song): | 91 | def play(self, song): |
92 | """Play callback | 92 | """Play callback |
93 | """ | 93 | """ |
94 | print("{} by {}".format(Colors.cyan(song.song_name), | 94 | if song.is_ad: |
95 | Colors.yellow(song.artist_name))) | 95 | print("{} ".format(Colors.cyan("Advertisement"))) |
96 | else: | ||
97 | print("{} by {}".format(Colors.cyan(song.song_name), | ||
98 | Colors.yellow(song.artist_name))) | ||
96 | 99 | ||
97 | def skip_song(self, song): | 100 | def skip_song(self, song): |
98 | self.player.stop() | 101 | if song.is_ad: |
102 | Screen.print_error("Cannot skip advertisements") | ||
103 | else: | ||
104 | self.player.stop() | ||
99 | 105 | ||
100 | def pause_song(self, song): | 106 | def pause_song(self, song): |
101 | self.player.pause() | 107 | self.player.pause() |
@@ -104,26 +110,51 @@ class PlayerApp(object): | |||
104 | self.player.end_station() | 110 | self.player.end_station() |
105 | 111 | ||
106 | def dislike_song(self, song): | 112 | def dislike_song(self, song): |
107 | song.thumbs_down() | 113 | try: |
108 | Screen.print_success("Track disliked") | 114 | if song.thumbs_down(): |
109 | self.player.stop() | 115 | Screen.print_success("Track disliked") |
116 | self.player.stop() | ||
117 | else: | ||
118 | Screen.print_error("Failed to dislike track") | ||
119 | except NotImplementedError: | ||
120 | Screen.print_error("Cannot dislike this type of track") | ||
110 | 121 | ||
111 | def like_song(self, song): | 122 | def like_song(self, song): |
112 | song.thumbs_up() | 123 | try: |
113 | Screen.print_success("Track liked") | 124 | if song.thumbs_up(): |
125 | Screen.print_success("Track liked") | ||
126 | else: | ||
127 | Screen.print_error("Failed to like track") | ||
128 | except NotImplementedError: | ||
129 | Screen.print_error("Cannot like this type of track") | ||
114 | 130 | ||
115 | def bookmark_song(self, song): | 131 | def bookmark_song(self, song): |
116 | song.bookmark_song() | 132 | try: |
117 | Screen.print_success("Bookmarked song") | 133 | if song.bookmark_song(): |
134 | Screen.print_success("Bookmarked song") | ||
135 | else: | ||
136 | Screen.print_error("Failed to bookmark song") | ||
137 | except NotImplementedError: | ||
138 | Screen.print_error("Cannot bookmark this type of track") | ||
118 | 139 | ||
119 | def bookmark_artist(self, song): | 140 | def bookmark_artist(self, song): |
120 | song.bookmark_artist() | 141 | try: |
121 | Screen.print_success("Bookmarked artist") | 142 | if song.bookmark_artist(): |
143 | Screen.print_success("Bookmarked artist") | ||
144 | else: | ||
145 | Screen.print_error("Failed to bookmark artis") | ||
146 | except NotImplementedError: | ||
147 | Screen.print_error("Cannot bookmark artist for this type of track") | ||
122 | 148 | ||
123 | def sleep_song(self, song): | 149 | def sleep_song(self, song): |
124 | song.sleep() | 150 | try: |
125 | Screen.print_success("Song will not be played for 30 days") | 151 | if song.sleep(): |
126 | self.player.stop() | 152 | Screen.print_success("Song will not be played for 30 days") |
153 | self.player.stop() | ||
154 | else: | ||
155 | Screen.print_error("Failed to sleep song") | ||
156 | except NotImplementedError: | ||
157 | Screen.print_error("Cannot sleep this type of track") | ||
127 | 158 | ||
128 | def quit(self, song): | 159 | def quit(self, song): |
129 | self.player.end_station() | 160 | self.player.end_station() |
diff --git a/pydora/utils.py b/pydora/utils.py index be8381c..f58ff57 100644 --- a/pydora/utils.py +++ b/pydora/utils.py | |||
@@ -119,7 +119,7 @@ def iterate_forever(func, *args, **kwargs): | |||
119 | 119 | ||
120 | while True: | 120 | while True: |
121 | try: | 121 | try: |
122 | yield next(output) | 122 | yield next(output).prepare_playback() |
123 | except StopIteration: | 123 | except StopIteration: |
124 | output = func(*args, **kwargs) | 124 | output = func(*args, **kwargs) |
125 | 125 | ||