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)
|
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||||
{
|
{
|
||||||
|
|
||||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
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);
|
var results = await client.GetStringAsync(searchUrl);
|
||||||
CQ dom = results;
|
CQ dom = results;
|
||||||
|
|
||||||
@@ -181,6 +184,7 @@ namespace Jackett
|
|||||||
release.Peers = int.Parse(row.ChildElements.ElementAt(9).Cq().Text()) + release.Seeders;
|
release.Peers = int.Parse(row.ChildElements.ElementAt(9).Cq().Text()) + release.Seeders;
|
||||||
releases.Add(release);
|
releases.Add(release);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return releases.ToArray();
|
return releases.ToArray();
|
||||||
|
|
||||||
|
@@ -120,7 +120,10 @@ namespace Jackett.Indexers
|
|||||||
{
|
{
|
||||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
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
|
var message = new HttpRequestMessage
|
||||||
{
|
{
|
||||||
@@ -185,7 +188,7 @@ namespace Jackett.Indexers
|
|||||||
|
|
||||||
releases.Add(release);
|
releases.Add(release);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return releases.ToArray();
|
return releases.ToArray();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -99,6 +99,11 @@ namespace Jackett
|
|||||||
}
|
}
|
||||||
|
|
||||||
var torznabQuery = TorznabQuery.FromHttpQuery(query);
|
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 severUrl = string.Format("{0}://{1}:{2}/", context.Request.Url.Scheme, context.Request.Url.Host, context.Request.Url.Port);
|
||||||
|
|
||||||
var resultPage = new ResultPage(new ChannelInfo
|
var resultPage = new ResultPage(new ChannelInfo
|
||||||
@@ -112,8 +117,6 @@ namespace Jackett
|
|||||||
ImageDescription = indexer.DisplayName
|
ImageDescription = indexer.DisplayName
|
||||||
});
|
});
|
||||||
|
|
||||||
var releases = await indexer.PerformQuery(torznabQuery);
|
|
||||||
|
|
||||||
// add Jackett proxy to download links...
|
// add Jackett proxy to download links...
|
||||||
foreach (var release in releases)
|
foreach (var release in releases)
|
||||||
{
|
{
|
||||||
|
@@ -45,6 +45,8 @@ namespace Jackett
|
|||||||
HttpClientHandler handler;
|
HttpClientHandler handler;
|
||||||
HttpClient client;
|
HttpClient client;
|
||||||
|
|
||||||
|
Dictionary<int, string[]> IdNameMappings;
|
||||||
|
|
||||||
public SonarrApi()
|
public SonarrApi()
|
||||||
{
|
{
|
||||||
LoadSettings();
|
LoadSettings();
|
||||||
@@ -57,6 +59,28 @@ namespace Jackett
|
|||||||
UseCookies = true,
|
UseCookies = true,
|
||||||
};
|
};
|
||||||
client = new HttpClient(handler);
|
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()
|
void LoadSettings()
|
||||||
@@ -99,7 +123,7 @@ namespace Jackett
|
|||||||
{
|
{
|
||||||
var config = new ConfigurationSonarr();
|
var config = new ConfigurationSonarr();
|
||||||
config.LoadValuesFromJson(configJson);
|
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;
|
Host = "http://" + new Uri(config.Host.Value).Host;
|
||||||
Port = int.Parse(config.Port.Value);
|
Port = int.Parse(config.Port.Value);
|
||||||
ApiKey = config.ApiKey.Value;
|
ApiKey = config.ApiKey.Value;
|
||||||
@@ -108,15 +132,24 @@ namespace Jackett
|
|||||||
|
|
||||||
public async Task TestConnection()
|
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);
|
if (rid == 0)
|
||||||
var queryUrl = string.Format("http://{0}:{1}/api/series?apikey={2}", hostUri.Host, port, apiKey);
|
return null;
|
||||||
var response = await client.GetStringAsync(queryUrl);
|
|
||||||
var json = JArray.Parse(response);
|
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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -17,7 +18,23 @@ namespace Jackett
|
|||||||
public int Offset { get; private set; }
|
public int Offset { get; private set; }
|
||||||
public int RageID { get; private set; }
|
public int RageID { get; private set; }
|
||||||
public int Season { 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)
|
public static TorznabQuery FromHttpQuery(NameValueCollection query)
|
||||||
{
|
{
|
||||||
@@ -36,8 +53,8 @@ namespace Jackett
|
|||||||
q.RageID = temp;
|
q.RageID = temp;
|
||||||
if (int.TryParse(query["season"], out temp))
|
if (int.TryParse(query["season"], out temp))
|
||||||
q.Season = temp;
|
q.Season = temp;
|
||||||
if (int.TryParse(query["ep"], out temp))
|
|
||||||
q.Episode = int.Parse(query["ep"]);
|
q.Episode = query["ep"];
|
||||||
|
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
@@ -308,12 +308,12 @@
|
|||||||
<div class="setup-item-value">{{{value_element}}}</div>
|
<div class="setup-item-value">{{{value_element}}}</div>
|
||||||
</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">
|
<div class="setup-item-checkbox">
|
||||||
{{#if value}}
|
{{#if value}}
|
||||||
<input type="checkbox" class="form-control" checked></input>
|
<input type="checkbox" class="form-control" checked />
|
||||||
{{else}}
|
{{else}}
|
||||||
<input type="checkbox" class="form-control"></input>
|
<input type="checkbox" class="form-control" />
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
<img class="setup-item-displayimage" src="{{{value}}}" />
|
<img class="setup-item-displayimage" src="{{{value}}}" />
|
||||||
|
Reference in New Issue
Block a user