Changeset 4


Ignore:
Timestamp:
Jan 17, 2015, 5:06:09 PM (10 years ago)
Author:
chronos
Message:
  • Added: Support to generate XSPF playlist format with cleaner title and album extracted from file names.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GenPlaylist.pas

    r3 r4  
    22
    33uses
    4   SysUtils;
     4  SysUtils, Classes;
    55 
    66type
     
    1717end;
    1818 
    19 procedure FileSearch(const PathName: string; ExtList: array of string; BasePath : string) ;
     19procedure FileSearch(Files: TStringList; const PathName: string; ExtList: array of string; BasePath : string) ;
    2020var
    2121  Rec: TSearchRec;
     
    3131      if Rec.Name = '..' then continue
    3232      else if Rec.Name = '.' then continue
    33       else if (Rec.Attr and faDirectory) > 0 then FileSearch(Path + Rec.Name, ExtList, BasePAth)
     33      else if (Rec.Attr and faDirectory) > 0 then FileSearch(Files, Path + Rec.Name, ExtList, BasePAth)
    3434      else if InStrArray(LowerCase(ExtractFileExt(Rec.Name)), ExtList) then begin
    3535        //WriteLn('File: ' + Rec.Name);
    3636        ItemFileName := ParamStr(2) + Copy(Path + Rec.Name, Length(BasePath) + 2, High(Integer));
    3737        //ItemFileName := StringReplace(ItemFileName, ' ', '%20', [rfReplaceAll]);
    38         WriteLn(ItemFileName);
     38        Files.Add(ItemFileName);
    3939      end;
    4040    until FindNext(Rec) <> 0;
     
    4444end;
    4545
     46procedure GenerateM3U;
     47var
     48  Files: TStringList;
     49  I: Integer;
    4650begin
     51  Files := TStringList.Create;
    4752  WriteLn('#EXTM3U');
    48   FileSearch(ParamStr(1), ['.mp3', '.ac3', '.flac', '.it', '.m4a', '.wma', '.s3m', '.ogg'], ParamStr(1));
     53  FileSearch(Files, ParamStr(1), ['.mp3', '.ac3', '.flac', '.it', '.m4a', '.wma', '.s3m', '.ogg'], ParamStr(1));
     54  for I := 0 to Files.Count - 1 do
     55    WriteLn(Files[I]);
     56  Files.Free;
     57end;
     58
     59procedure GenerateXSPF;
     60var
     61  Files: TStringList;
     62  I: Integer;
     63  FileName: string;
     64begin
     65  Files := TStringList.Create;
     66  WriteLn('<?xml version="1.0" encoding="UTF-8"?>');
     67  WriteLn('<playlist version="1" xmlns="http://xspf.org/ns/0/">');
     68  WriteLn('<trackList>');
     69  FileSearch(Files, ParamStr(1), ['.mp3', '.ac3', '.flac', '.it', '.m4a', '.wma', '.s3m', '.ogg'], ParamStr(1));
     70  for I := 0 to Files.Count - 1 do begin
     71    FileName := StringReplace(Files[I], '&', '&amp;', [rfReplaceAll]);
     72    WriteLn('<track>');
     73    WriteLn('<title>' + Copy(ExtractFileName(FileName), 1, Length(ExtractFileName(FileName)) - Length(ExtractFileExt(FileName))) + '</title>');
     74    WriteLn('<location>' + FileName + '</location>');
     75    WriteLn('<album>' + ExtractFileName(ExtractFileDir(FileName)) + '</album>');
     76    WriteLn('</track>');
     77  end;
     78  WriteLn('</trackList>');
     79  WriteLn('</playlist>');
     80  Files.Free;
     81end;
     82
     83begin
     84  GenerateXSPF;
    4985end.
Note: See TracChangeset for help on using the changeset viewer.