Skip to content

Wrapper for yt-dlp that makes searching and downloading songs easier

License

Notifications You must be signed in to change notification settings

hackerb9/getsong

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

getsong

Given a song name, artist, lyrics or whatever, search for and download a song using yt-dlp.

  • Handles multiple arguments (including embedded spaces) correctly.
  • Uses youtube.com URL, instead of yt-dlp's ytsearch.
  • Allows -c to restrict search to videos with closed captions (manually generated lyrics/subtitles).
  • Can read search terms from a file, downloading one song per line.
  • If xsel is installed, will search for whatever words are currently highlighted by the mouse cursor and download that song.
  • Can download videos instead by changing the script's name: ln -s getsong getvideo

Installation

It's just a bash script. Download it, make it executable, and put it in your PATH.

wget https://raw.githubusercontent.com/hackerb9/getsong/main/getsong
chmod +x getsong
sudo mv getsong /usr/local/bin/

Usage

Usage: getsong [ -c ] [ keywords ... ]

    -c: filter to only results with closed captions (subtitles)

    keywords: a song title, lyrics, artist name, or anything, really.

If no keywords are specified, then the X selection (the last text highlighted by the mouse) will be used.

If you redirect a file to stdin, then getsong will perform a search for every song listed in the file, one per line.

Examples

Search YouTube for a term and download the audio:

getsong genjer

Search and download audio that matches two phrases:

getsong "Mr. Orange" "Dengue Fever"

Limit search to only results with "closed captions" (i.e., lyrics or other subtitles manually generated by the uploader):

getsong -c "A week ago last Thursday"

Seeing lyrics on the command line as audio plays

The mpv program displays subtitles on the terminal if no video window was opened. While playing, one can hit the j key to see the subtitles. Alternately, one can use a command line argument --sid=1:

$ mpv --vo null --sid=1 makeba.mka
 (+) Audio --aid=1 --alang=eng (opus 2ch 48000Hz)
 (+) Subs  --sid=1 --slang=eng 'English - en' (webvtt-webm)
AO: [pipewire] 48000Hz stereo 2ch floatp
"Ooohe" Makeba, Makeba
ma qué bella Can I get a
A: 00:00:40 / 00:03:43 (18%)

Caveats

Note, that the -c option makes captions a requirement, not just a preference. Ideally, we'd get an error message if no captioned version exists, but instead YouTube mangles and ignores the search terms until it finds an incorrect video that does have closed captions.

Another possible issue: YouTube doesn't look at the quality or even quantity of the captions, only whether they exist or not. Occasionally, the "lyrics" to a song will be a single subtitle which reads, unhelpfully, "🎜 (singing) 🎝". In those cases, using the 2nd result (--playlist-items 2:2) usually helps.

Releases

No releases published

Packages

No packages published

Languages