-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlist.pas
2026 lines (1903 loc) · 67.2 KB
/
Plist.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{ MPUI-hcb, an MPlayer frontend for Windows
Copyright (C) 2006-2013 Huang Chen Bin <[email protected]>
based on work by Martin J. Fiedler <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
unit Plist;
interface
{$WARN SYMBOL_PLATFORM OFF}
uses
Windows, TntWindows, Messages, SysUtils, TntSysUtils, Variants, Graphics, TntGraphics,
Forms, TntForms, StdCtrls, TntStdCtrls, Controls, ShellAPI, Math,
Dialogs, TntDialogs, Buttons, TntButtons, Menus, TntMenus,
ComCtrls, TntComCtrls, Classes, TntClasses, TntSystem, ExtCtrls,
TntExtCtrls, TntFileCtrl;
const
chsdetDll='uchardet.dll';
type
TOpenDir = class(TThread)
private
Directory: Widestring; msg:boolean;
protected
procedure Execute; override;
end;
TPFF = class(TThread)
protected
procedure Execute; override;
end;
type
TPlaybackState = (psNotPlayed, psPlaying, psPlayed, psSkipped);
TPlaylistEntry = record
State: TPlaybackState;
Selected: boolean;
FullURL: widestring;
DisplayURL: widestring;
end;
TLyricTimeCodeEntry = record
timecode, LyricEntry: integer;
end;
type TPlaylist = class
private
Data: array of TPlaylistEntry;
function GetCount: integer;
function GetItem(Index: integer): TPlaylistEntry;
function GetSelected(Index: integer): boolean;
procedure SetSelected(Index: integer; Value: boolean);
public
procedure Clear;
procedure Add(const Entry: TPlaylistEntry);
procedure AddFiles(const URL: widestring; msg:boolean);
function AddM3U(const FileName: WideString; FileExtIndex: integer; msg:boolean): boolean;
procedure AddDir(Directory: WideString; msg:boolean);
procedure AddDirectory(Directory: WideString; msg:boolean);
property Count: integer read GetCount;
property Items[Index: integer]: TPlaylistEntry read GetItem; default;
property Selected[Index: integer]: boolean read GetSelected write SetSelected;
function GetNext(ExitState: TPlaybackState; Direction: integer): integer;
procedure NowPlaying(Index: integer);
procedure Changed;
procedure MoveSelectedUp;
procedure MoveSelectedDown;
function FindItem(CheckStr, MovieName: widestring): integer;
function FindPW(FileURL: widestring): string;
procedure SetState(Index: integer; Value: TPlaybackState);
procedure play;
end;
type TLyric = class
private
IsParsed: boolean;
LyricStringsA: TStringList; LyricStringsW: TTntStringList;
procedure ParseLyricA(const FileName: WideString);
procedure ParseLyricW(const FileName: WideString; mode: TTntStreamCharSet);
procedure SortLyric;
procedure Draw;
public
LyricTime: array of TLyricTimeCodeEntry;
BitMap: TBitmap;
ItemHeight, TY, dt:Integer;
procedure ParseLyric(FileName: WideString);
procedure GetCurrentLyric;
procedure ClearLyric;
procedure DownloadLyric;
function GetLyricString(i:Integer):WideString;
function GetMaxLyricString(i:Integer):WideString;
constructor Create; overload;
destructor Destroy; override;
end;
type
TWStringList = class;
TMySortCompare = function(List: TWStringList; Index1, Index2: Integer): Int64;
TWStringList = class(TTntStringList)
public
procedure SortStr(c:TMySortCompare);
procedure LoadFile(const FileName: WideString; CharSet: TTntStreamCharSet);
end;
type
TPlaylistForm = class(TTntForm)
PlaylistBox: TTntListBox;
BPlay: TBitBtn;
BAdd: TTntBitBtn;
BMoveUp: TTntBitBtn;
BMoveDown: TTntBitBtn;
BDelete: TTntBitBtn;
BSave: TTntBitBtn;
SaveDialog: TTntSaveDialog;
BAddDir: TTntBitBtn;
CShuffle: TTntSpeedButton;
CLoop: TTntSpeedButton;
COneLoop: TTntSpeedButton;
BClear: TTntBitBtn;
TntPageControl1: TTntPageControl;
TntTabSheet1: TTntTabSheet;
TntTabSheet2: TTntTabSheet;
TntCP: TTntPopupMenu;
CP0: TTntMenuItem;
CPO: TTntMenuItem;
SC: TTntMenuItem;
TC: TTntMenuItem;
AR: TTntMenuItem;
TU: TTntMenuItem;
HE: TTntMenuItem;
JA: TTntMenuItem;
KO: TTntMenuItem;
TH: TTntMenuItem;
FR: TTntMenuItem;
IC: TTntMenuItem;
PO: TTntMenuItem;
KO2: TTntMenuItem;
GR0: TTntMenuItem;
TU2: TTntMenuItem;
GR1: TTntMenuItem;
BA: TTntMenuItem;
CY: TTntMenuItem;
Ar0: TTntMenuItem;
Ar1: TTntMenuItem;
Ar2: TTntMenuItem;
Ar3: TTntMenuItem;
Ar4: TTntMenuItem;
Ar5: TTntMenuItem;
Ar6: TTntMenuItem;
Ba0: TTntMenuItem;
Ba1: TTntMenuItem;
Ba2: TTntMenuItem;
CE: TTntMenuItem;
Ce0: TTntMenuItem;
Ce1: TTntMenuItem;
Ce2: TTntMenuItem;
Ce3: TTntMenuItem;
sc0: TTntMenuItem;
sc1: TTntMenuItem;
sc2: TTntMenuItem;
sc3: TTntMenuItem;
sc4: TTntMenuItem;
tc0: TTntMenuItem;
tc1: TTntMenuItem;
sc5: TTntMenuItem;
tc2: TTntMenuItem;
tc3: TTntMenuItem;
tc4: TTntMenuItem;
tc5: TTntMenuItem;
tc6: TTntMenuItem;
CA1: TTntMenuItem;
tc8: TTntMenuItem;
cy0: TTntMenuItem;
cy1: TTntMenuItem;
cy2: TTntMenuItem;
cy3: TTntMenuItem;
cy4: TTntMenuItem;
cy5: TTntMenuItem;
cy6: TTntMenuItem;
cy7: TTntMenuItem;
Gr: TTntMenuItem;
gr2: TTntMenuItem;
gr3: TTntMenuItem;
gr4: TTntMenuItem;
he0: TTntMenuItem;
he1: TTntMenuItem;
he2: TTntMenuItem;
he4: TTntMenuItem;
he3: TTntMenuItem;
he5: TTntMenuItem;
jp0: TTntMenuItem;
jp1: TTntMenuItem;
jp2: TTntMenuItem;
jp3: TTntMenuItem;
jp4: TTntMenuItem;
jp5: TTntMenuItem;
jp6: TTntMenuItem;
jp7: TTntMenuItem;
ko0: TTntMenuItem;
ko1: TTntMenuItem;
ko3: TTntMenuItem;
ko4: TTntMenuItem;
ko5: TTntMenuItem;
ko6: TTntMenuItem;
lt0: TTntMenuItem;
th0: TTntMenuItem;
th1: TTntMenuItem;
th2: TTntMenuItem;
tu0: TTntMenuItem;
tu1: TTntMenuItem;
tu3: TTntMenuItem;
tu4: TTntMenuItem;
vi: TTntMenuItem;
we: TTntMenuItem;
fr0: TTntMenuItem;
fr1: TTntMenuItem;
fr2: TTntMenuItem;
ic0: TTntMenuItem;
ic1: TTntMenuItem;
ic2: TTntMenuItem;
gr5: TTntMenuItem;
jp8: TTntMenuItem;
iso0: TTntMenuItem;
iso9: TTntMenuItem;
iso15: TTntMenuItem;
gr6: TTntMenuItem;
he6: TTntMenuItem;
RO: TTntMenuItem;
RM: TTntMenuItem;
CO: TTntMenuItem;
I18: TTntMenuItem;
DV: TTntMenuItem;
BE: TTntMenuItem;
TA: TTntMenuItem;
TE: TTntMenuItem;
AM: TTntMenuItem;
OY: TTntMenuItem;
KA: TTntMenuItem;
MA: TTntMenuItem;
ISCII1: TTntMenuItem;
GU: TTntMenuItem;
PG: TTntMenuItem;
ND: TTntMenuItem;
CLyricF: TComboBox;
CLyricS: TComboBox;
PLTC: TTntPanel;
PLHC: TTntPanel;
PLBC: TTntPanel;
MGB: TTntMenuItem;
MG2B: TTntMenuItem;
MB2G: TTntMenuItem;
N1: TTntMenuItem;
BG: TTntMenuItem;
N2: TTntMenuItem;
MLoadLyric: TTntMenuItem;
MDownloadLyric: TTntMenuItem;
TMLyric: TPaintBox;
CPA: TTntMenuItem;
dLyric: TTntBitBtn;
dlyric1: TTntBitBtn;
procedure BAddDirClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormHide(Sender: TObject);
procedure PlaylistBoxDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure FormCreate(Sender: TObject);
procedure BPlayClick(Sender: TObject);
procedure BDeleteClick(Sender: TObject);
procedure BAddClick(Sender: TObject);
procedure BMoveClick(Sender: TObject);
procedure CShuffleClick(Sender: TObject);
procedure CLoopClick(Sender: TObject);
procedure BSaveClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure COneLoopClick(Sender: TObject);
procedure BClearClick(Sender: TObject);
procedure FormDblClick(Sender: TObject);
procedure TntCPClick(Sender: TObject);
procedure CLyricFChange(Sender: TObject);
procedure CLyricSChange(Sender: TObject);
procedure PLTCClick(Sender: TObject);
procedure PLHCClick(Sender: TObject);
procedure PLBCClick(Sender: TObject);
procedure MDownloadLyricClick(Sender: TObject);
procedure MLoadLyricClick(Sender: TObject);
procedure TMLyricPaint(Sender: TObject);
private
{ Private declarations }
BMPpsPlaying, BMPpsPlayed, BMPpsSkipped: TBitmap;
procedure FormDropFiles(var msg: TMessage); message WM_DROPFILES;
procedure FormMove(var msg: TMessage); message WM_MOVE;
public
{ Public declarations }
ControlledMove: boolean;
end;
var
PlaylistForm: TPlaylistForm;
Playlist: TPlaylist;
Lyric: TLyric;
LDocked, RDocked, TDocked, BDocked: boolean;
LL, TT: integer;
IsCLoaded:THandle = 0;
GuessStrChardet : function(str,nameBuf:PChar):PChar; stdcall;
procedure addEpisode(s: widestring);
function mysort(s: TWStringList; P1, P2: Integer): Int64;
procedure LoadCLibrary;
procedure UnLoadCLibrary;
function isNum(n: WChar): boolean;
function Big52Gb(str: string): string;
function Gb2Big5(str: string): string;
implementation
uses Main, Core, Locale, Options,
DLyric, GDILyrics, LyricShow;
{$R *.dfm}
{$R plist_img.res}
procedure LoadCLibrary;
begin
if IsCLoaded <> 0 then exit;
IsCLoaded := Tnt_LoadLibraryW(chsdetDll);
if IsCLoaded <> 0 then begin
@GuessStrChardet := GetProcAddress(IsCLoaded, 'GuessStrChardet');
end;
end;
procedure UnLoadCLibrary;
begin
if IsCLoaded <> 0 then begin
FreeLibrary(IsCLoaded);
IsCLoaded := 0;
GuessStrChardet :=nil;
end;
end;
procedure TWStringList.SortStr(c:TMySortCompare);
var i, j: integer;
begin
for i := 0 to Count - 2 do begin
for j := 1 to Count - i -1 do begin
if c(self,j,j-1)<0 then
Exchange(j - 1,j);
end;
end;
end;
procedure TWStringList.LoadFile(const FileName: WideString; CharSet: TTntStreamCharSet);
var Stream: TStream; DataLeft: Integer; SW: WideString; SA: AnsiString;
begin
Stream := TTntFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
Stream.Position := 0;
BeginUpdate;
try
DataLeft := Stream.Size - Stream.Position;
if (CharSet in [csUnicode, csUnicodeSwapped]) then begin
if DataLeft < SizeOf(WideChar) then SW := ''
else begin
SetLength(SW, DataLeft div SizeOf(WideChar));
Stream.Read(PWideChar(SW)^, DataLeft);
if CharSet = csUnicodeSwapped then
StrSwapByteOrder(PWideChar(SW));
SetTextStr(SW);
end;
end
else begin
SetLength(SA, DataLeft div SizeOf(AnsiChar));
Stream.Read(PAnsiChar(SA)^, DataLeft);
if CharSet = csUtf8 then SetTextStr(UTF8Decode(SA))
else SetTextStr(SA);
end;
finally
EndUpdate;
end;
finally
Stream.Free;
end;
end;
function LoadBitmapResource(const ResName: string; Transparent: boolean): TBitmap;
begin
Result := TBitmap.Create;
Result.LoadFromResourceName(HInstance, ResName);
if Transparent then begin
Result.Transparent := true;
Result.TransparentMode := tmAuto;
end;
end;
procedure TPlaylist.Clear;
begin
SetLength(Data, 0); CurPlay := -1;
end;
procedure TLyric.ClearLyric;
begin
if length(LyricTime) > 0 then begin
SetLength(LyricTime, 0);
if Assigned(LyricShowForm) then GDILyric.DisplayLyricD('','');
case HaveLyric of
1: if LyricStringsW <> nil then LyricStringsW.Free;
2: if LyricStringsA <> nil then LyricStringsA.Free;
end;
end;
HaveLyric := 0; PlaylistForm.CPA.Tag:=0;
PlaylistForm.TMLyricPaint(nil);
if dlod then LyricShowForm.Hide;
end;
procedure TPlaylist.Play;
begin
MainForm.UpdateParams;
CurPlay:=0;
Playlist.NowPlaying(CurPlay);
MainForm.DoOpen(Playlist[CurPlay].FullURL, Playlist[CurPlay].DisplayURL);
end;
procedure TPFF.Execute;
begin
Synchronize(Playlist.play);
end;
procedure TPlaylist.Add(const Entry: TPlaylistEntry);
var len: integer; t:TPFF;
begin
if PClear then Clear;
len := length(Data);
SetLength(Data, len + 1);
Data[len] := Entry;
if PlaylistForm.Visible then begin
PlaylistForm.PlaylistBox.Count := Count;
PlaylistForm.PlaylistBox.Repaint;
end;
if PClear then begin
PClear := false;
if GetCurrentThreadId = MainThreadId then play
else begin
t:=TPFF.Create(True);
t.FreeOnTerminate:=True;
t.Priority := tpTimeCritical;
t.Resume;
SwitchToThread;;
end;
end;
end;
procedure TPlaylist.AddFiles(const URL: widestring; msg:boolean);
var PlistEntry: TPlaylistEntry; j: WideString; i,a: integer;
begin
// check for .m3u .pls .asx .wpl .xspf playlist file
j := Tnt_WideLowerCase(WideExtractFileExt(URL));
i := CheckInfo(PlaylistType, j);
if (i > -1) and AddM3U(URL, i, msg) then exit;
// no playlist -> check for Arc file
a:= CheckInfo(MediaType, j);
if (a > -1) and (a <= ZipTypeCount) then begin
if IsLoaded(j) then AddMovies(URL, FindPW(URL), true, msg);
exit;
end;
// no playlist and Arc file-> enter directly
if (Pos('://', URL) > 1) or WideFileExists(URL) then begin
with PlistEntry do begin
State := psNotPlayed;
FullURL := URL;
if Pos('://', URL) > 1 then // why this? well, the above two lines read like the regexp
DisplayURL := URL // /.{1,5}p:/,which matches http:, ftp:, rtp: and so on ...
else
DisplayURL := WideExtractFileName(URL);
end;
Add(PlistEntry);
if msg then PlayMsgAt := GetTickCount() + 500;
end;
end;
procedure TOpenDir.Execute;
begin
EndOpenDir:=false;
Playlist.AddDir(Directory,msg);
Synchronize(Playlist.Changed);
end;
procedure TPlaylist.AddDirectory(Directory: Widestring; msg:boolean);
var t:TOpenDir;
begin
t:=TOpenDir.Create(True);
t.FreeOnTerminate:=True;
t.Directory:=Directory; t.msg:=msg;
t.Priority := tpTimeCritical;
t.Resume;
SwitchToThread;
// main thread
//EndOpenDir:=false;
//AddDir(Directory,msg);
end;
procedure TPlaylist.AddDir(Directory: Widestring; msg:boolean);
var SR: TSearchRecW; Entry: TPlaylistEntry; a,s,d:WideString;
FList:TWStringList; i:integer;
begin
Directory := WideIncludeTrailingPathDelimiter(WideExpandUNCFileName(Directory));
// check for DVD directory
if WideDirectoryExists(Directory + 'VIDEO_TS') then begin
// Directory:=WideExcludeTrailingPathDelimiter(Directory);
with Entry do begin
State := psNotPlayed;
s:=' -dvd-device '; a:='DVD-1 <-- '; d:=' dvd';
if (Pos(#32, Directory) > 0) or (not IsWideStringMappableToAnsi(Directory)) then
FullURL := s + WideExtractShortPathName(Directory) + d
else
FullURL := s + Directory + d;
DisplayURL := a + Directory;
end;
if not EndOpenDir then begin
Add(Entry);
if msg then PlayMsgAt := GetTickCount() + 500;
end;
exit;
end;
// check for BlueRay directory
if WideDirectoryExists(Directory + 'BDMV') then begin
//Directory:=WideExcludeTrailingPathDelimiter(Directory);
with Entry do begin
State := psNotPlayed;
s:=' -bluray-device '; a:='BlueRay-1 <-- '; d:=' br';
if (Pos(#32, Directory) > 0) or (not IsWideStringMappableToAnsi(Directory)) then
FullURL := s + WideExtractShortPathName(Directory) + d
else
FullURL := s + Directory + d;
DisplayURL := a + Directory;
end;
if not EndOpenDir then begin
Add(Entry);
if msg then PlayMsgAt := GetTickCount() + 500;
end;
exit;
end;
// check for CD directory
if WideFileExists(Directory + 'Track01.cda') then begin
Directory:=WideExcludeTrailingPathDelimiter(Directory);
with Entry do begin
State := psNotPlayed;
s:=' -cdrom-device '; a:='CD <-- '; d:=' cdda://';
if (Pos(#32, Directory) > 0) or (not IsWideStringMappableToAnsi(Directory)) then
FullURL := s + WideExtractShortPathName(Directory) + d
else
FullURL := s + Directory + d;
DisplayURL := a + Directory;
end;
if not EndOpenDir then begin
Add(Entry);
if msg then PlayMsgAt := GetTickCount() + 500;
end;
exit;
end;
{ if WideDirectoryExists(Directory + 'MPEGAV') or WideDirectoryExists(Directory + 'MPEG2') then begin
Directory:=WideExcludeTrailingPathDelimiter(Directory);
with Entry do begin
State := psNotPlayed;
if IsWideStringMappableToAnsi(Directory) then
FullURL := ' -cdrom-device ' + EscapeParam(Directory) + ' vcd://'
else
FullURL := ' -cdrom-device ' + EscapeParam(WideExtractShortPathName(Directory)) + ' vcd://';
DisplayURL := 'VCD <-- ' + Directory;
end;
if not EndOpenDir then Add(Entry);
exit;
end;}
// no CD ->is it a (S)VCD directory?
if WideDirectoryExists(Directory + 'MPEGAV') then Directory := Directory + 'MPEGAV\'
else if WideDirectoryExists(Directory + 'MPEG2') then Directory := Directory + 'MPEG2\';
// no (S)VCD -> search the directory recursively
if WideFindFirst(Directory + '*.*', faAnyFile, SR) = 0 then begin
FList:=TWStringList.Create;
repeat
if SR.Name[1] <> '.' then begin // exclude . or .. Directory
if (not EndOpenDir) and ((SR.Attr and faDirectory) <> 0) then AddDir(Directory + SR.Name,msg)
else if (not EndOpenDir) and (CheckInfo(MediaType, Tnt_WideLowerCase(WideExtractFileExt(SR.Name))) > -1) then
FList.Add(SR.Name);
end;
until EndOpenDir or (WideFindNext(SR) <> 0);
WideFindClose(SR);
FList.SortStr(mysort);
for i:=0 to FList.Count-1 do begin
if not EndOpenDir then AddFiles(Directory + FList[i],msg);
end;
FList.Free;
exit;
end;
// directory is empty, or no filesystem -> try use TrackMode to access directory
Directory:=WideExcludeTrailingPathDelimiter(Directory);
with Entry do begin
State := psNotPlayed;
s:=' -cdrom-device '; a:='VCD <-- '; d:=' vcd://';
if (Pos(#32, Directory) > 0) or (not IsWideStringMappableToAnsi(Directory)) then
FullURL := s + WideExtractShortPathName(Directory) + d
else
FullURL := s + Directory + d;
DisplayURL := a + Directory;
end;
if not EndOpenDir then begin
Add(Entry);
if msg then PlayMsgAt := GetTickCount() + 500;
end;
end;
function TPlaylist.GetCount: integer;
begin
Result := length(Data);
end;
function TPlaylist.GetItem(Index: integer): TPlaylistEntry;
begin
if (Index < Low(Data)) or (Index > High(Data))
then raise ERangeError.Create('invalid playlist item')
else Result := Data[Index];
end;
procedure TPlaylist.SetState(Index: integer; Value: TPlaybackState);
begin
if (Index < Low(Data)) or (Index > High(Data))
then exit
else Data[Index].State := Value;
end;
function TPlaylist.GetSelected(Index: integer): boolean;
begin
if (Index < Low(Data)) or (Index > High(Data))
then raise ERangeError.Create('invalid playlist item')
else Result := Data[Index].Selected;
end;
procedure TPlaylist.SetSelected(Index: integer; Value: boolean);
begin
if (Index < Low(Data)) or (Index > High(Data))
then raise ERangeError.Create('invalid playlist item')
else Data[Index].Selected := Value;
end;
function TPlaylist.FindItem(CheckStr, MovieName: widestring): integer;
var i, j,a: integer; k: widestring;
begin
Result := -1;
if Count < 1 then exit;
i := Pos(CheckStr, MovieName);
if i > 0 then MovieName := copy(MovieName, 1, i - 1);
for j := High(Data) downto Low(Data) do begin
k := Data[j].DisplayURL;
if i>0 then begin
a := Pos(CheckStr, Data[j].DisplayURL);
if a > 0 then k := copy(k, 1, a - 1)
else continue;
end;
if MovieName = k then begin
Result := j;
exit;
end;
end;
end;
function TPlaylist.FindPW(FileURL: widestring): string;
var a,i,h,c: integer; s,w: WideString;
begin
Result := '';
if Count < 1 then exit;
FileURL := Tnt_WideLowerCase(FileURL);
a := Pos('.part', FileURL);
if a > 0 then begin w := copy(FileURL, 1, a - 1); c:=1; end
else begin
a := Pos('.zip.', FileURL);
if a > 0 then begin w := copy(FileURL, 1, a - 1); c:=2; end
else begin
a := Pos('.7z.', FileURL);
if a > 0 then begin w := copy(FileURL, 1, a - 1); c:=3; end
else begin w:= FileURL; c:=0; end;
end;
end;
for i := High(Data) downto Low(Data) do begin
h := Pos(':', Data[i].DisplayURL);
if h > 0 then begin
s := Tnt_WideLowerCase(Data[i].FullURL);
case c of
1: begin
a := Pos('.part', s);
if a > 0 then s := copy(s, 1, a - 1)
else continue;
end;
2: begin
a := Pos('.zip.', s);
if a > 0 then s := copy(s, 1, a - 1)
else continue;
end;
3: begin
a := Pos('.7z', s);
if a > 0 then s := copy(s, 1, a - 1)
else continue;
end;
end;
if s = w then begin
Result := copy(Data[i].DisplayURL, h + 1, MaxInt);
exit;
end;
end;
end;
end;
function TPlaylist.GetNext(ExitState: TPlaybackState; Direction: integer): integer;
var i, UPCount: integer;
begin
if Count = 0 then begin Result := -1; CurPlay := -1; exit; end
else Result := CurPlay;
if Result < 0 then Result := 0
else if Result < Count then Data[Result].State := ExitState; // mark State of current track
if (OneLoop and AutoNext) or (Direction=0) then exit;
AutoNext := true;
if Shuffle and (not OneLoop) then begin // ***** SHUFFLE MODE *****
// unplayed tracks left?
UPCount := 0;
for i := 0 to Count - 1 do
if Data[i].State = psNotPlayed then inc(UPCount);
if UPCount = 0 then begin
if not Loop then Result := -1
else if Count > 1 then begin
repeat Result := Random(Count);
until Result <> CurPlay;
end
end
else begin
repeat Result := Random(Count);
until Data[Result].State = psNotPlayed;
end;
end
else begin // ***** NORMAL MODE *****
inc(Result, Direction);
if (Result < 0) or (Result > Count - 1) then begin
if Loop and (not OneLoop) then Result := (Result + Count) mod Count
else Result := -1;
end;
end;
if PlaylistForm.Visible then PlaylistForm.PlaylistBox.Invalidate;
MainForm.BPrev.Enabled := (Result > 0);
if Result < 0 then MainForm.BNext.Enabled := (1 < Playlist.Count)
else MainForm.BNext.Enabled := (Result + 1 < Playlist.Count);
CurPlay := Result;
end;
procedure TPlaylist.NowPlaying(Index: integer);
begin
if (Index < Low(Data)) or (Index > High(Data)) then exit;
Data[Index].State := psPlaying;
if PlaylistForm.Visible then PlaylistForm.PlaylistBox.Invalidate;
PlaylistForm.PlaylistBox.ItemIndex := Index;
end;
procedure TPlaylist.Changed;
begin
if PlaylistForm.Visible then begin
PlaylistForm.PlaylistBox.Count := Count;
PlaylistForm.PlaylistBox.Repaint;
end;
if (Count = 0) and (not Running) then MainForm.BPlay.Enabled := false;
//if CurPlay<0 then CurPlay:=0;
MainForm.BPrev.Enabled := (CurPlay > 0);
if CurPlay < 0 then MainForm.BNext.Enabled := (1 < Playlist.Count)
else MainForm.BNext.Enabled := (CurPlay + 1 < Playlist.Count);
end;
procedure TPlaylist.MoveSelectedUp;
var i: integer; temp: TPlaylistEntry;
begin
for i := 1 to High(Data) do
if Data[i].Selected and not (Data[i - 1].Selected) then begin
if Data[i].State = psPlaying then dec(CurPlay);
temp := Data[i];
Data[i] := Data[i - 1];
Data[i - 1] := temp;
end;
Changed;
end;
procedure TPlaylist.MoveSelectedDown;
var i: integer; temp: TPlaylistEntry;
begin
for i := (High(Data) - 1) downto 0 do
if Data[i].Selected and not (Data[i + 1].Selected) then begin
if Data[i].State = psPlaying then inc(CurPlay);
temp := Data[i];
Data[i] := Data[i + 1];
Data[i + 1] := temp;
end;
Changed;
end;
function TPlaylist.AddM3U(const FileName: WideString; FileExtIndex: integer; msg:boolean): boolean;
var BasePath, s: WideString;
procedure AddToPls(str: WideString);
begin
if WideDirectoryExists(str) then AddDirectory(str,msg)
else begin
str := ExpandName(BasePath, str);
if (Pos('://', str) > 1) or WideFileExists(str) then AddFiles(str,msg)
else exit;
end;
Result := true;
end;
procedure HandleStr(const b, e: WideString);
var r: integer;
begin
r := pos(b, s);
while r > 0 do begin
s := copy(s, r + length(b), MaxInt);
r := pos(b, s);
if e <> '' then AddToPls(copy(s, 1, pos(e, s) - 1))
else begin
if r > 0 then AddToPls(copy(s, 1, r - 1))
else AddToPls(s);
end;
end;
end;
procedure parseFile(mode: TTntStreamCharSet);
var FileNameList: TWStringList; i: integer;
begin
if Result then exit;
FileNameList := TWStringList.Create;
FileNameList.LoadFile(FileName, mode);
if FileNameList.Count > 0 then begin
for i := 0 to FileNameList.Count - 1 do begin
s := Trim(FileNameList[i]);
if length(s) < 1 then continue;
case FileExtIndex of
{m3u} 0: if s[1] <> '#' then AddToPls(s);
{asx} 1: HandleStr('<Param Name = "SourceURL" Value = "', '"');
{wpl} 2: HandleStr('<media src="', '"');
{pls} 3: if s[1] = 'F' then AddToPls(copy(s, pos('=', s) + 1, MaxInt));
{ttpl} 4: HandleStr('<item file="', '"');
{rmp} 5: HandleStr('<FILENAME>', '</FILENAME>');
{xspf} 6: HandleStr('<location>', '</location>');
{smpl} 7: HandleStr('path="', '"/>');
{m3u8} 8: if s[1] <> '#' then AddToPls(s);
{mpcpl} 9: HandleStr('filename,', '');
end;
end;
end;
FileNameList.Free;
end;
begin
Result := false;
BasePath := WideIncludeTrailingPathDelimiter(WideExtractFilePath(FileName));
parseFile(csUtf8);
parseFile(csUnicode);
parseFile(csUnicodeSwapped);
parseFile(csAnsi);
end;
procedure TLyric.ParseLyric(FileName: WideString);
begin
if not IsWideStringMappableToAnsi(FileName) then
FileName:=WideExtractShortPathName(FileName);
Isparsed := false;
ParseLyricW(FileName, csUtf8);
ParseLyricW(FileName, csUnicode);
ParseLyricW(FileName, csUnicodeSwapped);
ParseLyricA(FileName);
end;
procedure TLyric.ParseLyricA(const FileName: WideString);
var s: string; TimeEntry: TLyricTimeCodeEntry;
lc, rc, lo, ro, offset, mins, secs, ms, len, Lyricindex, sMaxLen, i, j: integer;
First: boolean; a: TStringList; NoTag: boolean;
begin
if IsParsed then exit;
a := TStringList.Create;
a.LoadFromFile(FileName);
if a.Count < 1 then begin a.Free; exit; end;
Lyricindex := 0; offset := 0; len := -1; sMaxLen := 0; First := true;
for j := 0 to a.Count - 1 do begin
s := Trim(a[j]);
if length(s) < 6 then continue;
NoTag := true;
repeat
lc := pos('[', s); rc := pos(']', s);
if (lc < 1) or (rc < lc + 2) then break;
lo := pos(':', s);
if (lo>0) and (lo<lc) then break;
if lo>rc then lo:=0;
if Lyricindex = 0 then begin
ro := pos('offset', LowerCase(s));
if ro > lc then begin
if lo > ro then offset := StrToIntDef(StringReplace(copy(s, lo + 1, rc - lo - 1), #32, '', [rfReplaceAll]), 0);
break;
end;
end;
ro := pos('.', s);
if (ro > lc) and (ro < lo) then break;
if ro>rc then ro:=0;
if lo>0 then mins := StrToIntDef(StringReplace(copy(s, lc + 1, lo - lc - 1), #32, '', [rfReplaceAll]), -1)
else mins:=0;
if (mins < 0) or (mins > 59) then break;
ms := offset;
if ro > lc then begin
if lo>lc then secs := StrToIntDef(StringReplace(copy(s, lo + 1, ro - lo - 1), #32, '', [rfReplaceAll]), -1)
else secs := StrToIntDef(StringReplace(copy(s, lc + 1, ro - lc - 1), #32, '', [rfReplaceAll]), -1);
ms := ms + StrToIntDef(StringReplace(copy(s, ro + 1, rc -ro -1), #32, '', [rfReplaceAll]), 0) * 10;
end
else begin
if lo>lc then secs := StrToIntDef(StringReplace(copy(s, lo + 1, rc - lo - 1), #32, '', [rfReplaceAll]), -1)
else secs := StrToIntDef(StringReplace(copy(s, lc + 1, rc - lc - 1), #32, '', [rfReplaceAll]), -1);
end;
if (secs < 0) or (secs > 59) then break;
ms := ms + (mins * 60 + secs) * 1000;
if ms < 0 then break;
if First then begin
First := false; ClearLyric;
LyricStringsA := TStringList.Create;
end;
NoTag := false;
TimeEntry.timecode := ms div 100;
TimeEntry.LyricEntry := Lyricindex;
len := length(LyricTime);
SetLength(LyricTime, len + 1);
LyricTime[len] := TimeEntry;
s := copy(s, rc + 1, length(s));
until false;
if NoTag or (LyricStringsA = nil) then continue;
s := Trim(s);
LyricStringsA.Add(s);
i := WideCanvasTextWidth(BitMap.Canvas, s);
if i > sMaxLen then begin
sMaxLen := i; MaxLenLyric := Lyricindex;
end;
inc(Lyricindex);
end;
a.Free;
if len = -1 then exit;
LyricCount := len;
SortLyric; TY:=0;
if PlaylistForm.CPA.Visible then begin
LoadCLibrary;
if IsCLoaded <> 0 then begin
setLength(s,129);
GuessStrChardet(LyricStringsA.GetText,PChar(s));
i:= Pos(' ',s);
if i<>0 then begin
CP:=StrToIntDef(Copy(s,i,MaxInt),CP); PlaylistForm.CPA.Tag:=CP;
s:=Copy(s,0,i-1);
i:= Pos('(', PlaylistForm.CPA.Caption);
if i>1 then
PlaylistForm.CPA.Caption := Copy(PlaylistForm.CPA.Caption, 1, i-2) + ' ('+ s +')'
else PlaylistForm.CPA.Caption :=PlaylistForm.CPA.Caption + ' ('+ s +')';
PlaylistForm.TntCPClick(PlaylistForm.CPA);
end;
end;
end;
HaveLyric := 2; LyricURL := FileName; IsParsed := true;
if dlod then begin
GDILyric.SetFont(BitMap.Canvas.Font.Name);
LyricShowForm.Show;
end;
with PlaylistForm do begin
UpdatePW := True;
if Visible then TMLyricPaint(nil)
else if not dlod then begin
TntPageControl1.TabIndex := 1;
Show;
end;
end;
end;
procedure TLyric.ParseLyricW(const FileName: WideString; mode: TTntStreamCharSet);
var s: WideString; TimeEntry: TLyricTimeCodeEntry;
lc, rc, lo, ro, offset, mins, secs, ms, len, Lyricindex, sMaxLen, i, j: integer;