fix(indexers): fixed and optimized xthor indexer

* feat(utils): added sha1 hash function and refactored md5 hash function

* fix(indexers): now use cross plateform path building for dev mode

* fix(indexers): fix output log of xthor for dev mode

* feat(release): added ToString method

* refactor(dev): optimized dev mode

* style(clean): cleanup code

* feat(indexer): added tmdb info to releases

* fix(cat): enabled categories on xthor
This commit is contained in:
JigSaw
2017-08-13 20:49:03 +02:00
committed by GitHub
parent 7a8d83b693
commit 8707e6b2e9
3 changed files with 112 additions and 44 deletions

View File

@@ -55,20 +55,46 @@ namespace Jackett.Utils
return new FormUrlEncodedContent(dict).ReadAsStringAsync().Result;
}
public static string Hash(string input)
/// <summary>
/// Convert an array of bytes to a string of hex digits
/// </summary>
/// <param name="bytes">array of bytes</param>
/// <returns>String of hex digits</returns>
public static string HexStringFromBytes(byte[] bytes)
{
var sb = new StringBuilder();
foreach (byte b in bytes)
{
var hex = b.ToString("x2");
sb.Append(hex);
}
return sb.ToString();
}
/// <summary>
/// Compute hash for string encoded as UTF8
/// </summary>
/// <param name="s">String to be hashed</param>
/// <returns>40-character hex string</returns>
public static string HashSHA1(string s)
{
var sha1 = SHA1.Create();
byte[] bytes = Encoding.UTF8.GetBytes(s);
byte[] hashBytes = sha1.ComputeHash(bytes);
return HexStringFromBytes(hashBytes);
}
public static string Hash(string s)
{
// Use input string to calculate MD5 hash
MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(s);
byte[] hashBytes = md5.ComputeHash(inputBytes);
// Convert the byte array to hexadecimal string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString();
return HexStringFromBytes(hashBytes);
}
public static string GetExceptionDetails(this Exception exception)