commit 5542a44d5f1d27ed35b4a20bd181ac36019f8f53
parent d06d02372d503510dea7026bfabea5e6848dc01f
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Sat, 16 Jun 2018 16:13:13 +0200
itunes_style_getter bugfix
Diffstat:
2 files changed, 99 insertions(+), 102 deletions(-)
diff --git a/bin/itunes_style_getter b/bin/itunes_style_getter
@@ -1,122 +1,123 @@
-#!/bin/bash
-
-if [ $# -ne 0 ]; then
+ #!/bin/bash
+while :; do
+ if [ $# -ne 0 ]; then
case $1 in
- "-p")
- artist=`osascript -e "tell application \"iTunes\" to return artist of current track"`;
- album=`osascript -e "tell application \"iTunes\" to return album of current track"`;
- name=`osascript -e "tell application \"iTunes\" to return name of current track"`;
- ;;
- "-s")
- 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"`;
+ "-p")
+ artist=`osascript -e "tell application \"iTunes\" to return artist of current track"`;
+ album=`osascript -e "tell application \"iTunes\" to return album of current track"`;
+ name=`osascript -e "tell application \"iTunes\" to return name of current track"`;
+ ;;
+ "-s")
+ 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"`;
esac
-else
+ else
echo "Which track?"
select sc in "Selected" "Playing"; do
- case $sc in
- Selected)
- 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"`;
- break;;
- Playing)
- artist=`osascript -e "tell application \"iTunes\" to return artist of current track"`;
- album=`osascript -e "tell application \"iTunes\" to return album of current track"`;
- name=`osascript -e "tell application \"iTunes\" to return name of current track"`;
- break;;
- esac
+ case $sc in
+ Selected)
+ 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"`;
+ break;;
+ Playing)
+ artist=`osascript -e "tell application \"iTunes\" to return artist of current track"`;
+ album=`osascript -e "tell application \"iTunes\" to return album of current track"`;
+ name=`osascript -e "tell application \"iTunes\" to return name of current track"`;
+ break;;
+ esac
done
-fi
+ fi
-if [ -z "$album" ]; then
+ if [ -z "$album" ]; then
# If there's no album, query without an album
genre=$(ruby /Users/alex/.bin/itunes_style_getter_helper.rb g "$artist" "$name");
style=$(ruby /Users/alex/.bin/itunes_style_getter_helper.rb s "$artist" "$name");
url=$(ruby /Users/alex/.bin/itunes_style_getter_helper.rb u "$artist" "$name");
-else
+ else
# Otherwise, add the album to query for precision
genre=$(ruby /Users/alex/.bin/itunes_style_getter_helper.rb g "$artist" "$album" "$name");
style=$(ruby /Users/alex/.bin/itunes_style_getter_helper.rb s "$artist" "$album" "$name");
- url=$(ruby /Users/alex/.bin/itunes_style_getter_helper.rb u "$artist" "$name");
-fi
+ url=$(ruby /Users/alex/.bin/itunes_style_getter_helper.rb u "$artist" "$album");
+ fi
-# Parsing the arrays
-# Split the Ruby arrays into Bash arrays, do some replacements to make it look nice
-IFS=',' read -ra genre <<< "${genre}"
-genre[0]=$(echo ${genre[0]} | sed -e 's/\[//') # Remove front [
-genre[$((${#genre[@]}-1))]=$(echo ${genre[$((${#genre[@]}-1))]} | sed -e 's/\]//') # Remove back ]
+ # Parsing the arrays
+ # Split the Ruby arrays into Bash arrays, do some replacements to make it look nice
+ IFS=',' read -ra genre <<< "${genre}"
+ genre[0]=$(echo ${genre[0]} | sed -e 's/\[//') # Remove front [
+ genre[$((${#genre[@]}-1))]=$(echo ${genre[$((${#genre[@]}-1))]} | sed -e 's/\]//') # Remove back ]
-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 ]
+ 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 ]
-IFS=',' read -ra url <<< "${url}"
-url[0]=$(echo ${url[0]} | sed -e 's/\[//') # Remove front [
-url[$((${#url[@]}-1))]=$(echo ${url[$((${#url[@]}-1))]} | sed -e 's/\]//') # Remove back ]
+ IFS=',' read -ra url <<< "${url}"
+ url[0]=$(echo ${url[0]} | sed -e 's/\[//') # Remove front [
+ url[$((${#url[@]}-1))]=$(echo ${url[$((${#url[@]}-1))]} | sed -e 's/\]//') # Remove back ]
-# Give the user the source information
-echo "URL: $url"
-echo "You're changing the album \"$album\" by \"$artist\""
-printf '\n'
+ # Give the user the source information
+ echo "URL: $url"
+ echo "You're changing the album \"$album\" by \"$artist\""
+ printf '\n'
-# Select menu for genre
-echo "Genre options:"
-printf '%s\n' "${genre[@]}"
-printf "\nWould you like to use one of these?\n"
-select yn in "Yes" "No"; do
+ # Select menu for genre
+ echo "Genre options:"
+ printf '%s\n' "${genre[@]}"
+ printf "\nWould you like to use one of these?\n"
+ select yn in "Yes" "No"; do
case $yn in
- Yes)
- select opt in "${genre[@]}"; do
- case $opt in
- *)
- finalg=$(echo $opt | sed -e 's/"//g')
- if [[ $finalg = "Hip Hop" ]]; then finalg="Hip-Hop"; fi
- break;;
- esac
- done
- break;;
- No)
- echo "Write your own then:"
- read finalg
- if [[ $finalg = "Hip Hop" ]]; then finalg="Hip-Hop"; fi
- if [[ $finalg = "Post-Rock" ]]; then finalg="Post Rock"; fi
- break;;
+ Yes)
+ select opt in "${genre[@]}"; do
+ case $opt in
+ *)
+ finalg=$(echo $opt | sed -e 's/"//g')
+ if [[ $finalg = "Hip Hop" ]]; then finalg="Hip-Hop"; fi
+ break;;
+ esac
+ done
+ break;;
+ No)
+ echo "Write your own then:"
+ read finalg
+ if [[ $finalg = "Hip Hop" ]]; then finalg="Hip-Hop"; fi
+ if [[ $finalg = "Post-Rock" ]]; then finalg="Post Rock"; fi
+ break;;
esac
-done
+ done
-# Select menu for style
-echo "Style options:"
-printf '%s\n' "${style[@]}"
-printf "\nWould you like to use one of these?\n"
-select yn in "Yes" "No" "None needed"; do
+ # Select menu for style
+ echo "Style options:"
+ printf '%s\n' "${style[@]}"
+ printf "\nWould you like to use one of these?\n"
+ select yn in "Yes" "No" "None needed"; do
case $yn in
- Yes)
- select opt in "${style[@]}"; do
- case $opt in
- *)
- finals=$(echo \/$opt | sed -e 's/"//g')
- break;;
- esac
- done
- break;;
- No)
- echo "Write your own then:"
- read finals
- finals="/$finals"
- break;;
- "None needed")
- break;;
+ Yes)
+ select opt in "${style[@]}"; do
+ case $opt in
+ *)
+ finals=$(echo \/$opt | sed -e 's/"//g')
+ break;;
+ esac
+ done
+ break;;
+ No)
+ echo "Write your own then:"
+ read finals
+ finals="/$finals"
+ break;;
+ "None needed")
+ break;;
esac
-done
+ done
-# Finally, write the info to the iTunes track (AppleScript)
-if [ -z "$album" ]; then
+ # Finally, write the info to the iTunes track (AppleScript)
+ if [ -z "$album" ]; then
osascript -e "tell application \"iTunes\" to set the genre of every track whose name is \"$name\" and artist is \"${artist}\" to \"$finalg$finals\"" > /dev/null
-else
+ else
osascript -e "tell application \"iTunes\" to set the genre of every track whose album is \"$album\" and artist is \"${artist}\" to \"$finalg$finals\"" > /dev/null
-fi
+ fi
-# ...and give a status message.
-printf "\nGenre set to: $finalg$finals\n"-
\ No newline at end of file
+ # ...and give a status message.
+ printf "\nGenre set to: $finalg$finals\n"
+done+
\ No newline at end of file
diff --git a/bin/itunes_style_getter_helper.rb b/bin/itunes_style_getter_helper.rb
@@ -31,10 +31,6 @@ elsif (flag=="s")
end
# If searching for url
else
- search.results.each do |result|
- if result.style? && !result.style.empty?
- res="http://discogs.com#{result.uri}".split(" ")
- end
- p res
- end
+ res="http://discogs.com#{search.results[0].uri}".split(" ")
+ p res
end
\ No newline at end of file