2024-10-24 23:53:21 +02:00
|
|
|
using MediaBrowser.Controller;
|
|
|
|
|
|
|
|
namespace Jellyfin.Plugin.SmartPlaylist {
|
|
|
|
|
|
|
|
public interface ISmartPlaylistFileSystem {
|
|
|
|
public string StoragePath { get; }
|
|
|
|
public string GetSmartPlaylistFilePath(SmartPlaylistId smartPlaylistId);
|
|
|
|
public string FindSmartPlaylistFilePath(SmartPlaylistId smartPlaylistId);
|
|
|
|
public string[] FindAllSmartPlaylistFilePaths();
|
|
|
|
}
|
|
|
|
|
2024-10-25 02:18:13 +02:00
|
|
|
public class SmartPlaylistFileSystem : ISmartPlaylistFileSystem {
|
|
|
|
public SmartPlaylistFileSystem(IServerApplicationPaths serverApplicationPaths) {
|
2024-10-24 23:53:21 +02:00
|
|
|
StoragePath = Path.Combine(serverApplicationPaths.DataPath, "smartplaylists");
|
|
|
|
if (!Directory.Exists(StoragePath)) { Directory.CreateDirectory(StoragePath); }
|
|
|
|
}
|
|
|
|
public string StoragePath { get; }
|
|
|
|
public string GetSmartPlaylistFilePath(SmartPlaylistId smartPlaylistId) {
|
2024-10-28 00:26:42 +01:00
|
|
|
return Path.Combine(StoragePath, $"{smartPlaylistId}.yaml");
|
2024-10-24 23:53:21 +02:00
|
|
|
}
|
|
|
|
public string FindSmartPlaylistFilePath(SmartPlaylistId smartPlaylistId) {
|
2024-10-28 00:26:42 +01:00
|
|
|
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();
|
2024-10-24 23:53:21 +02:00
|
|
|
}
|
|
|
|
public string[] FindAllSmartPlaylistFilePaths() {
|
2024-10-28 00:26:42 +01:00
|
|
|
return Directory.GetFiles(StoragePath, "*.yaml", SearchOption.AllDirectories).Concat(
|
|
|
|
Directory.GetFiles(StoragePath, "*.yml", SearchOption.AllDirectories)
|
|
|
|
).Concat(
|
|
|
|
Directory.GetFiles(StoragePath, "*.json", SearchOption.AllDirectories)
|
|
|
|
).ToArray();
|
2024-10-24 23:53:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|