public object Post(MetadataUpdaterTVShowUpdateRequest request) { // Convert the request to a tvshow. var tvShow = new MetadataUpdaterTVShow(request); // Create notifications. var notificationQueued = new Notification() { Id = string.Format("MetadataUpdaterRequest{0}", _notificationCount++), Heading = "Metadata Updater Request Queued", Message = string.Format("Queued metadata update on file {0}", request.Path.UrlDecode()), Type = NotificationType.Informational }; var notificationStarted = new Notification() { Id = string.Format("MetadataUpdaterRequest{0}", _notificationCount++), Heading = "Metadata Updater Request Started", Message = string.Format("Started metadata update on file {0}", request.Path.UrlDecode()), Type = NotificationType.Warning }; var notificationCompleted = new AutoExpireNotification(new TimeSpan(0, 0, 30)) { Id = string.Format("MetadataUpdaterRequest{0}", _notificationCount++), Heading = "Metadata Updater Request Completed", Message = string.Format("Completed metadata update on file {0}", request.Path.UrlDecode()), Type = NotificationType.Success }; var notificationError = new AutoExpireNotification(new TimeSpan(0, 2, 0)) { Id = string.Format("MetadataUpdaterRequest{0}", _notificationCount++), Heading = "Metadata Updater Request Errored", Message = string.Format("Error occured during metadata update on file {0}", request.Path.UrlDecode()), Type = NotificationType.Error }; // Create task. var task = new RemuxEncodeMetadataAndAddToLibrary(new FileSystem(), tvShow, false); task.PreInvokeHandle = () => { notificationQueued.HasExpired = true; ResourceManager.NotificationManager.Add(notificationStarted); }; task.PostInvokeHandle = () => { notificationQueued.HasExpired = true; notificationStarted.HasExpired = true; notificationError.HasExpired = true; ResourceManager.NotificationManager.Add(notificationCompleted); }; task.InvokeErrorHandle = () => { notificationQueued.HasExpired = true; notificationStarted.HasExpired = true; notificationCompleted.HasExpired = true; ResourceManager.NotificationManager.Add(notificationError); }; ResourceManager.QueuedTaskManager.Enqueue(task); ResourceManager.NotificationManager.Add(notificationQueued); // Return null. return null; }
public MetadataUpdaterTVShow(MetadataUpdaterTVShowUpdateRequest request) { File = request.Path.FromSiteFilePath(); Definition = MediaPod.Interfaces.Models.Definition.Unknown; TVShowName = request.TVShowName; SeasonNumber = Convert.ToInt32(request.SeasonNumber); EpisodeNumber = Convert.ToInt32(request.EpisodeNumber); Name = request.Name; Description = request.Description; Genres = request.Genres.Split(',').Select(genre => genre.Trim()).ToList(); Cast = request.Cast.Split(',').Select(cast => cast.Trim()).ToList(); Directors = request.Directors.Split(',').Select(director => director.Trim()).ToList(); Screenwriters = request.Screenwriters.Split(',').Select(screenwriters => screenwriters.Trim()).ToList(); ReleaseDate = DateTime.ParseExact(request.ReleaseDate, "yyyy-MM-dd", CultureInfo.InvariantCulture); Network = request.Network; Artwork = request.Artwork.FromWebImage(); // Determine definition. var streams = new MediaStreamsExtractor(File).Extract(); var height = streams.Where(stream => stream is MediaStreamsExtractor.IVideoStream).Select(stream => ((MediaStreamsExtractor.IVideoStream) stream).Height).OrderByDescending(h => h).First(); if(height >= 1080) { Definition = Definition.HD1080; } else if(height >= 720) { Definition = Definition.HD720; } else { Definition = Definition.SD; } }