diff --git a/alarm.py b/alarm.py index 60e54e1..aba232a 100644 --- a/alarm.py +++ b/alarm.py @@ -1,6 +1,8 @@ from spotframework.net.user import User from spotframework.net.network import Network import spotframework.log.log as log +import spotframework.net.const as const +import spotframework.io.json as json import os import datetime @@ -31,17 +33,23 @@ if __name__ == '__main__': if found: - date = datetime.datetime.now() + if os.path.exists(os.path.join(const.config_path, 'config.json')): + data = json.load_json(os.path.join(const.config_path, 'config.json')) - playlists = network.get_user_playlists() + date = datetime.datetime.now() - playlisturi = next((i.uri for i in playlists if i.name == date.strftime("%B %-y").lower()), os.environ['SPOTALARMURI']) + playlists = network.get_user_playlists() - network.play(playlisturi, network.get_device_id(os.environ['SPOTALARMDEVICENAME'])) + if data['alarm']['use_month']: + playlisturi = next((i.uri for i in playlists if i.name == date.strftime("%B %-y").lower()), data['alarm']['uri']) + else: + playlisturi = data['alarm']['uri'] - network.set_shuffle(True) - network.set_volume(os.environ['SPOTALARMVOLUME']) - network.next() + network.play(playlisturi, network.get_device_id(data['alarm']['device_name'])) + + network.set_shuffle(True) + network.set_volume(data['alarm']['volume']) + network.next() log.dump_log() diff --git a/generateplaylists.py b/generateplaylists.py index d9f7aa4..368010a 100644 --- a/generateplaylists.py +++ b/generateplaylists.py @@ -58,6 +58,10 @@ def update_recents_playlist(engine, data): if 'playlists' in data['recents']: recent_parts += data['recents']['playlists'] + if 'exclude' in data['recents']: + for exclusion in data['recents']['exclude']: + recent_parts.remove(exclusion) + processors = [DeduplicateByName(), SortReverseReleaseDate()] recent_tracks = engine.get_recent_playlist(boundary_date, recent_parts, processors) @@ -68,9 +72,9 @@ def update_recents_playlist(engine, data): def go(): try: - if os.path.exists(os.path.join(const.config_path, 'playlists.json')): + if os.path.exists(os.path.join(const.config_path, 'config.json')): - data = json.load_json(os.path.join(const.config_path, 'playlists.json')) + data = json.load_json(os.path.join(const.config_path, 'config.json')) to_execute = [] not_found = [] diff --git a/main.py b/main.py index a12e281..7cfc494 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ import spotframework.io.json as json if __name__ == '__main__': print('hello world') - # data = json.loadJson('.spot/playlists.json') + # data = json.loadJson('.spot/config.json') # print(data) diff --git a/spotframework/engine/playlistengine.py b/spotframework/engine/playlistengine.py index 376b538..048cc90 100644 --- a/spotframework/engine/playlistengine.py +++ b/spotframework/engine/playlistengine.py @@ -58,7 +58,7 @@ class PlaylistEngine: this_month = monthstrings.get_this_month() last_month = monthstrings.get_last_month() - datefilter = AddedSince(boundary_date, recent_playlist_parts) + datefilter = AddedSince(boundary_date, recent_playlist_parts + [last_month]) processors.append(datefilter)