Skip to content

Commit

Permalink
Use a provided "quality" settings, rather than requesting a format.
Browse files Browse the repository at this point in the history
Based on / thanks to:
	Pianobar 524abb974
        glennimoss pull request
  • Loading branch information
kevinmehall committed Sep 22, 2012
1 parent 6b89924 commit ce9d3c4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 40 deletions.
4 changes: 2 additions & 2 deletions bin/pithos
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class PithosWindow(gtk.Window):
self.worker_run('set_url_opener', (control_opener,))

def set_audio_format(self):
self.worker_run('set_audio_format', (self.preferences['jsonapi_audio_format'],))
self.worker_run('set_audio_quality', (self.preferences['audio_quality'],))

def pandora_connect(self, message="Logging in...", callback=None):
args = (self.preferences['username'],
Expand Down Expand Up @@ -813,7 +813,7 @@ class PithosWindow(gtk.Window):
if ( self.preferences['proxy'] != old_prefs['proxy']
or self.preferences['control_proxy'] != old_prefs['control_proxy']):
self.set_proxy()
if self.preferences['jsonapi_audio_format'] != old_prefs['jsonapi_audio_format']:
if self.preferences['audio_quality'] != old_prefs['audio_quality']:
self.set_audio_format()
if ( self.preferences['username'] != old_prefs['username']
or self.preferences['password'] != old_prefs['password']):
Expand Down
6 changes: 3 additions & 3 deletions data/ui/PreferencesPithosDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,11 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="audioFormatLabel">
<object class="GtkLabel" id="audioQualityLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Audio Format</property>
<property name="label" translatable="yes">Audio Quality</property>
</object>
<packing>
<property name="left_attach">1</property>
Expand All @@ -303,7 +303,7 @@
</packing>
</child>
<child>
<object class="GtkComboBox" id="prefs_audio_format">
<object class="GtkComboBox" id="prefs_audio_quality">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
Expand Down
36 changes: 16 additions & 20 deletions pithos/PreferencesPithosDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ def finish_initializing(self, builder):
self.builder = builder
self.builder.connect_signals(self)

# initialize the "Audio format" combobox backing list
audio_format_combo = self.builder.get_object('prefs_audio_format')
# initialize the "Audio quality" combobox backing list
audio_quality_combo = self.builder.get_object('prefs_audio_quality')
fmt_store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
for audio_format in valid_audio_formats:
fmt_store.append(audio_format)
audio_format_combo.set_model(fmt_store)
for audio_quality in valid_audio_formats:
fmt_store.append(audio_quality)
audio_quality_combo.set_model(fmt_store)
render_text = gtk.CellRendererText()
audio_format_combo.pack_start(render_text, expand=True)
audio_format_combo.add_attribute(render_text, "text", 0)
audio_quality_combo.pack_start(render_text, expand=True)
audio_quality_combo.add_attribute(render_text, "text", 1)

self.__load_preferences()

Expand All @@ -97,7 +97,7 @@ def __load_preferences(self):
"volume": 1.0,
# If set, allow insecure permissions. Implements CVE-2011-1500
"unsafe_permissions": False,
"jsonapi_audio_format": default_audio_format,
"audio_quality": default_audio_quality,
}

try:
Expand All @@ -115,11 +115,7 @@ def __load_preferences(self):
self.__preferences[key]=val

if 'audio_format' in self.__preferences:
# translate old XMLRPC formats
old_format = self.__preferences['audio_format']
translate = {'aacplus': 'HTTP_64_AACPLUS', 'mp3': 'HTTP_128_MP3', 'mp3-hifi': 'HTTP_192_MP3'}
if format in translate:
self.__preferences['jsonapi_audio_format'] = translate[format]
# Pithos <= 0.3.17, replaced by audio_quality
del self.__preferences['audio_format']

self.setup_fields()
Expand Down Expand Up @@ -187,10 +183,10 @@ def setup_fields(self):
self.builder.get_object('prefs_proxy').set_text(self.__preferences["proxy"])
self.builder.get_object('prefs_control_proxy').set_text(self.__preferences["control_proxy"])

audio_format_combo = self.builder.get_object('prefs_audio_format')
for row in audio_format_combo.get_model():
if row[1] == self.__preferences["jsonapi_audio_format"]:
audio_format_combo.set_active_iter(row.iter)
audio_quality_combo = self.builder.get_object('prefs_audio_quality')
for row in audio_quality_combo.get_model():
if row[0] == self.__preferences["audio_quality"]:
audio_quality_combo.set_active_iter(row.iter)
break

