28.10.2007, 13:46
|
|
Активный
|
|
Регистрация: 05.12.2006
Адрес: где-то там...
Сообщения: 321
Репутация: 35
|
|
Код:
//Открытие файла .m3u
function NotFullPathToFullPath(FM3U, FM: string): string;
var
Ress: string;
begin
Ress := '';
Result := '';
if FM[1] = '\' then
begin
Result := ExtractFileDrive(FM3U) + FM;
exit;
end else
begin
if FileExists(ExtractFilePath(FM3U) + FM) then
begin
Result := ExtractFilePath(FM3U) + FM;
exit;
end;
if FileExists(FM) then
begin
Result := FM;
exit;
end;
end;
end;
procedure ReadM3U(files: string);
var List: TStringList;
i, n: integer;
s, a: string;
ListItem: TListItem;
begin
Form1.ListView1.Clear;
List := TStringList.Create;
try
List.LoadFromFile(files);
for i := 0 to List.Count - 1 do
begin
if List.Strings[0] = '#EXTM3U' then
begin
s := List.Strings[i];
if s[1] <> '#' then
begin
ListItem.SubItems.Add('');
s := NotFullPathToFullPath(Files, s);
ListItem.SubItems[1] := s;
end else
begin
if s <> '#EXTM3U' then
begin
Delete(S, 1, 8);
a := '';
n := 1;
repeat
a := a + s[n];
Inc(n);
until s[n] = ',';
Delete(S, 1, Length(a) + 1);
ListItem := Form1.ListView1.Items.Add;
ListItem.Caption := s;
ListItem.SubItems.Add(Format('%d:%.2d', [StrToInt(a) div 60, StrToInt(a) mod 60]));
end;
end;
end;
end;
finally
List.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
ReadM3U(OpenDialog1.FileName) else exit;
end;
Код:
//Сохранение в формат .m3u
function ExtNotFullPath(FM3U, FM: string): string;
var
i: integer;
Ress: string;
begin
Ress := '';
Result := '';
for i := 1 to Length(FM3U) do
begin
if FM3U[i] = FM[i] then
begin
Ress := Ress + FM3U[i];
if FM3U[i] = '\' then Result := Ress;
end else exit;
end;
end;
function MinToSec(tim: string): string;
var n: integer;
a: string;
begin
n := 1;
a := '';
repeat
a := a + tim[n];
Inc(n);
until tim[n] = ':';
Delete(tim, 1, Length(a) + 1);
result := IntToStr((StrToInt(a) * 60) + StrToInt(tim));
end;
procedure SaveList(SaveFile: string);
var List: TStringList;
i: integer;
b, s: string;
begin
List := TStringList.Create;
List.Add('#EXTM3U');
for i := 0 to Form1.ListView1.Items.Count - 1 do
begin
s := '';
List.Add('#EXTINF:' + MinToSec(Form1.ListView1.Items.Item[i].SubItems.Strings[0]) + ',' + Form1.ListView1.Items.Item[i].Caption);
b := ExtNotFullPath(SaveFile, Form1.ListView1.Items.Item[i].SubItems.Strings[1]);
if Length(b) < Length(ExtractFilePath(SaveFile)) then
begin
s := Form1.ListView1.Items.Item[i].SubItems.Strings[1];
if b<>`` then
Delete(s, 1, 2);
end else
s := AnsiReplaceText(Form1.ListView1.Items.Item[i].SubItems.Strings[1], b, '');
List.Add(s);
end;
List.SaveToFile(SaveFile);
List.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if SaveDialog1.Execute then
begin
if ExtractFileExt(SaveDialog1.FileName) = '.m3u' then
SaveList(SaveDialog1.FileName) else SaveList(SaveDialog1.FileName + '.m3u');
end;
end;
Надеюсь на твой отзыв.
__________________
Программирование - это искусство и наш смысл жизни.
|