···13131414## Nushell
15151616+## LyricFetch
1717+1818+Fetches lyrics from Genius and adds them to your music library's metadata.
1919+2020+Currently only supports FLAC files. In the future, timesynced lyrics may be
2121+supported, and auto-fetching may be more reliable.
2222+2323+I don't recommend using this right now. It's pretty bad at searching, and most
2424+of the time can't auto-fetch the lyrics anyway. Personally, I just fetch the lyrics
2525+manually and save them using Recordbox.
2626+1627### ADB Auto Connect
1728Automatically find and connect to an Android device with Wireless Debugging over the local network.
1829
+90
nushell/lyricfetch.nu
···11+#!/usr/bin/nu
22+33+def main [
44+ --noconfirm (-y)
55+] {
66+ const library = "~/Music" | path expand
77+ print $"Library path set to (ansi blue)($library)(ansi reset)"
88+99+ if (which metaflac | is-empty) {
1010+ error make {
1111+ msg: "Could not find metaflac."
1212+ help: "Install the FLAC utils."
1313+ }
1414+ }
1515+ if (which fd | is-empty) {
1616+ error make {
1717+ msg: "Could not find fd"
1818+ help: "Install fd-find."
1919+ }
2020+ }
2121+2222+ print "Indexing Library..."
2323+ let tracks = fd -g '*.flac' $library | lines
2424+ print $"Found (ansi green)($tracks | length)(ansi reset) supported tracks in this library."
2525+2626+ for track in $tracks {
2727+ let meta = metaflac $track --show-all-tags
2828+ | parse "{key}={value}"
2929+ | reduce --fold {} {|it, acc| $acc | upsert ($it.key | str downcase) $it.value}
3030+3131+ if ($meta.artist? == null) or ($meta.title? == null) {
3232+ print $"(ansi red)($track)(ansi yellow) doesn't contain artist and title tags, cannot search for lyrics. Skipping.(ansi reset)"
3333+ continue
3434+ }
3535+3636+ print $"\n<- (ansi blue)($meta.title)(ansi reset) by (ansi purple)($meta.artist)(ansi reset) ->"
3737+3838+ if ($meta.lyrics? | is-not-empty) {
3939+ print $"(ansi green)Track already contains lyrics. Skipping.(ansi reset)"
4040+ continue
4141+ } else if ($meta.unsyncedlyrics? | is-not-empty) {
4242+ print -n $"Track already contains unsynced lyrics. Would you like to copy them to the lyrics tag? [Y/n]: "
4343+ match (input) {
4444+ "n" | "N" => (print "Not copying unsynced lyrics, continuing.")
4545+ _ => {
4646+ print "Copying unsynced lyrics to lyrics tag..."
4747+ metaflac $track --set-tag $"LYRICS=($meta.unsyncedlyrics)"
4848+ continue
4949+ }
5050+ }
5151+ }
5252+5353+ print $"Fetching lyrics..."
5454+ let info = try {
5555+ http get $"https://lyrics.astrid.sh/api/search?q=($meta.artist) ($meta.title)"
5656+ } catch {
5757+ print $"(ansi yellow)Could not find lyrics, skipping.(ansi reset)"
5858+ continue
5959+ }
6060+6161+ let lyrics = if ($info.lyrics | is-empty) {
6262+ print $"(ansi yellow)Could not automatically fetch lyrics.(ansi reset)"
6363+ print -n $"Please manually fetch the lyrics from (ansi default_dimmed)($info.url | ansi link)(ansi reset), then paste them here \(enter to skip\):"
6464+ let input = input
6565+ if ($input | is-empty) {
6666+ print $"(ansi yellow)Manually skipped.(ansi reset)"
6767+ continue
6868+ } else {
6969+ $input
7070+ }
7171+ } else {
7272+ print "Successfully fetched lyrics."
7373+ $info.lyrics
7474+ }
7575+7676+ print $"(ansi green_dimmed)<========>(ansi reset)\n(ansi green)($lyrics)(ansi reset)\n(ansi green_dimmed)<========>(ansi reset)"
7777+ print -n $"\nAre the above lyrics correct? [Y/n]: "
7878+ match (input) {
7979+ "n" | "N" => {
8080+ print $"(ansi yellow)Manually skipped.(ansi reset)"
8181+ continue
8282+ }
8383+ _ => {
8484+ print "Writing lyrics to track metadata..."
8585+ metaflac $track --set-tag $"LYRICS=($lyrics)"
8686+ }
8787+ }
8888+ }
8989+}
9090+