Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

lyrics search

Posted on 1999-01-10
6
Medium Priority
?
242 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 1500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Screencast - Getting to Know the Pipeline
Suggested Courses

810 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