mirror of
https://github.com/ZetaKebab/MpcNET.git
synced 2025-07-01 08:47:36 +00:00
Response from MPD will be specific type. MpdDirectory and MpdFile created. Metadata for MpdFile still to be done.
This commit is contained in:
70
LibMpc/Types/MpdDirectory.cs
Normal file
70
LibMpc/Types/MpdDirectory.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace LibMpc.Types
|
||||
{
|
||||
public class MpdDirectory
|
||||
{
|
||||
private readonly IList<MpdFile> _files = new List<MpdFile>();
|
||||
private readonly IList<MpdDirectory> _subDirectories = new List<MpdDirectory>();
|
||||
|
||||
public MpdDirectory(string path)
|
||||
{
|
||||
path.CheckNotNull();
|
||||
|
||||
Path = path;
|
||||
|
||||
var name = path.Split('/').Last();
|
||||
Name = string.IsNullOrEmpty(name) ? "root" : name;
|
||||
}
|
||||
|
||||
public string Path { get; }
|
||||
public string Name { get; }
|
||||
public IEnumerable<MpdFile> Files => _files;
|
||||
public IEnumerable<MpdDirectory> SubDirectories => _subDirectories;
|
||||
|
||||
internal void AddFile(string file)
|
||||
{
|
||||
var filePath = file.Split('/');
|
||||
var name = filePath[filePath.Length - 1];
|
||||
|
||||
if (filePath.Length == 1)
|
||||
{
|
||||
_files.Add(new MpdFile(name));
|
||||
}
|
||||
else
|
||||
{
|
||||
var filePathWithoutCurrentDirectory = string.Join("/", filePath.Skip(1));
|
||||
foreach (var subDirectory in _subDirectories)
|
||||
{
|
||||
if (subDirectory.Path.Equals(filePath[0]))
|
||||
{
|
||||
subDirectory.AddFile(filePathWithoutCurrentDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddDirectory(string directory)
|
||||
{
|
||||
var directoryPath = directory.Split('/');
|
||||
var name = directoryPath[directoryPath.Length - 1];
|
||||
|
||||
if (directoryPath.Length == 1)
|
||||
{
|
||||
_subDirectories.Add(new MpdDirectory(name));
|
||||
}
|
||||
else
|
||||
{
|
||||
var directoryPathWithoutCurrentDirectory = string.Join("/", directoryPath.Skip(1));
|
||||
foreach (var subDirectory in _subDirectories)
|
||||
{
|
||||
if (subDirectory.Path.Equals(directoryPath[0]))
|
||||
{
|
||||
subDirectory.AddDirectory(directoryPathWithoutCurrentDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
73
LibMpc/Types/MpdFile.cs
Normal file
73
LibMpc/Types/MpdFile.cs
Normal file
@ -0,0 +1,73 @@
|
||||
namespace LibMpc.Types
|
||||
{
|
||||
public class MpdFileBuidler
|
||||
{
|
||||
private const string TagFile = "file";
|
||||
private const string TagTime = "Time";
|
||||
private const string TagArtist = "Artist";
|
||||
private const string TagAlbum = "Album";
|
||||
private const string TagTitle = "Title";
|
||||
private const string TagTrack = "Track";
|
||||
private const string TagName = "Name";
|
||||
private const string TagGenre = "Genre";
|
||||
private const string TagDate = "Date";
|
||||
private const string TagComposer = "Composer";
|
||||
private const string TagPerformer = "Performer";
|
||||
private const string TagComment = "Comment";
|
||||
private const string TagDisc = "Disc";
|
||||
private const string TagPos = "Pos";
|
||||
private const string TagId = "Id";
|
||||
|
||||
private MpdFile _mpdFile;
|
||||
|
||||
public bool IsInitialized => _mpdFile != null;
|
||||
|
||||
public MpdFileBuidler Init(string file)
|
||||
{
|
||||
_mpdFile = new MpdFile(file);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MpdFileBuidler WithProperty(string tag, string value)
|
||||
{
|
||||
_mpdFile.CheckNotNull();
|
||||
|
||||
// TODO: Parse tag
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MpdFile Build()
|
||||
{
|
||||
return _mpdFile;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The MpdFile class contains all meta data for a file of the MPD.
|
||||
/// </summary>
|
||||
public class MpdFile
|
||||
{
|
||||
public MpdFile(string file)
|
||||
{
|
||||
File = file;
|
||||
}
|
||||
|
||||
public string File { get; }
|
||||
public int Time { get; internal set; } = -1;
|
||||
public string Album { get; internal set; } = string.Empty;
|
||||
public string Artist { get; internal set; } = string.Empty;
|
||||
public string Title { get; internal set; } = string.Empty;
|
||||
public string Track { get; internal set; } = string.Empty;
|
||||
public string Name { get; internal set; } = string.Empty;
|
||||
public string Genre { get; internal set; } = string.Empty;
|
||||
public string Date { get; internal set; } = string.Empty;
|
||||
public string Composer { get; internal set; } = string.Empty;
|
||||
public string Performer { get; internal set; } = string.Empty;
|
||||
public string Comment { get; internal set; } = string.Empty;
|
||||
public int Disc { get; internal set; } = -1;
|
||||
public int Pos { get; internal set; } = -1;
|
||||
public int Id { get; internal set; } = -1;
|
||||
}
|
||||
}
|
21
LibMpc/Types/MpdOutput.cs
Normal file
21
LibMpc/Types/MpdOutput.cs
Normal file
@ -0,0 +1,21 @@
|
||||
namespace LibMpc.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// The MpdOutput class contains all attributes of an output device of the MPD.
|
||||
/// </summary>
|
||||
public class MpdOutput
|
||||
{
|
||||
public MpdOutput(int id, string name, bool enabled)
|
||||
{
|
||||
name.CheckNotNull();
|
||||
|
||||
Id = id;
|
||||
Name = name;
|
||||
IsEnabled = enabled;
|
||||
}
|
||||
|
||||
public int Id { get; }
|
||||
public string Name { get; }
|
||||
public bool IsEnabled { get; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user