Initial commit

This commit is contained in:
zone117x 2015-04-13 00:25:21 -06:00
parent cdc829cece
commit 2fd026b7d4
25 changed files with 1556 additions and 0 deletions

22
src/Jackett.sln Normal file
View File

@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jackett", "Jackett\Jackett.csproj", "{E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

6
src/Jackett/App.config Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
</startup>
</configuration>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jackett
{
public class ChannelInfo
{
public string Title { get; set; }
public string Description { get; set; }
public Uri Link { get; set; }
public string Language { get; set; }
public string Category { get; set; }
public Uri ImageUrl { get; set; }
public string ImageTitle { get; set; }
public Uri ImageLink { get; set; }
public string ImageDescription { get; set; }
public ChannelInfo()
{
// Set default values
Language = "en-us";
Category = "search";
}
}
}

View File

@ -0,0 +1,94 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jackett
{
public abstract class ConfigurationData
{
public enum ItemType
{
InputString,
InputBool,
DisplayImage,
DisplayInfo,
HiddenData
}
public void LoadValuesFromJson(JToken json)
{
// todo: match up ids with items and fill values
IDictionary<string, JToken> dictionary = (JObject)json;
foreach (var item in GetItems())
{
switch (item.ItemType)
{
case ItemType.InputString:
((StringItem)item).Value = (string)dictionary[item.ID];
break;
case ItemType.InputBool:
((BoolItem)item).Value = (bool)dictionary[item.ID];
break;
}
}
}
public JToken ToJson()
{
var items = GetItems();
var jArray = new JArray();
foreach (var item in items)
{
var jObject = new JObject();
jObject["id"] = item.ID;
jObject["type"] = item.ItemType.ToString().ToLower();
jObject["name"] = item.Name;
switch (item.ItemType)
{
case ItemType.InputString:
case ItemType.HiddenData:
case ItemType.DisplayInfo:
jObject["value"] = ((StringItem)item).Value;
break;
case ItemType.InputBool:
jObject["value"] = ((BoolItem)item).Value;
break;
case ItemType.DisplayImage:
string dataUri = "data:image/jpeg;base64," + Convert.ToBase64String(((ImageItem)item).Value);
jObject["value"] = dataUri;
break;
}
jArray.Add(jObject);
}
return jArray;
}
public class Item
{
public ItemType ItemType { get; set; }
public string Name { get; set; }
public string ID { get { return Name.Replace(" ", "").ToLower(); } }
}
public class StringItem : Item
{
public string Value { get; set; }
}
public class BoolItem : Item
{
public bool Value { get; set; }
}
public class ImageItem : Item
{
public byte[] Value { get; set; }
}
public abstract Item[] GetItems();
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jackett
{
public class ExceptionWithConfigData : Exception
{
public ConfigurationData ConfigData { get; private set; }
public ExceptionWithConfigData(string message, ConfigurationData data)
: base(message)
{
ConfigData = data;
}
}
}

View File

@ -0,0 +1,10 @@
function getUrlParams() {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
home
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,117 @@
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<script src="jquery-2.1.3.min.js"></script>
<script src="common.js"></script>
<style>
#formItemTemplateContainer {
display: none;
}
</style>
<title></title>
</head>
<body>
<script>
$(function () {
var urlParams = getUrlParams();
var jqxhr = $.post("get_config_form", JSON.stringify({ indexer: urlParams.indexer }), function (data) {
populateForm(data);
})
.fail(function () {
alert("error");
});
$("#loginButton").click(function () {
var data = { indexer: urlParams.indexer, config: {} };
$("#formItems").children().each(function (i, item) {
var $item = $(item);
var type = $item.data("type");
var id = $item.data("id");
var $valEl = $item.find(".formItemValue").children().first();
switch (type) {
case "inputstring":
data.config[id] = $valEl.val();
break;
case "inputbool":
data.config[id] = $valEl.val();
break;
}
});
var jqxhr = $.post("configure_indexer", JSON.stringify(data), function (data) {
if (data.result == "error") {
if (data.config) {
populateForm(data.config);
}
alert(data.error);
}
})
.fail(function () {
alert("error");
});
});
});
function populateForm(data) {
$("#formItems").empty();
for (var i = 0; i < data.length; i++) {
$("#formItems").append(createFormItem(data[i]));
}
}
function createFormItem(itemData) {
var $template = $("#formItemTemplate").clone();
$template.attr("id", "item" + itemData.id);
$template.data("id", itemData.id);
$template.data("type", itemData.type);
$template.attr("data-type", itemData.type);
$template.data("value", itemData.value);
$template.find(".formItemName").text(itemData.name);
$valueElement = $template.find(".formItemValue");
switch (itemData.type) {
case "inputstring":
$valueElement.append($("<input type='text'></input>").val(itemData.value));
break;
case "inputbool":
$valueElement.append($("<input type='checkbox'></input>").prop("checked", itemData.value));
break;
case "displayimage":
$valueElement.append($("<img src='" + itemData.value + "'>"));
break;
case "displayinfo":
$valueElement.append($("<span></span>").text(itemData.value));
break;
}
return $template;
}
</script>
<div id="formItems">
</div>
<button id="loginButton">Login</button>
<div id="formItemTemplateContainer">
<div id="formItemTemplate">
<div class="formItemName"></div>
<div class="formItemValue"></div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,30 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jackett
{
public interface IndexerInterface
{
// Retrieved for starting setup for the indexer via web API
Task<ConfigurationData> GetConfigurationForSetup();
// Called when web API wants to apply setup configuration via web API, usually this is where login and storing cookie happens
Task ApplyConfiguration(JToken jsonConfig);
// Called to check if configuration (cookie) is correct and indexer connection works
Task VerifyConnection();
// Invoked when the indexer configuration has been applied and verified so the cookie needs to be saved
event Action<JToken> OnSaveConfigurationRequested;
// Whether this indexer has been configured, verified and saved in the past and has the settings required for functioning
bool IsConfigured { get; }
// Called on startup when initializing indexers from saved configuration
void LoadFromSavedConfiguration(JToken jsonConfig);
}
}

View File

@ -0,0 +1,81 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jackett
{
public class IndexerManager
{
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;
public IndexerManager()
{
loadedIndexers = new Dictionary<string, IndexerInterface>();
}
IndexerInterface LoadIndexer(string name)
{
IndexerInterface newIndexer;
IndexerName indexerName;
try
{
indexerName = (IndexerName)Enum.Parse(typeof(IndexerName), name, true);
}
catch (Exception)
{
throw new ArgumentException(string.Format("Unsupported indexer '{0}'", name));
}
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());
if (File.Exists(configFilePath))
{
string jsonString = File.ReadAllText(configFilePath);
newIndexer.LoadFromSavedConfiguration(jsonString);
}
//newIndexer.VerifyConnection();
loadedIndexers.Add(name, newIndexer);
return newIndexer;
}
public IndexerInterface GetIndexer(string name)
{
IndexerInterface indexer;
if (!loadedIndexers.TryGetValue(name, out indexer))
indexer = LoadIndexer(name);
return indexer;
}
}
}

View File

@ -0,0 +1,132 @@
using CsQuery;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace Jackett
{
public class BitMeTV : IndexerInterface
{
class BmtvConfig : ConfigurationData
{
public StringItem Username { get; private set; }
public StringItem Password { get; private set; }
public ImageItem CaptchaImage { get; private set; }
public StringItem CaptchaText { get; private set; }
public BmtvConfig()
{
Username = new StringItem { Name = "Username", ItemType = ItemType.InputString };
Password = new StringItem { Name = "Password", ItemType = ItemType.InputString };
CaptchaImage = new ImageItem { Name = "Captcha Image", ItemType = ItemType.DisplayImage };
CaptchaText = new StringItem { Name = "Captcha Text", ItemType = ItemType.InputString };
}
public override Item[] GetItems()
{
return new Item[] { Username, Password, CaptchaImage, CaptchaText };
}
}
static string BaseUrl = "http://www.bitmetv.org";
static string LoginUrl = BaseUrl + "/login.php";
static string LoginPost = BaseUrl + "/takelogin.php";
static string CaptchaUrl = BaseUrl + "/visual.php";
static string SearchUrl = BaseUrl + "/browse.php";
CookieContainer cookies;
HttpClientHandler handler;
HttpClient client;
public event Action<JToken> OnSaveConfigurationRequested;
public BitMeTV()
{
IsConfigured = false;
cookies = new CookieContainer();
handler = new HttpClientHandler
{
CookieContainer = cookies,
AllowAutoRedirect = true,
UseCookies = true,
};
client = new HttpClient(handler);
}
public bool IsConfigured { get; private set; }
public Task<ConfigurationData> GetConfigurationForSetup()
{
return Task.Run(async () =>
{
var loginPage = await client.GetAsync(LoginUrl);
var captchaImage = await client.GetByteArrayAsync(CaptchaUrl);
var config = new BmtvConfig();
config.CaptchaImage.Value = captchaImage;
return (ConfigurationData)config;
});
}
public Task ApplyConfiguration(JToken configJson)
{
return Task.Run(async () =>
{
var config = new BmtvConfig();
config.LoadValuesFromJson(configJson["config"]);
var pairs = new Dictionary<string, string>
{
{ "username", config.Username.Value},
{ "password", config.Password.Value},
{ "secimage", config.CaptchaText.Value}
};
var content = new FormUrlEncodedContent(pairs);
var response = await client.PostAsync(LoginPost, content);
var responseContent = await response.Content.ReadAsStringAsync();
if (!responseContent.Contains("/logout.php"))
{
CQ dom = responseContent;
var messageEl = dom["table tr > td.embedded > h2"].Last();
var errorMessage = messageEl.Text();
var captchaImage = await client.GetByteArrayAsync(CaptchaUrl);
config.CaptchaImage.Value = captchaImage;
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config);
}
else
{
var configSaveData = new JObject();
configSaveData["cookies"] = new JArray((
from cookie in cookies.GetCookies(new Uri(BaseUrl)).Cast<Cookie>()
select cookie.Name + ":" + cookie.Value
).ToArray());
if (OnSaveConfigurationRequested != null)
OnSaveConfigurationRequested(configSaveData);
}
});
}
public Task VerifyConnection()
{
return Task.Run(async () =>
{
var result = await client.GetStringAsync(new Uri(SearchUrl));
});
}
public void LoadFromSavedConfiguration(JToken jsonConfig)
{
// todo: set cookie data...
IsConfigured = true;
}
}
}

View File

@ -0,0 +1,40 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jackett
{
public class Freshon : IndexerInterface
{
public Task<ConfigurationData> GetConfigurationForSetup()
{
throw new NotImplementedException();
}
public Task ApplyConfiguration(JToken jsonConfig)
{
throw new NotImplementedException();
}
public Task VerifyConnection()
{
throw new NotImplementedException();
}
public event Action<JToken> OnSaveConfigurationRequested;
public bool IsConfigured
{
get { throw new NotImplementedException(); }
}
public void LoadFromSavedConfiguration(JToken jsonConfig)
{
throw new NotImplementedException();
}
}
}

142
src/Jackett/Jackett.csproj Normal file
View File

@ -0,0 +1,142 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E636D5F8-68B4-4903-B4ED-CCFD9C9E899F}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Jackett</RootNamespace>
<AssemblyName>Jackett</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="CsQuery">
<HintPath>..\packages\CsQuery.1.3.4\lib\net40\CsQuery.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ChannelInfo.cs" />
<Compile Include="ConfigurationData.cs" />
<Compile Include="ExceptionWithConfigData.cs" />
<Compile Include="IndexerInterface.cs" />
<Compile Include="IndexerManager.cs" />
<Compile Include="Indexers\BitMeTV.cs" />
<Compile Include="Indexers\Freshon.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="ReleaseInfo.cs" />
<Compile Include="ResultPage.cs" />
<Compile Include="Server.cs" />
<Compile Include="TorznabQuery.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\test.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="HtmlContent\common.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="HtmlContent\index.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="HtmlContent\jquery-2.1.3.min.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="HtmlContent\setup_indexer.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Resources\validator_reply.xml" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5.1 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

