{http://www.bootlegzone.com} // =================================================================== // ======== Godfather/bootlegzone.com auto-ID3 tagging script ======== // =================================================================== // ======== Script I made to grab disc information ======== // ======== and import ID3 tag info from bootlegzone ======== // ======== disc pages and auto-import to MP3 files. ======== // ======== Free to use/modify/distribute. ======== // ======== Enjoy! ======== // ======== ======== // ======== Latest version can always be found here: ======== // ======== http://www.pharaohweb.com/blog/?p=777 ======== // ======== ======== // ======== dave ======== // =================================================================== Program bootlegzone; var slMain: TStringList; iRow: integer; //--- procedure GetArtistAlbum( sLine: string ); var iPos: integer; begin sLine := on_cleanHTMLLine( sLine ); iPos := rPos( ' -- ', sLine ); if iPos > 0 then begin on_setArtist( Trim( Copy( sLine, 14, iPos - 14 ) ) ); on_setAlbum( Trim( Copy( sLine, iPos + 3, 9999 ) ) ); end; end; //--- procedure GetImage( sLine: string ); var iPos: integer; sTmp: string; begin iPos := Pos( '/scans/', sLine ); if iPos > 0 then begin sTmp := Copy( sLine, iPos + 7, 99999 ); iPos := Pos( '.jpg"', sTmp ); if iPos = 0 then iPos := Pos( '.gif"', sTmp ); // maybe gif file if iPos > 0 then begin sTmp := Copy( sTmp, 1, iPos + 3 ); sTmp := 'http://www.bootlegzone.com/beatleg/discs/scans/' + sTmp; on_setPicture( sTmp ); end; end; end; //============================================================================================= //======================= BEGIN track title super-loop BEGIN ======================= //============================================================================================= procedure GetTracks( sLine: string ); var iUpToRow, iPos, iPos2, nxtTrackLn, nxtArtistLn, medleyLoopRow, sameCnt, versionLn, medleyAppend, i: integer; sTrack, sArtist, sTitle, medleyTrack, prevMedTrack, sVersion, sSubVersion: string; begin iUpToRow := iRow + 1; if not on_FindRow( iUpToRow, 0, '

Reviews

', slMain ) then exit; // find last row with track info //the track super-loop. the big while loop which looks for tracks. while iRow <= iUpToRow do begin //grab the track number off the current row. current row will //always contains a track number per while loop. iPos := Pos( 'e3b59d', slMain.Strings[ iRow ] ); iPos2 := Pos( '.', slMain.Strings[ iRow ] ); if (iPos > 0) And (iPos2 > 0) then begin sTrack := ( Trim( Copy( slMain.Strings[ iRow ], iPos+7, ipos2-(ipos+7) ) ) ); end; //move forward 5 rows, and grab the track title if iRow <= iUpToRow then iRow := iRow + 5; sTitle := sys_RegexReplace( on_cleanHTMLLine( slMain.Strings[ iRow ] ), '[\(\):]', '', false ) //============================================================================================= //======================= BEGIN version & sub-version string-grab BEGIN ======================= //============================================================================================= //enter the version/sub-version loop only if the verstion string for //the bootlegzone entry has data in it. we can check this by looking for //the presence of the default string, 'unidentified', in the version field. //if we find that string, we'll skip grabbing version/sub-version strings //initiate strings to null sVersion := ''; sSubVersion := ''; versionLn := iRow; on_FindRow( versionLn, 0, 'version.php?vid=', slMain ) if not sys_RegexFind ( slMain.Strings[ versionLn ], '.unidentified.') then begin //get the track version string sVersion := on_cleanHTMLLine( slMain.Strings[ versionLn ] ); //move forward two lines, and look for any sub-version string //if we find a the "version" URL, let's capture the sub-version string and //compile the version and subversion strings into parenthetical information //which we'll append to the song title at the end if sys_RegexFind ( slMain.Strings[ versionLn + 2 ], '.version\.php.') then begin sSubVersion := on_cleanHTMLLine( slMain.Strings[ versionLn + 2 ] ); sVersion := '(' + sVersion + ', ' + sSubVersion + ')'; end else begin sVersion := '(' + sVersion + ')'; end; //Bootlegzone's default version nomenclature for "commercial release" versions //is the string 'Regular'. I find this information useless, and therefore strip //any version information shown as 'Regular'. Some users also enter multiple takes //under the 'Recording Sessions' version, with the take number as the sub-version. //For my use, I would rather not have the 'Recording Sessions' nomenclature, so I kill it too //Note: I also kill some other common version tags... I need to upgade this list to a user-defineable array... if sys_RegexFind ( sVersion, '\(Regular\)') then sVersion := sys_RegexReplace( sVersion, '\(Regular\)', '', false); if sys_RegexFind ( sVersion, '\(Regular, ') then sVersion := sys_RegexReplace( sVersion, '\(Regular, ', '(', false); if sys_RegexFind ( sVersion, '\(Recording Sessions\)') then sVersion := sys_RegexReplace( sVersion, '\(Recording Sessions\)', '', false); if sys_RegexFind ( sVersion, '\(Recording Sessions, ') then sVersion := sys_RegexReplace( sVersion, '\(Recording Sessions, ', '(', false); if sys_RegexFind ( sVersion, '\(Recording Session\)') then sVersion := sys_RegexReplace( sVersion, '\(Recording Session\)', '', false); if sys_RegexFind ( sVersion, '\(Recording Session, ') then sVersion := sys_RegexReplace( sVersion, '\(Recording Session, ', '(', false); if sys_RegexFind ( sVersion, '\(Concert\)') then sVersion := sys_RegexReplace( sVersion, '\(Concert\)', '', false); if sys_RegexFind ( sVersion, '\(Concert, ') then sVersion := sys_RegexReplace( sVersion, '\(Concert, ', '(', false); if sys_RegexFind ( sVersion, '\(Radio\)') then sVersion := sys_RegexReplace( sVersion, '\(Radio\)', '', false); if sys_RegexFind ( sVersion, '\(Radio, ') then sVersion := sys_RegexReplace( sVersion, '\(Radio, ', '(', false); if sys_RegexFind ( sVersion, '\(Get Back Session\)') then sVersion := sys_RegexReplace( sVersion, '\(Get Back Session\)', '', false); if sys_RegexFind ( sVersion, '\(Get Back Session, ') then sVersion := sys_RegexReplace( sVersion, '\(Get Back Session, ', '(', false); if sys_RegexFind ( sVersion, '\(In Concert\)') then sVersion := sys_RegexReplace( sVersion, '\(In Concert\)', '', false); if sys_RegexFind ( sVersion, '\(In Concert, ') then sVersion := sys_RegexReplace( sVersion, '\(In Concert, ', '(', false); end; //============================================================================================= //======================= END version & sub-version string-grab END ======================= //============================================================================================= //============================================================================================= //======================= BEGIN medley track naming routine BEGIN ======================= //============================================================================================= //init variables needed for medley/subsong loop-check i := 1; medleyTrack := ''; sameCnt := 1; //if a sub-song exists (checked on the page's html string 'TxNy' where x is the current sTrack //in the track super-loop and y is any number greater than zero), then loop through looking //for all subsongs of the main track (as in the case of a medley-type track), and concat them //into a single track title line, separated by pipes while on_FindRow( medleyLoopRow, 0, ' 0 then sTitle := 'Medley:'; prevMedTrack := medleyTrack; end else begin if (AnsiCompareText( prevMedTrack, Trim( on_cleanHTMLLine( slMain.Strings[ medleyLoopRow + 6 ] ) )) = 0) then begin sameCnt := sameCnt + 1; //the medleyAppend integer holds the character length of a medley track's Nx appended string, //this length is used several times through the loop to combine the medley sub-tracks. The //value is the length sameCnt plus two chars for the whitespace and 'x'. medleyAppend := Length(InttoStr(SameCnt))+2; //sys_MessageDlg('medleyAppend' + InttoStr(medleyAppend),3,0); //sys_MessageDlg('medleyTrack' + medleyTrack,3,0); //regex will match 0-199, but loop limited to supporting 0-99x repeat strings if sys_RegexFind( Copy( medleyTrack, Length(medleyTrack)-medleyAppend, 9999), '[0-9]|[1-9][0-9]|1[0-9]x') then begin //a quick if-else that checks if we have a one-char or two-char sameCnt (<=10) //so we can subtract the right amount of chars from the end of the track before //continuing to combine it. A one-char length sameCnt means we trim 3 chars //for 'x' and whitespace, a two-char sameCnt means trim 4. if (sameCnt <= 10) then medleyTrack := Copy( medleyTrack, 1, Length(medleyTrack)-3) + ' ' + InttoStr(sameCnt) + 'x' else medleyTrack := Copy( medleyTrack, 1, Length(medleyTrack)-4) + ' ' + InttoStr(sameCnt) + 'x'; sTitle := Copy( sTitle, 1, Length(sTitle)-(Length(prevMedTrack)+medleyAppend)); prevMedTrack := Trim( on_cleanHTMLLine( slMain.Strings[ medleyLoopRow + 6 ] ) ); //sys_MessageDlg(medleyTrack,3,0); end else begin if sys_RegexFind( sTitle, '[0-9]|[1-9][0-9]|1[0-9]x') then sameCnt := 2; medleyTrack := medleyTrack + ' ' + InttoStr(sameCnt) + 'x'; sTitle := Copy( sTitle, 1, Length(sTitle)-Length(prevMedTrack)); prevMedTrack := Trim( on_cleanHTMLLine( slMain.Strings[ medleyLoopRow + 6 ] ) ); end; end else begin medleyTrack := on_cleanHTMLLine( slMain.Strings[ medleyLoopRow + 6 ] ); prevMedTrack := Trim( on_cleanHTMLLine( slMain.Strings[ medleyLoopRow + 6 ] ) ); end; end; //lets append the medley tracks to the main track, but take care not to //append pipes for back-to-back medley tracks that were combined into Nx format //also watch out for main tracks with "ghost" medley tracks that got a colon //appended per the "1st medley track" if-statement above. if sys_RegexFind( Copy( sTitle, Length(sTitle)-3, 9999), '\|') then sTitle := Copy( sTitle, 1, Length(sTitle)-3); if sys_RegexFind( Copy( Trim(sTitle), Length(Trim(sTitle))-1, 9999), ':') and (AnsiCompareText(medleyTrack, '') = 0) then sTitle := Copy( Trim(sTitle), 1, Length(Trim(sTitle))-1); if (AnsiCompareText(medleyTrack, '') <> 0) then sTitle := sTitle + ' | ' + medleyTrack; medleyLoopRow := medleyLoopRow + 1; i := i + 1; end; //============================================================================================= //======================= END medley track naming routine END ======================= //============================================================================================= //============================================================================================= //======================= BEGIN various artists naming routine BEGIN ======================= //============================================================================================= //find the next lines which contain an artist name and track number //for "various artists" naming accounting nxtTrackLn := iRow; nxtArtistLn := iRow; on_FindRow( nxtTrackLn, 0, 'TD width=30 bgColor=#e3b59d', slMain ) on_FindRow( nxtArtistLn, 0, '', slMain ) //get string begin/end for extracting the track artist string from the found line iPos := Pos( '', slMain.Strings[ nxtArtistLn ] ); iPos2 := Pos( '', slMain.Strings[ nxtArtistLn ] ); //if you don't find an artist specified for the track, set the //track artist string to the album artist. //else set the artist to the string on the found line if (nxtArtistLn > nxtTrackLn) And (iPos > 0) And (iPos2 > 0) then sArtist := on_getArtist else sArtist := ( Trim( Copy( slMain.Strings[ nxtArtistLn ], iPos+14, ipos2-(ipos+14) ) ) ); //if the artist string for the track doesn't equal the artist for //the album, assume this is a various artists compilation and //default to the "artist_name - track_name" naming scheme if (AnsiCompareText(sArtist, on_getArtist) <> 0) then begin sTitle := sArtist + ' - ' + sTitle; end; //Doing last check of medley tracks to remove any colon/pipe combos and //pesky underscores that (honestly) result from lack of dutiful checking above. //I look for malformed 'medley'/colon/pipe/underscore stuff and fix. sTitle := sys_RegexReplace( sTitle, '(:.\|)', ':', false); sTitle := sys_RegexReplace( sTitle, '(_)', '', false); sTitle := sys_RegexReplace( sTitle, 'Medley \|', 'Medley: ', false); //============================================================================================= //======================= END various artists naming routine END ======================= //============================================================================================= //============================================================================================= //======================= BEGIN final track string cleanup BEGIN ======================= //============================================================================================= //append the version info to the final track title sTitle := sTitle + ' ' + sVersion; //write the track on_addTrack( sTrack, sTitle, '', '' ); //move the super-loop forward to the next title track while ( not on_FindRow( iRow, 0, 'TD width=30 bgColor=#e3b59d', slMain ) ) And ( iRow <= iUpToRow ) do begin iRow := iRow + 1; end; end; end; //============================================================================================= //======================= END final track string cleanup END ======================= //============================================================================================= //============================================================================================= //======================= END track title super-loop END ======================= //============================================================================================= //--- procedure GetLabel( sLine: string ); var iPos, iPos2: integer; begin iPos := Pos( 'Publisher:', sLine ); iPos2 := Pos( '
Reference :', sLine ); if iPos > 0 then begin on_setLabel( Trim( Copy( sLine, iPos+15, ipos2-(ipos+15) ) ) ); end; end; //--- procedure GetDate( sLine: string ); var iPos, iPos2: integer; begin iPos := Pos( 'Date :', sLine ); iPos2 := Pos( '
Made', sLine ); if iPos > 0 then begin on_setYear( Trim( Copy( sLine, iPos+10, ipos2-(ipos+10) ) ) ); end; end; //--- procedure GetComment( sLine: string ); var iPos, iPos2: integer; begin iPos := Pos( 'Comments', sLine ); iPos2 := Pos( '', sLine ); if iPos > 0 then begin on_setComment( on_cleanHTMLLine (Trim( Copy( sLine, iPos+20, ipos2-(ipos+20) ) ) ) ); end; end; // -------------------- begin page parse -------------------- begin on_Init; // clear values slMain := TStringList.Create; try iRow := 0; on_loadHTML( slMain ); // load page to stringlist slMain.SaveToFile( 'c:\1.html' ); // save to a file to see what we have to deal with // artist - album if on_FindRow( iRow, 0, 'BootlegZone : ', slMain ) then GetArtistAlbum( slMain.Strings[ iRow ] ); // album artwork if on_FindRow( iRow, 0, 'Scan submitted/created by', slMain ) then GetImage( slMain.Strings[ iRow ] ); // date if on_FindRow( iRow, 0, 'BR><B>Date :', slMain ) then GetDate( slMain.Strings[ iRow ] ); // label if on_FindRow( iRow, 0, '<TD align=left><B>Publisher:', slMain ) then GetLabel( slMain.Strings[ iRow ] ); // comments if on_FindRow( iRow, 0, '</TABLE><BR><U><B>Comments', slMain ) then GetComment( slMain.Strings[ iRow ] ); // tracks if on_FindRow( iRow, 0, 'TD width=30 bgColor=#e3b59d', slMain ) then GetTracks( slMain.Strings[ iRow ] ); finally slMain.Free; end; end.