diff --git a/src/Jackett/ConfigurationData.cs b/src/Jackett/ConfigurationData.cs index 060619635..00a9b8801 100644 --- a/src/Jackett/ConfigurationData.cs +++ b/src/Jackett/ConfigurationData.cs @@ -57,7 +57,7 @@ namespace Jackett jObject["value"] = ((BoolItem)item).Value; break; case ItemType.DisplayImage: - string dataUri = "data:image/jpeg;base64," + Convert.ToBase64String(((ImageItem)item).Value); + string dataUri = DataUrl.BytesToDataUrl(((ImageItem)item).Value, "image/jpeg"); jObject["value"] = dataUri; break; } diff --git a/src/Jackett/DataUrl.cs b/src/Jackett/DataUrl.cs new file mode 100644 index 000000000..53022463d --- /dev/null +++ b/src/Jackett/DataUrl.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Jackett +{ + public class DataUrl + { + static Dictionary ImageMimeTypes = new Dictionary{ + { ".jpg", "data:image/jpeg" }, + { ".jpeg", "data:image/jpeg" }, + { ".png", "data:image/png" }, + { ".gif", "data:image/gif" } + }; + + public static string ReadFileToDataUrl(string file) + { + string mime = ImageMimeTypes[Path.GetExtension(file)]; + return "data:" + mime + ";base64," + Convert.ToBase64String(File.ReadAllBytes(file)); + } + + public static string BytesToDataUrl(byte[] bytes, string mimeType = "image/jpg") + { + return "data:" + mimeType + ";base64," + Convert.ToBase64String(bytes); + } + } +} diff --git a/src/Jackett/IndexerInterface.cs b/src/Jackett/IndexerInterface.cs index 288a10fad..2ee106302 100644 --- a/src/Jackett/IndexerInterface.cs +++ b/src/Jackett/IndexerInterface.cs @@ -4,11 +4,17 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Web.UI.WebControls; namespace Jackett { public interface IndexerInterface { + string DisplayName { get; } + string DisplayDescription { get; } + Uri SitLink { get; } + + // Retrieved for starting setup for the indexer via web API Task GetConfigurationForSetup(); diff --git a/src/Jackett/IndexerManager.cs b/src/Jackett/IndexerManager.cs index 5b253db9c..3928c686f 100644 --- a/src/Jackett/IndexerManager.cs +++ b/src/Jackett/IndexerManager.cs @@ -13,58 +13,40 @@ namespace Jackett static string AppConfigDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); static string IndexerConfigDirectory = Path.Combine(AppConfigDirectory, "Indexers"); - - enum IndexerName - { - BitMeTV, - Freshon, - IPTorrents, - BaconBits, - } - Dictionary loadedIndexers; + Dictionary implementedIndexerTypes; + public IndexerManager() { loadedIndexers = new Dictionary(); + + implementedIndexerTypes = (AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(s => s.GetTypes()) + .Where(p => typeof(IndexerInterface).IsAssignableFrom(p))) + .ToDictionary(t => t.Name.ToLower()); + + + // TODO: initialize all indexers at start, read all saved config json files then fill their indexers } IndexerInterface LoadIndexer(string name) { - IndexerInterface newIndexer; + name = name.Trim().ToLower(); - IndexerName indexerName; + Type indexerType; + if (!implementedIndexerTypes.TryGetValue(name, out indexerType)) + throw new Exception(string.Format("No indexer of type '{0}'", name)); - try - { - indexerName = (IndexerName)Enum.Parse(typeof(IndexerName), name, true); - } - catch (Exception) - { - throw new ArgumentException(string.Format("Unsupported indexer '{0}'", name)); - } + IndexerInterface newIndexer = (IndexerInterface)Activator.CreateInstance(indexerType); - switch (indexerName) - { - case IndexerName.BitMeTV: - newIndexer = new BitMeTV(); - break; - case IndexerName.Freshon: - newIndexer = new Freshon(); - break; - default: - throw new ArgumentException(string.Format("Unsupported indexer '{0}'", name)); - } - - - var configFilePath = Path.Combine(IndexerConfigDirectory, indexerName.ToString().ToLower()); + var configFilePath = Path.Combine(IndexerConfigDirectory, name.ToString().ToLower()); if (File.Exists(configFilePath)) { string jsonString = File.ReadAllText(configFilePath); newIndexer.LoadFromSavedConfiguration(jsonString); } - //newIndexer.VerifyConnection(); loadedIndexers.Add(name, newIndexer); return newIndexer; } diff --git a/src/Jackett/Indexers/BitMeTV.cs b/src/Jackett/Indexers/BitMeTV.cs index 6ff8f4465..a66fd0e9e 100644 --- a/src/Jackett/Indexers/BitMeTV.cs +++ b/src/Jackett/Indexers/BitMeTV.cs @@ -58,8 +58,11 @@ namespace Jackett client = new HttpClient(handler); } - public bool IsConfigured { get; private set; } + public string DisplayName { get { return "BitMeTV.org"; } } + public string DisplayDescription { get { return "TV Episode specialty tracker"; } } + public Uri SitLink { get { return new Uri("https://bitmetv.org"); } } + public bool IsConfigured { get; private set; } public Task GetConfigurationForSetup() { diff --git a/src/Jackett/Indexers/Freshon.cs b/src/Jackett/Indexers/Freshon.cs index 93ade0605..913d31046 100644 --- a/src/Jackett/Indexers/Freshon.cs +++ b/src/Jackett/Indexers/Freshon.cs @@ -4,12 +4,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Web.UI.WebControls; namespace Jackett { public class Freshon : IndexerInterface { + public string DisplayName { get; private set; } + + public Task GetConfigurationForSetup() { throw new NotImplementedException(); @@ -36,5 +40,16 @@ namespace Jackett { throw new NotImplementedException(); } + + + public string DisplayDescription + { + get { throw new NotImplementedException(); } + } + + public Uri SitLink + { + get { throw new NotImplementedException(); } + } } } diff --git a/src/Jackett/Jackett.csproj b/src/Jackett/Jackett.csproj index 80769f846..71cfcd85d 100644 --- a/src/Jackett/Jackett.csproj +++ b/src/Jackett/Jackett.csproj @@ -68,6 +68,7 @@ + @@ -99,16 +100,19 @@ - + Always - + Always - + Always - + + Always + + Always diff --git a/src/Jackett/Server.cs b/src/Jackett/Server.cs index 75a241c73..42e41cc42 100644 --- a/src/Jackett/Server.cs +++ b/src/Jackett/Server.cs @@ -15,7 +15,7 @@ namespace Jackett HttpListener listener; IndexerManager indexerManager; - static string[] StaticFiles = Directory.EnumerateFiles("HtmlContent", "*", SearchOption.AllDirectories).Select(Path.GetFileName).ToArray(); + static string[] StaticFiles = Directory.EnumerateFiles("WebContent", "*", SearchOption.AllDirectories).Select(Path.GetFileName).ToArray(); enum WebApiMethod { @@ -59,7 +59,7 @@ namespace Jackett async void ServeStaticFile(HttpListenerContext context, string file) { - var contentFile = File.ReadAllBytes(Path.Combine("HtmlContent", file)); + var contentFile = File.ReadAllBytes(Path.Combine("WebContent", file)); string contentType; MimeMapping.TryGetValue(Path.GetExtension(file), out contentType); diff --git a/src/Jackett/WebContent/IndexerImages/bitmetv.jpg b/src/Jackett/WebContent/IndexerImages/bitmetv.jpg new file mode 100644 index 000000000..d88202b02 Binary files /dev/null and b/src/Jackett/WebContent/IndexerImages/bitmetv.jpg differ diff --git a/src/Jackett/HtmlContent/common.js b/src/Jackett/WebContent/common.js similarity index 100% rename from src/Jackett/HtmlContent/common.js rename to src/Jackett/WebContent/common.js diff --git a/src/Jackett/HtmlContent/index.html b/src/Jackett/WebContent/index.html similarity index 100% rename from src/Jackett/HtmlContent/index.html rename to src/Jackett/WebContent/index.html diff --git a/src/Jackett/HtmlContent/jquery-2.1.3.min.js b/src/Jackett/WebContent/jquery-2.1.3.min.js similarity index 100% rename from src/Jackett/HtmlContent/jquery-2.1.3.min.js rename to src/Jackett/WebContent/jquery-2.1.3.min.js diff --git a/src/Jackett/HtmlContent/setup_indexer.html b/src/Jackett/WebContent/setup_indexer.html similarity index 100% rename from src/Jackett/HtmlContent/setup_indexer.html rename to src/Jackett/WebContent/setup_indexer.html