dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 72232eeaf65c9640e169d07bd1b9ce479894e841
parent 6ee01a42ea32ea18281004ca671af8388565ccfd
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Sat,  1 Sep 2018 16:28:05 +0200

Bugfixes for itunes_style_getter

Diffstat:
Mdotfiles/bin/itunes_style_getter | 66++++++++++++++++++++++++++++++++++++++++--------------------------
Mdotfiles/bin/itunes_style_getter_helper.rb | 12+++++++-----
2 files changed, 47 insertions(+), 31 deletions(-)

diff --git a/dotfiles/bin/itunes_style_getter b/dotfiles/bin/itunes_style_getter @@ -32,15 +32,22 @@ while :; do if [ -z "$album" ]; then # If there's no album, query without an album + echo "Querying: \"$artist $name\" (https://www.discogs.com/search/?q=`sed -e 's/ /%20/g' -e 's/&/%26/g' <<< \"$artist $name\"`)" 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 # 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"); + echo "Querying: \"$artist $album\" (https://www.discogs.com/search/?q=`sed -e 's/ /%20/g' -e 's/&/%26/g' <<< \"$artist $album\"`)" + genre=$(ruby /Users/alex/.bin/itunes_style_getter_helper.rb g "$artist" "$album"); + style=$(ruby /Users/alex/.bin/itunes_style_getter_helper.rb s "$artist" "$album"); url=$(ruby /Users/alex/.bin/itunes_style_getter_helper.rb u "$artist" "$album"); fi + + if [ -z "$genre" ] || [ -z "$url" ]; then + echo "Not found." + exit 1 + fi # Parsing the arrays # Split the Ruby arrays into Bash arrays, do some replacements to make it look nice @@ -87,30 +94,37 @@ while :; do 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 - case $yn in - Yes) - select opt in "${style[@]}"; do - case $opt in - *) - finals="/"$(echo $opt | cut -d ' ' -f1- | sed -e 's/"//g') - break;; - esac - done - break;; - No) - echo "Write your own then:" - read finals - finals="/$finals" - break;; - "None needed") - finals="" - break;; - esac - done + if [ -z "$style" ]; then + echo "No style from Discogs." + echo "Write your own:" + read finals + finals="/$finals" + else + 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 | cut -d ' ' -f1- | sed -e 's/"//g') + break;; + esac + done + break;; + No) + echo "Write your own then:" + read finals + finals="/$finals" + break;; + "None needed") + finals="" + break;; + esac + done + fi # Finally, write the info to the iTunes track (AppleScript) if [ -z "$album" ]; then diff --git a/dotfiles/bin/itunes_style_getter_helper.rb b/dotfiles/bin/itunes_style_getter_helper.rb @@ -18,18 +18,20 @@ if (flag=="g") result.genre.each do |g| res.push("#{g}") end - p res + p res + break + end end -end -# If searching for a style + # If searching for a style elsif (flag=="s") search.results.each do |result| if result.style? && !result.style.empty? - result.style.to_a.each {|x| res.push x} + result.style.to_a.each {|x| res.push "#{x}"} end p res + break end -# If searching for url + # If searching for url else res="http://discogs.com#{search.results[0].uri}".split(" ") p res