Skip to content

Commit

Permalink
Handle volume unavailable (digital output) #1
Browse files Browse the repository at this point in the history
Show message if an update is available
  • Loading branch information
deanishe committed Jun 8, 2017
1 parent 3c4b52e commit dda5f65
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
Binary file not shown.
64 changes: 36 additions & 28 deletions src/ampd
Original file line number Diff line number Diff line change
Expand Up @@ -240,34 +240,35 @@ def search_actions(query):
None)
]

if st.volume > 0:
actions.extend([
Action(
'Mute Volume',
'Set volume to zero',
'volume mute',
'mute',
ICON_MUTE,
None),
Action(
'Volume Down',
'Decrease volume to {}%'.format(st.volume - 10),
'volume down quiet decrease',
'turn-down',
ICON_VOLUME_DOWN,
None),
])

if st.volume < 100:
actions.append(
Action(
'Volume Up',
'Increase volume to {}%'.format(st.volume + 10),
'volume up loud increase',
'turn-up',
ICON_VOLUME_UP,
None)
)
if st.volume != 'n/a': # volume not available for Digital Out
if st.volume > 0:
actions.extend([
Action(
'Mute Volume',
'Set volume to zero',
'volume mute',
'mute',
ICON_MUTE,
None),
Action(
'Volume Down',
'Decrease volume to {}%'.format(st.volume - 10),
'volume down quiet decrease',
'turn-down',
ICON_VOLUME_DOWN,
None),
])

if st.volume < 100:
actions.append(
Action(
'Volume Up',
'Increase volume to {}%'.format(st.volume + 10),
'volume up loud increase',
'turn-up',
ICON_VOLUME_UP,
None)
)

canprev = cannext = False
if len(queue):
Expand Down Expand Up @@ -603,6 +604,13 @@ def _plural(s, n, plural=None):

def do_stats(opts):
"""Fetch MPD stats and show in Alfred."""
if wf.update_available:
wf.add_item('A workflow update is available',
u'↩ or ⇥ to install',
valid=False,
autocomplete='workflow:update',
icon=ICON_UPDATE_AVAILABLE)

st = mpd.stats()

if not st.songs: # empty library
Expand Down
2 changes: 1 addition & 1 deletion src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ Search &amp; control an mpd server from Alfred.</string>
<string>6600</string>
</dict>
<key>version</key>
<string>0.1.1</string>
<string>0.1.2</string>
<key>webaddress</key>
<string>https://github.com/deanishe/alfred-mpd</string>
</dict>
Expand Down
7 changes: 5 additions & 2 deletions src/lib/mpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def stats():
.* # anything else
""", re.VERBOSE).match

_find_playback_settings = re.compile(r'(\w+): ([0-9%ofn]+)').findall
_find_playback_settings = re.compile(r'(\w+): ?([0-9%ofn/a]+)').findall


def _parse_status(out):
Expand All @@ -301,7 +301,10 @@ def _parse_status(out):
elif line.startswith('volume'): # playback settings
for k, v in _find_playback_settings(line):
if k == 'volume':
volume = int(v.rstrip('%'))
if v.strip() == 'n/a': # digital output
volume = 'n/a'
else:
volume = int(v.rstrip('%'))
log.debug('volume=%r', volume)

elif DELIMITER in line: # current track
Expand Down

0 comments on commit dda5f65

Please sign in to comment.