Fixed settings folder bug

This commit is contained in:
zone117x 2015-04-18 20:05:38 -06:00
parent c3e1fd17c4
commit b68e4c0553
3 changed files with 216 additions and 40 deletions

View File

@ -0,0 +1,191 @@
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;
using System.Web;
namespace Jackett.Indexers
{
public class MoreThanTV : IndexerInterface
{
public string DisplayName
{
get { return "MoreThanTV"; }
}
public string DisplayDescription
{
get { return "ROMANIAN Private Torrent Tracker for TV / MOVIES, and the internal tracker for the release group DRACULA"; }
}
public Uri SiteLink
{
get { return new Uri(BaseUrl); }
}
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
public bool IsConfigured { get; private set; }
static string BaseUrl = "http://www.morethan.tv";
static string LoginUrl = BaseUrl + "/login.php";
static string SearchUrl = BaseUrl + "/ajax.php?action=browse&searchstr=";
static string DownloadUrl = BaseUrl + "/torrents.php?action=download&id=";
static string GuidUrl = BaseUrl + "/torrents.php?torrentid=";
CookieContainer cookies;
HttpClientHandler handler;
HttpClient client;
public MoreThanTV()
{
IsConfigured = false;
cookies = new CookieContainer();
handler = new HttpClientHandler
{
CookieContainer = cookies,
AllowAutoRedirect = true,
UseCookies = true,
};
client = new HttpClient(handler);
}
public Task<ConfigurationData> GetConfigurationForSetup()
{
var config = new ConfigurationDataBasicLogin();
return Task.FromResult<ConfigurationData>(config);
}
public async Task ApplyConfiguration(Newtonsoft.Json.Linq.JToken configJson)
{
var config = new ConfigurationDataBasicLogin();
config.LoadValuesFromJson(configJson);
var pairs = new Dictionary<string, string>
{
{ "username", config.Username.Value},
{ "password", config.Password.Value},
{ "login", "Log in" },
{ "keeplogged", "1" }
};
var content = new FormUrlEncodedContent(pairs);
var response = await client.PostAsync(LoginUrl, content);
var responseContent = await response.Content.ReadAsStringAsync();
if (!responseContent.Contains("logout.php?"))
{
CQ dom = responseContent;
dom["#loginform > table"].Remove();
var errorMessage = dom["#loginform"].Text().Trim().Replace("\n\t", " ");
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(this, configSaveData);
IsConfigured = true;
}
}
public async Task VerifyConnection()
{
var response = await client.GetStringAsync(BaseUrl);
if (!response.Contains("logout.php?"))
throw new Exception("Detected as not logged in");
}
public void LoadFromSavedConfiguration(Newtonsoft.Json.Linq.JToken jsonConfig)
{
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
IsConfigured = true;
}
void FillReleaseInfoFromJson(ReleaseInfo release, JObject r)
{
var id = r["torrentId"];
release.Size = (long)r["size"];
release.Seeders = (int)r["seeders"];
release.Peers = (int)r["leechers"] + release.Seeders;
release.Guid = new Uri(GuidUrl + id);
release.Comments = release.Guid;
release.Link = new Uri(DownloadUrl + id);
}
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
var results = await client.GetStringAsync(episodeSearchUrl);
var json = JObject.Parse(results);
foreach (JObject r in json["response"]["results"])
{
var pubDate = UnixTimestampToDateTime(double.Parse((string)r["groupTime"]));
var groupName = (string)r["groupName"];
if (r["torrents"] is JArray)
{
foreach (JObject t in r["torrents"])
{
var release = new ReleaseInfo();
release.PublishDate = pubDate;
release.Title = groupName;
release.Description = groupName;
FillReleaseInfoFromJson(release, t);
releases.Add(release);
}
}
else
{
var release = new ReleaseInfo();
release.PublishDate = pubDate;
release.Title = groupName;
release.Description = groupName;
FillReleaseInfoFromJson(release, r);
releases.Add(release);
}
}
}
return releases.ToArray();
}
static DateTime UnixTimestampToDateTime(double unixTime)
{
DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
long unixTimeStampInTicks = (long)(unixTime * TimeSpan.TicksPerSecond);
return new DateTime(unixStart.Ticks + unixTimeStampInTicks);
}
public Task<byte[]> Download(Uri link)
{
return client.GetByteArrayAsync(link);
}
}
}

View File

@ -17,48 +17,16 @@ namespace Jackett
static void Main(string[] args)
{
//var descRegex = new Regex("Uploaded (?<month>.*?)-(?<day>.*?) (?<year>.*?), Size (?<size>.*?) (?<unit>.*?), ULed");
var descRegex = new Regex("Uploaded (?<month>.*?)-(?<day>.*?) (?<year>.*?), Size (?<size>.*?) (?<unit>.*?), ULed by");
var m = descRegex.Match(("Uploaded 06-03 2013, Size 329.84 MiB, ULed by"));
List<string> matches = new List<string>();
var date = m.Groups["month"].Value;
for (var i = 0; i < m.Groups.Count; i++)
try
{
var group = m.Groups[i];
matches.Add(group.Value); ;
if (!Directory.Exists(AppConfigDirectory))
Directory.CreateDirectory(AppConfigDirectory);
}
//Uploaded 08-02&nbsp;2007, Size 47.15&nbsp;MiB, ULed
//Uploaded (<date>.*?)&nbsp;2007, Size 47.15&nbsp;MiB, ULed
var resultPage = new ResultPage(new ChannelInfo
catch (Exception ex)
{
Title = "HDAccess",
Description = "Jackett for HDAccess",
Link = new Uri("http://hdaccess.net"),
ImageUrl = new Uri("https://hdaccess.net/logo_small.png"),
ImageTitle = "HDAccess",
ImageLink = new Uri("https://hdaccess.net"),
ImageDescription = "Jackett for HDAccess"
});
resultPage.Releases.Add(new ReleaseInfo
{
Title = "Better Call Saul S01E05 Alpine Shepherd 1080p NF WEBRip DD5.1 x264",
Guid = new Uri("https://hdaccess.net/details.php?id=11515"),
Link = new Uri("https://hdaccess.net/download.php?torrent=11515&amp;passkey=123456"),
Comments = new Uri("https://hdaccess.net/details.php?id=11515&amp;hit=1#comments"),
PublishDate = DateTime.Now,
Category = "HDTV 1080p",
Size = 2538463390,
Description = "Better.Call.Saul.S01E05.Alpine.Shepherd.1080p.NF.WEBRip.DD5.1.x264.torrent",
Seeders = 7,
Peers = 6,
InfoHash = "63e07ff523710ca268567dad344ce1e0e6b7e8a3",
MinimumRatio = 1.0,
MinimumSeedTime = 172800
});
var f = resultPage.ToXml(new Uri("http://localhost:9117"));
Console.WriteLine(ex.Message);
Console.WriteLine("Could not create settings directory");
}
Task.Run(() =>
{

View File

@ -44,7 +44,23 @@ namespace Jackett
public async void Start()
{
listener.Start();
Console.WriteLine("Starting HTTP server...");
try
{
listener.Start();
}
catch (HttpListenerException ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine("App must be ran as Admin for permission to use port");
return;
}
catch (Exception ex)
{
Console.WriteLine("Error " + ex.ToString());
return;
}
Console.WriteLine("Server started on port 9117");
while (true)
{
var context = await listener.GetContextAsync();
@ -60,6 +76,7 @@ namespace Jackett
async void ProcessHttpRequest(HttpListenerContext context)
{
Console.WriteLine("Received request: " + context.Request.Url.ToString());
Exception exception = null;
try
{