mirror of https://github.com/Jackett/Jackett
Fixed bug where search queries were unused
This commit is contained in:
parent
59cf8c3e9f
commit
26f1ba7016
|
@ -13,169 +13,179 @@ using System.Web;
|
|||
|
||||
namespace Jackett
|
||||
{
|
||||
public class BitMeTV : IndexerInterface
|
||||
{
|
||||
class BmtvConfig : ConfigurationData
|
||||
{
|
||||
public StringItem Username { get; private set; }
|
||||
public class BitMeTV : IndexerInterface
|
||||
{
|
||||
class BmtvConfig : ConfigurationData
|
||||
{
|
||||
public StringItem Username { get; private set; }
|
||||
|
||||
public StringItem Password { get; private set; }
|
||||
public StringItem Password { get; private set; }
|
||||
|
||||
public ImageItem CaptchaImage { get; private set; }
|
||||
public ImageItem CaptchaImage { get; private set; }
|
||||
|
||||
public StringItem CaptchaText { get; private set; }
|
||||
public StringItem CaptchaText { get; private set; }
|
||||
|
||||
public BmtvConfig ()
|
||||
{
|
||||
Username = new StringItem { Name = "Username" };
|
||||
Password = new StringItem { Name = "Password" };
|
||||
CaptchaImage = new ImageItem { Name = "Captcha Image" };
|
||||
CaptchaText = new StringItem { Name = "Captcha Text" };
|
||||
}
|
||||
public BmtvConfig()
|
||||
{
|
||||
Username = new StringItem { Name = "Username" };
|
||||
Password = new StringItem { Name = "Password" };
|
||||
CaptchaImage = new ImageItem { Name = "Captcha Image" };
|
||||
CaptchaText = new StringItem { Name = "Captcha Text" };
|
||||
}
|
||||
|
||||
public override Item[] GetItems ()
|
||||
{
|
||||
return new Item[] { Username, Password, CaptchaImage, CaptchaText };
|
||||
}
|
||||
}
|
||||
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";
|
||||
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;
|
||||
CookieContainer cookies;
|
||||
HttpClientHandler handler;
|
||||
HttpClient client;
|
||||
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
|
||||
public BitMeTV ()
|
||||
{
|
||||
IsConfigured = false;
|
||||
cookies = new CookieContainer ();
|
||||
handler = new HttpClientHandler {
|
||||
CookieContainer = cookies,
|
||||
AllowAutoRedirect = true,
|
||||
UseCookies = true,
|
||||
};
|
||||
client = new HttpClient (handler);
|
||||
}
|
||||
public BitMeTV()
|
||||
{
|
||||
IsConfigured = false;
|
||||
cookies = new CookieContainer();
|
||||
handler = new HttpClientHandler
|
||||
{
|
||||
CookieContainer = cookies,
|
||||
AllowAutoRedirect = true,
|
||||
UseCookies = true,
|
||||
};
|
||||
client = new HttpClient(handler);
|
||||
}
|
||||
|
||||
public string DisplayName { get { return "BitMeTV"; } }
|
||||
public string DisplayName { get { return "BitMeTV"; } }
|
||||
|
||||
public string DisplayDescription { get { return "TV Episode specialty tracker"; } }
|
||||
public string DisplayDescription { get { return "TV Episode specialty tracker"; } }
|
||||
|
||||
public Uri SiteLink { get { return new Uri (BaseUrl); } }
|
||||
public Uri SiteLink { get { return new Uri(BaseUrl); } }
|
||||
|
||||
public bool IsConfigured { get; private set; }
|
||||
public bool IsConfigured { get; private set; }
|
||||
|
||||
public async Task<ConfigurationData> GetConfigurationForSetup ()
|
||||
{
|
||||
await client.GetAsync (LoginUrl);
|
||||
var captchaImage = await client.GetByteArrayAsync (CaptchaUrl);
|
||||
var config = new BmtvConfig ();
|
||||
config.CaptchaImage.Value = captchaImage;
|
||||
return (ConfigurationData)config;
|
||||
}
|
||||
public async Task<ConfigurationData> GetConfigurationForSetup()
|
||||
{
|
||||
await client.GetAsync(LoginUrl);
|
||||
var captchaImage = await client.GetByteArrayAsync(CaptchaUrl);
|
||||
var config = new BmtvConfig();
|
||||
config.CaptchaImage.Value = captchaImage;
|
||||
return (ConfigurationData)config;
|
||||
}
|
||||
|
||||
public async Task ApplyConfiguration (JToken configJson)
|
||||
{
|
||||
var config = new BmtvConfig ();
|
||||
config.LoadValuesFromJson (configJson);
|
||||
public async Task ApplyConfiguration(JToken configJson)
|
||||
{
|
||||
var config = new BmtvConfig();
|
||||
config.LoadValuesFromJson(configJson);
|
||||
|
||||
var pairs = new Dictionary<string, string> {
|
||||
var pairs = new Dictionary<string, string> {
|
||||
{ "username", config.Username.Value },
|
||||
{ "password", config.Password.Value },
|
||||
{ "secimage", config.CaptchaText.Value }
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent (pairs);
|
||||
var content = new FormUrlEncodedContent(pairs);
|
||||
|
||||
var response = await client.PostAsync (LoginPost, content);
|
||||
var responseContent = await response.Content.ReadAsStringAsync ();
|
||||
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;
|
||||
config.CaptchaText.Value = "";
|
||||
throw new ExceptionWithConfigData (errorMessage, (ConfigurationData)config);
|
||||
} else {
|
||||
var configSaveData = new JObject ();
|
||||
configSaveData ["cookies"] = cookies.ToJson (SiteLink);
|
||||
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;
|
||||
config.CaptchaText.Value = "";
|
||||
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config);
|
||||
}
|
||||
else
|
||||
{
|
||||
var configSaveData = new JObject();
|
||||
configSaveData["cookies"] = cookies.ToJson(SiteLink);
|
||||
|
||||
if (OnSaveConfigurationRequested != null)
|
||||
OnSaveConfigurationRequested (this, configSaveData);
|
||||
if (OnSaveConfigurationRequested != null)
|
||||
OnSaveConfigurationRequested(this, configSaveData);
|
||||
|
||||
IsConfigured = true;
|
||||
}
|
||||
}
|
||||
IsConfigured = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadFromSavedConfiguration (JToken jsonConfig)
|
||||
{
|
||||
cookies.FillFromJson (new Uri (BaseUrl), (JArray)jsonConfig ["cookies"]);
|
||||
IsConfigured = true;
|
||||
}
|
||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||
{
|
||||
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||
IsConfigured = true;
|
||||
}
|
||||
|
||||
public async Task<ReleaseInfo[]> PerformQuery (TorznabQuery query)
|
||||
{
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo> ();
|
||||
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||
{
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
||||
|
||||
|
||||
foreach (var title in query.ShowTitles ?? new string[] { string.Empty }) {
|
||||
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
|
||||
{
|
||||
|
||||
var searchString = title + " " + query.GetEpisodeSearchString ();
|
||||
var episodeSearchUrl = string.Format ("{0}?search={1}&cat=0", SearchUrl, HttpUtility.UrlEncode (searchString));
|
||||
var results = await client.GetStringAsync (episodeSearchUrl);
|
||||
CQ dom = results;
|
||||
var searchString = title + " " + query.GetEpisodeSearchString();
|
||||
var episodeSearchUrl = string.Format("{0}?search={1}&cat=0", SearchUrl, HttpUtility.UrlEncode(searchString));
|
||||
var results = await client.GetStringAsync(episodeSearchUrl);
|
||||
CQ dom = results;
|
||||
|
||||
var table = dom ["tbody > tr > .latest"].Parent ().Parent ();
|
||||
var table = dom["tbody > tr > .latest"].Parent().Parent();
|
||||
|
||||
foreach (var row in table.Children().Skip(1)) {
|
||||
var release = new ReleaseInfo ();
|
||||
foreach (var row in table.Children().Skip(1))
|
||||
{
|
||||
var release = new ReleaseInfo();
|
||||
|
||||
CQ qDetailsCol = row.ChildElements.ElementAt (1).Cq ();
|
||||
CQ qLink = qDetailsCol.Children ("a").First ();
|
||||
CQ qDetailsCol = row.ChildElements.ElementAt(1).Cq();
|
||||
CQ qLink = qDetailsCol.Children("a").First();
|
||||
|
||||
release.MinimumRatio = 1;
|
||||
release.MinimumSeedTime = 172800;
|
||||
release.Comments = new Uri (BaseUrl + "/" + qLink.Attr ("href"));
|
||||
release.Guid = release.Comments;
|
||||
release.Title = qLink.Attr ("title");
|
||||
release.Description = release.Title;
|
||||
release.MinimumRatio = 1;
|
||||
release.MinimumSeedTime = 172800;
|
||||
release.Comments = new Uri(BaseUrl + "/" + qLink.Attr("href"));
|
||||
release.Guid = release.Comments;
|
||||
release.Title = qLink.Attr("title");
|
||||
release.Description = release.Title;
|
||||
|
||||
//"Tuesday, June 11th 2013 at 03:52:53 AM" to...
|
||||
//"Tuesday June 11 2013 03:52:53 AM"
|
||||
var timestamp = qDetailsCol.Children ("font").Text ().Trim () + " ";
|
||||
var timeParts = new List<string> (timestamp.Replace (" at", "").Replace (",", "").Split (' '));
|
||||
timeParts [2] = Regex.Replace (timeParts [2], "[^0-9.]", "");
|
||||
var formattedTimeString = string.Join (" ", timeParts.ToArray ()).Trim ();
|
||||
release.PublishDate = DateTime.ParseExact (formattedTimeString, "dddd MMMM d yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
|
||||
//"Tuesday, June 11th 2013 at 03:52:53 AM" to...
|
||||
//"Tuesday June 11 2013 03:52:53 AM"
|
||||
var timestamp = qDetailsCol.Children("font").Text().Trim() + " ";
|
||||
var timeParts = new List<string>(timestamp.Replace(" at", "").Replace(",", "").Split(' '));
|
||||
timeParts[2] = Regex.Replace(timeParts[2], "[^0-9.]", "");
|
||||
var formattedTimeString = string.Join(" ", timeParts.ToArray()).Trim();
|
||||
release.PublishDate = DateTime.ParseExact(formattedTimeString, "dddd MMMM d yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
|
||||
|
||||
release.Link = new Uri (BaseUrl + "/" + row.ChildElements.ElementAt (2).Cq ().Children ("a.index").Attr ("href"));
|
||||
release.Link = new Uri(BaseUrl + "/" + row.ChildElements.ElementAt(2).Cq().Children("a.index").Attr("href"));
|
||||
|
||||
var sizeCol = row.ChildElements.ElementAt (6);
|
||||
var sizeVal = float.Parse (sizeCol.ChildNodes [0].NodeValue);
|
||||
var sizeUnit = sizeCol.ChildNodes [2].NodeValue;
|
||||
release.Size = ReleaseInfo.GetBytes (sizeUnit, sizeVal);
|
||||
var sizeCol = row.ChildElements.ElementAt(6);
|
||||
var sizeVal = float.Parse(sizeCol.ChildNodes[0].NodeValue);
|
||||
var sizeUnit = sizeCol.ChildNodes[2].NodeValue;
|
||||
release.Size = ReleaseInfo.GetBytes(sizeUnit, sizeVal);
|
||||
|
||||
release.Seeders = int.Parse (row.ChildElements.ElementAt (8).Cq ().Text ());
|
||||
release.Peers = int.Parse (row.ChildElements.ElementAt (9).Cq ().Text ()) + release.Seeders;
|
||||
releases.Add (release);
|
||||
}
|
||||
}
|
||||
release.Seeders = int.Parse(row.ChildElements.ElementAt(8).Cq().Text());
|
||||
release.Peers = int.Parse(row.ChildElements.ElementAt(9).Cq().Text()) + release.Seeders;
|
||||
|
||||
return releases.ToArray ();
|
||||
if (!release.Title.ToLower().Contains(title.ToLower()))
|
||||
continue;
|
||||
|
||||
}
|
||||
releases.Add(release);
|
||||
}
|
||||
}
|
||||
|
||||
public Task<byte[]> Download (Uri link)
|
||||
{
|
||||
return client.GetByteArrayAsync (link);
|
||||
}
|
||||
}
|
||||
return releases.ToArray();
|
||||
|
||||
}
|
||||
|
||||
public Task<byte[]> Download(Uri link)
|
||||
{
|
||||
return client.GetByteArrayAsync(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -198,7 +198,10 @@ namespace Jackett
|
|||
|
||||
var torznabQuery = TorznabQuery.FromHttpQuery(query);
|
||||
|
||||
torznabQuery.ShowTitles = await sonarrApi.GetShowTitle(torznabQuery.RageID);
|
||||
if (torznabQuery.RageID != 0)
|
||||
torznabQuery.ShowTitles = await sonarrApi.GetShowTitle(torznabQuery.RageID);
|
||||
else
|
||||
torznabQuery.ShowTitles = new string[] { torznabQuery.SearchTerm };
|
||||
|
||||
var releases = await indexer.PerformQuery(torznabQuery);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace Jackett
|
|||
public int Season { get; private set; }
|
||||
public string Episode { get; private set; }
|
||||
public string[] ShowTitles { get; set; }
|
||||
public string SearchTerm { get; set; }
|
||||
|
||||
public string GetEpisodeSearchString()
|
||||
{
|
||||
|
@ -44,6 +45,7 @@ namespace Jackett
|
|||
//{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.SearchTerm = query["q"];
|
||||
q.Categories = query["cat"].Split(',');
|
||||
q.Extended = int.Parse(query["extended"]);
|
||||
q.ApiKey = query["apikey"];
|
||||
|
|
Loading…
Reference in New Issue