Author Topic: Lyrister - Song Lyrics Scrapper  (Read 982 times)

0 Members and 3 Guests are viewing this topic.

Offline Psycho_Coder

  • Knight
  • **
  • Posts: 166
  • Cookies: 84
  • Programmer, Forensic Analyst
    • View Profile
    • Code Hackers Blog
Lyrister - Song Lyrics Scrapper
« on: May 18, 2014, 11:09:39 am »
Hello Everyone,

Today I will share a little snippet I wrote to get scrap or download lyrics of your favorite songs and save on your harddrive as .txt files.

I have used python 2.7.4 for this and have used the BeautifulSoup python package for web requests

You can get the code here : https://github.com/PsychoCoderHC/Lyrister

I hope I have taken care of most things that may cause you problems.

How to Use ?

On the terminal run the following and follow the instructions that follow:-

Code: [Select]
python lyrister.py

You have the option of giving command line arguments as the parameters. The following format is to be followed :-

Code: [Select]
python lyrister.py <name-of-song> <path-of-directory> <filename>

It takes three parameters. The first parameter is the name of the song for which you want to download the lyrics. Please note that if you intend to write the song name with spaces then use double quotes and your directory path must end with separator.

Example 1:

Here we download the song Carnival by Natalie Merchant. Since we have not provided the song name with space there is no problem.

Code: [Select]
python lyrister.py carnival /home/psychocoder/ carnivallyric
Example 2:

Here we download the song Carnival Of Rust by "Poets Of Fall". Since we have provided the song name with space there won't be any problem.

Code: [Select]
python lyrister.py "carnival of rust" /home/psychocoder/ CarnivalOfRust
If a file with the same name exists in the directory then it won't let to save the song and will ask you to try another name to download the lyric.

If you want to save the file in some directory which doesn't have write permission then you wont be able to save the lyrics.

These checking have been done already and I hope the rest you can understand by yourself. I have given a good description for every step in the code itself and also how to resolve the errors. I hope you enjoy.

"Don't do anything by half. If you love someone, love them with all your soul. When you hate someone, hate them until it hurts."--- Henry Rollins

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Lyrister - Song Lyrics Scrapper
« Reply #1 on: May 18, 2014, 01:09:20 pm »
You know my opinion:



I downloaded your project and tried to run it. The first problem I encountered was a missing library:

Code: [Select]
Traceback (most recent call last):
  File "lyrister.py", line 5, in <module>
    from bs4 import BeautifulSoup
ImportError: No module named bs4

You should somehow include these dependencies. I don't know what is a good build tool for Python, but either this or mention them in your README.

--some time later--
Just searched for build tools and this is one I found: https://paver.github.io/paver/
I don't know if there is a general build tool every Python programmer should have. But this is what I mean and you should use one for a serious project to make building easy for other programmers. So at least for every larger project. In Java it is almost always Maven (and yes, I didn't include it in all of my projects, my husband always bugs me about it.)

In case of lyrister a small requirements.txt for pip should be enough. See here: https://devcenter.heroku.com/articles/python-pip

Oh, and in case anyone else has trouble with BeautifulSoup:

Code: [Select]
sudo pip install BeautifulSoup4solved it for me.

Now about your program. I would love an option where it just prints the results to stdout. Maybe if you give all options via command line instead of interactive mode.

It works great, btw. I will keep it on my computer, might come in handy.

Offline Psycho_Coder

  • Knight
  • **
  • Posts: 166
  • Cookies: 84
  • Programmer, Forensic Analyst
    • View Profile
    • Code Hackers Blog
Re: Lyrister - Song Lyrics Scrapper
« Reply #2 on: May 18, 2014, 02:04:31 pm »
You know my opinion:



I downloaded your project and tried to run it. The first problem I encountered was a missing library:

Code: [Select]
Traceback (most recent call last):
  File "lyrister.py", line 5, in <module>
    from bs4 import BeautifulSoup
ImportError: No module named bs4

You should somehow include these dependencies. I don't know what is a good build tool for Python, but either this or mention them in your README.

--some time later--
Just searched for build tools and this is one I found: https://paver.github.io/paver/
I don't know if there is a general build tool every Python programmer should have. But this is what I mean and you should use one for a serious project to make building easy for other programmers. So at least for every larger project. In Java it is almost always Maven (and yes, I didn't include it in all of my projects, my husband always bugs me about it.)

