Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Let users downloads Icons from Professional mode, that are only available to watchers of that deviation #208

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions FoliCon/Models/Api/DArtBrowseResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ public class Author
public string Type { get; set; }
}

public class PremiumFolderData
{
[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("has_access")]
public bool HasAccess { get; set; }

[JsonProperty("gallery_id")]
public string GallaryId { get; set; }
}

public class Stats
{
[JsonProperty("comments")]
Expand Down Expand Up @@ -108,6 +120,9 @@ public class Result

[JsonProperty("thumbs")]
public Thumb[] Thumbs { get; set; }

[JsonProperty("premium_folder_data")]
public PremiumFolderData PremiumFolderData { get; set; }
}

public class DArtBrowseResult
Expand Down
5 changes: 4 additions & 1 deletion FoliCon/Models/Data/DArtImageList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ public class DArtImageList : BindableBase
private string _url;
private BitmapSource _image;
private string _deviationId;
private bool _mustWatch;

public DArtImageList(string url, BitmapSource bmp)
{
Url = url ?? throw new ArgumentNullException(nameof(url));
Image = bmp ?? throw new ArgumentNullException(nameof(bmp));
}

public DArtImageList(string url, BitmapSource bmp, string deviationId) : this(url, bmp)
public DArtImageList(string url, BitmapSource bmp, string deviationId, bool mustWatch) : this(url, bmp)
{
DeviationId = deviationId ?? throw new ArgumentNullException(nameof(deviationId));
MustWatch = mustWatch;
}

public string Url { get => _url; set => SetProperty(ref _url, value); }
public BitmapSource Image { get => _image; set => SetProperty(ref _image, value); }
public string DeviationId { get => _deviationId; set => SetProperty(ref _deviationId, value); }
public bool MustWatch { get => _mustWatch; set => SetProperty(ref _mustWatch, value); }
}
55 changes: 42 additions & 13 deletions FoliCon/ViewModels/ProSearchResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public bool IsSearchFocused
}

public DelegateCommand SkipCommand { get; set; }
public DelegateCommand<object> PickCommand { get; set; }
public DelegateCommand<object> OpenImageCommand { get; set; }
public DelegateCommand<DArtImageList> PickCommand { get; set; }
public DelegateCommand<DArtImageList> OpenImageCommand { get; set; }
public DelegateCommand<object> ExtractManuallyCommand { get; set; }
public DelegateCommand SearchAgainCommand { get; set; }
public DelegateCommand StopSearchCommand { get; set; }
Expand All @@ -70,18 +70,23 @@ public ProSearchResultViewModel(IDialogService dialogService)
Logger.Debug("ProSearchResultViewModel Constructor");
ImageUrl = [];
StopSearchCommand = new DelegateCommand(delegate { StopSearch = true; });
PickCommand = new DelegateCommand<object>(PickMethod);
OpenImageCommand = new DelegateCommand<object>(OpenImageMethod);
PickCommand = new DelegateCommand<DArtImageList>(PickMethod);
OpenImageCommand = new DelegateCommand<DArtImageList>(OpenImageMethod);
ExtractManuallyCommand = new DelegateCommand<object>(ExtractManually);
SkipCommand = new DelegateCommand(SkipMethod);
SearchAgainCommand = new DelegateCommand(PrepareForSearch);
_dialogService = dialogService;
}

private void OpenImageMethod(object parameter)
private void OpenImageMethod(DArtImageList parameter)
{
Logger.Debug("Opening Image {Image}", parameter);
var link = (string)parameter;
if (parameter.MustWatch)
{
//TODO:watch
parameter.MustWatch = false;
}
var link = parameter.Url;
var browser = new ImageBrowser(link)
{
ShowTitle = false,
Expand Down Expand Up @@ -133,10 +138,17 @@ private async Task Search(string query, int offset = 0)
Logger.Debug("Total Posters: {TotalPosters} for {Title}", TotalPosters, query);
foreach (var item in searchResult.Results.GetEnumeratorWithIndex())
{
var mustWatch = false;
if (!item.Value.IsDownloadable)
{
Logger.Warn("Poster {Index} is not downloadable", item.Value.Url);
continue;
if (item.Value.PremiumFolderData is null || item.Value.PremiumFolderData.Type != "watchers")
{
Logger.Warn("Poster {URL} is not downloadable", item.Value.Url);
continue;
}
mustWatch = true;
Logger.Warn("Poster {URL} is not downloadable, but can be watched to download", item.Value.Url);

}
var response = await Services.HttpC.GetAsync(item.Value.Thumbs[0].Src);
if (response.StatusCode != HttpStatusCode.OK)
Expand All @@ -147,7 +159,8 @@ private async Task Search(string query, int offset = 0)
}
using (var bm = await response.GetBitmap())
{
ImageUrl.Add(new DArtImageList(item.Value.Content.Src, ImageUtils.LoadBitmap(bm), item.Value.Deviationid));
ImageUrl.Add(new DArtImageList(item.Value.Content.Src, ImageUtils.LoadBitmap(bm),
item.Value.Deviationid, mustWatch));
}
if (_stopSearch)
{
Expand Down Expand Up @@ -180,15 +193,31 @@ private async Task Search(string query, int offset = 0)
}
}

private void PickMethod(object parameter)
private void PickMethod(DArtImageList parameter)
{
if (parameter.MustWatch)
{
//TODO:Watch
parameter.MustWatch = false;
}
var link = parameter.Url;
ProcessPick(link);
}

private void PickMethod(string link)
{
ProcessPick(link);
}

private void ProcessPick(string link)
{
Logger.Debug("Picking Image {Image}", parameter);
Logger.Debug("Picking Image {Image}", link);
var extension = Path.GetExtension(new Uri(link).LocalPath) == ".ico" ? ".ico" : ".png";
SearchAgainTitle = null;
var link = (string)parameter;
var currentPath = $@"{_folderPath}\{Fnames[_i]}";
var tempImage = new ImageToDownload
{
LocalPath = $"{currentPath}\\{IconUtils.GetImageName()}.png",
LocalPath = $"{currentPath}\\{IconUtils.GetImageName()}{extension}",
RemotePath = new Uri(link)
};
Logger.Debug("Adding Image to Download List {@Image}", tempImage);
Expand Down
2 changes: 1 addition & 1 deletion FoliCon/Views/ProSearchResult.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<Image Source="{Binding Image}" Tag="{Binding }" Height="128" Width="128"
RenderOptions.BitmapScalingMode="HighQuality" Margin="5, 5, 5, 5">
<i:Interaction.Behaviors>
<ui:ClickBehavior CommandParameter="{Binding Path=Tag.Url, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Image}}}" DoubleClickCommand="{Binding RelativeSource={RelativeSource FindAncestor,
<ui:ClickBehavior CommandParameter="{Binding Path=Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Image}}}" DoubleClickCommand="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.(viewModels:ProSearchResultViewModel.PickCommand)}"
ClickCommand="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.(viewModels:ProSearchResultViewModel.OpenImageCommand)}"/>
Expand Down