Initial implementation of voice works scanning.
This commit is contained in:
49
JSMR.Infrastructure/Scanning/ScannerUtilities.cs
Normal file
49
JSMR.Infrastructure/Scanning/ScannerUtilities.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using HtmlAgilityPack;
|
||||
using System.Web;
|
||||
|
||||
namespace JSMR.Infrastructure.Scanning;
|
||||
|
||||
public static class ScannerUtilities
|
||||
{
|
||||
public static List<string> GetStringListFromNodes(List<HtmlNode> nodes)
|
||||
{
|
||||
return nodes
|
||||
.Where(node => string.IsNullOrEmpty(node.InnerHtml) == false)
|
||||
.Select(node => HttpUtility.HtmlDecode(node.InnerHtml))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static string GetDecodedText(HtmlNode node)
|
||||
{
|
||||
if (node == null)
|
||||
return string.Empty;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(node.InnerHtml))
|
||||
return string.Empty;
|
||||
|
||||
return HttpUtility.HtmlDecode(node.InnerHtml.Replace("\n", "")).Trim();
|
||||
}
|
||||
|
||||
public static string GetTextBetween(string text, string startText, string endText)
|
||||
{
|
||||
int startIndex = text.IndexOf(startText) + startText.Length;
|
||||
int endIndex = text.IndexOf(endText);
|
||||
|
||||
int length = endIndex - startIndex;
|
||||
|
||||
if (length <= 0)
|
||||
return "";
|
||||
|
||||
return text.Substring(startIndex, length);
|
||||
}
|
||||
|
||||
public static string GetImageSource(HtmlNode imageNode)
|
||||
{
|
||||
string imageSource = imageNode.GetAttributeValue("src", "");
|
||||
|
||||
if (string.IsNullOrEmpty(imageSource))
|
||||
imageSource = imageNode.GetAttributeValue("data-src", "");
|
||||
|
||||
return imageSource;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user