Skip to content

Commit

Permalink
Update music_caster.py
Browse files Browse the repository at this point in the history
  • Loading branch information
elibroftw committed Aug 5, 2019
1 parent 4fbbca1 commit a34903f
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions music_caster.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def save_json():
json.dump(settings, outfile, indent=4)


def change_settings(name, value):
settings[name] = value
save_json()
return value

# check if settings file is valid
if os.path.exists(settings_file):
with open(settings_file) as json_file:
Expand Down Expand Up @@ -193,9 +198,7 @@ def chromecast_callback(chromecast):
notifications_enabled = settings['notifications']
if notifications_enabled: tray.ShowMessage('Music Caster', 'Music Caster is running in the tray', time=500)
music_directories = settings['music directories']
if not music_directories:
music_directories = settings['music directories'] = [home_music_dir]
save_json()
if not music_directories: music_directories = change_settings('music directories', [home_music_dir])
DEFAULT_DIR = music_directories[0]

music_queue = []
Expand Down Expand Up @@ -392,13 +395,12 @@ def on_press(key):
cast = new_cast
volume = settings['volume'] / 100
if cast is None:
settings['previous device'] = None
change_settings('previous device', None)
local_music_player.music.set_volume(volume)
else:
settings['previous device'] = str(cast.uuid)
change_settings('previous device', str(cast.uuid))
cast.wait()
cast.set_volume(volume)
save_json()
current_pos = 0
if local_music_player.music.get_busy():
current_pos = song_position + local_music_player.music.get_pos() / 1000
Expand Down Expand Up @@ -472,8 +474,7 @@ def on_press(key):
next_song(from_timeout=time() > song_end)
elif 'Previous Song' in (menu_item, keyboard_command): previous()
elif menu_item == 'Repeat':
repeat_setting = settings['repeat'] = not settings['repeat']
save_json()
repeat_setting = change_settings('repeat', not settings['repeat'])
if notifications_enabled:
if repeat_setting: tray.ShowMessage('Music Caster', 'Repeating current song')
else: tray.ShowMessage('Music Caster', 'Not repeating current song')
Expand Down Expand Up @@ -501,8 +502,7 @@ def on_press(key):
settings_active = False
settings_window.CloseNonBlocking()
elif settings_event in ('auto update', 'run on startup', 'notifications'):
settings[settings_event] = settings_value
save_json()
change_settings(settings_event, settings_value)
if settings_event == 'run on startup':
startup_setting()
elif settings_event == 'notifications':
Expand All @@ -520,8 +520,7 @@ def on_press(key):
elif settings_event == 'd':
delta = 5
new_volume = settings_values['volume'] + delta
settings['volume'] = new_volume
save_json()
change_settings('volume', new_volume)
volume = new_volume / 100
if update_slider or delta != 0: settings_window.Element('volume').Update(value=new_volume)
if cast is None:
Expand Down Expand Up @@ -550,6 +549,5 @@ def on_press(key):
volume = settings['volume']
cast_volume = int(cast.status.volume_level * 100)
if volume != cast_volume:
volume = settings['volume'] = cast_volume
save_json()
volume = change_settings('volume', cast_volume)
cast_last_checked = time()

0 comments on commit a34903f

Please sign in to comment.