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#2.sco < prev    next >
Encoding:
Text File  |  2005-02-06  |  4.3 KB  |  140 lines

  1. {http://www.discogs.com}
  2.  
  3. {?
  4.  ARTIST=FORM;TYPE=artists:str|Q=%:str|btn=#:click
  5. /?}
  6.  
  7. // demonstration of some automation
  8. // auto saves pictures a folder.jpg and also uses the apply button.
  9. Program Discogs;
  10.  
  11. var
  12.   slMain: TStringList;
  13.   iRow: integer;
  14.  
  15.   //---
  16.   procedure GetImage( sLine: string );
  17.   var
  18.     iPos: integer;
  19.     sTmp: string;
  20.   begin
  21.     iPos := Pos( '"http:', sLine );
  22.     if iPos > 0 then begin
  23.        sTmp := Copy( sLine, iPos + 1, 99999 );
  24.        iPos := Pos( '.jpg"', sTmp );
  25.        if iPos = 0 then iPos := Pos( '.gif"', sTmp ); // maybe gif file
  26.        if iPos > 0 then begin
  27.           sTmp := Copy( sTmp, 1, iPos + 3 );
  28.           on_setPicture( sTmp );
  29.           on_SavePicture( 1, false );
  30.  
  31.        end;
  32.     end;
  33.   end;
  34.  
  35.   //---
  36.   procedure GetArtistAlbum( sLine: string );
  37.   var
  38.     iPos: integer;
  39.   begin
  40.     sLine := on_cleanHTMLLine( sLine );
  41.     iPos := RPos( ' - ', sLine );
  42.     if iPos > 0 then begin
  43.        on_setArtist( Trim( Copy( sLine, 1, iPos - 1 ) ) );
  44.        on_setAlbum( Copy( sLine, iPos + 3, 9999 ) );
  45.     end;
  46.   end;
  47.  
  48.   //------
  49.   procedure GetTracks;
  50.   var
  51.     iUpToRow: integer;
  52.     sTrack, sArtist, sTmp, sTitle, sTime: string;
  53.     iPos: integer;
  54.   begin
  55.     iUpToRow := iRow + 1;
  56.     if not on_FindRow( iUpToRow, 0, '<P>', slMain ) then exit; // find last row with track info
  57.  
  58.     iRow := iRow + 4;
  59.     while iRow <= iUpToRow do begin
  60.  
  61.        sTrack := on_cleanHTMLLine( slMain.Strings[ iRow ] ); // track no
  62.        iRow := iRow + 1;
  63.        sArtist := on_cleanHTMLLine( slMain.Strings[ iRow ] ); // performer or empty
  64.        iRow := iRow + 1;
  65.        sTmp := on_cleanHTMLLine( slMain.Strings[ iRow ] ); // title and time
  66.  
  67.        iPos := RPos( ' (', sTmp );
  68.        if (iPos > 0) and (Pos( ':', sTmp ) > 0) then begin
  69.           sTitle := Trim( Copy( sTmp, 1, iPos - 1 ) );
  70.           sTime := Trim( Copy( sTmp, iPos + 2, 9999 ) );
  71.           sTime := Copy( sTime, 1, Length( sTime ) - 1);
  72.        end else begin
  73.           sTitle := sTmp;
  74.           sTime := '';
  75.        end;
  76.  
  77.        if sArtist <> '' then sTitle := sArtist + ' / ' + sTitle;
  78.  
  79.        on_addTrack( sTrack, sTitle, '', sTime );
  80.  
  81.        iRow := iRow + 2; // move on
  82.        if Pos( 'Producer -', slMain.Strings[ iRow + 1 ] ) > 0 then begin // producer lines skip
  83.           iRow := iRow + 3;
  84.        end;
  85.        if Pos( 'Mixed By -', slMain.Strings[ iRow + 1 ] ) > 0 then begin // mixed by lines skip
  86.           iRow := iRow + 3;
  87.        end;
  88.        if Pos( 'Remix -', slMain.Strings[ iRow + 1 ] ) > 0 then begin // remix lines skip
  89.           iRow := iRow + 3;
  90.        end;
  91.        if Pos( 'Featuring -', slMain.Strings[ iRow + 1 ] ) > 0 then begin // Featuring lines skip
  92.           iRow := iRow + 3;
  93.        end;
  94.        if Pos( 'Vocals -', slMain.Strings[ iRow + 1 ] ) > 0 then begin // Vocals lines skip
  95.           iRow := iRow + 3;
  96.        end;
  97.        if Pos( 'Vocals -', slMain.Strings[ iRow + 1 ] ) > 0 then begin // background Vocals lines skip
  98.           iRow := iRow + 3;
  99.        end;
  100.  
  101.     end;
  102.  
  103.   end;
  104.  
  105. begin
  106.  
  107.   on_Init; // clear values
  108.  
  109.  
  110.   slMain := TStringList.Create;
  111.   try
  112.  
  113.     iRow := 0;
  114.     on_loadHTML( slMain ); // load page to stringlist
  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.     on_Apply;
  134.  
  135.   finally
  136.     slMain.Free;
  137.   end;
  138.  
  139. end.
  140.