Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
Improves detection in liked-by downloader
Browse files Browse the repository at this point in the history
- Uses a more generic regex pattern for matching images and videos in
the TumblrLikedByDownloader (#77).
  • Loading branch information
johanneszab committed May 14, 2017
1 parent 3fc23a4 commit b963599
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ private string ResizeTumblrImageUrl(string imageUrl)
.ToString();
}

/// <returns>
/// Return the url without the size and type suffix (e.g.
/// https://68.media.tumblr.com/51a99943f4aa7068b6fd9a6b36e4961b/tumblr_mnj6m9Huml1qat3lvo1).
/// </returns>
protected override string GetCoreImageUrl(string url)
{
return url.Split('_')[0] + "_" + url.Split('_')[1];
}

protected override bool CheckIfFileExistsInDirectory(string url)
{
string fileName = url.Split('/').Last();
Expand Down Expand Up @@ -199,10 +190,13 @@ private void AddPhotoUrlToDownloadList(string document, IList<string> tags)
{
if (blog.DownloadPhoto)
{
var regex = new Regex("data-big-photo=\"(.*)\" ");
var regex = new Regex("\"http[\\S]*media.tumblr.com[\\S]*(jpg|png|gif)\"");
foreach (Match match in regex.Matches(document))
{
string imageUrl = match.Groups[1].Value;
string imageUrl = match.Groups[0].Value;
if (imageUrl.Contains("avatar") || imageUrl.Contains("previews"))
continue;
imageUrl = imageUrl.Substring(1, imageUrl.Length - 2);
if (blog.SkipGif && imageUrl.EndsWith(".gif"))
{
continue;
Expand All @@ -218,10 +212,11 @@ private void AddVideoUrlToDownloadList(string document, IList<string> tags)
{
if (blog.DownloadVideo)
{
var regex = new Regex("<source src=\"(.*)\" type=\"video/mp4\"");
var regex = new Regex("\"http[\\S]*.com/video_file/[\\S]*\"");
foreach (Match match in regex.Matches(document))
{
string videoUrl = match.Groups[1].Value;
string videoUrl = match.Groups[0].Value;
videoUrl = videoUrl.Substring(1, videoUrl.Length - 2);
// FIXME: postId
if (shellService.Settings.VideoSize == 1080)
{
Expand Down

0 comments on commit b963599

Please sign in to comment.