Guest User

Untitled

a guest
Oct 17th, 2017
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // GET: api/MovieInfo/5
  3. public JObject GetMovie(short id)
  4. {
  5. var data = db.Movies.Find(id);
  6.  
  7. return MovieData(data);
  8. }
  9.  
  10. JObject MovieData(Movie data)
  11. {
  12. string requestStringUA = $"https://api.themoviedb.org/3/search/{data.Extras}?page=1&query={data.Name}&api_key={key}";
  13. string requestStringRU = $"https://api.themoviedb.org/3/search/{data.Extras}?page=1&query={data.Name}&api_key={key}";
  14. string requestStringUS = $"https://api.themoviedb.org/3/search/{data.Extras}?page=1&query={data.Name}&api_key={key}";
  15.  
  16. if (data.Extras == "movie")
  17. requestStringUS = requestStringRU = requestStringUA += data.Year > 0 ? $"&year={data.Year}" : "";
  18. else if (data.Extras == "tv")
  19. requestStringUS = requestStringRU = requestStringUA += data.Year > 0 ? $"&first_air_date_year={data.Year}" : "";
  20.  
  21. requestStringUA += "&language=uk-UA";
  22. requestStringRU += "&language=ru-RU";
  23. requestStringUS += "&language=en-US";
  24.  
  25. var clientUA = new RestClient(requestStringUA);
  26. var clientRU = new RestClient(requestStringRU);
  27. var clientUS = new RestClient(requestStringUS);
  28.  
  29. var request = new RestRequest(Method.GET);
  30. request.AddParameter("undefined", "{}", ParameterType.RequestBody);
  31.  
  32. //ua try
  33. var json = JObject.Parse(clientUA.Execute(request).Content);
  34. if (json["total_results"] == null)
  35. return json;
  36. if (json["total_results"].Value<int>() > 0)
  37. {
  38. if (json["results"][0]["overview"].Value<string>() != "")
  39. return json;
  40. }
  41.  
  42. //ru try
  43. json = JObject.Parse(clientRU.Execute(request).Content);
  44. if (json["total_results"] == null)
  45. return json;
  46. if (json["total_results"].Value<int>() > 0)
  47. {
  48. if (json["results"][0]["overview"].Value<string>() != "")
  49. return json;
  50. }
  51.  
  52. //us
  53. return JObject.Parse(clientUS.Execute(request).Content);
  54. }
  55.  
  56. JObject MergeJsonObjects(params JObject[] objects)
  57. {
  58.  
  59. JObject json = new JObject();
  60. foreach (JObject JSONObject in objects)
  61. {
  62. foreach (var property in JSONObject)
  63. {
  64. string name = property.Key;
  65. JToken value = property.Value;
  66.  
  67. json.Add(name, value);
  68. }
  69. }
  70.  
  71. return json;
  72. }
RAW Paste Data