15

I have a large music library (most of them are .mp3 & .m4a) and none of them have lyrics. Is there any program or plug-in that automatically adds lyrics to all of my music by querying the internet?

Because I don't usually have an Internet connection I need a program which automatically adds all lyrics to music file tags so I can view them offline.

Glutanimate
  • 21,393
Bharat
  • 687
  • 3
  • 7
  • 25
  • 2
    Add lyrics how? To each music file? What format is your music collection? How do you intend to view the lyrics that is found? – fossfreedom May 05 '14 at 16:49
  • All I want is that when music files(mostly .mp3 & .m4a) get played in a music player and I click on "display lyrics" It should be able to display lyrics.And I need some software which does that for every music file(all my tags for music files are correct). – Bharat May 06 '14 at 04:13
  • 2
    This comment is far different from the original question. You should at least update the question to make it reflect your new aims. – Luís de Sousa May 07 '14 at 11:11
  • Amarok and Clementine have an option to edit the lyrics which are fetched. I haven't tried it, but it must store them somewhere local and then retrieve them for you. Doing this on a song by song basis would be really tedious, but it would probably work. – Joe May 08 '14 at 07:17
  • There is a nice software called clementine. Try it. It has support for different lyrics online DBs. (Fork of the old Amarok 1*). – ddmytrenko Oct 19 '15 at 20:08

8 Answers8

6

This is a semi answer as I don't know your environment and the code I provide is intended to serve as an example only - running it as is shouldn't do any harm but I can't give any guarantee.

Tasks like this can be dealt with using simple bash scripts, e.g. in the following example I use eyeD3 to extract artist and title, then any WikiLirics-like web service to fetch lyrics and then eyeD3 again to add them as a tag. I encourage everyone who will use this code to look up their own lyrics website as exploiting the same service over and over can be considered malicious.

[edit] Someone have actually provided a lyrics API under the URL from this script and it works!

#!/bin/bash

url_template='http://makeitpersonal.co/lyrics?artist=<artist>&title=<title>' failure_message="Sorry, We don't have lyrics for this song yet."

[ "$1" ] && cd "$1" # if argument provided, use it as working directory

for file in {.mp3,.m4a}; do if [[ ! -r "$file" ]]; then # if file isn't readable continue # skip to the next one fi # but if it is readable... # get artist&title line from eyeD3 song=$(eyeD3 --no-color "$file" | grep title) # e.g. title: Alive artist: Bon Jovi artist="${song#"artist: "}" # use everything after artist: as artist title="${song%"artist: "}" # use everything before artist: as title title="${title#"title: "}" # but cut the title: keyword out

echo -n &quot;$artist - $title&quot;    # $title has extra space at the end but YOLO

artist=&quot;${artist// /+}&quot;       # replace spaces in $artist and $title with
title=&quot;${title// /+}&quot;         # `+` characters for use in $url_template
url=&quot;${url_template//&quot;&lt;artist&gt;&quot;/$artist}&quot;  # replace `&lt;artist&gt;` with $artist
url=&quot;${url//&quot;&lt;title&gt;&quot;/$title}&quot;             # replace `&lt;title&gt;` with $title

lyrics=$(wget -qO- $url)      # make `wget` read the response from $url
                              # which is lyrics or $failure_message
if [ &quot;$lyrics&quot; == &quot;$failure_message&quot; ]; then  # if it is $failure_message
    echo &quot;No lyrics found... skipping!&quot;       # then lyrics aren't available
else                                          # else save $lyrics in $file
    eyeD3 --lyrics=eng:Lyrics:&quot;$lyrics&quot; &quot;$file&quot; 1&gt;/dev/null
fi

done

Instructions (run commands in terminal):

  1. install wget and eyeD3 with command sudo apt install wget eyed3
  2. save above code to a file, e.g. ~/bin/lyrics_fetcher.sh
  3. add permission to run the file: chmod u+x ~/bin/lyrics_fetcher.sh
  4. run the file (mind the quotes): ~/bin/lyrics_fetcher.sh "path/to/my album"
  5. you can stop script execution at any time by pressing ctrl+c

I checked this code with "AM" album by Arctic Monkeys and it did sweetly.

If you really want to fetch lyrics for all of your albums at once you can run the script in a loop for each directory:

cd path/to/my_music_directory
for album in */; do ~/bin/lyrics_fetcher.sh "$album"; done

Still, I wouldn't use it as a final solution - wikilyrics and everyone who supports it by mirroring are good guys and this answer is here to promote thinking, not abuse.

cprn
  • 1,169
  • 2
  • 12
  • 22
  • I did exactly as you said,saved the given code as lyrics_fetcher.sh in home and then ran the command in point 2 in the terminal.then ran this command "./lyrics_fetcher.sh /home/bharat/Music/Linkin-park/LIVING-THINGS ", now there is no further output.I am a complete beginner,please help me out.. – Bharat May 10 '14 at 08:20
  • Do you run all commands in terminal? (there should be terminal output) 2. Do you have wget and eyeD3 installed? If not, run 'sudo apt-get install wget eyed3'
  • – cprn May 10 '14 at 11:58
  • @Bharat , you should've used the command ./lyrics_fetcher.sh "/home/bharat/Music/Linkin-park/LIVING-THINGS" In the folder that the script is in. You missed out the quote marks. – Ads20000 May 14 '14 at 09:26
  • I got an error (in red) "'ascii' codec can't encode characters in position 25-26: ordinal not in range(128)" while running the script. What does it mean? – noir1993 Apr 29 '15 at 20:10
  • You have a unicode character in given position of your string (I don't know whether it's in your artist/title or in fetched lyrics) that can't be converted to ASCII (simple non-diacritical characters). I should probably add some code to handle encoding but as I said in the answer, it's just an example of how such tasks things can be accomplished with simple scripts (mostly to interest some people and make them think a little). Feel free to improve on the code any way you need, mate. :) You should look at @yask's answer, he's python script is way more user friendly. – cprn Apr 30 '15 at 11:06