From 7068a61ea79c2d7f97a2464dcc28c283cbdfe45f Mon Sep 17 00:00:00 2001 From: Jonas Krogh <36476478+Badgie@users.noreply.github.com> Date: Tue, 10 Mar 2020 15:11:29 +0100 Subject: [PATCH] Add tuning option to print (#67) * add tuning option to print * update readme to reflect install changes * spelling --- README.md | 4 +++- spotirec.py | 25 +++++++++++++++++++++++-- tuning-opts | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 tuning-opts diff --git a/README.md b/README.md index 148a19e..61e7876 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ yay -S spotirec-git ``` #### Manual -On any other distribution you need to install Spotirec manually. Spotirec has two dependencies +On any other distribution you need to install Spotirec manually. Spotirec has three dependencies ``` bottle>=0.12.17 requests>=2.22.0 @@ -53,6 +53,7 @@ mkdir -p /usr/lib/spotirec mkdir -p /usr/bin mkdir -p $HOME/.config/spotirec +install tuning-opts -t $HOME/.config/spotirec install spotirec.py oauth2.py conf.py recommendation.py api.py -t /usr/lib/spotirec ln -s /usr/lib/spotirec/spotirec.py /usr/bin/spotirec @@ -248,6 +249,7 @@ $ spotirec --print devices $ spotirec --print blacklist $ spotirec --print presets $ spotirec --print playlists +$ spotirec --print tuning ``` You can also print various features of a track with the `--track-features` flag followed by either a URI or 'current' if you want information about the currently playing track. Features include track attributes (as used in [tuning](#tuning)) and URIs. diff --git a/spotirec.py b/spotirec.py index 4523cdf..03129d8 100644 --- a/spotirec.py +++ b/spotirec.py @@ -109,8 +109,8 @@ print_group = parser.add_argument_group(title='Printing') print_group.add_argument('--print', metavar='TYPE', nargs=1, type=str, choices=['artists', 'tracks', 'genres', 'genre-seeds', 'devices', 'blacklist', 'presets', - 'playlists'], - help='print a list of genre seeds, or your top artists, tracks, or genres, where' + 'playlists', 'tuning'], + help='print a list of genre seeds, or your top artists, tracks, or genres, where ' 'TYPE=[artists|tracks|genres|genre-seeds|devices|blacklist]') print_group.add_argument('--version', action='version', version=f'%(prog)s v{version}') print_group.add_argument('--track-features', metavar='[URI | current]', nargs=1, type=str, @@ -678,6 +678,25 @@ def filter_recommendations(data: json) -> list: return valid_tracks +def print_tuning_options(): + try: + with open(f'{Path.home()}/.config/spotirec/tuning-opts', 'r') as file: + tuning_opts = file.readlines() + except FileNotFoundError: + print('Error: could not find tuning options file.') + exit(1) + if len(tuning_opts) == 0: + print('Error: tuning options file is empty.') + exit(1) + for x in tuning_opts: + if tuning_opts.index(x) == 0: + print('\033[1m' + x.strip('\n') + '\033[0m') + else: + print(x.strip('\n')) + print('Note that recommendations may be scarce outside the recommended ranges. If the recommended range is not ' + 'available, they may only be scarce at extreme values.') + + def recommend(): """ Main function for recommendations. Retrieves recommendations and tops up list if any tracks @@ -795,6 +814,8 @@ def parse(): print_presets() elif args.print[0] == 'playlists': print_playlists() + elif args.print[0] == 'tuning': + print_tuning_options() exit(1) if args.track_features: print_track_features(api.get_current_track(headers) if diff --git a/tuning-opts b/tuning-opts new file mode 100644 index 0000000..5b02678 --- /dev/null +++ b/tuning-opts @@ -0,0 +1,15 @@ +Attribute Data type Range Recommended range Function +duration_ms int R+ N/A The duration of the track in milliseconds +key int 0-11 N/A Pitch class of the track +mode int 0-1 N/A Modality of the track. 1 is major, 0 is minor +time_signature int N/A N/A Estimated overall time signature of the track +popularity int 0-100 0-100 Popularity of the track. High is popular, low is barely known +acousticness float 0-1 0-1 Confidence measure for whether or not the track is acoustic. High value is acoustic +danceability float 0-1 0.1-0.9 How well fit a track is for dancing. Measurement includes among others tempo, rhythm stability, and beat strength. High value is suitable for dancing +energy float 0-1 0-1 Perceptual measure of intensity and activity. High energy is fast, loud, and noisy, and low is slow and mellow +instrumentalness float 0-1 0-1 Whether or not a track contains vocals. Low contains vocals, high is purely instrumental +liveness float 0-1 0-0.4 Predicts whether or not a track is live. High value is live +loudness float -60-0 -20-0 Overall loudness of the track, measured in decibels +speechiness float 0-1 0-0.3 Presence of spoken words. Low is a song, and high is likely to be a talk show or podcast +valence float 0-1 0-1 Positivity of the track. High value is positive, low value is negative +tempo float 0-220 60-210 Overall estimated beats per minute of the track \ No newline at end of file