-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
29 lines (26 loc) · 1022 Bytes
/
Program.cs
File metadata and controls
29 lines (26 loc) · 1022 Bytes
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
using Fringilla.Media;
WMPLib.WindowsMediaPlayer? player = null;
string path = (args.Length > 0 ? args[0] : Environment.CurrentDirectory).ExcludeTrailingPathDelimiter();
if (!Directory.Exists(path))
throw new DirectoryNotFoundException(path);
Playlist playlist = Playlist.CreateFromDirectory(path, GetExtendedInfo);
if (playlist.Count > 0)
{
playlist.WriteToM3uFile(Path.Combine(path, "playlist.m3u"));
playlist.WriteToPlsFile(Path.Combine(path, "playlist.pls"));
playlist.WriteToPlainTextFile(Path.Combine(path, "playlist.txt"));
}
else
{
File.Delete(Path.Combine(path, "playlist.m3u"));
File.Delete(Path.Combine(path, "playlist.pls"));
File.Delete(Path.Combine(path, "playlist.txt"));
}
ExtendedInfo GetExtendedInfo(string path)
{
WMPLib.IWMPMedia clip = (player ??= new()).newMedia(path);
int duration = clip.GetDuration();
string title = clip.GetTitle(() => Path.ChangeExtension(Path.GetFileName(path), null));
player.close();
return new(duration, title, path);
}