forked from Ombi-app/Ombi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tidusjar
committed
Apr 5, 2017
1 parent
1c301f2
commit e80f0bc
Showing
16 changed files
with
571 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Ombi.Core.Models.Search; | ||
|
||
namespace Ombi.Core | ||
{ | ||
public interface IMovieEngine | ||
{ | ||
Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies(); | ||
Task<IEnumerable<SearchMovieViewModel>> PopularMovies(); | ||
Task<IEnumerable<SearchMovieViewModel>> ProcessMovieSearch(string search); | ||
Task<IEnumerable<SearchMovieViewModel>> TopRatedMovies(); | ||
Task<IEnumerable<SearchMovieViewModel>> UpcomingMovies(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#region Copyright | ||
// /************************************************************************ | ||
// Copyright (c) 2017 Jamie Rees | ||
// File: SearchMovieViewModel.cs | ||
// Created By: Jamie Rees | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// ************************************************************************/ | ||
#endregion | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Ombi.Core.Models.Search | ||
{ | ||
public class SearchMovieViewModel : SearchViewModel | ||
{ | ||
public bool Adult { get; set; } | ||
public string BackdropPath { get; set; } | ||
public List<int> GenreIds { get; set; } | ||
public int Id { get; set; } | ||
public string OriginalLanguage { get; set; } | ||
public string OriginalTitle { get; set; } | ||
public string Overview { get; set; } | ||
public double Popularity { get; set; } | ||
public string PosterPath { get; set; } | ||
public DateTime? ReleaseDate { get; set; } | ||
public string Title { get; set; } | ||
public bool Video { get; set; } | ||
public double VoteAverage { get; set; } | ||
public int VoteCount { get; set; } | ||
public bool AlreadyInCp { get; set; } | ||
public string Trailer { get; set; } | ||
public string Homepage { get; set; } | ||
public string ImdbId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#region Copyright | ||
// /************************************************************************ | ||
// Copyright (c) 2017 Jamie Rees | ||
// File: SearchViewModel.cs | ||
// Created By: Jamie Rees | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// ************************************************************************/ | ||
#endregion | ||
namespace Ombi.Core.Models.Search | ||
{ | ||
public class SearchViewModel | ||
{ | ||
public bool Approved { get; set; } | ||
public bool Requested { get; set; } | ||
public bool Available { get; set; } | ||
public string PlexUrl { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Ombi.Core.Models.Search; | ||
using Ombi.TheMovieDbApi.Models; | ||
|
||
namespace Ombi.Core | ||
{ | ||
public class MovieEngine : IMovieEngine | ||
{ | ||
|
||
public async Task<IEnumerable<SearchMovieViewModel>> ProcessMovieSearch(string search) | ||
{ | ||
var api = new TheMovieDbApi.TheMovieDbApi(); | ||
var result = await api.SearchMovie(search); | ||
if (result != null) | ||
{ | ||
return await TransformMovieResultsToResponse(result.results); | ||
} | ||
return null; | ||
} | ||
public async Task<IEnumerable<SearchMovieViewModel>> PopularMovies() | ||
{ | ||
var api = new TheMovieDbApi.TheMovieDbApi(); | ||
var result = await api.PopularMovies(); | ||
if (result != null) | ||
{ | ||
return await TransformMovieResultsToResponse(result.results); | ||
} | ||
return null; | ||
} | ||
|
||
public async Task<IEnumerable<SearchMovieViewModel>> TopRatedMovies() | ||
{ | ||
var api = new TheMovieDbApi.TheMovieDbApi(); | ||
var result = await api.TopRated(); | ||
if (result != null) | ||
{ | ||
return await TransformMovieResultsToResponse(result.results); | ||
} | ||
return null; | ||
} | ||
|
||
public async Task<IEnumerable<SearchMovieViewModel>> UpcomingMovies() | ||
{ | ||
var api = new TheMovieDbApi.TheMovieDbApi(); | ||
var result = await api.Upcoming(); | ||
if (result != null) | ||
{ | ||
return await TransformMovieResultsToResponse(result.results); | ||
} | ||
return null; | ||
} | ||
public async Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies() | ||
{ | ||
var api = new TheMovieDbApi.TheMovieDbApi(); | ||
var result = await api.NowPlaying(); | ||
if (result != null) | ||
{ | ||
return await TransformMovieResultsToResponse(result.results); | ||
} | ||
return null; | ||
} | ||
|
||
|
||
private async Task<List<SearchMovieViewModel>> TransformMovieResultsToResponse(IEnumerable<SearchResult> movies) | ||
{ | ||
await Task.Yield(); | ||
var viewMovies = new List<SearchMovieViewModel>(); | ||
var counter = 0; | ||
//Dictionary<int, RequestedModel> dbMovies = await RequestedMovies(); | ||
foreach (var movie in movies) | ||
{ | ||
var viewMovie = new SearchMovieViewModel | ||
{ | ||
Adult = movie.adult, | ||
BackdropPath = movie.backdrop_path, | ||
Id = movie.id, | ||
OriginalLanguage = movie.original_language, | ||
OriginalTitle = movie.original_title, | ||
Overview = movie.overview, | ||
Popularity = movie.popularity, | ||
PosterPath = movie.poster_path, | ||
ReleaseDate = string.IsNullOrEmpty(movie.release_date) ? DateTime.MinValue : DateTime.Parse(movie.release_date), | ||
Title = movie.title, | ||
Video = movie.video, | ||
VoteAverage = movie.vote_average, | ||
VoteCount = movie.vote_count | ||
}; | ||
viewMovies.Add(viewMovie); | ||
|
||
//if (counter <= 5) // Let's only do it for the first 5 items | ||
//{ | ||
// var movieInfo = MovieApi.GetMovieInformationWithVideos(movie.Id); | ||
|
||
// // TODO needs to be careful about this, it's adding extra time to search... | ||
// // https://www.themoviedb.org/talk/5807f4cdc3a36812160041f2 | ||
// viewMovie.ImdbId = movieInfo?.imdb_id; | ||
// viewMovie.Homepage = movieInfo?.homepage; | ||
// var videoId = movieInfo?.video ?? false | ||
// ? movieInfo?.videos?.results?.FirstOrDefault()?.key | ||
// : string.Empty; | ||
|
||
// viewMovie.Trailer = string.IsNullOrEmpty(videoId) | ||
// ? string.Empty | ||
// : $"https://www.youtube.com/watch?v={videoId}"; | ||
|
||
// counter++; | ||
//} | ||
|
||
// var canSee = CanUserSeeThisRequest(viewMovie.Id, Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests), dbMovies); | ||
|
||
// var plexSettings = await PlexService.GetSettingsAsync(); | ||
// var embySettings = await EmbySettings.GetSettingsAsync(); | ||
// if (plexSettings.Enable) | ||
// { | ||
// var content = PlexContentRepository.GetAll(); | ||
// var plexMovies = PlexChecker.GetPlexMovies(content); | ||
|
||
// var plexMovie = PlexChecker.GetMovie(plexMovies.ToArray(), movie.Title, | ||
// movie.ReleaseDate?.Year.ToString(), | ||
// viewMovie.ImdbId); | ||
// if (plexMovie != null) | ||
// { | ||
// viewMovie.Available = true; | ||
// viewMovie.PlexUrl = plexMovie.Url; | ||
// } | ||
// } | ||
// if (embySettings.Enable) | ||
// { | ||
// var embyContent = EmbyContentRepository.GetAll(); | ||
// var embyMovies = EmbyChecker.GetEmbyMovies(embyContent); | ||
|
||
// var embyMovie = EmbyChecker.GetMovie(embyMovies.ToArray(), movie.Title, | ||
// movie.ReleaseDate?.Year.ToString(), viewMovie.ImdbId); | ||
// if (embyMovie != null) | ||
// { | ||
// viewMovie.Available = true; | ||
// } | ||
// } | ||
// if (dbMovies.ContainsKey(movie.Id) && canSee) // compare to the requests db | ||
// { | ||
// var dbm = dbMovies[movie.Id]; | ||
|
||
// viewMovie.Requested = true; | ||
// viewMovie.Approved = dbm.Approved; | ||
// viewMovie.Available = dbm.Available; | ||
// } | ||
// else if (canSee) | ||
// { | ||
// bool exists = IsMovieInCache(movie, viewMovie.ImdbId); | ||
// viewMovie.Approved = exists; | ||
// viewMovie.Requested = exists; | ||
// } | ||
// viewMovies.Add(viewMovie); | ||
//} | ||
|
||
|
||
} | ||
return viewMovies; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard1.4</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Ombi.TheMovieDbApi\Ombi.TheMovieDbApi.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.