Merge branch 'yaml'
This commit is contained in:
commit
4e5cb8e64e
3 changed files with 19 additions and 9 deletions
|
@ -16,13 +16,21 @@ namespace Jellyfin.Plugin.SmartPlaylist {
|
||||||
}
|
}
|
||||||
public string StoragePath { get; }
|
public string StoragePath { get; }
|
||||||
public string GetSmartPlaylistFilePath(SmartPlaylistId smartPlaylistId) {
|
public string GetSmartPlaylistFilePath(SmartPlaylistId smartPlaylistId) {
|
||||||
return Path.Combine(StoragePath, $"{smartPlaylistId}.json");
|
return Path.Combine(StoragePath, $"{smartPlaylistId}.yaml");
|
||||||
}
|
}
|
||||||
public string FindSmartPlaylistFilePath(SmartPlaylistId smartPlaylistId) {
|
public string FindSmartPlaylistFilePath(SmartPlaylistId smartPlaylistId) {
|
||||||
return Directory.GetFiles(StoragePath, $"{smartPlaylistId}.json", SearchOption.AllDirectories).First();
|
return Directory.GetFiles(StoragePath, $"{smartPlaylistId}.yaml", SearchOption.AllDirectories).Concat(
|
||||||
|
Directory.GetFiles(StoragePath, $"{smartPlaylistId}.yml", SearchOption.AllDirectories)
|
||||||
|
).Concat(
|
||||||
|
Directory.GetFiles(StoragePath, $"{smartPlaylistId}.json", SearchOption.AllDirectories)
|
||||||
|
).First();
|
||||||
}
|
}
|
||||||
public string[] FindAllSmartPlaylistFilePaths() {
|
public string[] FindAllSmartPlaylistFilePaths() {
|
||||||
return Directory.GetFiles(StoragePath, "*.json", SearchOption.AllDirectories);
|
return Directory.GetFiles(StoragePath, "*.yaml", SearchOption.AllDirectories).Concat(
|
||||||
|
Directory.GetFiles(StoragePath, "*.yml", SearchOption.AllDirectories)
|
||||||
|
).Concat(
|
||||||
|
Directory.GetFiles(StoragePath, "*.json", SearchOption.AllDirectories)
|
||||||
|
).ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using System.Text.Json;
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.SmartPlaylist {
|
namespace Jellyfin.Plugin.SmartPlaylist {
|
||||||
public interface IStore {
|
public interface IStore {
|
||||||
|
@ -14,9 +14,10 @@ namespace Jellyfin.Plugin.SmartPlaylist {
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
private async Task<SmartPlaylistDto> LoadPlaylistAsync(string filename) {
|
private async Task<SmartPlaylistDto> LoadPlaylistAsync(string filename) {
|
||||||
await using var r = File.OpenRead(filename);
|
var r = File.ReadAllText(filename);
|
||||||
var dto = (await JsonSerializer.DeserializeAsync<SmartPlaylistDto>(r).ConfigureAwait(false));
|
var dto = new DeserializerBuilder().Build().Deserialize<SmartPlaylistDto>(r);
|
||||||
if (dto == null) {
|
if (dto == null)
|
||||||
|
{
|
||||||
throw new ApplicationException("");
|
throw new ApplicationException("");
|
||||||
}
|
}
|
||||||
if (dto.Id == Path.GetFileNameWithoutExtension(filename)) {
|
if (dto.Id == Path.GetFileNameWithoutExtension(filename)) {
|
||||||
|
@ -38,8 +39,8 @@ namespace Jellyfin.Plugin.SmartPlaylist {
|
||||||
}
|
}
|
||||||
public async Task SaveSmartPlaylistAsync(SmartPlaylistDto smartPlaylist) {
|
public async Task SaveSmartPlaylistAsync(SmartPlaylistDto smartPlaylist) {
|
||||||
string filename = _fileSystem.GetSmartPlaylistFilePath(smartPlaylist.Id);
|
string filename = _fileSystem.GetSmartPlaylistFilePath(smartPlaylist.Id);
|
||||||
await using var w = File.Create(filename);
|
var text = new SerializerBuilder().Build().Serialize(smartPlaylist);
|
||||||
await JsonSerializer.SerializeAsync(w, smartPlaylist).ConfigureAwait(false);
|
File.WriteAllText(filename, text);
|
||||||
}
|
}
|
||||||
private void DeleteSmartPlaylistById(SmartPlaylistId smartPlaylistId) {
|
private void DeleteSmartPlaylistById(SmartPlaylistId smartPlaylistId) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Jellyfin.Controller" Version="10.10.0" />
|
<PackageReference Include="Jellyfin.Controller" Version="10.10.0" />
|
||||||
<PackageReference Include="Jellyfin.Model" Version="10.10.0" />
|
<PackageReference Include="Jellyfin.Model" Version="10.10.0" />
|
||||||
|
<PackageReference Include="YamlDotNet" Version="16.1.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Reference in a new issue