Solved

lyrics search

Posted on 1999-01-10
6
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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