mirror of
https://github.com/Jackett/Jackett
synced 2025-03-04 02:38:08 +00:00
Freshon setup complete
This commit is contained in:
parent
213e8c062c
commit
5b745af7f6
5 changed files with 137 additions and 29 deletions
22
src/Jackett/CookieContainerExtensions.cs
Normal file
22
src/Jackett/CookieContainerExtensions.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jackett
|
||||
{
|
||||
public static class CookieContainerExtensions
|
||||
{
|
||||
public static void FillFromJson(this CookieContainer cookies, Uri uri, JArray json)
|
||||
{
|
||||
foreach (var cookie in json)
|
||||
{
|
||||
var w = ((string)cookie).Split(':');
|
||||
cookies.Add(uri, new Cookie(w[0], w[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ namespace Jackett
|
|||
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);
|
||||
Task ApplyConfiguration(JToken configJson);
|
||||
|
||||
// Called to check if configuration (cookie) is correct and indexer connection works
|
||||
Task VerifyConnection();
|
||||
|
|
|
@ -133,13 +133,7 @@ namespace Jackett
|
|||
|
||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||
{
|
||||
|
||||
foreach (var cookie in jsonConfig["cookies"])
|
||||
{
|
||||
var w = ((string)cookie).Split(':');
|
||||
cookies.Add(new Uri(BaseUrl), new Cookie(w[0], w[1]));
|
||||
}
|
||||
|
||||
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||
IsConfigured = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
using Newtonsoft.Json.Linq;
|
||||
using CsQuery;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.UI.WebControls;
|
||||
|
@ -10,47 +14,134 @@ namespace Jackett
|
|||
{
|
||||
public class Freshon : IndexerInterface
|
||||
{
|
||||
|
||||
public string DisplayName
|
||||
class FreshonConfig : ConfigurationData
|
||||
{
|
||||
get { return "FreshOnTV"; }
|
||||
public StringItem Username { get; private set; }
|
||||
public StringItem Password { get; private set; }
|
||||
|
||||
public FreshonConfig()
|
||||
{
|
||||
Username = new StringItem { Name = "Username", ItemType = ItemType.InputString };
|
||||
Password = new StringItem { Name = "Password", ItemType = ItemType.InputString };
|
||||
}
|
||||
|
||||
public override Item[] GetItems()
|
||||
{
|
||||
return new Item[] { Username, Password };
|
||||
}
|
||||
}
|
||||
|
||||
public string DisplayDescription
|
||||
{
|
||||
get { return "Our goal is to provide the latest stuff in the TV show domain"; }
|
||||
}
|
||||
static string BaseUrl = "https://freshon.tv";
|
||||
static string LoginUrl = BaseUrl + "/login.php";
|
||||
static string LoginPostUrl = BaseUrl + "/login.php?action=makelogin";
|
||||
static string SearchUrl = BaseUrl + "/browse.php";
|
||||
|
||||
public Uri SiteLink
|
||||
static string chromeUserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36";
|
||||
|
||||
CookieContainer cookies;
|
||||
HttpClientHandler handler;
|
||||
HttpClient client;
|
||||
|
||||
public bool IsConfigured { get; private set; }
|
||||
|
||||
public string DisplayName { get { return "FreshOnTV"; } }
|
||||
|
||||
public string DisplayDescription { get { return "Our goal is to provide the latest stuff in the TV show domain"; } }
|
||||
|
||||
public Uri SiteLink { get { return new Uri("https://freshon.tv/"); } }
|
||||
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
|
||||
public Freshon()
|
||||
{
|
||||
get { return new Uri("https://freshon.tv/"); }
|
||||
IsConfigured = false;
|
||||
cookies = new CookieContainer();
|
||||
handler = new HttpClientHandler
|
||||
{
|
||||
CookieContainer = cookies,
|
||||
AllowAutoRedirect = true,
|
||||
UseCookies = true,
|
||||
};
|
||||
client = new HttpClient(handler);
|
||||
}
|
||||
|
||||
public Task<ConfigurationData> GetConfigurationForSetup()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
//var loginPage = await client.GetAsync(LoginUrl);
|
||||
var config = new FreshonConfig();
|
||||
return (ConfigurationData)config;
|
||||
});
|
||||
}
|
||||
|
||||
public Task ApplyConfiguration(JToken jsonConfig)
|
||||
public Task ApplyConfiguration(JToken configJson)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
var config = new FreshonConfig();
|
||||
config.LoadValuesFromJson(configJson);
|
||||
|
||||
var pairs = new Dictionary<string, string>
|
||||
{
|
||||
{ "username", config.Username.Value},
|
||||
{ "password", config.Password.Value}
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent(pairs);
|
||||
var message = new HttpRequestMessage();
|
||||
message.Method = HttpMethod.Post;
|
||||
message.Content = content;
|
||||
message.RequestUri = new Uri(LoginPostUrl);
|
||||
message.Headers.Referrer = new Uri(LoginUrl);
|
||||
message.Headers.UserAgent.ParseAdd(chromeUserAgent);
|
||||
|
||||
var response = await client.SendAsync(message);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (!responseContent.Contains("/logout.php"))
|
||||
{
|
||||
CQ dom = responseContent;
|
||||
var messageEl = dom[".error_text"];
|
||||
var errorMessage = messageEl.Text().Trim();
|
||||
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(this, configSaveData);
|
||||
|
||||
IsConfigured = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Task VerifyConnection()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
var message = new HttpRequestMessage();
|
||||
message.Method = HttpMethod.Get;
|
||||
message.RequestUri = new Uri(SearchUrl);
|
||||
message.Headers.UserAgent.ParseAdd(chromeUserAgent);
|
||||
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
|
||||
public bool IsConfigured
|
||||
{
|
||||
get { return false; }
|
||||
var response = await client.SendAsync(message);
|
||||
var result = await response.Content.ReadAsStringAsync();
|
||||
if (!result.Contains("/logout.php"))
|
||||
throw new Exception("Detected as not logged in");
|
||||
});
|
||||
}
|
||||
|
||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||
IsConfigured = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
<Compile Include="ApiKey.cs" />
|
||||
<Compile Include="ChannelInfo.cs" />
|
||||
<Compile Include="ConfigurationData.cs" />
|
||||
<Compile Include="CookieContainerExtensions.cs" />
|
||||
<Compile Include="DataUrl.cs" />
|
||||
<Compile Include="ExceptionWithConfigData.cs" />
|
||||
<Compile Include="IndexerInterface.cs" />
|
||||
|
|
Loading…
Add table
Reference in a new issue