-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPlugin.cs
144 lines (129 loc) · 4.36 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using subbuzz.Configuration;
using subbuzz.Extensions;
using subbuzz.Helpers;
using System;
using System.Collections.Generic;
using System.IO;
#if EMBY
using MediaBrowser.Model.Drawing;
#endif
namespace subbuzz
{
#if EMBY
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages, IHasThumbImage
{
public const string SERVER = "Emby";
#else
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
{
public const string SERVER = "Jellyfin";
#endif
public const string NAME = "subbuzz";
private readonly IApplicationPaths _appPaths;
private readonly object _cacheSyncLock = new object();
private FileCache? _cache = null;
public override string Name => NAME;
public override string Description => "Download subtitles from various sites";
public override Guid Id => Guid.Parse("5aeab01b-2ef8-45c6-bb6b-16ce9cb268d4");
public static Plugin? Instance { get; private set; } = null;
public FileCache? Cache
{
get {
return GetCache();
}
}
public Plugin(
IApplicationPaths applicationPaths,
IXmlSerializer xmlSerializer)
: base(applicationPaths, xmlSerializer)
{
Instance = this;
_appPaths = applicationPaths;
}
private FileCache? GetCache()
{
lock (_cacheSyncLock)
{
if (_cache != null && _cache.CacheDir == base.Configuration.Cache.BasePath)
return _cache;
if (base.Configuration.Cache.BasePath.IsNotNullOrWhiteSpace())
{
try
{
Directory.CreateDirectory(base.Configuration.Cache.BasePath);
_cache = new FileCache(base.Configuration.Cache.BasePath);
return _cache;
}
catch
{
}
}
try
{
string defaultPath = Path.Combine(_appPaths.CachePath, NAME);
_cache = new FileCache(defaultPath);
base.Configuration.Cache.BasePath = _cache.CacheDir;
base.SaveConfiguration();
return _cache;
}
catch
{
return null;
}
}
}
public override void UpdateConfiguration(BasePluginConfiguration configuration)
{
base.UpdateConfiguration(configuration);
}
#if EMBY
public Stream GetThumbImage()
{
var type = GetType();
return type.Assembly.GetManifestResourceStream(type.Namespace + ".thumb.png");
}
public ImageFormat ThumbImageFormat
{
get
{
return ImageFormat.Png;
}
}
#endif
public IEnumerable<PluginPageInfo> GetPages()
{
return new[]
{
new PluginPageInfo
{
DisplayName = "SubBuzz",
Name = "SubbuzzConfigPage",
EmbeddedResourcePath = GetType().Namespace + $".Configuration.{SERVER}.configPage.html",
EnableInMainMenu = true,
MenuSection = "server",
MenuIcon = "subtitles",
},
new PluginPageInfo
{
Name = "SubbuzzConfigPageJs",
EmbeddedResourcePath = GetType().Namespace + $".Configuration.{SERVER}.configPage.js"
},
new PluginPageInfo
{
Name = "SubbuzzConfigCachePage",
EmbeddedResourcePath = GetType().Namespace + $".Configuration.{SERVER}.configCachePage.html",
MenuIcon = "closed_caption"
},
new PluginPageInfo
{
Name = "SubbuzzConfigCachePageJs",
EmbeddedResourcePath = GetType().Namespace + $".Configuration.{SERVER}.configCachePage.js"
},
};
}
}
}