mirror of https://github.com/Jackett/Jackett
Dynamic indexer type list
This commit is contained in:
parent
2fd026b7d4
commit
7b4e6f97d5
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<string, string> ImageMimeTypes = new Dictionary<string, string>{
|
||||
{ ".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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<ConfigurationData> GetConfigurationForSetup();
|
||||
|
||||
|
|
|
@ -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<string, IndexerInterface> loadedIndexers;
|
||||
|
||||
Dictionary<string, Type> implementedIndexerTypes;
|
||||
|
||||
public IndexerManager()
|
||||
{
|
||||
loadedIndexers = new Dictionary<string, IndexerInterface>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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<ConfigurationData> GetConfigurationForSetup()
|
||||
{
|
||||
|
|
|
@ -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<ConfigurationData> 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(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="ChannelInfo.cs" />
|
||||
<Compile Include="ConfigurationData.cs" />
|
||||
<Compile Include="DataUrl.cs" />
|
||||
<Compile Include="ExceptionWithConfigData.cs" />
|
||||
<Compile Include="IndexerInterface.cs" />
|
||||
<Compile Include="IndexerManager.cs" />
|
||||
|
@ -99,16 +100,19 @@
|
|||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="HtmlContent\common.js">
|
||||
<Content Include="WebContent\common.js">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="HtmlContent\index.html">
|
||||
<Content Include="WebContent\index.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="HtmlContent\jquery-2.1.3.min.js">
|
||||
<Content Include="WebContent\jquery-2.1.3.min.js">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="HtmlContent\setup_indexer.html">
|
||||
<Content Include="WebContent\setup_indexer.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="WebContent\IndexerImages\bitmetv.jpg">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Resources\validator_reply.xml" />
|
||||
|
|
|
@ -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);
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
Loading…
Reference in New Issue