Solved

lyrics search

Posted on 1999-01-10
6
233 Views
Last Modified: 2010-04-06
does anybody know how to search and retrieve cd lyrics from the lyrics server at www.lyrics.ch? I have a couple of http components but dont know how to do what i want.

thanks for your help
cando
0
Comment
Question by:cando
  • 3
  • 2
6 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1355815
Can't help you, but your project seems to be interesting..,

Will the result of your work will be freeware?   :-)

Regards, Madshi.
0
 
LVL 4

Accepted Solution

by:
BoRiS earned 500 total points
ID: 1355816
cando

This is a unit I created to search yahoo for but I have addapted it to do your search, you just need to copy and paste this unit and then included it in your projects uses clause

uses
Windows, Forms, ..., LyFind;

unit LyFind;

interface

uses
  Classes;

type
  TFindWebThread = class(TThread)
  protected
    strAddr, strStatus: string;
    procedure Execute; override;
    procedure AddToList;
    procedure ShowStatus;
  public

    strUrl: string;
  end;

implementation

{ TFindWebThread }

uses
  WinInet, WebMainFrm, SysUtils;

procedure TFindWebThread.AddToList;
begin
  Form1.SearchMemo.Items.Add (strAddr);//this adds the found url to a memo called searchmemo on form1
end;

procedure TFindWebThread.Execute;
var
  hHttpSession, hReqUrl: HInternet;
  Buffer: array [0..1023] of Char;
  nRead: Cardinal;
  strRead: string;
  nBegin, nEnd: Integer;
begin
  strRead := '';
  hHttpSession := InternetOpen ('FindWeb',
    INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  try
    hReqUrl := InternetOpenURL (hHttpSession, PChar(StrUrl),
      nil, 0,0,0);
    strStatus := 'Connected to ' + StrUrl;
    Synchronize (ShowStatus);
    try
      // read all the data
      repeat
        InternetReadFile (hReqUrl, @Buffer,
          sizeof (Buffer), nRead);
        strRead := strRead + string (Buffer);
        strStatus := 'Retrieved ' + IntToStr (Length (strRead)) +
          ' of ' + StrUrl;
        Synchronize (ShowStatus);
      until nRead = 0;
    finally
      InternetCloseHandle (hReqUrl);
    end;
  finally
    InternetCloseHandle (hHttpSession);
  end;
  // extract the HTTP headers
  strStatus := 'Extracting headers from ' + StrUrl;
  Synchronize (ShowStatus);
  strRead := LowerCase (strRead);
  repeat
    // find the initial part HTTP reference
    nBegin := Pos ('href="http', strRead);
    if nBegin <> 0 then
    begin
      // get the remaining part of the string
      strRead := Copy (strRead, nBegin + 6,
        Length (strRead) - nBegin - 6);
      // find the end of the HTTP reference
      nEnd := Pos ('>', strRead);
      strAddr := Copy (strRead, 0, nEnd - 2);
      // add the URL if 'lyrics' is not in it
      if (strAddr <> '') and (Pos ('lyrics', strAddr) = 0) then
        Synchronize (AddToList);
    end;
  until nBegin = 0;
  strStatus := 'Done with ' + StrUrl;
  Synchronize (ShowStatus);
end;

procedure TFindWebThread.ShowStatus;
begin
  Form1.StatusBar1.SimpleText := strStatus; //this is to keep you updated on the form1 statusbar
end;

end.

then on a button click on the form you useing to search add this

procedure TForm1.SerButClick(Sender: TObject);
var
  FindThread: TFindWebThread;
begin
    FindThread := TFindWebThread.Create (True);
    FindThread.FreeOnTerminate := True;
    FindThread.strUrl :=
    'http://search.lyrics.ch/query/normal?' +
    ArtistEdit.Text + AlbumEdit.Text + SongEdit.Text';
    FindThread.Resume;
end;

remember that the unit I gave you must be in this forms uses clause

uses
Windows, Forms, ..., LyFind;

if you have problems don't reject the answer, let me know and I will mail you a working example...also this was written in delphi 4 and not tested on delphi 3 yet but I will test it for on D3...

Later
BoRiS
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1355817
cando

I tested it and it works fine but here is the new button click procedure on the mainform

procedure TForm1.Button1Click(Sender: TObject);
var
FindThread: TFindWebThread;
begin
    FindThread := TFindWebThread.Create (True);
    FindThread.FreeOnTerminate := True;
    FindThread.strUrl :=
    'http://search.lyrics.ch/query/normal?' + 'artist=' +
    ArtistEdit.Text + '&album=' + AlbumEdit.Text + '&song=' + SongEdit.Text;
    FindThread.Resume;
end;

also you may need to check the edit for spaces and replace them with + signs

Later
BoRiS
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:cando
ID: 1355818
I seem to be having trouble with the piece that recieves the data, there are variable problems. If you would send me a working example, that would be great.

cando
cando@ix.netcom.com
0
 

Author Comment

by:cando
ID: 1355819
I seem to be having trouble with the piece that recieves the data, there are variable problems. If you would send me a working example, that would be great.

cando
cando@ix.netcom.com
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1355820
cando

I have mailed it to you....

Later
BoRiS
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sending Gmail through Delphi 3 91
delphi prevent click fast 2 191
find a node in VST 2 64
Firemonkey webbrowser scrollbars ? 1 29
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now