Skip to content

Commit

Permalink
Added DeviantArt support; Small UI Changes (changed the icons)
Browse files Browse the repository at this point in the history
  • Loading branch information
sentouki committed Jul 13, 2020
1 parent 8d0ee48 commit 15503f6
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 20 deletions.
4 changes: 4 additions & 0 deletions ArtAPI/ArtAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\PublishProfiles\" />
</ItemGroup>

</Project>
7 changes: 1 addition & 6 deletions ArtAPI/ArtStationAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@ public override async Task<bool> CheckArtistExistsAsync(string artistName)
return response.IsSuccessStatusCode;
}

public override async Task GetImagesAsync(string artistUrl)
{
await GetImagesAsync(new Uri(artistUrl)).ConfigureAwait(false);
}

public override async Task GetImagesAsync(Uri artistUrl)
{
OnDownloadStateChanged(new DownloadStateChangedEventArgs(State.DownloadPreparing));
var artistname = artistUrl?.AbsolutePath.Split('/')[1];
if (artistname == null) return;
CreateSaveDir(artistname);
await GetImagesMetadataAsync(string.Format(ApiUrl, artistname)).ConfigureAwait(false);
await DownloadImagesAsync().ConfigureAwait(false);
}

protected override async Task GetImagesMetadataAsync(string apiUrl)
Expand Down Expand Up @@ -60,7 +56,6 @@ protected override async Task GetImagesMetadataAsync(string apiUrl)
try { await t.ConfigureAwait(false); }
catch (Exception e)
{ OnDownloadStateChanged(new DownloadStateChangedEventArgs(State.DownloadCanceled, e.Message)); return; }
await DownloadImagesAsync().ConfigureAwait(false);
}

// get all the images from a project
Expand Down
95 changes: 95 additions & 0 deletions ArtAPI/DeviantArtAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace ArtAPI
{
public sealed class DeviantArtAPI : RequestArt
{
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=";

private const int Offset = 20;

public bool IsLoggedIn { get; private set; }

public override Uri CreateUrlFromName(string artistName)
{
return new Uri($"https://www.deviantart.com/{artistName}");
}

public override async Task<bool> CheckArtistExistsAsync(string artistName)
{
var response = await Client.GetAsync($"https://www.deviantart.com/{artistName}");
return response.IsSuccessStatusCode;
}

public override async Task GetImagesAsync(Uri artistUrl)
{
if (!IsLoggedIn)
{
OnDownloadStateChanged(new DownloadStateChangedEventArgs(State.DownloadCanceled, "not logged in"));
return;
}
OnDownloadStateChanged(new DownloadStateChangedEventArgs(State.DownloadPreparing));
var artistName = artistUrl?.AbsolutePath.Split('/')[1];
if (artistName == null) return;
CreateSaveDir(artistName);
await GetImagesMetadataAsync(string.Format(GALLERY_URL, artistName)).ConfigureAwait(false);
await DownloadImagesAsync().ConfigureAwait(false);
}

protected override async Task GetImagesMetadataAsync(string apiUrl)
{
var paginationOffset = 0;
while (true)
{
var rawResponse = await Client.GetStringAsync(apiUrl + paginationOffset).ConfigureAwait(false);
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)
{
if (image["content"] == null) continue;
ImagesToDownload.Add(new ImageModel()
{
Url = image["content"]["src"].ToString(),
Name = image["title"].ToString(),
ID = image["deviationid"].ToString()
}
);
}
if (responseJson["has_more"].ToString() == "False") return;
paginationOffset += Offset;
}
}

public override async Task<bool> auth(string refreshToken)
{
var data = new Dictionary<string, string>()
{
{"grant_type", "client_credentials" },
{"client_id", ClientID},
{"client_secret", ClientSecret}
};
using var content = new FormUrlEncodedContent(data);
try
{
var response = await Client.PostAsync(AUTH_URL, content).ConfigureAwait(false);
var jsonResponse = JObject.Parse(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
if (jsonResponse["status"].ToString() == "error") return false;
Client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jsonResponse["access_token"]}");
}
catch(HttpRequestException)
{
return false;
}
return IsLoggedIn = true;
}
}
}
7 changes: 1 addition & 6 deletions ArtAPI/PixivAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ private async Task<string> GetArtistName(string artistID)
return JObject.Parse(response)["body"]["user_details"]["user_name"].ToString();
}

public override async Task GetImagesAsync(string ArtistUrl)
{
await GetImagesAsync(new Uri(ArtistUrl)).ConfigureAwait(false);
}

public override async Task GetImagesAsync(Uri artistUrl)
{
OnDownloadStateChanged(new DownloadStateChangedEventArgs(State.DownloadPreparing));
Expand All @@ -75,6 +70,7 @@ public override async Task GetImagesAsync(Uri artistUrl)
{
await GetImagesMetadataAsync(string.Format(APIUrlWithoutLogin, artistID)).ConfigureAwait(false);
}
await DownloadImagesAsync().ConfigureAwait(false);
}

protected override async Task GetImagesMetadataAsync(string apiUrl)
Expand Down Expand Up @@ -114,7 +110,6 @@ await GetImageURLsWithoutLoginAsync(string.Format(IllustProjectUrl, illust_id))
{
OnDownloadStateChanged(new DownloadStateChangedEventArgs(State.DownloadCanceled, e.Message));
}
await DownloadImagesAsync().ConfigureAwait(false);
}