58
src/Jackett/Program.cs Normal file
View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Jackett
{
class Program
{
public static ManualResetEvent ExitEvent = new ManualResetEvent(false);
static IndexerManager indexerManager;
static void Main(string[] args)
{
indexerManager = new IndexerManager();
var resultPage = new ResultPage(new ChannelInfo
{
Title = "HDAccess",
Description = "Jackett for HDAccess",
Link = new Uri("http://hdaccess.net"),
ImageUrl = new Uri("https://hdaccess.net/logo_small.png"),
ImageTitle = "HDAccess",
ImageLink = new Uri("https://hdaccess.net"),
ImageDescription = "Jackett for HDAccess"
});
resultPage.Releases.Add(new ReleaseInfo
{
Title = "Better Call Saul S01E05 Alpine Shepherd 1080p NF WEBRip DD5.1 x264",
Guid = new Uri("https://hdaccess.net/details.php?id=11515"),
Link = new Uri("https://hdaccess.net/download.php?torrent=11515&amp;passkey=123456"),
Comments = new Uri("https://hdaccess.net/details.php?id=11515&amp;hit=1#comments"),
PublishDate = DateTime.Now,
Category = "HDTV 1080p",
Size = 2538463390,
Description = "Better.Call.Saul.S01E05.Alpine.Shepherd.1080p.NF.WEBRip.DD5.1.x264.torrent",
Seeders = 7,
Peers = 6,
InfoHash = "63e07ff523710ca268567dad344ce1e0e6b7e8a3",
MinimumRatio = 1.0,
MinimumSeedTime = 172800
});
var f = resultPage.ToXml(new Uri("http://localhost:9117"));
Task.Run(() =>
{
var server = new Server();
server.Start();
});
ExitEvent.WaitOne();
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Jackett")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Jackett")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5881fb69-3cb2-42b7-a744-2c1e537176bd")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,101 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Jackett.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Jackett.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
///&lt;rss version=&quot;1.0&quot; xmlns:atom=&quot;http://www.w3.org/2005/Atom&quot; xmlns:torznab=&quot;http://torznab.com/schemas/2015/feed&quot;&gt;
/// &lt;channel&gt;
/// &lt;atom:link href=&quot;https://hdaccess.net/api&quot; rel=&quot;self&quot; type=&quot;application/rss+xml&quot; /&gt;
/// &lt;title&gt;HDAccess&lt;/title&gt;
/// &lt;description&gt;HDAccess API&lt;/description&gt;
/// &lt;link&gt;https://hdaccess.net&lt;/link&gt;
/// &lt;language&gt;en-us&lt;/language&gt;
/// &lt;webMaster&gt;($email) (HDA Invites)&lt;/webMaster&gt;
/// &lt;category&gt;search&lt;/category&gt;
/// &lt;image&gt;
/// &lt;url&gt;https://hdac [rest of string was truncated]&quot;;.
/// </summary>
internal static string test {
get {
return ResourceManager.GetString("test", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
///&lt;rss version=&quot;1.0&quot; xmlns:atom=&quot;http://www.w3.org/2005/Atom&quot; xmlns:torznab=&quot;http://torznab.com/schemas/2015/feed&quot;&gt;
/// &lt;channel&gt;
/// &lt;item&gt;
/// &lt;link&gt;https://example.com&lt;/link&gt;
/// &lt;pubDate&gt;Sat, 14 Mar 2015 17:10:42 -0400&lt;/pubDate&gt;
/// &lt;enclosure url=&quot;https://example.com&quot; length=&quot;1&quot; type=&quot;application/x-bittorrent&quot; /&gt;
/// &lt;/item&gt;
/// &lt;/channel&gt;
///&lt;/rss&gt;.
/// </summary>
internal static string validator_reply {
get {
return ResourceManager.GetString("validator_reply", resourceCulture);
}
}
}
}

View File

@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="test" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\test.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="validator_reply" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\validator_reply.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
</root>

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jackett
{
public class ReleaseInfo
{
public string Title { get; set; }
public Uri Guid { get; set; }
public Uri Link { get; set; }
public Uri Comments { get; set; }
public DateTime PublishDate { get; set; }
public string Category { get; set; }
public long? Size { get; set; }
public string Description { get; set; }
public long? RageID { get; set; }
public long? Imdb { get; set; }
public int? Seeders { get; set; }
public int? Peers { get; set; }
public Uri ConverUrl { get; set; }
public Uri BannerUrl { get; set; }
public string InfoHash { get; set; }
public double? MinimumRatio { get; set; }
public long? MinimumSeedTime { get; set; }
}
}

View File

@ -0,0 +1,143 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="1.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:torznab="http://torznab.com/schemas/2015/feed">
<channel>
<atom:link href="https://hdaccess.net/api" rel="self" type="application/rss+xml" />
<title>HDAccess</title>
<description>HDAccess API</description>
<link>https://hdaccess.net</link>
<language>en-us</language>
<webMaster>($email) (HDA Invites)</webMaster>
<category>search</category>
<image>
<url>https://hdaccess.net/logo_small.png</url>
<title>HDAccess</title>
<link>https://hdaccess.net</link>
<description>HDAccess API</description>
</image>
<item>
<title>Better Call Saul S01E05 Alpine Shepherd 1080p NF WEBRip DD5.1 x264</title>
<guid isPermaLink="true">https://hdaccess.net/details.php?id=11515</guid>
<link>https://hdaccess.net/download.php?torrent=11515&amp;passkey=123456</link>
<comments>https://hdaccess.net/details.php?id=11515&amp;hit=1#comments</comments>
<pubDate>Sat, 14 Mar 2015 17:10:42 -0400</pubDate>
<category>HDTV 1080p</category>
<size>2538463390</size>
<description>Better.Call.Saul.S01E05.Alpine.Shepherd.1080p.NF.WEBRip.DD5.1.x264.torrent</description>
<enclosure url="https://hdaccess.net/download.php?torrent=11515&amp;passkey=123456" length="2538463390" type="application/x-bittorrent" />
<torznab:attr name="rageid" value="37780" />
<torznab:attr name="imdb" value="3032476" />
<torznab:attr name="tvdbid" value="273181" />
<torznab:attr name="category" value="5000" />
<torznab:attr name="category" value="5040" />
<torznab:attr name="category" value="100009" />
<torznab:attr name="category" value="100036" />
<torznab:attr name="type" value="series" />
<torznab:attr name="seeders" value="7" />
<torznab:attr name="peers" value="7" />
<torznab:attr name="coverurl" value="https://hdaccess.net/images/posters/273181.jpg" />
<torznab:attr name="bannerurl" value="https://hdaccess.net/images/banners/273181.jpg" />
<torznab:attr name="infohash" value="63e07ff523710ca268567dad344ce1e0e6b7e8a3" />
<torznab:attr name="minimumratio" value="1.0" />
<torznab:attr name="minimumseedtime" value="172800" />
</item>
<item>
<title>Ocean Giants 2013 1080p 3D BluRay Remux MVC DTS-HD MA 5.1-HDAccess</title>
<guid isPermaLink="true">https://hdaccess.net/details.php?id=11511</guid>
<link>https://hdaccess.net/download.php?torrent=11511&amp;passkey=123456</link>
<comments>https://hdaccess.net/details.php?id=11511&amp;hit=1#comments</comments>
<pubDate>Sat, 14 Mar 2015 16:33:42 -0400</pubDate>
<category>CUSTOM 3D BD</category>
<size>15330508800</size>
<description>Ocean Giants 2013 1080p 3D BluRay Remux MVC DTS-HD MA 5.1-HDAccess.torrent</description>
<enclosure url="https://hdaccess.net/download.php?torrent=11511&amp;passkey=123456" length="15330508800" type="application/x-bittorrent" />
<torznab:attr name="category" value="2000" />
<torznab:attr name="category" value="2060" />
<torznab:attr name="category" value="100001" />
<torznab:attr name="category" value="100018" />
<torznab:attr name="type" value="movie" />
<torznab:attr name="seeders" value="41" />
<torznab:attr name="peers" value="41" />
<torznab:attr name="coverurl" value="http://s5.postimg.org/gl7z658on/screenshot_1008.png" />
<torznab:attr name="infohash" value="ec039a525a6feac4b15889323f4f443de381e7cc" />
<torznab:attr name="minimumratio" value="1.0" />
<torznab:attr name="minimumseedtime" value="172800" />
</item>
<item>
<title>Wild 2014 720p BluRay DTS x264-HDAccess</title>
<guid isPermaLink="true">https://hdaccess.net/details.php?id=11506</guid>
<link>https://hdaccess.net/download.php?torrent=11506&amp;passkey=123456</link>
<comments>https://hdaccess.net/details.php?id=11506&amp;hit=1#comments</comments>
<pubDate>Sat, 14 Mar 2015 14:28:43 -0400</pubDate>
<category>720p</category>
<size>6501510357</size>
<description>Wild.2014.720p.BluRay.DTS.x264-HDAccess.torrent</description>
<enclosure url="https://hdaccess.net/download.php?torrent=11506&amp;passkey=123456" length="6501510357" type="application/x-bittorrent" />
<torznab:attr name="imdb" value="2305051" />
<torznab:attr name="category" value="2000" />
<torznab:attr name="category" value="2060" />
<torznab:attr name="category" value="100002" />
<torznab:attr name="category" value="100022" />
<torznab:attr name="type" value="movie" />
<torznab:attr name="seeders" value="57" />
<torznab:attr name="peers" value="58" />
<torznab:attr name="coverurl" value="https://hdaccess.net/imdb/images/2305051.jpg" />
<torznab:attr name="infohash" value="6704c29a00304f01b7dbb7959bfea5ccefe7d7d5" />
<torznab:attr name="minimumratio" value="1.0" />
<torznab:attr name="minimumseedtime" value="172800" />
</item>
<item>
<title>Absolute Power 1997.1080p BluRay Remux AVC DTS-HD MA 5.1-HDX</title>
<guid isPermaLink="true">https://hdaccess.net/details.php?id=11504</guid>
<link>https://hdaccess.net/download.php?torrent=11504&amp;passkey=123456</link>
<comments>https://hdaccess.net/details.php?id=11504&amp;hit=1#comments</comments>
<pubDate>Sat, 14 Mar 2015 13:34:08 -0400</pubDate>
<category>REMUX</category>
<size>25267070253</size>
<description>Absolute.Power.1997.1080p.BluRay.Remux.AVC.DTS-HD.MA.5.1-HDX.mkv.torrent</description>
<enclosure url="https://hdaccess.net/download.php?torrent=11504&amp;passkey=123456" length="25267070253" type="application/x-bittorrent" />
<torznab:attr name="imdb" value="0118548" />
<torznab:attr name="category" value="2000" />
<torznab:attr name="category" value="2060" />
<torznab:attr name="category" value="100002" />
<torznab:attr name="category" value="100026" />
<torznab:attr name="type" value="movie" />
<torznab:attr name="seeders" value="6" />
<torznab:attr name="peers" value="7" />
<torznab:attr name="coverurl" value="https://hdaccess.net/imdb/images/0118548.jpg" />
<torznab:attr name="infohash" value="668c1fed4b6bad43b1c84656da30d5f4eb58afdb" />
<torznab:attr name="minimumratio" value="1.0" />
<torznab:attr name="minimumseedtime" value="172800" />
</item>
<item>
<title>12 Monkeys S01E09 Tomorrow 720p WEB-DL DD5.1 H.264-BS</title>
<guid isPermaLink="true">https://hdaccess.net/details.php?id=11501</guid>
<link>https://hdaccess.net/download.php?torrent=11501&amp;passkey=123456</link>
<comments>https://hdaccess.net/details.php?id=11501&amp;hit=1#comments</comments>
<pubDate>Sat, 14 Mar 2015 12:42:19 -0400</pubDate>
<category>TV 720p WEB-DL</category>
<size>1397243303</size>
<description>12.Monkeys.S01E09.Tomorrow.720p.WEB-DL.DD5.1.H.264-BS.torrent</description>
<enclosure url="https://hdaccess.net/download.php?torrent=11501&amp;passkey=123456" length="1397243303" type="application/x-bittorrent" />
<torznab:attr name="rageid" value="36903" />
<torznab:attr name="imdb" value="3148266" />
<torznab:attr name="tvdbid" value="272644" />
<torznab:attr name="category" value="5000" />
<torznab:attr name="category" value="5040" />
<torznab:attr name="category" value="100004" />
<torznab:attr name="category" value="100038" />
<torznab:attr name="type" value="series" />
<torznab:attr name="seeders" value="6" />
<torznab:attr name="peers" value="6" />
<torznab:attr name="coverurl" value="https://hdaccess.net/images/posters/272644.jpg" />
<torznab:attr name="bannerurl" value="https://hdaccess.net/images/banners/272644.jpg" />
<torznab:attr name="infohash" value="9fbf7d6d52eb9847700591dad758988fb0799c53" />
<torznab:attr name="minimumratio" value="1.0" />
<torznab:attr name="minimumseedtime" value="172800" />
</item>
</channel>
</rss>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="1.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:torznab="http://torznab.com/schemas/2015/feed">
<channel>
<item>
<link>https://example.com</link>
<pubDate>Sat, 14 Mar 2015 17:10:42 -0400</pubDate>
<enclosure url="https://example.com" length="1" type="application/x-bittorrent" />
</item>
</channel>
</rss>

88
src/Jackett/ResultPage.cs Normal file
View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
namespace Jackett
{
public class ResultPage
{
static XNamespace atomNs = "http://www.w3.org/2005/Atom";
static XNamespace torznabNs = "http://torznab.com/schemas/2015/feed";
public ChannelInfo ChannelInfo { get; private set; }
public List<ReleaseInfo> Releases { get; private set; }
public ResultPage(ChannelInfo channelInfo)
{
ChannelInfo = channelInfo;
Releases = new List<ReleaseInfo>();
}
string xmlDateFormat(DateTime dt)
{
//Sat, 14 Mar 2015 17:10:42 -0400
var f = string.Format(@"{0:ddd, dd MMM yyyy HH:mm:ss }{1}", dt, string.Format("{0:zzz}", dt).Replace(":", ""));
return f;
}
XElement getTorznabElement(string name, object value)
{
return value == null ? null : new XElement(torznabNs + "attr", new XAttribute(name, "rageid"), new XAttribute("value", value));
}
public string ToXml(Uri selfAtom)
{
var doc = new XDocument(
new XDeclaration("1.0", "UTF-8", null),
new XElement("rss",
new XAttribute("version", "1.0"),
new XAttribute(XNamespace.Xmlns + "atom", atomNs.NamespaceName),
new XAttribute(XNamespace.Xmlns + "torznab", torznabNs.NamespaceName),
new XElement("channel",
new XElement(atomNs + "link",
new XAttribute("href", selfAtom.ToString()),
new XAttribute("rel", "self"),
new XAttribute("type", "application/rss+xml")
),
new XElement("title", ChannelInfo.Title),
new XElement("description", ChannelInfo.Description),
new XElement("link", ChannelInfo.Link),
new XElement("lanuage", ChannelInfo.Language),
new XElement("category", ChannelInfo.Category),
new XElement("image",
new XElement("url", ChannelInfo.ImageUrl.ToString()),
new XElement("title", ChannelInfo.ImageTitle),
new XElement("link", ChannelInfo.ImageLink.ToString()),
new XElement("description", ChannelInfo.ImageDescription)
)
),
from r in Releases
select new XElement("item",
new XElement("title", r.Title),
new XElement("guid", r.Guid),
new XElement("link", r.Link),
new XElement("comments", r.Comments.ToString()),
new XElement("pubDate", xmlDateFormat(r.PublishDate)),
new XElement("category", r.Category),
new XElement("size", r.Size),
new XElement("description", r.Description),
new XElement("enclosure", new XAttribute("url", r.Link), new XAttribute("length", r.Size), new XAttribute("type", "application/x-bittorrent")),
getTorznabElement("rageid", r.RageID),
getTorznabElement("seeders", r.Seeders),
getTorznabElement("peers", r.Peers),
getTorznabElement("infohash", r.InfoHash),
getTorznabElement("minimumratio", r.MinimumRatio),
getTorznabElement("minimumseedtime", r.MinimumSeedTime)
)
)
);
return doc.ToString();
}
}
}

182
src/Jackett/Server.cs Normal file
View File

@ -0,0 +1,182 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace Jackett
{
public class Server
{
HttpListener listener;
IndexerManager indexerManager;
static string[] StaticFiles = Directory.EnumerateFiles("HtmlContent", "*", SearchOption.AllDirectories).Select(Path.GetFileName).ToArray();
enum WebApiMethod
{
GetConfigForm,
ConfigureIndexer
}
static Dictionary<string, WebApiMethod> WebApiMethods = new Dictionary<string, WebApiMethod>
{
{ "get_config_form", WebApiMethod.GetConfigForm },
{ "configure_indexer", WebApiMethod.ConfigureIndexer }
};
public Server()
{
indexerManager = new IndexerManager();
listener = new HttpListener();
listener.Prefixes.Add("http://*:9117/");
}
public async void Start()
{
listener.Start();
while (true)
{
var context = await listener.GetContextAsync();
ProcessContext(context);
}
}
public void Stop()
{
listener.Stop();
listener.Abort();
}
static Dictionary<string, string> MimeMapping = new Dictionary<string, string> {
{ ".html", "text/html" },
{ ".js", "application/javascript" }
};
async void ServeStaticFile(HttpListenerContext context, string file)
{
var contentFile = File.ReadAllBytes(Path.Combine("HtmlContent", file));
string contentType;
MimeMapping.TryGetValue(Path.GetExtension(file), out contentType);
context.Response.ContentType = contentType;
context.Response.StatusCode = (int)HttpStatusCode.OK;
await context.Response.OutputStream.WriteAsync(contentFile, 0, contentFile.Length);
context.Response.OutputStream.Close();
}
async void ProcessWebApiRequest(HttpListenerContext context, WebApiMethod method)
{
var query = HttpUtility.ParseQueryString(context.Request.Url.Query);
string postData = await new StreamReader(context.Request.InputStream).ReadToEndAsync();
JToken dataJson = JObject.Parse(postData);
JToken jsonReply = new JObject();
var indexerString = (string)dataJson["indexer"];
IndexerInterface indexer;
try
{
indexer = indexerManager.GetIndexer(indexerString);
}
catch (Exception ex)
{
jsonReply["result"] = "error";
jsonReply["error"] = ex.Message;
ReplyWithJson(context, jsonReply);
return;
}
context.Response.ContentType = "text/json";
context.Response.StatusCode = (int)HttpStatusCode.OK;
switch (method)
{
case WebApiMethod.GetConfigForm:
try
{
var config = await indexer.GetConfigurationForSetup();
jsonReply = config.ToJson();
}
catch (Exception ex)
{
jsonReply["result"] = "error";
jsonReply["error"] = ex.Message;
}
break;
case WebApiMethod.ConfigureIndexer:
try
{
await indexer.ApplyConfiguration(dataJson);
await indexer.VerifyConnection();
jsonReply["result"] = "success";
}
catch (Exception ex)
{
jsonReply["result"] = "error";
jsonReply["error"] = ex.Message;
if (ex is ExceptionWithConfigData)
{
jsonReply["config"] = ((ExceptionWithConfigData)ex).ConfigData.ToJson();
}
}
break;
default:
jsonReply["result"] = "error";
jsonReply["error"] = "Invalid API method";
break;
}
ReplyWithJson(context, jsonReply);
}
async void ReplyWithJson(HttpListenerContext context, JToken json)
{
byte[] jsonBytes = Encoding.UTF8.GetBytes(json.ToString());
await context.Response.OutputStream.WriteAsync(jsonBytes, 0, jsonBytes.Length);
context.Response.OutputStream.Close();
}
async void ProcessContext(HttpListenerContext context)
{
Console.WriteLine(context.Request.Url.Query);
string path = context.Request.Url.AbsolutePath.TrimStart('/');
if (path == "")
path = "index.html";
if (Array.IndexOf(StaticFiles, path) > -1)
{
ServeStaticFile(context, path);
return;
}
WebApiMethod apiMethod;
if (WebApiMethods.TryGetValue(path, out apiMethod))
{
ProcessWebApiRequest(context, apiMethod);
return;
}
var query = HttpUtility.ParseQueryString(context.Request.Url.Query);
var inputStream = context.Request.InputStream;
var reader = new StreamReader(inputStream, context.Request.ContentEncoding);
var bytes = await reader.ReadToEndAsync();
var indexer = context.Request.Url.AbsolutePath.TrimStart('/').Replace("/api", "").ToLower();
var responseBytes = Encoding.UTF8.GetBytes(Properties.Resources.validator_reply);
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.ContentLength64 = responseBytes.LongLength;
context.Response.ContentType = "application/rss+xml";
await context.Response.OutputStream.WriteAsync(responseBytes, 0, responseBytes.Length);
context.Response.Close();
}
}
}

View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jackett
{
public class TorznabQuery
{
public string QueryType { get; private set; }
public string[] Categories { get; private set; }
public int Extended { get; private set; }
public string ApiKey { get; private set; }
public int Limit { get; private set; }
public int Offset { get; private set; }
public int RageID { get; private set; }
public int Season { get; private set; }
public int Episode { get; private set; }
public static TorznabQuery FromHttpQuery(NameValueCollection query)
{
//{t=tvsearch&cat=5030%2c5040&extended=1&apikey=test&offset=0&limit=100&rid=24493&season=5&ep=1}
var q = new TorznabQuery();
q.QueryType = query["t"];
q.Categories = query["cat"].Split(',');
q.Extended = int.Parse(query["extended"]);
q.ApiKey = query["apikey"];
q.Limit = int.Parse(query["limit"]);
q.Offset = int.Parse(query["offset"]);
q.RageID = int.Parse(query["rid"]);
q.Season = int.Parse(query["season"]);
q.Episode = int.Parse(query["ep"]);
return q;
}
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CsQuery" version="1.3.4" targetFramework="net451" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net451" />
</packages>