commit 37ee69e5fb1342c7dd98ca953f2fcdc6c225af32
parent 5b3eca6c6980111ee55ecdeaebe4201b7f5b07c6
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Fri, 20 Dec 2019 20:04:45 -0500
Made the discogs query tool separate
Former-commit-id: d0c4e41d240835e8dd0ca8db599011cc25aea9a9
Diffstat:
3 files changed, 55 insertions(+), 54 deletions(-)
diff --git a/scripts/discogs b/scripts/discogs
@@ -0,0 +1,52 @@
+#!/usr/bin/env ruby
+require "discogs-wrapper" # Needed for API access
+
+my_user_token = ENV['DISCOGS_API_TOKEN']
+
+if my_user_token == nil
+ raise "No user token set."
+end
+
+# Create a wrapper
+wrapper=Discogs::Wrapper.new("iTunesStyleGetter", user_token: my_user_token)
+
+# Join the rest of the arguments into a search string
+query=ARGV.join(" ")
+
+# Initialise arrays
+genres,styles=[],[]
+
+# Search for the query
+search=wrapper.search("#{query}")
+
+# Add the genres of the first result
+search.results.each do |result|
+ if result.genre? && !result.genre.empty?
+ result.genre.each do |g|
+ if g.include? ","
+ g.split(",").each { |x| genres.push "#{x}" }
+ else
+ genres.push "#{g}"
+ end
+ end
+ break
+ end
+end
+
+# Add the styles of the first result
+search.results.each do |result|
+ if result.style? && !result.style.empty?
+ result.style.to_a.each {|x| styles.push "#{x}"}
+ end
+ break
+end
+
+# Add the url of the first result
+url = "http://discogs.com#{search.results[0].uri}".split(" ")
+
+# Join everything together into a 2d array
+# 2 different separators ("~", ",") because bash
+result = [genres.join("~"), styles.join("~"), url]
+
+# Send result to stdout
+p result+
\ No newline at end of file
diff --git a/scripts/it-style b/scripts/it-style
@@ -74,12 +74,12 @@ while :; do
# If there's no album, query without an album
search_url="https://www.discogs.com/search/?q="$(sed -e 's/ /%20/g' -e 's/&/%26/g' <<< "${artist%%feat*} $name")
echo "Querying: \"$artist $name\" ($search_url)"
- response=$(ruby $DOTFILES/scripts/it-style-helper.rb "${artist%%feat*}" "$name");
+ response=$(ruby $DOTFILES/scripts/discogs "${artist%%feat*}" "$name");
else
# Otherwise, add the album to query for precision
search_url="https://www.discogs.com/search/?q="$(sed -e 's/ /%20/g' -e 's/&/%26/g' <<< "${artist%%feat*} $album")
echo "Querying: \"$artist $album $name\" ($search_url)"
- response=$(ruby $DOTFILES/scripts/it-style-helper.rb "${artist%%feat*}" "$album");
+ response=$(ruby $DOTFILES/scripts/discogs "${artist%%feat*}" "$album");
fi
# Remove brackets from the Ruby array
diff --git a/scripts/it-style-helper.rb b/scripts/it-style-helper.rb
@@ -1,51 +0,0 @@
-require "discogs-wrapper" # Needed for API access
-
-my_user_token = ENV['DISCOGS_API_TOKEN']
-
-if my_user_token == nil
- raise "No user token set."
-end
-
-# Create a wrapper
-wrapper=Discogs::Wrapper.new("iTunesStyleGetter", user_token: my_user_token)
-
-# Join the rest of the arguments into a search string
-query=ARGV.join(" ")
-
-# Initialise arrays
-genres,styles=[],[]
-
-# Search for the query
-search=wrapper.search("#{query}")
-
-# Add the genres of the first result
-search.results.each do |result|
- if result.genre? && !result.genre.empty?
- result.genre.each do |g|
- if g.include? ","
- g.split(",").each { |x| genres.push "#{x}" }
- else
- genres.push "#{g}"
- end
- end
- break
- end
-end
-
-# Add the styles of the first result
-search.results.each do |result|
- if result.style? && !result.style.empty?
- result.style.to_a.each {|x| styles.push "#{x}"}
- end
- break
-end
-
-# Add the url of the first result
-url = "http://discogs.com#{search.results[0].uri}".split(" ")
-
-# Join everything together into a 2d array
-# 2 different separators ("~", ",") because bash
-result = [genres.join("~"), styles.join("~"), url]
-
-# Send result to stdout
-p result-
\ No newline at end of file