private async Task GetImageURLsWithoutLoginAsync(string illustProject)
Expand Down
9 changes: 7 additions & 2 deletions Artify/Artify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<ApplicationIcon>assets/icons/artify.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<None Remove="assets\logos\artstation_logo.png" />
<None Remove="assets\logos\deviantart_logo.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PropertyChanged.Fody" Version="3.2.8" />
</ItemGroup>
Expand All @@ -17,7 +22,6 @@

<ItemGroup>
<Resource Include="assets\icons\artify.png" />
<Resource Include="assets\icons\artify2.png" />
<Resource Include="assets\icons\check_box.png" />
<Resource Include="assets\icons\check_box_outline_blank.png" />
<Resource Include="assets\icons\close.png" />
Expand All @@ -26,7 +30,8 @@
<Resource Include="assets\icons\minimize.png" />
<Resource Include="assets\icons\open_in_full.png" />
<Resource Include="assets\icons\settings.png" />
<Resource Include="assets\logos\ArtStation-logomark-white.png" />
<Resource Include="assets\logos\artstation_logo.png" />
<Resource Include="assets\logos\deviantart_logo.png" />
<Resource Include="assets\logos\pixiv_logo.png" />
</ItemGroup>

Expand Down
6 changes: 4 additions & 2 deletions Artify/Models/ArtifyModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ public class ArtifyModel
{
{"general", new Regex(@"(https?://)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}(\/?[a-zA-Z0-9]*\/?)*") },
{"artstation", new Regex(@"(https://)?(www\.)?artstation\.com/[0-9a-zA-Z]+/?") },
{"pixiv", new Regex(@"(https://)?(www\.)?pixiv\.net/[a-z]{0,6}/users/[0-9]+/?") }
{"pixiv", new Regex(@"(https://)?(www\.)?pixiv\.net/[a-z]{0,6}/users/[0-9]+/?") },
{"deviantart", new Regex(@"(https://)?(www\.)?deviantart\.com/[0-9a-zA-Z]+/?")}
};
// container for the classes
private readonly Dictionary<string, Func<IRequestArt>> ArtPlatform = new Dictionary<string, Func<IRequestArt>>()
{
{ "artstation", () => new ArtStationAPI() },
{ "pixiv", () => new PixivAPI() }
{ "pixiv", () => new PixivAPI() },
{ "deviantart", () => new DeviantArtAPI()}
};
public IRequestArt Platform
{
Expand Down
10 changes: 8 additions & 2 deletions Artify/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,14 @@
<Style TargetType="{x:Type Image}">
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedPlatform}" Value="artstation">
<Setter Property="Source" Value="../assets/logos/ArtStation-logomark-white.png"/>
<Setter Property="Source" Value="../assets/logos/artstation_logo.png"/>
</DataTrigger>
<DataTrigger Binding="{Binding SelectedPlatform}" Value="pixiv">
<Setter Property="Source" Value="../assets/logos/pixiv_logo.png"/>
</DataTrigger>
<DataTrigger Binding="{Binding SelectedPlatform}" Value="deviantart">
<Setter Property="Source" Value="../assets/logos/deviantart_logo.png"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
Expand All @@ -117,7 +120,10 @@
</Grid.RowDefinitions>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Tag="artstation" Click="SelectionMenuButton_Click" Style="{StaticResource SelectPlatformMenu}">
<Image Source="../assets/logos/ArtStation-logomark-white.png"/>
<Image Source="../assets/logos/artstation_logo.png"/>
</Button>
<Button Tag="deviantart" Click="SelectionMenuButton_Click" Style="{StaticResource SelectPlatformMenu}">
<Image Source="../assets/logos/deviantart_logo.png"/>
</Button>
<Button Tag="pixiv" Click="SelectionMenuButton_Click" Style="{StaticResource SelectPlatformMenu}">
<Image Source="../assets/logos/pixiv_logo.png"/>
Expand Down
Binary file modified Artify/assets/icons/artify.ico
Binary file not shown.
Binary file removed Artify/assets/icons/artify2.png
Binary file not shown.
Binary file removed Artify/assets/logos/ArtStation-logomark-white.png
Binary file not shown.
Binary file added Artify/assets/logos/artstation_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Artify/assets/logos/deviantart_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Artify/assets/logos/pixiv_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Artify ![Artify](https://raw.githubusercontent.com/sentouki/Artify/master/Artify/assets/icons/artify.png)
###### a fun project of mine
## Description
Artify allows you to easily download artwork from an artist.
Artify allows you to easily download artwork of an artist from a platform of your choice.
The App uses ArtAPI lib which is also part of this project.

## Using
Expand All @@ -13,7 +13,7 @@ Press ***ESC*** to select another platform
#### Available platforms
- [x] ArtStation
- [x] Pixiv (with & without login¹)
- [ ] DeviantArt
- [x] DeviantArt

##### Warning
- Do NOT overuse this program as the platforms may ban your IP (or even your account if you're logged in)
Expand All @@ -36,6 +36,7 @@ Please feel free to submit any feedback or issues you have
- [ArtStation Logo](https://www.artstation.com/about/logo)
- [Pixiv Logo](https://commons.wikimedia.org/wiki/File:Pixiv_Icon.svg)
- [Research on the Pixiv OAuth API](https://github.com/azuline/pixiv-api)
- [DeviantArt API](https://www.deviantart.com/developers/http/v1/20200519)
- [UI icons](https://material.io/resources/icons/)
-------------------

Expand Down

0 comments on commit 15503f6

Please sign in to comment.