home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / software / temacd / godfather / TGF_069.exe / $INSTDIR / Scripts / Discogs.sco < prev    next >
Encoding:
Text File  |  2005-02-06  |  4.4 KB  |  139 lines

  1. {http://www.discogs.com}
  2. // first line must be the home page of the site you want to use
  3.  
  4. {?
  5.  ARTIST=FORM;TYPE=artists:str|Q=%:str|btn=#:click
  6. /?}
  7.  
  8. // This a simple sample script to use with the discogs electronic music site
  9. // use it as the basis for more scripts
  10. Program Discogs;
  11.  
  12. var
  13.   slMain: TStringList;
  14.   iRow: integer;
  15.  
  16.   //---
  17.   procedure GetImage( sLine: string );
  18.   var
  19.     iPos: integer;
  20.     sTmp: string;
  21.   begin
  22.     iPos := Pos( '"http:', sLine );
  23.     if iPos > 0 then begin
  24.        sTmp := Copy( sLine, iPos + 1, 99999 );
  25.        iPos := Pos( '.jpg"', sTmp );
  26.        if iPos = 0 then iPos := Pos( '.gif"', sTmp ); // maybe gif file
  27.        if iPos > 0 then begin
  28.           sTmp := Copy( sTmp, 1, iPos + 3 );
  29.           on_setPicture( sTmp );
  30.        end;
  31.     end;
  32.   end;
  33.  
  34.   //---
  35.   procedure GetArtistAlbum( sLine: string );
  36.   var
  37.     iPos: integer;
  38.   begin
  39.     sLine := on_cleanHTMLLine( sLine );
  40.     iPos := RPos( ' - ', sLine );
  41.     if iPos > 0 then begin
  42.        on_setArtist( Trim( Copy( sLine, 1, iPos - 1 ) ) );
  43.        on_setAlbum( Copy( sLine, iPos + 3, 9999 ) );
  44.     end;
  45.   end;
  46.  
  47.   //------
  48.   procedure GetTracks;
  49.   var
  50.     iUpToRow: integer;
  51.     sTrack, sArtist, sTmp, sTitle, sTime: string;
  52.     iPos: integer;
  53.   begin
  54.     iUpToRow := iRow + 1;
  55.     if not on_FindRow( iUpToRow, 0, '<P>', slMain ) then exit; // find last row with track info
  56.  
  57.     iRow := iRow + 4;
  58.     while iRow <= iUpToRow do begin
  59.  
  60.        sTrack := on_cleanHTMLLine( slMain.Strings[ iRow ] ); // track no
  61.        iRow := iRow + 1;
  62.        sArtist := on_cleanHTMLLine( slMain.Strings[ iRow ] ); // performer or empty
  63.        iRow := iRow + 1;
  64.        sTmp := on_cleanHTMLLine( slMain.Strings[ iRow ] ); // title and time
  65.  
  66.        iPos := RPos( ' (', sTmp );
  67.        if (iPos > 0) and (Pos( ':', sTmp ) > 0) then begin
  68.           sTitle := Trim( Copy( sTmp, 1, iPos - 1 ) );
  69.           sTime := Trim( Copy( sTmp, iPos + 2, 9999 ) );
  70.           sTime := Copy( sTime, 1, Length( sTime ) - 1);
  71.        end else begin
  72.           sTitle := sTmp;
  73.           sTime := '';
  74.        end;
  75.  
  76.        if sArtist <> '' then sTitle := sArtist + ' / ' + sTitle;
  77.  
  78.        on_addTrack( sTrack, sTitle, '', sTime );
  79.  
  80.        iRow := iRow + 2; // move on
  81.        if Pos( 'Producer -', slMain.Strings[ iRow + 1 ] ) > 0 then begin // producer lines skip
  82.           iRow := iRow + 3;
  83.        end;
  84.        if Pos( 'Mixed By -', slMain.Strings[ iRow + 1 ] ) > 0 then begin // mixed by lines skip
  85.           iRow := iRow + 3;
  86.        end;
  87.        if Pos( 'Remix -', slMain.Strings[ iRow + 1 ] ) > 0 then begin // remix lines skip
  88.           iRow := iRow + 3;
  89.        end;
  90.        if Pos( 'Featuring -', slMain.Strings[ iRow + 1 ] ) > 0 then begin // Featuring lines skip
  91.           iRow := iRow + 3;
  92.        end;
  93.        if Pos( 'Vocals -', slMain.Strings[ iRow + 1 ] ) > 0 then begin // Vocals lines skip
  94.           iRow := iRow + 3;
  95.        end;
  96.        if Pos( 'Vocals -', slMain.Strings[ iRow + 1 ] ) > 0 then begin // background Vocals lines skip
  97.           iRow := iRow + 3;
  98.        end;
  99.  
  100.     end;
  101.  
  102.   end;
  103.  
  104. begin
  105.  
  106.   on_Init; // clear values
  107.  
  108.   slMain := TStringList.Create;
  109.   try
  110.  
  111.     iRow := 0;
  112.     on_loadHTML( slMain ); // load page to stringlist
  113.  
  114.     //slMain.SaveToFile( 'c:\1.html' ); // save to a file to see what we have to deal with
  115.  
  116.     // artist - album
  117.     if on_FindRow( iRow, 0, 'href="/artist/', slMain ) then GetArtistAlbum( slMain.Strings[ iRow ] );
  118.  
  119.     // image if any
  120.     if on_FindRow( iRow, 0, '/viewimages', slMain ) or
  121.        on_FindRow( iRow, 0, '.jpg"', slMain ) then GetImage( slMain.Strings[ iRow ] );
  122.  
  123.     // generic stuff
  124.     if on_FindRow( iRow, 0, 'Label:</TD>', slMain )    then on_setLabel(   on_cleanHTMLLine( slMain.Strings[ iRow + 1 ] ) );
  125.     if on_FindRow( iRow, 0, 'Released:</TD>', slMain ) then on_setYear(    on_cleanHTMLLine( slMain.Strings[ iRow + 1 ] ) );
  126.     if on_FindRow( iRow, 0, 'Genre:</TD>', slMain )    then on_setGenre(   on_cleanHTMLLine( slMain.Strings[ iRow + 1 ] ) );
  127.     if on_FindRow( iRow, 0, 'Style:</TD>', slMain )    then on_setStyles(  on_cleanHTMLLine( slMain.Strings[ iRow + 1 ] ) );
  128.     if on_FindRow( iRow, 0, 'Notes:</TD>', slMain )    then on_setComment( on_cleanHTMLLine( slMain.Strings[ iRow + 1 ] ) );
  129.  
  130.     // tracks
  131.     if on_FindRow( iRow, 0, '<P><B>Tracklisting:</B><BR>', slMain ) then GetTracks;
  132.  
  133.  
  134.   finally
  135.     slMain.Free;
  136.   end;
  137.  
  138. end.
  139.