Skip to content

Commit

Permalink
Merge pull request #104 from Drewster727/dev
Browse files Browse the repository at this point in the history
#86 - display movie/show title + year in request notifications
  • Loading branch information
Jamie committed Mar 27, 2016
2 parents 29de229 + b72e897 commit cccb71b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 22 deletions.
2 changes: 1 addition & 1 deletion PlexRequests.UI/Content/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function sendRequestAjax(data, type, url, buttonId) {
success: function (response) {
console.log(response);
if (response.result === true) {
generateNotify("Success!", "success");
generateNotify(response.message || "Success!", "success");

$('#' + buttonId).html("<i class='fa fa-check'></i> Requested");
$('#' + buttonId).removeClass("btn-primary-outline");
Expand Down
47 changes: 26 additions & 21 deletions PlexRequests.UI/Modules/SearchModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,30 +172,32 @@ private Response CurrentlyPlayingMovies() // TODO : Not used

private Response RequestMovie(int movieId)
{
var movieApi = new TheMovieDbApi();
var movieInfo = movieApi.GetMovieInformation(movieId).Result;
string fullMovieName = string.Format("{0}{1}", movieInfo.Title, movieInfo.ReleaseDate.HasValue ? $" ({movieInfo.ReleaseDate.Value.Year})" : string.Empty);
Log.Trace("Getting movie info from TheMovieDb");
Log.Trace(movieInfo.DumpJson);
//#if !DEBUG

Log.Info("Requesting movie with id {0}", movieId);
if (RequestService.CheckRequest(movieId))
{
Log.Trace("movie with id {0} exists", movieId);
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Movie has already been requested!" });
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullMovieName} has already been requested!" });
}

Log.Debug("movie with id {0} doesnt exists", movieId);

var movieApi = new TheMovieDbApi();
var movieInfo = movieApi.GetMovieInformation(movieId).Result;
Log.Trace("Getting movie info from TheMovieDb");
Log.Trace(movieInfo.DumpJson);
//#if !DEBUG
try
{
if (CheckIfTitleExistsInPlex(movieInfo.Title, movieInfo.ReleaseDate?.Year.ToString()))
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{movieInfo.Title} is already in Plex!" });
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullMovieName} is already in Plex!" });
}
}
catch (ApplicationSettingsException)
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"We could not check if {movieInfo.Title} is in Plex, are you sure it's correctly setup?" });
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"We could not check if {fullMovieName} is in Plex, are you sure it's correctly setup?" });
}
//#endif

Expand Down Expand Up @@ -282,7 +284,7 @@ private Response RequestMovie(int movieId)
var notificationModel = new NotificationModel { Title = model.Title, User = model.RequestedBy, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
NotificationService.Publish(notificationModel);

return Response.AsJson(new JsonResponseModel { Result = true });
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullMovieName} was successfully added!" });
}
catch (Exception e)
{
Expand All @@ -300,30 +302,33 @@ private Response RequestMovie(int movieId)
/// <returns></returns>
private Response RequestTvShow(int showId, string seasons)
{
if (RequestService.CheckRequest(showId))
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "TV Show has already been requested!" });
}

var tvApi = new TvMazeApi();

var showInfo = tvApi.ShowLookupByTheTvDbId(showId);
DateTime firstAir;
DateTime.TryParse(showInfo.premiered, out firstAir);
string fullShowName = $"{showInfo.name} ({firstAir.Year})";
//#if !DEBUG

if (RequestService.CheckRequest(showId))
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullShowName} has already been requested!" });
}

try
{
if (CheckIfTitleExistsInPlex(showInfo.name, showInfo.premiered?.Substring(0, 4))) // Take only the year Format = 2014-01-01
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{showInfo.name} is already in Plex!" });
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullShowName} is already in Plex!" });
}
}
catch (ApplicationSettingsException)
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"We could not check if {showInfo.name} is in Plex, are you sure it's correctly setup?" });
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"We could not check if {fullShowName} is in Plex, are you sure it's correctly setup?" });
}
//#endif

DateTime firstAir;
DateTime.TryParse(showInfo.premiered, out firstAir);

var model = new RequestedModel
{
ProviderId = showInfo.externals?.thetvdb ?? 0,
Expand Down Expand Up @@ -372,7 +377,7 @@ private Response RequestTvShow(int showId, string seasons)
Log.Debug("Adding tv to database requests (No approval required & Sonarr)");
RequestService.AddRequest(model);

return Response.AsJson(new JsonResponseModel { Result = true });
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" });
}
var notify1 = new NotificationModel { Title = model.Title, User = model.RequestedBy, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
NotificationService.Publish(notify1);
Expand All @@ -394,7 +399,7 @@ private Response RequestTvShow(int showId, string seasons)
var notify2 = new NotificationModel { Title = model.Title, User = model.RequestedBy, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
NotificationService.Publish(notify2);

return Response.AsJson(new JsonResponseModel { Result = true });
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" });
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = result?.message != null ? "<b>Message From SickRage: </b>" + result.message : "Something went wrong adding the movie to SickRage! Please check your settings." });
}
Expand All @@ -408,7 +413,7 @@ private Response RequestTvShow(int showId, string seasons)
var notificationModel = new NotificationModel { Title = model.Title, User = model.RequestedBy, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
NotificationService.Publish(notificationModel);

return Response.AsJson(new { Result = true });
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" });
}

private bool CheckIfTitleExistsInPlex(string title, string year)
Expand Down
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,54 @@ You will then have a admin menu option once registered where you can setup Sonar

Looking for a Docker Image? Well [rogueosb](https://github.com/rogueosb/) has created a docker image for us, You can find it [here](https://github.com/rogueosb/docker-plexrequestsnet) :smile:

#Debian/Ubuntu

To configure PlexRequests to run on debian/ubuntu and set it to start up with the system, do the following (via terminal):

####Create a location to drop the files (up to you, we'll use /opt/PlexRequests as an example)

```sudo mkdir /opt/PlexRequests```

####Download the release zip
```
sudo wget {release zip file url}
sudo unzip PlexRequests.zip -d /opt/PlexRequests
```

####Install Mono (this app will be used to actually run the .net libraries and executable)

```sudo apt-get install mono-devel```

####Verify Mono properly runs PlexRequests

```sudo /usr/bin/mono /opt/PlexRequests/Release/PlexRequests.exe```

####Create an upstart script to auto-start PlexRequests with your system (using port 80 in this example)

```sudo nano /etc/init/plexrequests.conf```

#####Paste in the following:

```
start on runlevel [2345]
stop on runlevel [016]
respawn
expect fork
pre-start script
# echo ""
end script
script
exec /usr/bin/mono /opt/PlexRequests/Release/PlexRequests.exe 80
end script
```

####Reboot, then open up your browser to check that it's running!

```sudo shutdown -r 00```

# Contributors

We are looking for any contributions to the project! Just pick up a task, if you have any questions ask and i'll get straight on it!
Expand Down

0 comments on commit cccb71b

Please sign in to comment.