mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Grabbing show names from Sonarr API, finished with BitMeTV
This commit is contained in:
@@ -133,10 +133,13 @@ namespace Jackett
|
||||
|
||||
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||
{
|
||||
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
||||
|
||||
var searchUrl = string.Format("{0}?search={1}&cat=0", SearchUrl, HttpUtility.UrlEncode("game of thrones s03e09"));
|
||||
foreach (var title in query.ShowTitles)
|
||||
{
|
||||
|
||||
var searchString = title + " " + query.GetEpisodeSearchString();
|
||||
var searchUrl = string.Format("{0}?search={1}&cat=0", SearchUrl, HttpUtility.UrlEncode(searchString));
|
||||
var results = await client.GetStringAsync(searchUrl);
|
||||
CQ dom = results;
|
||||
|
||||
@@ -181,6 +184,7 @@ namespace Jackett
|
||||
release.Peers = int.Parse(row.ChildElements.ElementAt(9).Cq().Text()) + release.Seeders;
|
||||
releases.Add(release);
|
||||
}
|
||||
}
|
||||
|
||||
return releases.ToArray();
|
||||
|
||||
|
@@ -120,7 +120,10 @@ namespace Jackett.Indexers
|
||||
{
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
||||
|
||||
var searchUrl = BaseUrl + string.Format(SearchUrl, HttpUtility.UrlEncode("game of thrones s05e01"));
|
||||
foreach (var title in query.ShowTitles)
|
||||
{
|
||||
var searchString = title + " " + query.GetEpisodeSearchString();
|
||||
var searchUrl = BaseUrl + string.Format(SearchUrl, HttpUtility.UrlEncode(searchString));
|
||||
|
||||
var message = new HttpRequestMessage
|
||||
{
|
||||
@@ -185,7 +188,7 @@ namespace Jackett.Indexers
|
||||
|
||||
releases.Add(release);
|
||||
}
|
||||
|
||||
}
|
||||
return releases.ToArray();
|
||||
|
||||
}
|
||||
|
@@ -99,6 +99,11 @@ namespace Jackett
|
||||
}
|
||||
|
||||
var torznabQuery = TorznabQuery.FromHttpQuery(query);
|
||||
|
||||
torznabQuery.ShowTitles = await sonarrApi.GetShowTitle(torznabQuery.RageID);
|
||||
|
||||
var releases = await indexer.PerformQuery(torznabQuery);
|
||||
|
||||
var severUrl = string.Format("{0}://{1}:{2}/", context.Request.Url.Scheme, context.Request.Url.Host, context.Request.Url.Port);
|
||||
|
||||
var resultPage = new ResultPage(new ChannelInfo
|
||||
@@ -112,8 +117,6 @@ namespace Jackett
|
||||
ImageDescription = indexer.DisplayName
|
||||
});
|
||||
|
||||
var releases = await indexer.PerformQuery(torznabQuery);
|
||||
|
||||
// add Jackett proxy to download links...
|
||||
foreach (var release in releases)
|
||||
{
|
||||
|
@@ -45,6 +45,8 @@ namespace Jackett
|
||||
HttpClientHandler handler;
|
||||
HttpClient client;
|
||||
|
||||
Dictionary<int, string[]> IdNameMappings;
|
||||
|
||||
public SonarrApi()
|
||||
{
|
||||
LoadSettings();
|
||||
@@ -57,6 +59,28 @@ namespace Jackett
|
||||
UseCookies = true,
|
||||
};
|
||||
client = new HttpClient(handler);
|
||||
|
||||
IdNameMappings = new Dictionary<int, string[]>();
|
||||
}
|
||||
|
||||
async Task ReloadNameMappings(string host, int port, string apiKey)
|
||||
{
|
||||
Uri hostUri = new Uri(host);
|
||||
var queryUrl = string.Format("http://{0}:{1}/api/series?apikey={2}", hostUri.Host, port, apiKey);
|
||||
var response = await client.GetStringAsync(queryUrl);
|
||||
var json = JArray.Parse(response);
|
||||
|
||||
IdNameMappings.Clear();
|
||||
foreach (var item in json)
|
||||
{
|
||||
var titles = new List<string>();
|
||||
titles.Add((string)item["title"]);
|
||||
foreach (var t in item["alternateTitles"])
|
||||
{
|
||||
titles.Add((string)t["title"]);
|
||||
}
|
||||
IdNameMappings.Add((int)item["tvRageId"], titles.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
void LoadSettings()
|
||||
@@ -99,7 +123,7 @@ namespace Jackett
|
||||
{
|
||||
var config = new ConfigurationSonarr();
|
||||
config.LoadValuesFromJson(configJson);
|
||||
await TestConnection(config.Host.Value, int.Parse(config.Port.Value), config.ApiKey.Value);
|
||||
await ReloadNameMappings(config.Host.Value, int.Parse(config.Port.Value), config.ApiKey.Value);
|
||||
Host = "http://" + new Uri(config.Host.Value).Host;
|
||||
Port = int.Parse(config.Port.Value);
|
||||
ApiKey = config.ApiKey.Value;
|
||||
@@ -108,15 +132,24 @@ namespace Jackett
|
||||
|
||||
public async Task TestConnection()
|
||||
{
|
||||
await TestConnection(Host, Port, ApiKey);
|
||||
await ReloadNameMappings(Host, Port, ApiKey);
|
||||
}
|
||||
|
||||
async Task TestConnection(string host, int port, string apiKey)
|
||||
public async Task<string[]> GetShowTitle(int rid)
|
||||
{
|
||||
Uri hostUri = new Uri(host);
|
||||
var queryUrl = string.Format("http://{0}:{1}/api/series?apikey={2}", hostUri.Host, port, apiKey);
|
||||
var response = await client.GetStringAsync(queryUrl);
|
||||
var json = JArray.Parse(response);
|
||||
if (rid == 0)
|
||||
return null;
|
||||
|
||||
int tries = 0;
|
||||
while (tries < 2)
|
||||
{
|
||||
string[] titles;
|
||||
if (IdNameMappings.TryGetValue(rid, out titles))
|
||||
return titles;
|
||||
await ReloadNameMappings(Host, Port, ApiKey);
|
||||
tries++;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -17,7 +18,23 @@ namespace Jackett
|
||||
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 string Episode { get; private set; }
|
||||
public string[] ShowTitles { get; set; }
|
||||
|
||||
public string GetEpisodeSearchString()
|
||||
{
|
||||
if (Season == 0)
|
||||
return string.Empty;
|
||||
|
||||
string episodeString;
|
||||
DateTime showDate;
|
||||
if (DateTime.TryParseExact(string.Format("{0} {1}", Season, Episode), "yyyy MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out showDate))
|
||||
episodeString = showDate.ToString("yyyy.MM.dd");
|
||||
else
|
||||
episodeString = string.Format("S{0:00}E{1:00}", Season, int.Parse(Episode));
|
||||
|
||||
return episodeString;
|
||||
}
|
||||
|
||||
public static TorznabQuery FromHttpQuery(NameValueCollection query)
|
||||
{
|
||||
@@ -36,8 +53,8 @@ namespace Jackett
|
||||
q.RageID = temp;
|
||||
if (int.TryParse(query["season"], out temp))
|
||||
q.Season = temp;
|
||||
if (int.TryParse(query["ep"], out temp))
|
||||
q.Episode = int.Parse(query["ep"]);
|
||||
|
||||
q.Episode = query["ep"];
|
||||
|
||||
return q;
|
||||
}
|
||||
|
@@ -308,12 +308,12 @@
|
||||
<div class="setup-item-value">{{{value_element}}}</div>
|
||||
</div>
|
||||
|
||||
<input class="setup-item-inputstring form-control" type="text" value="{{{value}}}"></input>
|
||||
<input class="setup-item-inputstring form-control" type="text" value="{{{value}}}" />
|
||||
<div class="setup-item-checkbox">
|
||||
{{#if value}}
|
||||
<input type="checkbox" class="form-control" checked></input>
|
||||
<input type="checkbox" class="form-control" checked />
|
||||
{{else}}
|
||||
<input type="checkbox" class="form-control"></input>
|
||||
<input type="checkbox" class="form-control" />
|
||||
{{/if}}
|
||||
</div>
|
||||
<img class="setup-item-displayimage" src="{{{value}}}" />
|
||||
|
Reference in New Issue
Block a user