Description of the program : You can get the lyrics of songs with the artist name & the song name from this program.
As usual just create a new fresh project and add the following tools to your form
Now arrange your tools as you see in the following picture(add two labels for the TextBoxes)
First add these namespaces :
Now coming to the main parts, we are using a function to parse the lyrics so first add this function to your codes
Next double click the Button1(Button fetch) and add the following codes :
At last double click your save button and add the following codes to the click event
I hope you enjoyed making this program :)
As usual just create a new fresh project and add the following tools to your form
- 2 Buttons
- 2 TextBoxes
- 1 RichTextBox
- 1 SaveFileDialog
- Button1 - Fetch
- Button2 - Save
- TextBox1 - Artist Name
- TextBox2 - Song Name
- RichTextBox1 - Lyrics
Now arrange your tools as you see in the following picture(add two labels for the TextBoxes)
First add these namespaces :
Imports System.Net Imports System.Web.HttpUtility
Now coming to the main parts, we are using a function to parse the lyrics so first add this function to your codes
Public Function ParseBetween(ByVal Html As String, ByVal Before As String, ByVal After As String, ByVal Offset As Integer) As String If String.IsNullOrEmpty(Html) Then Return String.Empty If Html.Contains(Before) Then Dim Result As String = Html.Substring(Html.IndexOf(Before) + Offset) If Result.Contains(After) AndAlso Not String.IsNullOrEmpty(After) Then Result = Result.Substring(0, Result.IndexOf(After)) Return Result Else Return String.Empty End If End Function
Next double click the Button1(Button fetch) and add the following codes :
If Not String.IsNullOrWhiteSpace(Textbox1.Text) AndAlso Not String.IsNullOrWhiteSpace(Textbox2.Text) Then
Try
Dim src As String = New WebClient().DownloadString(New Uri(String.Format("http://www.songlyrics.com/{0}/{1}-lyrics/", Textbox1.Text.Replace(" ", "-"), Textbox2.Text.Replace(" ", "-"))))
Dim elyrics As String = ParseBetween(src, "
", "
", "
".Length).Replace(vbCrLf, "").Replace("
", vbCrLf)
Richtextbox1.Text = HtmlDecode(elyrics).Replace(Environment.NewLine, "")
Richtextbox1.SelectAll()
Richtextbox1.SelectionAlignment = HorizontalAlignment.Center
Catch ex As Exception
If ex.Message.Contains("404") Then Richtextbox1.Text = "Lyrics not found"
End Try
Else
MessageBox.Show("Enter song name & artist name to get the lyrics", "Information Missing", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
End If
At last double click your save button and add the following codes to the click event
'Defining the savefiledialog1 and using the richtextbox plaintext to save the lyrics without messing up the text Dim savedialog As New SaveFileDialog savedialog.Title = "Save As..." savedialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*" If savedialog.ShowDialog = Windows.Forms.DialogResult.OK Then richtextBox1.SaveFile(savedialog.FileName, RichTextBoxStreamType.PlainText) End IfThat's all you just created your own Lyrics Fetcher, here is a working preview :
I hope you enjoyed making this program :)
16 comments
Mit vb.net 2010 Funktioniert es nicht....
Replywelche Art von Fehler bekommen Sie?
ReplyCould you please show us the full source code, or post project files somewhere? I have some issues (mostly System.ArgumentExceptions).
ReplyHi,
ReplyI just updated the button click codes, if you still have the errors please post the error details in the comment :)
Thank you
It Doesn't work properly
ReplyHello,
ReplyYour code still have many errors please can you check it agin or post us the full project please.
Thanks
Can you please let me know, what kind of error you get? It works well for me.
ReplyThe errors are as the fllowing:
ReplyError 2 String constants must end with a double quote. C:\Users\azer\AppData\Local\Temporary Projects\Lyrics Fetcher\Form1.vb 22 62 Lyrics Fetcher
Error 3 Syntax error. C:\Users\azer\AppData\Local\Temporary Projects\Lyrics Fetcher\Form1.vb 23 1 Lyrics Fetcher
Error 6 'HtmlDecode' is not declared. It may be inaccessible due to its protection level. C:\Users\azer\AppData\Local\Temporary Projects\Lyrics Fetcher\Form1.vb 26 37 Lyrics Fetcher
Error 7 'prselyrics' is not declared. It may be inaccessible due to its protection level. C:\Users\azer\AppData\Local\Temporary Projects\Lyrics Fetcher\Form1.vb 26 48 Lyrics Fetcher
Please help me because I like this project very very very much. Or please publish your project url
Hi,
ReplyI'm very sorry, it had small mistakes now I have solved them. Please try it again from the beginning :)
Thanks
Hi,
ReplyIt steel have the same problems (syntax error, HTMLDecode is unknown, also elyrics is unknown) All the problems are about the Button1(Fetch button) code. Please fix it again
Hi,
ReplyI have updated it again.. I'm sure this time it will work :)
Hi,
ReplyEvery think is fine, but it steel only one problem:
Error 2 'HtmlDecode' is not declared. It may be inaccessible due to its protection level. C:\Users\azer\Desktop\proh\WindowsApplication1\WindowsApplication1\Form1.vb 21 37 WindowsApplication1
Please help me to fix it.
Hi,
ReplyI fixed that problem but, when I enter the artist name, the song name and click fetch button it search for some time but the reachtextbox1 steel clear and when I enter wrong names it type"Lyrics not found"
Why when I click the fetch button it doesn't show the song lyrics.
You must enter the very correct artist name and the song name also that song should be available on the site we are using to get the lyrics :)
ReplyI am having problems in this part :
ReplyDim elyrics As String = ParseBetween(src, "
", "
", "
".Length).Replace(vbCrLf, "").Replace("
", vbCrLf)
Not able to write this code properly. Please can you help with this.
hi my friend have you the sln ??
ReplyPost a Comment
Note: Only a member of this blog may post a comment.