self.builder.get_object('checkbutton_notify').set_active(self.__preferences["notify"])
Expand All @@ -212,10 +208,10 @@ def ok(self, widget, data=None):
self.__preferences["enable_screensaverpause"] = self.builder.get_object('checkbutton_screensaverpause').get_active()
self.__preferences["show_icon"] = self.builder.get_object('checkbutton_icon').get_active()

audio_format = self.builder.get_object('prefs_audio_format')
active_idx = audio_format.get_active()
audio_quality = self.builder.get_object('prefs_audio_quality')
active_idx = audio_quality.get_active()
if active_idx != -1: # ignore unknown format
self.__preferences["jsonapi_audio_format"] = audio_format.get_model()[active_idx][1]
self.__preferences["audio_quality"] = audio_quality.get_model()[active_idx][0]

self.save()

Expand Down
26 changes: 17 additions & 9 deletions pithos/pandora/pandora.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def json_call(self, method, args={}, https=False, blowfish=True):
if 'result' in tree:
return tree['result']

def set_audio_format(self, fmt):
self.audio_format = fmt
def set_audio_quality(self, fmt):
self.audio_quality = fmt

def set_url_opener(self, opener):
self.opener = opener
Expand Down Expand Up @@ -251,7 +251,7 @@ def transformIfShared(self):

def get_playlist(self):
logging.info("pandora: Get Playlist")
playlist = self.pandora.json_call('station.getPlaylist', {'stationToken': self.idToken, 'additionalAudioUrl': self.pandora.audio_format}, https=True)
playlist = self.pandora.json_call('station.getPlaylist', {'stationToken': self.idToken}, https=True)
songs = []
for i in playlist['items']:
if 'songName' in i: # check for ads
Expand Down Expand Up @@ -279,12 +279,7 @@ def __init__(self, pandora, d):

self.album = d['albumName']
self.artist = d['artistName']
try:
self.audioUrl = d['additionalAudioUrl']
except KeyError:
logging.error("No audioUrl %s", repr(d.keys()))
raise PandoraError("Unable to use this audio format",
submsg="Change audio format in settings.")
self.audioUrlMap = d['audioUrlMap']
self.trackToken = d['trackToken']
self.rating = RATE_LOVE if d['songRating'] == 1 else RATE_NONE # banned songs won't play, so we don't care about them
self.stationId = d['stationId']
Expand All @@ -299,6 +294,18 @@ def __init__(self, pandora, d):
self.playlist_time = time.time()
self.feedbackId = None

@property
def audioUrl(self):
quality = self.pandora.audio_quality
try:
q = self.audioUrlMap[quality]
logging.info("Using audio quality %s: %s %s", quality, q['bitrate'], q['encoding'])
return q['audioUrl']
except KeyError:
logging.warn("Unable to use audio format %s. Using %s",
quality, self.audioUrlMap.keys()[0])
return self.audioUrlMap.values()[0]['audioUrl']

@property
def station(self):
return self.pandora.get_station_by_id(self.stationId)
Expand Down Expand Up @@ -337,6 +344,7 @@ def rating_str(self):
def is_still_valid(self):
return (time.time() - self.playlist_time) < PLAYLIST_VALIDITY_TIME


class SearchResult(object):
def __init__(self, resultType, d):
self.resultType = resultType
Expand Down
11 changes: 5 additions & 6 deletions pithos/pithosconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@
class project_path_not_found(Exception):
pass

# See http://pan-do-ra-api.wikia.com/wiki/Json/5/station.getPlaylist#Additional_Audio_Formats for all known formats
# See http://pan-do-ra-api.wikia.com/wiki/Json/5/station.getPlaylist
valid_audio_formats = [
('32kbps AAC+', 'HTTP_32_AACPLUS'),
('64kbps AAC+', 'HTTP_64_AACPLUS'),
('128kbps MP3', 'HTTP_128_MP3'),
('192kbps MP3', 'HTTP_192_MP3')
('highQuality', 'High'),
('mediumQuality', 'Medium'),
('lowQuality', 'Low'),
]
default_audio_format = 'HTTP_64_AACPLUS'
default_audio_quality = 'mediumQuality'

def get_data_file(*path_segments):
"""Get the full path to a data file.
Expand Down

0 comments on commit ce9d3c4

Please sign in to comment.