2024-10-24 23:53:21 +02:00
|
|
|
using MediaBrowser.Controller;
|
|
|
|
|
|
|
|
namespace Jellyfin.Plugin.SmartPlaylist {
|
|
|
|
|
|
|
|
public interface ISmartPlaylistFileSystem {
|
2025-01-19 15:30:32 +01:00
|
|
|
public string PlaylistStoragePath { get; }
|
|
|
|
public string CollectionStoragePath { get; }
|
|
|
|
|
|
|
|
public string GetSmartPlaylistFilePath(string id);
|
|
|
|
public string FindSmartPlaylistFilePath(string id);
|
2024-10-24 23:53:21 +02:00
|
|
|
public string[] FindAllSmartPlaylistFilePaths();
|
2025-01-19 15:30:32 +01:00
|
|
|
|
|
|
|
public string GetSmartCollectionFilePath(string id);
|
|
|
|
public string FindSmartCollectionFilePath(string id);
|
|
|
|
public string[] FindAllSmartCollectionFilePaths();
|
2024-10-24 23:53:21 +02:00
|
|
|
}
|
|
|
|
|
2025-01-19 15:30:32 +01:00
|
|
|
public class SmartFileSystem : ISmartPlaylistFileSystem {
|
|
|
|
public SmartFileSystem(IServerApplicationPaths serverApplicationPaths) {
|
|
|
|
PlaylistStoragePath = Path.Combine(serverApplicationPaths.DataPath, "smartplaylists");
|
|
|
|
CollectionStoragePath = Path.Combine(serverApplicationPaths.DataPath, "smartcollections");
|
|
|
|
if (!Directory.Exists(PlaylistStoragePath)) { Directory.CreateDirectory(PlaylistStoragePath); }
|
|
|
|
if (!Directory.Exists(CollectionStoragePath)) { Directory.CreateDirectory(CollectionStoragePath); }
|
2024-10-24 23:53:21 +02:00
|
|
|
}
|
2025-01-19 15:30:32 +01:00
|
|
|
public string PlaylistStoragePath { get; }
|
|
|
|
public string CollectionStoragePath { get; }
|
|
|
|
public string GetSmartPlaylistFilePath(string id) {
|
|
|
|
return Path.Combine(PlaylistStoragePath, $"{id}.yaml");
|
2024-10-24 23:53:21 +02:00
|
|
|
}
|
2025-01-19 15:30:32 +01:00
|
|
|
public string FindSmartPlaylistFilePath(string id) {
|
|
|
|
return Directory.GetFiles(PlaylistStoragePath, $"{id}.yaml", SearchOption.AllDirectories).Concat(
|
|
|
|
Directory.GetFiles(PlaylistStoragePath, $"{id}.yml", SearchOption.AllDirectories)
|
2024-10-28 00:26:42 +01:00
|
|
|
).Concat(
|
2025-01-19 15:30:32 +01:00
|
|
|
Directory.GetFiles(PlaylistStoragePath, $"{id}.json", SearchOption.AllDirectories)
|
2024-10-28 00:26:42 +01:00
|
|
|
).First();
|
2024-10-24 23:53:21 +02:00
|
|
|
}
|
|
|
|
public string[] FindAllSmartPlaylistFilePaths() {
|
2025-01-19 15:30:32 +01:00
|
|
|
return Directory.GetFiles(PlaylistStoragePath, "*.yaml", SearchOption.AllDirectories).Concat(
|
|
|
|
Directory.GetFiles(PlaylistStoragePath, "*.yml", SearchOption.AllDirectories)
|
|
|
|
).Concat(
|
|
|
|
Directory.GetFiles(PlaylistStoragePath, "*.json", SearchOption.AllDirectories)
|
|
|
|
).ToArray();
|
|
|
|
}
|
|
|
|
public string GetSmartCollectionFilePath(string id) {
|
|
|
|
return Path.Combine(CollectionStoragePath, $"{id}.yaml");
|
|
|
|
}
|
|
|
|
public string FindSmartCollectionFilePath(string id) {
|
|
|
|
return Directory.GetFiles(CollectionStoragePath, $"{id}.yaml", SearchOption.AllDirectories).Concat(
|
|
|
|
Directory.GetFiles(CollectionStoragePath, $"{id}.yml", SearchOption.AllDirectories)
|
2024-10-28 00:26:42 +01:00
|
|
|
).Concat(
|
2025-01-19 15:30:32 +01:00
|
|
|
Directory.GetFiles(CollectionStoragePath, $"{id}.json", SearchOption.AllDirectories)
|
|
|
|
).First();
|
|
|
|
}
|
|
|
|
public string[] FindAllSmartCollectionFilePaths() {
|
|
|
|
return Directory.GetFiles(CollectionStoragePath, "*.yaml", SearchOption.AllDirectories).Concat(
|
|
|
|
Directory.GetFiles(CollectionStoragePath, "*.yml", SearchOption.AllDirectories)
|
|
|
|
).Concat(
|
|
|
|
Directory.GetFiles(CollectionStoragePath, "*.json", SearchOption.AllDirectories)
|
2024-10-28 00:26:42 +01:00
|
|
|
).ToArray();
|
2024-10-24 23:53:21 +02:00
|
|
|
}
|
2025-01-19 15:30:32 +01:00
|
|
|
|
2024-10-24 23:53:21 +02:00
|
|
|
}
|
|
|
|
}
|