mirror of
https://github.com/ZetaKebab/MpcNET.git
synced 2025-07-01 16:47:37 +00:00
Test for Find command. MpdDirectory and MpdFile few changes.
This commit is contained in:
@ -6,7 +6,6 @@ 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)
|
||||
{
|
||||
@ -21,50 +20,10 @@ namespace LibMpc.Types
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
_files.Add(new MpdFile(file));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,14 @@
|
||||
namespace LibMpc.Types
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LibMpc.Types
|
||||
{
|
||||
public class MpdFileBuidler
|
||||
/// <summary>
|
||||
/// The MpdFile class contains all meta data for a file of the MPD.
|
||||
/// </summary>
|
||||
public class MpdFile
|
||||
{
|
||||
private const string TagFile = "file";
|
||||
public static readonly MpdFile EmptyFile = new MpdFile(string.Empty);
|
||||
|
||||
private const string TagTime = "Time";
|
||||
private const string TagArtist = "Artist";
|
||||
private const string TagAlbum = "Album";
|
||||
@ -18,56 +24,83 @@
|
||||
private const string TagPos = "Pos";
|
||||
private const string TagId = "Id";
|
||||
|
||||
private MpdFile _mpdFile;
|
||||
private readonly IDictionary<string, string> _unknownTags = new Dictionary<string, string>();
|
||||
|
||||
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;
|
||||
IsInitialized = !string.IsNullOrEmpty(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;
|
||||
public int Time { get; private set; } = -1;
|
||||
public string Album { get; private set; } = string.Empty;
|
||||
public string Artist { get; private set; } = string.Empty;
|
||||
public string Title { get; private set; } = string.Empty;
|
||||
public string Track { get; private set; } = string.Empty;
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public string Genre { get; private set; } = string.Empty;
|
||||
public string Date { get; private set; } = string.Empty;
|
||||
public string Composer { get; private set; } = string.Empty;
|
||||
public string Performer { get; private set; } = string.Empty;
|
||||
public string Comment { get; private set; } = string.Empty;
|
||||
public int Disc { get; private set; } = -1;
|
||||
public int Pos { get; private set; } = -1;
|
||||
public int Id { get; private set; } = -1;
|
||||
public IDictionary<string, string> UnknownTags => _unknownTags;
|
||||
|
||||
internal bool IsInitialized { get; }
|
||||
|
||||
internal void AddTag(string tag, string value)
|
||||
{
|
||||
switch (tag)
|
||||
{
|
||||
case TagTime:
|
||||
Time = int.Parse(value);
|
||||
break;
|
||||
case TagArtist:
|
||||
Artist = value;
|
||||
break;
|
||||
case TagAlbum:
|
||||
Album = value;
|
||||
break;
|
||||
case TagTitle:
|
||||
Title = value;
|
||||
break;
|
||||
case TagTrack:
|
||||
Track = value;
|
||||
break;
|
||||
case TagName:
|
||||
Name = value;
|
||||
break;
|
||||
case TagGenre:
|
||||
Genre = value;
|
||||
break;
|
||||
case TagDate:
|
||||
Date = value;
|
||||
break;
|
||||
case TagComposer:
|
||||
Composer = value;
|
||||
break;
|
||||
case TagPerformer:
|
||||
Performer = value;
|
||||
break;
|
||||
case TagComment:
|
||||
Comment = value;
|
||||
break;
|
||||
case TagDisc:
|
||||
Disc = int.Parse(value);
|
||||
break;
|
||||
case TagPos:
|
||||
Pos = int.Parse(value);
|
||||
break;
|
||||
case TagId:
|
||||
Id = int.Parse(value);
|
||||
break;
|
||||
default:
|
||||
_unknownTags.Add(tag, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user