Changeset 6


Ignore:
Timestamp:
Jan 13, 2016, 11:52:00 AM (8 years ago)
Author:
chronos
Message:
  • Added: Store file modification date to playlist annotation. This allows to sort tracks by date to see recent files.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GenPlaylist.pas

    r5 r6  
    1717end;
    1818 
    19 procedure FileSearch(Files: TStringList; const PathName: string; ExtList: array of string; BasePath : string) ;
     19procedure FileSearch(Files: TStringList; const PathName: string; ExtList: array of string);
    2020var
    2121  Rec: TSearchRec;
    2222  Path: string;
    23   ItemFileName: string;
    2423begin
    2524  Path := IncludeTrailingPathDelimiter(PathName);
     
    3130      if Rec.Name = '..' then continue
    3231      else if Rec.Name = '.' then continue
    33       else if (Rec.Attr and faDirectory) > 0 then FileSearch(Files, Path + Rec.Name, ExtList, BasePAth)
     32      else if (Rec.Attr and faDirectory) > 0 then FileSearch(Files, Path + Rec.Name, ExtList)
    3433      else if InStrArray(LowerCase(ExtractFileExt(Rec.Name)), ExtList) then begin
    3534        //WriteLn('File: ' + Rec.Name);
    36         ItemFileName := ParamStr(2) + Copy(Path + Rec.Name, Length(BasePath) + 2, High(Integer));
    37         //ItemFileName := StringReplace(ItemFileName, ' ', '%20', [rfReplaceAll]);
    38         Files.Add(ItemFileName);
     35        Files.Add(Path + Rec.Name);
    3936      end;
    4037    until FindNext(Rec) <> 0;
     
    5148  Files := TStringList.Create;
    5249  WriteLn('#EXTM3U');
    53   FileSearch(Files, ParamStr(1), ['.mp3', '.ac3', '.flac', '.it', '.m4a', '.wma', '.s3m', '.ogg'], ParamStr(1));
     50  FileSearch(Files, ParamStr(1), ['.mp3', '.ac3', '.flac', '.it', '.m4a', '.wma', '.s3m', '.ogg']);
    5451  for I := 0 to Files.Count - 1 do
    5552    WriteLn(Files[I]);
    5653  Files.Free;
     54end;
     55
     56function FileDate(FileName: string): TDateTime;
     57var
     58  fa: LongInt;
     59begin
     60  fa := FileAge(FileName);
     61  if Fa <> -1 then begin
     62    Result := FileDateToDateTime(fa);
     63  end else
     64    raise Exception.Create('File ''' + FileName + ''' not found ');
    5765end;
    5866
     
    7078  Out: Integer;
    7179  NameRemoved: Boolean;
     80  RemoteName: string;
    7281begin
    7382  Files := TStringList.Create;
     
    7584  WriteLn('<playlist version="1" xmlns="http://xspf.org/ns/0/">');
    7685  WriteLn('<trackList>');
    77   FileSearch(Files, ParamStr(1), ['.mp3', '.ac3', '.flac', '.it', '.m4a', '.wma', '.s3m', '.ogg'], ParamStr(1));
    78   for I := 0 to Files.Count - 1 do begin 
    79     LocationOriginal := StringReplace(Files[I], '&', '&amp;', [rfReplaceAll]);
     86  FileSearch(Files, ParamStr(1), ['.mp3', '.ac3', '.flac', '.it', '.m4a', '.wma', '.s3m', '.ogg']);
     87  for I := 0 to Files.Count - 1 do begin
     88    RemoteName := ParamStr(2) + Copy(Files[I], Length(ParamStr(1)) + 2, High(Integer));
     89    LocationOriginal := StringReplace(RemoteName, '&', '&amp;', [rfReplaceAll]);
    8090    Location := StringReplace(LocationOriginal, '_', ' ', [rfReplaceAll]);
    8191    Album := ExtractFileName(ExtractFileDir(Location));
     
    119129    WriteLn('<creator>' + Creator + '</creator>');
    120130    WriteLn('<trackNum>' + TrackNum + '</trackNum>');
     131    WriteLn('<annotation>' + FormatDateTime('yyyy-mm-dd', FileDate(Files[I])) + '</annotation>');
    121132    WriteLn('</track>');
    122133  end;
Note: See TracChangeset for help on using the changeset viewer.