In case of lyrister a small requirements.txt for pip should be enough. See here: https://devcenter.heroku.com/articles/python-pip

Oh, and in case anyone else has trouble with BeautifulSoup:

Code: [Select]
sudo pip install BeautifulSoup4solved it for me.

Now about your program. I would love an option where it just prints the results to stdout. Maybe if you give all options via command line instead of interactive mode.

It works great, btw. I will keep it on my computer, might come in handy.


Thanks for the feedback. I love it. I totally forget about writing the steps. I had given a links with some description where I have said that I have used BeautifulSoup but I should have given the instructions for that.

Thank you for letting me know about paver. I havn't used pip much, only a few times. I have always used apt-get or rpm for installing libraries. I will read through them and create packages and will take care of the deployment.

For now I have added an ImportError check and it will work for now but I will fix them soon. (I have exams next week and so I am a bit busy studying the theory and teaching few of my classmates so that they don't fail)

About the command line, Well yes I will, hmm....... I actually planned to do it that way and tried but I still don't understand python's argparser well. I don't know if I am retarted but it has been bugging me since very long. I know the concept and so I try will make one by myself which I can understand then use that for this and my future projects. It seems the only option left :(


Maven is a reason that I am still stuck with Java and also I am good in Java. But nowadays I am doing python a lot. But in future I will switch to some functional programming as its awesome (I read a few articles which has aroused my interest)

I have edited the README and updated the code it should be enough for now.

Thanks a lot.

Arigatou,
Psycho_Coder.
« Last Edit: May 18, 2014, 02:10:59 pm by Psycho_Coder »
"Don't do anything by half. If you love someone, love them with all your soul. When you hate someone, hate them until it hurts."--- Henry Rollins

Offline shimomura

  • Peasant
  • *
  • Posts: 57
  • Cookies: 0
    • View Profile
    • Shanaynay
Re: Lyrister - Song Lyrics Scrapper
« Reply #3 on: May 22, 2014, 10:28:28 pm »
Program ran all the way through without throwing a code although it didn't create the .txt file in the specified directory? You should modify it to pull off a site that provides chords for musicians along with the lyrics.
Who gives a fuck what color the dress is...

Offline Psycho_Coder

  • Knight
  • **
  • Posts: 166
  • Cookies: 84
  • Programmer, Forensic Analyst
    • View Profile
    • Code Hackers Blog
Re: Lyrister - Song Lyrics Scrapper
« Reply #4 on: May 23, 2014, 05:22:43 am »
Program ran all the way through without throwing a code although it didn't create the .txt file in the specified directory? You should modify it to pull off a site that provides chords for musicians along with the lyrics.

Well there is some problem then as it works fine here and for others who have tested it. Could you be more specific on the error out shows or how you are executing the code.
"Don't do anything by half. If you love someone, love them with all your soul. When you hate someone, hate them until it hurts."--- Henry Rollins

Offline d4rkcat

  • Knight
  • **
  • Posts: 287
  • Cookies: 115
  • He who controls the past controls the future. He who controls the present controls the past.
    • View Profile
    • Scripts
Re: Lyrister - Song Lyrics Scrapper
« Reply #5 on: January 08, 2015, 12:51:39 pm »
Hey Psyco_coder I just submitted a pull request to your github with some code tweaks.
Check it out when you have time.
Nice project thanks for this.
Jabber (OTR required): thed4rkcat@einfachjabber.de    Email (PGP required): thed4rkcat@yandex.com    PGP Key: here and here     Blog

<sofldan> not asking for anyone to hold my hand uber space shuttle door gunner guy.


Offline Psycho_Coder

  • Knight
  • **
  • Posts: 166
  • Cookies: 84
  • Programmer, Forensic Analyst
    • View Profile
    • Code Hackers Blog
Re: Lyrister - Song Lyrics Scrapper
« Reply #6 on: January 12, 2015, 02:37:43 am »
Hey Psyco_coder I just submitted a pull request to your github with some code tweaks.
Check it out when you have time.
Nice project thanks for this.

I merged. Thank you.
"Don't do anything by half. If you love someone, love them with all your soul. When you hate someone, hate them until it hurts."--- Henry Rollins