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

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;
}
}
}