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

实现了通过SauceNAO API和Imger API实现以图搜源 #19

Merged
20 commits merged into from
Oct 8, 2019
Merged
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
Binary file added PixivFSUWP/Assets/SauceNAO.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions PixivFSUWP/IllustDetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
{
((Frame.Parent as Grid)?.Parent as MainPage)?.SelectNavPlaceholder(GetResourceString("DetailPlain"));
illustID = (int)e.Parameter;
System.Diagnostics.Debug.WriteLine("View Pixiv ID = " + illustID.ToString());
base.OnNavigatedTo(e);
_ = loadContent();
}
Expand Down
4 changes: 2 additions & 2 deletions PixivFSUWP/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
<NavigationView.PaneFooter>
<StackPanel Orientation="Horizontal">
<AppBarButton Width="48" x:Name="btnMe" Click="BtnMe_Click">
<Grid Margin="-10">
<Grid Margin="-7">
<ProgressRing x:Name="avatarRing" Height="20" Width="20" IsActive="True"/>
<Ellipse VerticalAlignment="Center" Height="24" Width="24">
<Ellipse.Fill>
<ImageBrush x:Name="imgAvatar"/>
<ImageBrush x:Name="imgAvatar" Stretch="UniformToFill"/>
</Ellipse.Fill>
</Ellipse>
</Grid>
Expand Down
42 changes: 41 additions & 1 deletion PixivFSUWP/MultilingualResources/PixivFSUWP.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,49 @@
</trans-unit>
<trans-unit id="NewComment.Content" translate="yes" xml:space="preserve">
<source>New comment</source>
<target state="new">New comment</target>
<target state="needs-review-translation" state-qualifier="tm-suggestion">新しいコメント</target>
<note from="MultilingualBuild" annotates="source" priority="2">ToggleButton</note>
</trans-unit>
<trans-unit id="BtnSauceNAO.Content" translate="yes" xml:space="preserve">
<source>SauceNAO</source>
<target state="new">SauceNAO</target>
<note from="MultilingualBuild" annotates="source" priority="2">Button +</note>
</trans-unit>
<trans-unit id="GoPixivID.PlaceholderText" translate="yes" xml:space="preserve">
<source>Pixiv ID</source>
<target state="new">Pixiv ID</target>
<note from="MultilingualBuild" annotates="source" priority="2">AutoSuggestBox +</note>
</trans-unit>
<trans-unit id="ImageDir.Text" translate="yes" xml:space="preserve">
<source>Image Saving Folder:</source>
<target state="new">Image Saving Folder:</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="ImgurAPI.Text" translate="yes" xml:space="preserve">
<source>Imgur API:</source>
<target state="new">Imgur API:</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="SauceNaoAPI.Text" translate="yes" xml:space="preserve">
<source>SauceNAO API:</source>
<target state="new">SauceNAO API:</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="SearchMore.Text" translate="yes" xml:space="preserve">
<source>More Search Methods</source>
<target state="new">More Search Methods</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="GoToPixivID.Text" translate="yes" xml:space="preserve">
<source>Pixiv ID</source>
<target state="new">Pixiv ID</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="QuickLS.Text" translate="yes" xml:space="preserve">
<source>Like &amp; Save</source>
<target state="new">Like &amp; Save</target>
<note from="MultilingualBuild" annotates="source" priority="2">MenuFlyoutItem +</note>
</trans-unit>
</group>
</body>
</file>
Expand Down
40 changes: 40 additions & 0 deletions PixivFSUWP/MultilingualResources/PixivFSUWP.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,46 @@
<target state="translated">撰写评论</target>
<note from="MultilingualBuild" annotates="source" priority="2">ToggleButton</note>
</trans-unit>
<trans-unit id="BtnSauceNAO.Content" translate="yes" xml:space="preserve">
<source>SauceNAO</source>
<target state="translated">SauceNAO 以图搜图</target>
<note from="MultilingualBuild" annotates="source" priority="2">Button +</note>
</trans-unit>
<trans-unit id="GoPixivID.PlaceholderText" translate="yes" xml:space="preserve">
<source>Pixiv ID</source>
<target state="translated">Pixiv ID</target>
<note from="MultilingualBuild" annotates="source" priority="2">AutoSuggestBox +</note>
</trans-unit>
<trans-unit id="ImageDir.Text" translate="yes" xml:space="preserve">
<source>Image Saving Folder:</source>
<target state="translated">图像保存目录:</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="ImgurAPI.Text" translate="yes" xml:space="preserve">
<source>Imgur API:</source>
<target state="new">Imgur API:</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="SauceNaoAPI.Text" translate="yes" xml:space="preserve">
<source>SauceNAO API:</source>
<target state="new">SauceNAO API:</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="SearchMore.Text" translate="yes" xml:space="preserve">
<source>More Search Methods</source>
<target state="translated">更多搜索功能</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="GoToPixivID.Text" translate="yes" xml:space="preserve">
<source>Pixiv ID</source>
<target state="translated">Pixiv ID 直达</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="QuickLS.Text" translate="yes" xml:space="preserve">
<source>Like &amp; Save</source>
<target state="translated">一键二连</target>
<note from="MultilingualBuild" annotates="source" priority="2">MenuFlyoutItem +</note>
</trans-unit>
</group>
</body>
</file>
Expand Down
40 changes: 40 additions & 0 deletions PixivFSUWP/MultilingualResources/PixivFSUWP.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,46 @@
<target state="translated">撰写评论</target>
<note from="MultilingualBuild" annotates="source" priority="2">ToggleButton</note>
</trans-unit>
<trans-unit id="BtnSauceNAO.Content" translate="yes" xml:space="preserve">
<source>SauceNAO</source>
<target state="translated">SauceNAO 以圖搜圖</target>
<note from="MultilingualBuild" annotates="source" priority="2">Button +</note>
</trans-unit>
<trans-unit id="GoPixivID.PlaceholderText" translate="yes" xml:space="preserve">
<source>Pixiv ID</source>
<target state="new">Pixiv ID</target>
<note from="MultilingualBuild" annotates="source" priority="2">AutoSuggestBox +</note>
</trans-unit>
<trans-unit id="ImageDir.Text" translate="yes" xml:space="preserve">
<source>Image Saving Folder:</source>
<target state="translated">圖像保存目錄</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="ImgurAPI.Text" translate="yes" xml:space="preserve">
<source>Imgur API:</source>
<target state="new">Imgur API:</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="SauceNaoAPI.Text" translate="yes" xml:space="preserve">
<source>SauceNAO API:</source>
<target state="new">SauceNAO API:</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="SearchMore.Text" translate="yes" xml:space="preserve">
<source>More Search Methods</source>
<target state="translated">更多功能</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="GoToPixivID.Text" translate="yes" xml:space="preserve">
<source>Pixiv ID</source>
<target state="translated">Pixiv ID 直達</target>
<note from="MultilingualBuild" annotates="source" priority="2">TextBlock +</note>
</trans-unit>
<trans-unit id="QuickLS.Text" translate="yes" xml:space="preserve">
<source>Like &amp; Save</source>
<target state="translated">一鍵收藏保存</target>
<note from="MultilingualBuild" annotates="source" priority="2">MenuFlyoutItem +</note>
</trans-unit>
</group>
</body>
</file>
Expand Down
10 changes: 9 additions & 1 deletion PixivFSUWP/PixivFSUWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@
<Compile Include="ReportIssuePage.xaml.cs">
<DependentUpon>ReportIssuePage.xaml</DependentUpon>
</Compile>
<Compile Include="SauceNAOPage.xaml.cs">
<DependentUpon>SauceNAOPage.xaml</DependentUpon>
</Compile>
<Compile Include="SearchPage.xaml.cs">
<DependentUpon>SearchPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -212,6 +215,7 @@
<Content Include="Assets\PixivHeader.png" />
<Content Include="Assets\PixivText.png" />
<None Include="Package.StoreAssociation.xml" />
<Content Include="Assets\SauceNAO.png" />
<Content Include="Assets\Square44x44Logo.targetsize-256_altform-unplated.png" />
<Content Include="Assets\Square71x71Logo.scale-200.png" />
<Content Include="Properties\Default.rd.xml" />
Expand Down Expand Up @@ -246,6 +250,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SauceNAOPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SearchPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -281,7 +289,7 @@
<Version>5.1.1</Version>
</PackageReference>
<PackageReference Include="PixivCS">
<Version>0.2.2</Version>
<Version>0.3.1</Version>
</PackageReference>
<PackageReference Include="Win2D.uwp">
<Version>1.23.0</Version>
Expand Down
28 changes: 28 additions & 0 deletions PixivFSUWP/SauceNAO/Imgur.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace PixivFSUWP.SauceNao
{
static class Imgur {
public static string Upload(byte[] Image, string apiKey) {
using (var w = new WebClient()) {
w.Headers.Add("Authorization: Client-ID " + apiKey);
var values = new NameValueCollection {
{ "image", Convert.ToBase64String(Image) }
};

string response = System.Text.Encoding.UTF8.GetString(w.UploadValues("https://api.imgur.com/3/upload", values));
Console.WriteLine(response);
dynamic dynObj = JsonConvert.DeserializeObject(response);
return dynObj.data.link;
}
}
}
}
28 changes: 28 additions & 0 deletions PixivFSUWP/SauceNAO/Pixiv.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PixivFSUWP.SauceNao.Sauces {
class Pixiv : Sauce {
static string ENDPOINT = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=";
public new string Url {
get { return GetUrl(); }
}

public Pixiv(dynamic data) : base((string) data.title, (int) data.pixiv_id, (string) data.member_name, (int) data.member_id) {}

public override string ToString() {
return String.Format("Title: {0}\nPixiv ID: {1}\nAuthor: {2} (#{3})\nURL: {4}", Title, SauceId, AuthorName, AuthorId, Url);
}

protected override string GetUrl() {
return ENDPOINT + SauceId;
}

public new static bool IsTheRightAdapterFor(dynamic data) {
return data.pixiv_id != null;
}
}
}
36 changes: 36 additions & 0 deletions PixivFSUWP/SauceNAO/Response.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using PixivFSUWP.SauceNao.Sauces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PixivFSUWP.SauceNao {
class Response {
private dynamic data;
private Type provider;

public Response(dynamic data) {
this.data = data;
this.provider = guessTheProvider();
}

private Type guessTheProvider() {
Type[] providers = { typeof(Pixiv) };

foreach(Type provider in providers) {
bool isTheRightAdapter = (bool) provider.GetMethod("IsTheRightAdapterFor").Invoke(null, new object[] { data });

if(isTheRightAdapter) {
return provider;
}
}

return null;
}

public Sauce GetResponse() {
return provider == null ? null : Activator.CreateInstance(provider, data);
}
}
}
25 changes: 25 additions & 0 deletions PixivFSUWP/SauceNAO/Result.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PixivFSUWP.SauceNao {
class Result {
public float Similarity;
public Sauce Response;

public Result(dynamic header, dynamic data) {
this.Similarity = (float) header.similarity;
this.Response = new Response(data).GetResponse();
}

public bool HasRecognizableSauce() {
return Response != null;
}

public override string ToString() {
return String.Format("Similarity: {0}\n{1}", Similarity, Response.ToString());
}
}
}
34 changes: 34 additions & 0 deletions PixivFSUWP/SauceNAO/Sauce.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PixivFSUWP.SauceNao {
class Sauce {
public string Title, AuthorName;
public int SauceId, AuthorId;
public string Url {
get { return GetUrl(); }
}

protected Sauce(string title, int sauceId, string authorName, int authorId) {
Title = title;
SauceId = sauceId;
AuthorName = authorName;
AuthorId = authorId;
}

public override string ToString() {
return String.Format("Title: {0}\nSauce ID: {1}\nAuthor: {2} (#{3})", Title, SauceId, AuthorName, AuthorId);
}

protected virtual string GetUrl() {
throw new NotImplementedException();
}

public static bool IsTheRightAdapterFor(dynamic data) {
throw new NotImplementedException();
}
}
}
Loading