Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added paste and drop for URLs including .url shortcuts
- Loading branch information
1 parent
6a7c53c
commit ad6ae80
Showing
10 changed files
with
345 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace OnlyM.Core.Utils | ||
{ | ||
using System; | ||
using System.IO; | ||
using Serilog; | ||
|
||
public class FileDownloader | ||
{ | ||
public bool Download(Uri remoteUri, string localFile, bool overwrite) | ||
{ | ||
if (File.Exists(localFile) && !overwrite) | ||
{ | ||
return false; | ||
} | ||
|
||
try | ||
{ | ||
using (var wc = WebUtils.CreateWebClient()) | ||
{ | ||
wc.DownloadFile(remoteUri, localFile); | ||
return true; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Logger.Error(ex, $"Could not download {remoteUri}"); | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace OnlyM.Core.Utils | ||
{ | ||
using System; | ||
using HtmlAgilityPack; | ||
|
||
public static class WebPageTitleHelper | ||
{ | ||
public static string Get(Uri webPageAddress) | ||
{ | ||
using (var wc = WebUtils.CreateWebClient()) | ||
{ | ||
var pageHtml = wc.DownloadString(webPageAddress); | ||
if (string.IsNullOrEmpty(pageHtml)) | ||
{ | ||
return null; | ||
} | ||
|
||
var document = new HtmlDocument(); | ||
document.LoadHtml(pageHtml); | ||
return document.DocumentNode?.SelectSingleNode("html/head/title")?.InnerText; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace OnlyM.Core.Utils | ||
{ | ||
using System.Net; | ||
using System.Text; | ||
|
||
public static class WebUtils | ||
{ | ||
private const string UserAgent = "SoundBox (+https://soundboxsoftware.com)"; | ||
|
||
public static WebClient CreateWebClient() | ||
{ | ||
var wc = new WebClient { Encoding = Encoding.UTF8 }; | ||
wc.Headers.Add("user-agent", UserAgent); | ||
return wc; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.