Various scripts that I maintain

Ask for confirmation if title/artist doesn't match

Signed-off-by: Shiloh Fen <shiloh@shilohfen.com>

Changed files
+16 -10
scripts
+16 -10
scripts/lyricfetch.nu
··· 90 90 91 91 if not $minimal_screen {print} 92 92 print $"<- Fetching lyrics for (ansi green)($meta.artist) – ($meta.title)(ansi reset) ->" 93 - fetch-lyrics dumb --instance $dumb_instance $"($meta.artist) ($meta.title)" 93 + fetch-lyrics dumb --instance $dumb_instance $meta.artist $meta.title 94 94 | if $in == null { 95 95 print $"(ansi red)No lyrics found for (ansi yellow)($meta.artist) – ($meta.title)(ansi reset)" 96 96 } else if ($in | is-empty) { ··· 105 105 106 106 def "fetch-lyrics dumb" [ 107 107 --instance: string 108 - search: string 108 + artist: string 109 + title: string 109 110 ] { 110 111 if $instance == null { 111 112 error make { 112 113 msg: "Please provide a Dumb instance URL with --instance. For example: `--instance='https://dumb.hyperreal.coffee'`" 113 114 } 114 115 } 116 + 117 + let search = $"($artist) ($title)" 115 118 116 119 log debug $"Searching for: `($search)`" 117 - parse-webpage dumb search $"($instance)/search?q=($search | url encode)" 118 - | if $in == null { 120 + let search_result = parse-webpage dumb search $"($instance)/search?q=($search | url encode)" 121 + 122 + if $search_result == null { 119 123 return null 120 - } else { 121 - print -n $"Best result: (ansi green)($in.title)(ansi reset) by (ansi green)($in.artist)(ansi reset). Is this correct? [Y/n]: " 124 + } 125 + 126 + if $search_result.title != $title or $search_result.artist != $artist { 127 + print -n $"Best result: (ansi green)($search_result.title)(ansi reset) by (ansi green)($search_result.artist)(ansi reset). Is this correct? [Y/n]: " 122 128 match (input -n 1 | str downcase) { 123 - "y" | "" => null 124 - "n" | _ => (return null) 129 + "n" => (return null) 125 130 } 126 - log debug $"Parsing lyrics from webpage: `($instance)($in.href)`" 127 - parse-webpage dumb lyrics $"($instance)($in.href)" 128 131 } 132 + 133 + parse-webpage dumb lyrics $"($instance)($search_result.href)" 129 134 } 130 135 131 136 def "parse-webpage dumb search" [ ··· 168 173 def "parse-webpage dumb lyrics" [ 169 174 url: string 170 175 ] { 176 + log debug $"Parsing lyrics from webpage: `($url)`" 171 177 http get $url 172 178 | xmllint --html --xmlout --nonet - e> (null-device) 173 179 | lines