commit 7d0f91021d704336d7c3514242695dc5b55b5ba9
parent 6da6e71d88993576d1ddf44771f378d5cf266110
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Fri, 13 Jan 2017 21:37:32 +0100
Added more options to itunes_style_getter
I can now select from more than one style
Diffstat:
2 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/itunes_style_getter b/itunes_style_getter
@@ -3,17 +3,36 @@ artist=`osascript -e "tell application \"iTunes\" to return artist of selection"
album=`osascript -e "tell application \"iTunes\" to return album of selection"`;
name=`osascript -e "tell application \"iTunes\" to return name of selection"`;
-style=$(ruby /Users/alex/.bin/itunes_style_getter_helper.rb \"$artist\" \"$album\" \"$name\");
-echo $style;
-echo "Manual override?";
+# Get the style using a Ruby helper script (much easier to use the API in Ruby...)
+style=$(ruby /Users/alex/.bin/itunes_style_getter_helper.rb ${artist} ${album} ${name});
+echo $style
+
+# Parsing the array
+# Split the Ruby array into a Bash array, do some replacements
+IFS=',' read -ra style <<< "${style}"
+style[0]=$(echo ${style[0]} | sed -e 's/\[//') # Remove front [
+style[$((${#style[@]}-1))]=$(echo ${style[$((${#style[@]}-1))]} | sed -e 's/\]//') # Remove back ]
+
+echo "You're changing the album \"$album\" by \"$artist\""
+echo "The options:"
+printf '%s\n' "${style[@]}"
+echo "Would you like to use one of these?"
select yn in "Yes" "No"; do
case $yn in
- Yes )
- read -p "What genre? " genre;
- style=$genre;
+ Yes)
+ select opt in "${style[@]}"; do
+ case $opt in
+ *)
+ final=$(echo $opt | sed -e 's/"//g')
+ break;;
+ esac
+ done
+ break;;
+ No)
+ echo "Write your own then:"
+ read final
break;;
- No ) break;;
esac
done
-osascript -e "tell application \"iTunes\" to set the genre of every track whose album is \"$album\" and artist is \"$artist\" to \"$style\"" > /dev/null
+osascript -e "tell application \"iTunes\" to set the genre of every track whose album is \"$album\" and artist is \"${artist}\" to \"$final\"" > /dev/null
diff --git a/itunes_style_getter_helper.rb b/itunes_style_getter_helper.rb
@@ -2,12 +2,12 @@ require "discogs-wrapper"
my_user_token = ENV["DISCOGS_API_TOKEN"]
-query="#{ARGV[0]} #{ARGV[1]}"
+query="#{ARGV[0]} #{ARGV[1]} #{ARGV[2]}"
wrapper=Discogs::Wrapper.new("iTunesStyleGetter", user_token: my_user_token)
search=wrapper.search("#{query}")
search.results.each do |result|
- if result.style?
- puts result.style[0]
- break
+ if result.style? && !result.style.empty?
+ p result.style.to_a
+ exit
end
end