-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.cs
125 lines (104 loc) · 3.91 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.IO;
using System.Collections.Generic;
using System.Net;
using System.Data;
using System.Net.NetworkInformation;
using Wox.Plugin;
using Newtonsoft.Json;
public class MovieSearch
{
public DataTable Search { get; set; }
public int totalResults { get; set; }
public bool Response { get; set; }
public string Error { get; set; }
}
public class Movie
{
public string Title { get; set; }
public string Year { get; set; }
public string Rated { get; set; }
public string Released { get; set; }
public string Runtime { get; set; }
public string Genre { get; set; }
public string Director { get; set; }
public string Writer { get; set; }
public string Actors { get; set; }
public string Plot { get; set; }
public string Language { get; set; }
public string Country { get; set; }
public string Awards { get; set; }
public string Poster { get; set; }
public DataTable Ratings { get; set; }
public string Metascore { get; set; }
public string imdbRating { get; set; }
public string imdbVotes { get; set; }
public string imdbID { get; set; }
public string Type { get; set; }
public string DVD { get; set; }
public string BoxOffice { get; set; }
public string Production { get; set; }
public string Website { get; set; }
public string Resposnse { get; set; } //can't be read as bool for some reason
}
namespace Wox.Plugin.Test
{
public class Program : IPlugin
{
public void Init(PluginInitContext context)
{
}
public List<Result> Query(Query query)
{
List<Result> results = new List<Result>();
String defaulticon = "image.png";
var queryString = query.Search;
if(string.IsNullOrWhiteSpace(queryString) || queryString.Length <= 1)
{
results.Add(Result("Enter Movie to Search for:", "", defaulticon, Action("null")));
return results;
}
var movieSearchJSON = new WebClient().DownloadString("http://www.omdbapi.com/?s=" + queryString + "&apikey=b57d40cf");
MovieSearch movieSearch = JsonConvert.DeserializeObject<MovieSearch>(movieSearchJSON);
if(!movieSearch.Response)
{
results.Add(Result("No Title found.", "No Title found.", defaulticon, Action("null")));
return results;
}
foreach (DataRow row in movieSearch.Search.Rows)
{
var movieJSON = new WebClient().DownloadString("http://www.omdbapi.com/?i=" + row["imdbID"] + "&apikey=b57d40cf");
Movie movie = JsonConvert.DeserializeObject<Movie>(movieJSON);
if (movie.Resposnse == "false")
{
continue;
}
results.Add(Result(movie.Title + " by " + movie.Director + " | " + movie.Actors, movie.Plot, defaulticon, Action(movie.imdbID)));
}
return results;
}
private static Result Result(String title, String subtitle, String icon, Func<ActionContext, bool> action)
{
return new Result()
{
Title = title,
SubTitle = subtitle,
IcoPath = icon,
Action = action
};
}
// The Action method is called after the user selects the item
private static Func<ActionContext, bool> Action(String text)
{
return e =>
{
if(text.StartsWith("tt"))
{
System.Diagnostics.Process.Start("https://www.imdb.com/title/"+text);
}
// return false to tell Wox don't hide query window, otherwise Wox will hide it automatically
return false;
};
}
}
}