mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
BitMeTV saving and loading cookies working
This commit is contained in:
@@ -24,7 +24,7 @@ namespace Jackett
|
|||||||
Task VerifyConnection();
|
Task VerifyConnection();
|
||||||
|
|
||||||
// Invoked when the indexer configuration has been applied and verified so the cookie needs to be saved
|
// Invoked when the indexer configuration has been applied and verified so the cookie needs to be saved
|
||||||
event Action<JToken> OnSaveConfigurationRequested;
|
event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||||
|
|
||||||
// Whether this indexer has been configured, verified and saved in the past and has the settings required for functioning
|
// Whether this indexer has been configured, verified and saved in the past and has the settings required for functioning
|
||||||
bool IsConfigured { get; }
|
bool IsConfigured { get; }
|
||||||
|
@@ -10,7 +10,8 @@ namespace Jackett
|
|||||||
{
|
{
|
||||||
public class IndexerManager
|
public class IndexerManager
|
||||||
{
|
{
|
||||||
static string AppConfigDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
|
||||||
|
static string AppConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Jackett");
|
||||||
static string IndexerConfigDirectory = Path.Combine(AppConfigDirectory, "Indexers");
|
static string IndexerConfigDirectory = Path.Combine(AppConfigDirectory, "Indexers");
|
||||||
|
|
||||||
public Dictionary<string, IndexerInterface> Indexers { get; private set; }
|
public Dictionary<string, IndexerInterface> Indexers { get; private set; }
|
||||||
@@ -35,11 +36,12 @@ namespace Jackett
|
|||||||
var name = indexerType.Name.Trim().ToLower();
|
var name = indexerType.Name.Trim().ToLower();
|
||||||
|
|
||||||
IndexerInterface newIndexer = (IndexerInterface)Activator.CreateInstance(indexerType);
|
IndexerInterface newIndexer = (IndexerInterface)Activator.CreateInstance(indexerType);
|
||||||
|
newIndexer.OnSaveConfigurationRequested += newIndexer_OnSaveConfigurationRequested;
|
||||||
|
|
||||||
var configFilePath = Path.Combine(IndexerConfigDirectory, name.ToString().ToLower());
|
var configFilePath = GetIndexerConfigFilePath(newIndexer);
|
||||||
if (File.Exists(configFilePath))
|
if (File.Exists(configFilePath))
|
||||||
{
|
{
|
||||||
string jsonString = File.ReadAllText(configFilePath);
|
var jsonString = JObject.Parse(File.ReadAllText(configFilePath));
|
||||||
newIndexer.LoadFromSavedConfiguration(jsonString);
|
newIndexer.LoadFromSavedConfiguration(jsonString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,6 +49,20 @@ namespace Jackett
|
|||||||
return newIndexer;
|
return newIndexer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string GetIndexerConfigFilePath(IndexerInterface indexer)
|
||||||
|
{
|
||||||
|
return Path.Combine(IndexerConfigDirectory, indexer.GetType().Name.ToLower() + ".json");
|
||||||
|
}
|
||||||
|
|
||||||
|
void newIndexer_OnSaveConfigurationRequested(IndexerInterface indexer, JToken obj)
|
||||||
|
{
|
||||||
|
var name = indexer.GetType().Name.Trim().ToLower();
|
||||||
|
var configFilePath = GetIndexerConfigFilePath(indexer);
|
||||||
|
if (!Directory.Exists(IndexerConfigDirectory))
|
||||||
|
Directory.CreateDirectory(IndexerConfigDirectory);
|
||||||
|
File.WriteAllText(configFilePath, obj.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
public IndexerInterface GetIndexer(string name)
|
public IndexerInterface GetIndexer(string name)
|
||||||
{
|
{
|
||||||
IndexerInterface indexer;
|
IndexerInterface indexer;
|
||||||
|
@@ -43,7 +43,7 @@ namespace Jackett
|
|||||||
HttpClientHandler handler;
|
HttpClientHandler handler;
|
||||||
HttpClient client;
|
HttpClient client;
|
||||||
|
|
||||||
public event Action<JToken> OnSaveConfigurationRequested;
|
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||||
|
|
||||||
public BitMeTV()
|
public BitMeTV()
|
||||||
{
|
{
|
||||||
@@ -114,7 +114,7 @@ namespace Jackett
|
|||||||
).ToArray());
|
).ToArray());
|
||||||
|
|
||||||
if (OnSaveConfigurationRequested != null)
|
if (OnSaveConfigurationRequested != null)
|
||||||
OnSaveConfigurationRequested(configSaveData);
|
OnSaveConfigurationRequested(this, configSaveData);
|
||||||
|
|
||||||
IsConfigured = true;
|
IsConfigured = true;
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,13 @@ namespace Jackett
|
|||||||
|
|
||||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||||
{
|
{
|
||||||
// todo: set cookie data...
|
|
||||||
|
foreach (var cookie in jsonConfig["cookies"])
|
||||||
|
{
|
||||||
|
var w = ((string)cookie).Split(':');
|
||||||
|
cookies.Add(new Uri(BaseUrl), new Cookie(w[0], w[1]));
|
||||||
|
}
|
||||||
|
|
||||||
IsConfigured = true;
|
IsConfigured = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,7 +41,7 @@ namespace Jackett
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public event Action<JToken> OnSaveConfigurationRequested;
|
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||||
|
|
||||||
public bool IsConfigured
|
public bool IsConfigured
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user