Skip to content

Commit

Permalink
- App will now download original sized images from Deviantart (Issue#1)
Browse files Browse the repository at this point in the history
- minor fixes and improvements
  • Loading branch information
sentouki committed Nov 10, 2020
1 parent ac5e7c1 commit 5d5f759
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
37 changes: 29 additions & 8 deletions ArtAPI/DeviantArtAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ private const string
ClientID = "12774",
ClientSecret = "597114f315705b9624c7c1d74ad729e1",
AUTH_URL = "https://www.deviantart.com/oauth2/token",
GALLERY_URL = "https://www.deviantart.com/api/v1/oauth2/gallery/all?mature_content=true&limit=20&username={0}&offset=";
GALLERY_URL = "https://www.deviantart.com/api/v1/oauth2/gallery/all?mature_content=true&limit=20&username={0}&offset=",
ORIGINIMAGE_URL = "https://www.deviantart.com/api/v1/oauth2/deviation/download/{0}?mature_content=true";

private const int Offset = 20;

Expand Down Expand Up @@ -54,21 +55,41 @@ protected override async Task GetImagesMetadataAsync(string apiUrl)
var responseJson = JObject.Parse(rawResponse);
var Gallery = (JContainer)responseJson["results"];
if (!(Gallery.HasValues)) return; // check if the user has any images in his gallery
foreach (var image in Gallery)
var tasks = Gallery.Select(async (image) =>
{
if (image["content"] == null) continue;
if (image["content"] == null) return;
var deviationID = image["deviationid"].ToString();
ImagesToDownload.Add(new ImageModel()
{
Url = image["content"]["src"].ToString(),
Url = (await GetOriginImage(deviationID) is { } url) ? url : image["content"]["src"].ToString(), // try to get the origin image, use the scaled down image if fails
Name = image["title"].ToString(),
ID = image["deviationid"].ToString(),
FileType = image["content"]["src"].ToString().Split('?')[0].Split('/').Last().Split('.')[1] // maybe not the best way but surely the the easiest one
ID = deviationID,
FileType = image["content"]["src"].ToString().Split('?')[0].Split('/').Last()
.Split('.')[1] // maybe not the best way but surely the the easiest one
});
}
});
await Task.WhenAll(tasks);
if (responseJson["has_more"].ToString() == "False") return;
paginationOffset += Offset;
}
}
/// <summary>
/// get the Url to the origin image, not the scaled down one
/// </summary>
private async Task<string> GetOriginImage(string deviationID)
{
try
{
var rawResponse = await Client.GetStringAsync(string.Format(ORIGINIMAGE_URL, deviationID))
.ConfigureAwait(false);
var responseJson = JObject.Parse(rawResponse);
return responseJson["src"].ToString();
}
catch (HttpRequestException)
{
return null;
}
}

public override async Task<bool> auth(string refreshToken)
{
Expand All @@ -89,7 +110,7 @@ public override async Task<bool> auth(string refreshToken)
Client.DefaultRequestHeaders.Remove("Authorization");
Client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jsonResponse["access_token"]}");
}
catch(HttpRequestException)
catch (HttpRequestException)
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Artify/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
</Grid.RowDefinitions>
<TextBlock x:Name="Notification" Text="{Binding Notification}" Grid.Row="0" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="23" TextWrapping="Wrap" TextAlignment="Center"/>
</Grid>
<Image x:Name="SelectedPlatformIcon" Grid.Column="1" Grid.Row="0" Margin="25">
<Image x:Name="SelectedPlatformIcon" Grid.Column="1" Grid.Row="0" Margin="25" MouseLeftButtonDown="SelectedPlatformIcon_MouseLeftButtonDown">
<!-- #region DataTriggers -->
<Image.Style>
<Style TargetType="{x:Type Image}">
Expand Down
7 changes: 7 additions & 0 deletions Artify/Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,14 @@ private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
HideSelectionMenu();
}
}
private void SelectedPlatformIcon_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
ShowSelectionMenu();
}

private void WindowChromeOnMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton != MouseButton.Left) return;
ResizeMode = ResizeMode.NoResize;
DragMove();
}
Expand Down Expand Up @@ -121,6 +127,7 @@ private void UserInputField_GotFocus(object sender, RoutedEventArgs e)
UserInputField.Tag = true;
InputValidationLabel.Content = "";
}

private void HideSelectionMenuAnimation_Completed(object sender, EventArgs e)
{
SelectionMenu.Visibility = Visibility.Hidden;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Press ***ESC*** to select another platform

#### Running the app
- [.NET Core 3.1 Runtime](https://dotnet.microsoft.com/download/visual-studio-sdks)
- or download the [self-contained version](https://github.com/sentouki/Artify/releases/download/v1.3.0/Artify.selfcontained.zip)
- or download the [self-contained version](https://github.com/sentouki/Artify/releases/download/v1.4.0/Artify.selfcontained.zip)

#### Building the app
- [.NET Core 3.1 SDK](https://dotnet.microsoft.com/download/visual-studio-sdks)
Expand Down

0 comments on commit 5d5f759

Please sign in to comment.