diff --git a/APIs/amazon b/APIs/amazon index 75d250a..cd54e09 100755 --- a/APIs/amazon +++ b/APIs/amazon @@ -3,7 +3,7 @@ # Author: https://github.com/BelkaDev urlencode() { -echo ${1// /"%20"} + echo ${1// /"%20"} } #settings @@ -12,4 +12,4 @@ echo ${1// /"%20"} url="https://completion.amazon.com/search/complete?search-alias=aps&mkt=1&q=$(urlencode "$*")" res=$(jq -r '.[1][]' <<< "$(curl -s "$url" &)" | tr -d '"' ) -echo "$res" \ No newline at end of file +echo "$res" diff --git a/APIs/archwiki b/APIs/archwiki index b28a38d..f1784d5 100755 --- a/APIs/archwiki +++ b/APIs/archwiki @@ -3,7 +3,7 @@ # Author: https://github.com/BelkaDev urlencode() { -echo ${1// /"%20"} + echo ${1// /"%20"} } #settings @@ -12,4 +12,4 @@ limit=10 url="https://wiki.archlinux.org/api.php?action=opensearch&format=json&formatversion=2&search=$(urlencode "$*")&namespace=0%7C3000&limit=$limit&suggest=true" res=$(jq -r '.[1][]' <<< "$(curl -s "$url" &)" | tr -d '"' ) -echo "$res" \ No newline at end of file +echo "$res" diff --git a/APIs/baidu b/APIs/baidu index be49097..fbba275 100755 --- a/APIs/baidu +++ b/APIs/baidu @@ -3,7 +3,7 @@ # Author: https://github.com/BelkaDev urlencode() { -echo ${1// /"%20"} + echo ${1// /"%20"} } url="http://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&sugsid=31726,1468,31672,21112,31111,31591,31605,31464,30823&wd=$(urlencode "$*")&csor=4&pwd=isn" diff --git a/APIs/ddg b/APIs/ddg index 8c2c773..b3294cd 100755 --- a/APIs/ddg +++ b/APIs/ddg @@ -3,7 +3,7 @@ # Author: https://github.com/BelkaDev urlencode() { -echo ${1// /"%20"} + echo ${1// /"%20"} } #settings @@ -12,4 +12,4 @@ lang="us-en" url="https://ac.duckduckgo.com/ac/?q=$(urlencode "$*")&type=list&kl=$lang" res=$(jq -r '.[1][]' <<< "$(curl -s "$url" &)" | tr -d '"' | sed 's/\(.*\),/\1 /') -echo "$res" \ No newline at end of file +echo "$res" diff --git a/APIs/deezer b/APIs/deezer index ce6ef35..5328458 100755 --- a/APIs/deezer +++ b/APIs/deezer @@ -3,7 +3,7 @@ # Author: https://github.com/Belkadev urlencode() { -echo ${1// /"%20"} + echo ${1// /"%20"} } # settings diff --git a/APIs/google b/APIs/google index e3e945c..9da1d47 100755 --- a/APIs/google +++ b/APIs/google @@ -3,7 +3,7 @@ # Author: https://github.com/Belkadev urlencode() { -echo ${1// /"%20"} + echo ${1// /"%20"} } #settings diff --git a/APIs/googlebooks b/APIs/googlebooks index b46ae10..b484917 100755 --- a/APIs/googlebooks +++ b/APIs/googlebooks @@ -9,7 +9,7 @@ orderBy="relevance" # {relevance,newest} # doc url https://developers.google.com/books/docs/v1/using urlencode() { -echo ${1// /"%20"} + echo ${1// /"%20"} } diff --git a/APIs/lastfm b/APIs/lastfm index ff9ccd1..69c6a3b 100755 --- a/APIs/lastfm +++ b/APIs/lastfm @@ -13,68 +13,68 @@ LASTFM_USER="" # useless LASTFM_API_KEY="" # get from here: https://www.last.fm/api/account/create search="album" # accepted: {album,track,artist} similar=false # returns recs based on your search - # instead of matching the result (only for artists) - # values: {true,false} +# instead of matching the result (only for artists) +# values: {true,false} catchError() { if [[ $? != 0 ]]; then - notify-send "error reaching servers" ; - exit -fi + notify-send "error reaching servers" ; + exit + fi } urlencode() { -echo ${1// /"%20"} + echo ${1// /"%20"} } updateUrl () { -unset URL -URL="http://ws.audioscrobbler.com/2.0/?method=$1"; shift -URL+="&api_key=$API_KEY&format=json" -URL+="&$@" + unset URL + URL="http://ws.audioscrobbler.com/2.0/?method=$1"; shift + URL+="&api_key=$API_KEY&format=json" + URL+="&$@" } [ -z LASTFM_API_KEY ] && echo "please enter your API key first" && exit 1 ######## ARTISTS function searchArtist { -URL= updateUrl "artist.search" "artist=$(urlencode "$1")" -artists=$(jq '.results.artistmatches.artist[].name' <<< "$(curl -s $URL)" | tr -d '"') -catchError -[ -z "$artists" ] && notify-send "nothing found" && exit 1 -echo $artists + URL= updateUrl "artist.search" "artist=$(urlencode "$1")" + artists=$(jq '.results.artistmatches.artist[].name' <<< "$(curl -s $URL)" | tr -d '"') + catchError + [ -z "$artists" ] && notify-send "nothing found" && exit 1 + echo $artists } function getRecs { -method=$1; shift -URL= updateUrl "$method.getsimilar" "$method=$(urlencode "$1")" -recs=$(jq '.similarartists.artist[].name' <<< "$(curl -s $URL)" | tr -d '"') -catchError -[ -z "$recs" ] && notify-send "nothing found" && exit 1 -echo $recs + method=$1; shift + URL= updateUrl "$method.getsimilar" "$method=$(urlencode "$1")" + recs=$(jq '.similarartists.artist[].name' <<< "$(curl -s $URL)" | tr -d '"') + catchError + [ -z "$recs" ] && notify-send "nothing found" && exit 1 + echo $recs } ######## ALBUMS function searchAlbum { -URL= updateUrl "album.search" "album=$(urlencode "$*")" -albums=$(jq '.results.albummatches.album[] | "\(.artist) - \(.name)"' <<< "$(curl -s $URL)" | tr -d '"' ) -catchError -[ -z "$albums" ] && notify-send "nothing found" && exit 1 -echo "$albums" + URL= updateUrl "album.search" "album=$(urlencode "$*")" + albums=$(jq '.results.albummatches.album[] | "\(.artist) - \(.name)"' <<< "$(curl -s $URL)" | tr -d '"' ) + catchError + [ -z "$albums" ] && notify-send "nothing found" && exit 1 + echo "$albums" } ######## TRACKS function searchTrack { -URL= updateUrl "track.search" "track=$(urlencode "$*")" -tracks=$(jq '.results.trackmatches.track[] | "\(.artist) - \(.name)\n"' <<< "$(curl -s $URL)" | tr -d '"' ) -catchError -[ -z "$tracks" ] && notify-send "nothing found" && exit 1 -echo $tracks + URL= updateUrl "track.search" "track=$(urlencode "$*")" + tracks=$(jq '.results.trackmatches.track[] | "\(.artist) - \(.name)\n"' <<< "$(curl -s $URL)" | tr -d '"' ) + catchError + [ -z "$tracks" ] && notify-send "nothing found" && exit 1 + echo $tracks } input="$*" case "$search" in -"album") res=$(searchAlbum "$search") ;; -"track") res=$(searchTrack "$search") ;; -"artist") [[ "$recs" == "true" ]] && res=$(searchArtist "$search") || res=$(getRecs "$search") ;; + "album") res=$(searchAlbum "$search") ;; + "track") res=$(searchTrack "$search") ;; + "artist") [[ "$recs" == "true" ]] && res=$(searchArtist "$search") || res=$(getRecs "$search") ;; -*) exit 1 ;; + *) exit 1 ;; esac wait diff --git a/APIs/wikipedia b/APIs/wikipedia index 2334d5b..65ffb9e 100755 --- a/APIs/wikipedia +++ b/APIs/wikipedia @@ -3,7 +3,7 @@ # Author: https://github.com/BelkaDev urlencode() { -echo ${1// /"%20"} + echo ${1// /"%20"} } #settings diff --git a/APIs/youtube b/APIs/youtube index c0a8815..cd14e37 100755 --- a/APIs/youtube +++ b/APIs/youtube @@ -3,7 +3,7 @@ # Author: https://github.com/BelkaDev urlencode() { -echo ${1// /"%20"} + echo ${1// /"%20"} } #settings diff --git a/README.md b/README.md index 4a0c0a2..2f8df8b 100644 --- a/README.md +++ b/README.md @@ -50,10 +50,10 @@ of the wrapper script: ``` Bash case "$API" in -"google") $BROWSER "https://www.google.com/search?q=$result" ;; -"deezer" | "lastfm") play "$selection" ;; -"youtube") youtube "$selection" ;; -"books") getBook "$selection" ;; + "google") $BROWSER "https://www.google.com/search?q=$result" ;; + "deezer" | "lastfm") play "$selection" ;; + "youtube") youtube "$selection" ;; + "books") getBook "$selection" ;; esac ``` diff --git a/handler b/handler index 60b094e..f7e63bf 100755 --- a/handler +++ b/handler @@ -26,17 +26,17 @@ logfile="$(dirname $0)/logfile.tmp" API=$(cat $logfile) rm "$logfile" case "$API" in -"ddg") search="$ddg_api" ; allowExcess=true ;; -"deezer") search="$deezer_api" ;; -"youtube") search="$youtube_api" ; allowExcess=true ;; -"google") search="$google_api" ; allowExcess=true ;; -"books") search="$googlebooks_api" ;; -"lastfm") search="$lastfm_api" ;; -"wikipedia") search="$wikipedia_api" allowExcess=true ;; -"amazon") search="$amazon_api" ; allowExcess=true ;; -"archwiki") search="$archwiki_api" ; allowExcess=true ;; -"baidu") search="$baidu_api" ; allowExcess=true ;; -*) echo "unrecognized api" && exit 1 ;; # unreachable + "ddg") search="$ddg_api" ; allowExcess=true ;; + "deezer") search="$deezer_api" ;; + "youtube") search="$youtube_api" ; allowExcess=true ;; + "google") search="$google_api" ; allowExcess=true ;; + "books") search="$googlebooks_api" ;; + "lastfm") search="$lastfm_api" ;; + "wikipedia") search="$wikipedia_api" allowExcess=true ;; + "amazon") search="$amazon_api" ; allowExcess=true ;; + "archwiki") search="$archwiki_api" ; allowExcess=true ;; + "baidu") search="$baidu_api" ; allowExcess=true ;; + *) echo "unrecognized api" && exit 1 ;; # unreachable esac suggestions="" @@ -44,7 +44,7 @@ default_custom_format="{{name_enum}}:{{value}}" custom_format="${format:-$default_custom_format}" urlencode() { -echo ${1// /"%20"} + echo ${1// /"%20"} } convertJson(){ @@ -52,18 +52,18 @@ convertJson(){ } removeIllegal(){ -##### https://github.com/fogine/rofi-blocks/commit/9f45da637baf0f0d342c2e2957535564aa622164 -##### if you care about special characters, the patch above -##### fixes the issue in which they break rofi -##### once installed you can omit this function -echo "$1" | tr -dc '[:alnum:][:space:]-\n\r' + ##### https://github.com/fogine/rofi-blocks/commit/9f45da637baf0f0d342c2e2957535564aa622164 + ##### if you care about special characters, the patch above + ##### fixes the issue in which they break rofi + ##### once installed you can omit this function + echo "$1" | tr -dc '[:alnum:][:space:]-\n\r' } fill_menu(){ JSON_LINES="$(convertJson "$suggestions")" - TEXT=$(cat <"$logfile" diff --git a/suggest b/suggest index 4f52912..3c8e554 100755 --- a/suggest +++ b/suggest @@ -8,19 +8,19 @@ API="$1" #Full path to the handler script handler=$(dirname $0)/handler - [ ! -f "$handler" ] && echo "invalid path to handler script" && exit 1 +[ ! -f "$handler" ] && echo "invalid path to handler script" && exit 1 case "$API" in -"google") prompt="Google: " ;; -"deezer") prompt="Music: " ;; -"youtube") prompt="Youtube: " ;; -"lastfm") prompt="Music: " ;; -"books") prompt="Books: " ;; -"wikipedia") prompt="Wikipedia: " ;; -"ddg") prompt="Ddg: " ;; -"amazon") prompt="Amazon: " ;; -"archwiki") prompt="Archwiki: " ;; -"baidu") prompt="Baidu: " ;; -*) echo "unrecognized API" && exit 1 ;; + "google") prompt="Google: " ;; + "deezer") prompt="Music: " ;; + "youtube") prompt="Youtube: " ;; + "lastfm") prompt="Music: " ;; + "books") prompt="Books: " ;; + "wikipedia") prompt="Wikipedia: " ;; + "ddg") prompt="Ddg: " ;; + "amazon") prompt="Amazon: " ;; + "archwiki") prompt="Archwiki: " ;; + "baidu") prompt="Baidu: " ;; + *) echo "unrecognized API" && exit 1 ;; esac ############### logfile="$(dirname $handler)/logfile.tmp" # logfile to communicate between two ends