Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added some extensions to search #142

Closed
Closed
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
21 changes: 17 additions & 4 deletions TMDbLib/Client/TMDbClientSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ public partial class TMDbClient

if (page >= 1)
req.AddParameter("page", page);
if (year >= 1)
req.AddParameter("year", year);
if (year >= 1) {
switch (method) {
case "tv":
req.AddParameter("first_air_date_year", year);
break;
default:
req.AddParameter("year", year);
break;
}
}
if (includeAdult.HasValue)
req.AddParameter("include_adult", includeAdult.Value ? "true" : "false");

Expand Down Expand Up @@ -83,9 +91,14 @@ public async Task<SearchContainer<SearchKeyword>> SearchKeyword(string query, in
return await SearchMethod<SearchContainer<SearchKeyword>>("keyword", query, page);
}

public async Task<SearchContainer<SearchTv>> SearchTvShow(string query, int page = 0)
public async Task<SearchContainer<SearchTv>> SearchTvShow(string query, int page = 0, int year = 0)
{
return await SearchMethod<SearchContainer<SearchTv>>("tv", query, page);
return await SearchMethod<SearchContainer<SearchTv>>("tv", query, page, year: year);
}

public async Task<SearchContainer<SearchTv>> SearchTvShow(string query, string language, int page = 0, int year = 0)
{
return await SearchMethod<SearchContainer<SearchTv>>("tv", query, page, language, year: year);
}
}
}
1 change: 1 addition & 0 deletions TMDbLib/Objects/Search/SearchMulti.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SearchMulti
public bool Adult { get; set; }
public DateTime? ReleaseDate { get; set; }
public MediaType Type { get; set; }
public List<int> GenreIds { get; set; }
public List<string> OriginCountry { get; set; }

public string MediaType
Expand Down
6 changes: 2 additions & 4 deletions TMDbLib/TMDbLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="RestSharp, Version=104.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.104.4.0\lib\net4\RestSharp.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Reference Include="RestSharp, Version=105.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\RestSharp.105.1.0\lib\net45\RestSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down Expand Up @@ -202,7 +201,6 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 1 addition & 1 deletion TMDbLib/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="RestSharp" version="104.4.0" targetFramework="net40" />
<package id="RestSharp" version="105.1.0" targetFramework="net45" />
</packages>
36 changes: 35 additions & 1 deletion TMDbLibTests/ClientSearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ public void TestSearchTvShow()
Assert.AreEqual("Breaking Bad", item.Name);
Assert.AreEqual("Breaking Bad", item.OriginalName);
Assert.AreEqual("en", item.OriginalLanguage);
Assert.AreEqual("/4yMXf3DW6oCL0lVPZaZM2GypgwE.jpg", item.PosterPath);
// has been replaced
// Assert.AreEqual("/4yMXf3DW6oCL0lVPZaZM2GypgwE.jpg", item.PosterPath);
Assert.IsNotNull(item.PosterPath);
Assert.AreEqual("Breaking Bad is an American crime drama television series created and produced by Vince Gilligan. Set and produced in Albuquerque, New Mexico, Breaking Bad is the story of Walter White, a struggling high school chemistry teacher who is diagnosed with inoperable lung cancer at the beginning of the series. He turns to a life of crime, producing and selling methamphetamine, in order to secure his family's financial future before he dies, teaming with his former student, Jesse Pinkman. Heavily serialized, the series is known for positioning its characters in seemingly inextricable corners and has been labeled a contemporary western by its creator.", item.Overview);
Assert.IsTrue(item.Popularity > 0);
Assert.IsTrue(item.VoteAverage > 0);
Expand All @@ -175,6 +177,37 @@ public void TestSearchTvShow()
Assert.AreEqual(1, item.OriginCountry.Count);
Assert.AreEqual("US", item.OriginCountry[0]);
}
/// <summary>
/// validate show search with language param
/// </summary>
[TestMethod]
public void TestSearchTvShowWithLanguage()
{
TestHelpers.SearchPages(i => _config.Client.SearchTvShow("Game of Thrones", "de", i).Result);
SearchContainer<SearchTv> result = _config.Client.SearchTvShow("Game of Thrones", "de").Result;
Assert.IsTrue(result.Results.Any());
SearchTv item = result.Results.SingleOrDefault(s => s.Id == 1399);
// validate language specific values
Assert.IsTrue(item.Overview.Contains("Handlung"));
Assert.IsTrue(item.Overview.Contains("Königreichen"));
Assert.IsTrue(item.Overview.Contains("Gefahr"));
}
/// <summary>
/// validate show search with language param
/// </summary>
[TestMethod]
public void TestSearchTvShowWithYear()
{
TestHelpers.SearchPages(i => _config.Client.SearchTvShow("Doctor Who", "de", i, 2005).Result);
SearchContainer<SearchTv> result = _config.Client.SearchTvShow("Doctor Who", "de", 0, 2005).Result;
Assert.IsTrue(result.Results.Any());
SearchTv item = result.Results.SingleOrDefault(s => s.Id == 57243);

TestHelpers.SearchPages(i => _config.Client.SearchTvShow("Doctor Who", "de", i, 1963).Result);
result = _config.Client.SearchTvShow("Doctor Who", "de", 0, 1963).Result;
Assert.IsTrue(result.Results.Any());
item = result.Results.SingleOrDefault(s => s.Id == 57243);
}

[TestMethod]
public void TestSearchMulti()
Expand All @@ -197,6 +230,7 @@ public void TestSearchMulti()
Assert.IsTrue(item.Popularity > 0);
Assert.IsTrue(item.VoteAverage > 0);
Assert.IsTrue(item.VoteCount > 0);
Assert.IsTrue(item.GenreIds.Any());

Assert.IsNotNull(item.OriginCountry);
Assert.AreEqual(2, item.OriginCountry.Count);
Expand Down