1 ### vim:ft=zsh:foldmethod=marker
2 ## letssingit.com search backend for lookup
3 ## Copyright: 2009, Frank Terbeck <ft@bewatermyfriend.org>
5 LOOKUP_guard || return 1
6 [[ -n ${lookup_describe} ]] &&
7 printf '%s' 'search letssingit.com' &&
10 local mode lookup_context
12 local -A opts supported_modes
15 lookup_context="$(LOOKUP_context)"
18 artist 'search by artist'
19 album 'search by album'
20 song 'search by song name'
21 lyrics 'search contents of lyrics'
24 LOOKUP_guard -fd LOOKUP_help_${backend} ||
25 function LOOKUP_help_${backend}() {
26 LOOKUP_guard || return 1
27 printf 'usage: %s [-m mode] <query>\n' ${backend}
28 printf ' -m <mode> specify search mode\n'
29 printf '\n Make music related queries via letssingit.com\n'
30 printf '\nAvailable modes are::\n'
31 for mode in ${(kon)supported_modes} ; do
32 printf '%8s - %s\n' ${mode} ${supported_modes[$mode]}
34 printf '\n The default mode is '\''artist'\'', which can be modified via the\n'
35 printf ' '\''default-mode'\'' style in this context: %s\n\n' ${lookup_context}
37 printf ' %% zstyle '\'':lookup:*:%s:*'\'' default-mode song\n' ${backend}
38 printf ' %% lookup %s Led Zeppelin\n' ${backend}
39 printf ' %% lookup %s -m album Machine Head\n' ${backend}
40 printf ' %% lookup %s -m song Paint it Black\n' ${backend}
42 LOOKUP_help && return 0
44 if [[ -n ${lookup_complete} ]] ; then
45 LOOKUP_guard -fd __lookup_${backend}_supported_modes ||
46 function __lookup_${backend}_supported_modes() {
51 for m in ${(k)supported_modes}; do
52 ms+=("$m:${supported_modes[$m]}")
54 _describe -t letssingit_modes 'supported search modes' ms
58 '-m[set search mode]:supported search modes:__lookup_'${backend}'_supported_modes'
59 '*:letssingit.com query:true'
62 _arguments -s -w -A '-*' ${comp_args} && return 0
63 _message 'letssingit.com query'
67 lu_parseopts_args=( m string )
68 LOOKUP_parseopts "$@" || return 1
71 if [[ -z ${mode} ]] ; then
72 zstyle -s "${lookup_context}" default-mode mode || mode='artist'
76 lookup_communicate[mode]=${mode}
77 LOOKUP_query_handler || return 1
78 if [[ -z ${(Mk)supported_modes:#$mode} ]] ; then
79 printf 'Unknown search mode: '\''%s'\''.\n\n' ${mode}
82 if [[ -z ${QUERY} ]] ; then
88 LOOKUP_browser "http://search.letssingit.com/cgi-exe/am.cgi?a=search_quick&l=${mode}&s=${QUERY}"