Skip to content

Commit

Permalink
Add tuning option to print (#67)
Browse files Browse the repository at this point in the history
* add tuning option to print

* update readme to reflect install changes

* spelling
  • Loading branch information
Badgie authored Mar 10, 2020
1 parent f3cb77e commit 7068a61
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
25 changes: 23 additions & 2 deletions spotirec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tuning-opts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7068a61

Please sign in to comment.