forked from Fishes/TMDbWrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheMovieDbMovie.cs
178 lines (165 loc) · 7.27 KB
/
TheMovieDbMovie.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TmdbWrapper.Cache;
using TmdbWrapper.Image;
using TmdbWrapper.Movies;
using TmdbWrapper.Search;
using TmdbWrapper.Utilities;
namespace TmdbWrapper
{
/// <summary>
/// Enumeration of extras that should be prefilled on retrieving the movie info
/// </summary>
[Flags]
public enum MovieExtras
{
/// <summary>
/// Retrieve the cast
/// </summary>
casts = 1
}
public static partial class TheMovieDb
{
/// <summary>
/// Gets a movie by the movie database id.
/// </summary>
/// <param name="MovieID">Id of the movie</param>
/// <param name="extra">Indicates which parts should be prefetched.</param>
/// <returns>The specified movie.</returns>
public static async Task<Movie> GetMovieAsync(int MovieID, MovieExtras extra = 0)
{
Movie movie = DatabaseCache.GetObject<Movie>(MovieID);
if (movie == null)
{
Request<Movie> request = new Request<Movie>("movie/" + MovieID.ToString());
if (!string.IsNullOrEmpty(Language))
request.AddParameter("language", Language);
if (extra != 0)
{
request.AddParameter("append_to_response", extra.ToString().Replace(" ", ""));
}
movie = await request.ProcesRequestAsync();
DatabaseCache.SetObject(MovieID, movie);
}
return movie;
}
/// <summary>
/// Gets a movie by the IMDB id.
/// </summary>
/// <param name="IMDBId">The IMDB id</param>
/// <returns>The specified movie.</returns>
public static async Task<Movie> GetMovieByIMDBAsync(string IMDBId)
{
Request<Movie> request = new Request<Movie>("movie/" + IMDBId);
if (!string.IsNullOrEmpty(Language))
request.AddParameter("language", Language);
return await request.ProcesRequestAsync();
}
/// <summary>
/// Gets a list of altenative titles for the specified country
/// </summary>
/// <param name="MovieID">Id of the movie</param>
/// <param name="Country">Code of the country</param>
/// <returns>A list of alternative titles.</returns>
public static async Task<IReadOnlyList<AlternativeTitle>> GetMovieAlternateTitlesAsync(int MovieID, string Country)
{
Request<AlternativeTitle> request = new Request<AlternativeTitle>("movie/" + MovieID.ToString() + "/alternative_titles");
if (!string.IsNullOrEmpty(Country))
request.AddParameter("country", Country);
return await request.ProcesRequestListAsync("titles");
}
/// <summary>
/// Gets the credits of a specific movie.
/// </summary>
/// <param name="MovieID">The id of the movie.</param>
/// <returns>The credits of the movie.</returns>
public static async Task<Credits> GetMovieCastAsync(int MovieID)
{
Credits credits = DatabaseCache.GetObject<Credits>(MovieID);
if (credits == null)
{
Request<Credits> request = new Request<Credits>(string.Format("movie/{0}/casts", MovieID));
credits = await request.ProcesRequestAsync();
DatabaseCache.SetObject(MovieID, credits);
}
return credits;
}
/// <summary>
/// All images of a specific movie.
/// </summary>
/// <param name="MovieID">The id of the movie.</param>
/// <returns>The images.</returns>
public static async Task<Images> GetMovieImagesAsync(int MovieID)
{
Images images = DatabaseCache.GetObject<Images>(MovieID);
if (images == null)
{
Request<Images> request = new Request<Images>("movie/" + MovieID.ToString() + "/images");
if (!string.IsNullOrEmpty(Language))
request.AddParameter("language", Language);
images = await request.ProcesRequestAsync();
DatabaseCache.SetObject(MovieID, images);
}
return images;
}
/// <summary>
/// The keywords of a specific movie.
/// </summary>
/// <param name="MovieID">The id of the movie.</param>
/// <returns>A list of movie keywords.</returns>
public static async Task<IReadOnlyList<Keyword>> GetMovieKeywordsAsync(int MovieID)
{
Request<Keyword> request = new Request<Keyword>("movie/" + MovieID.ToString() + "/keywords");
return await request.ProcesRequestListAsync("keywords");
}
/// <summary>
/// Releases of a specific movie.
/// </summary>
/// <param name="MovieID">Id of the movie</param>
/// <returns>A list of releases.</returns>
public static async Task<IReadOnlyList<Release>> GetMovieReleasesAsync(int MovieID)
{
Request<Release> request = new Request<Release>("movie/" + MovieID.ToString() + "/releases");
return await request.ProcesRequestListAsync("releases");
}
/// <summary>
/// Gets the trailer of a specific movie.
/// </summary>
/// <param name="MovieID">The id of the movie.</param>
/// <returns>The trailers of the movie.</returns>
public static async Task<Trailers> GetMovieTrailersAsync(int MovieID)
{
Request<Trailers> request = new Request<Trailers>("movie/" + MovieID.ToString() + "/trailers");
if (!string.IsNullOrEmpty(Language))
request.AddParameter("language", Language);
return await request.ProcesRequestAsync();
}
/// <summary>
/// Gets movies that are similiar to the specified movie.
/// </summary>
/// <param name="MovieID">The specific movie.</param>
/// <param name="page">The request page of the search results, giving 0 will give all results.</param>
/// <returns>A result set with movie summaries.</returns>
public static async Task<SearchResult<MovieSummary>> GetSimilarMoviesAsync(int MovieID, int page = 1)
{
Request<MovieSummary> request = new Request<MovieSummary>("movie/" + MovieID.ToString() + "/similar_movies");
request.AddParameter("page", page);
if (!string.IsNullOrEmpty(Language))
request.AddParameter("language", Language);
return await request.ProcessSearchRequestAsync();
}
/// <summary>
/// Gets the languages that a specific movie is translated into.
/// </summary>
/// <param name="MovieID">The id of the movie.</param>
/// <returns></returns>
public static async Task<SpokenLanguage> GetMovieTranslationsAsync(int MovieID)
{
Request<SpokenLanguage> request = new Request<SpokenLanguage>("movie/" + MovieID.ToString() + "/translations");
return await request.ProcesRequestAsync();
}
}
}