/// <summary> /// Downloads the trailer. /// </summary> /// <param name="trailer">The trailer.</param> /// <param name="trailerFolder">The trailer folder.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> private async Task DownloadTrailer(TrailerInfo trailer, Folder trailerFolder, CancellationToken cancellationToken) { var video = trailer.Video; var existing = trailerFolder .Children .OfType <Trailer>() .FirstOrDefault(i => string.Equals(i.Path, trailer.TrailerUrl, StringComparison.OrdinalIgnoreCase)); if (existing != null) { video = existing; } else { video.Path = trailer.TrailerUrl; await trailerFolder.AddChild(video, cancellationToken).ConfigureAwait(false); } // Figure out which image we're going to download var imageUrl = trailer.HdImageUrl ?? trailer.ImageUrl; if (!video.HasImage(ImageType.Primary) && !string.IsNullOrEmpty(imageUrl)) { await ProviderManager.SaveImage(video, imageUrl, Plugin.Instance.AppleTrailers, ImageType.Primary, null, cancellationToken).ConfigureAwait(false); await LibraryManager.UpdateItem(video, ItemUpdateType.ImageUpdate, cancellationToken).ConfigureAwait(false); } }
public string ProxyUrl(MBTrailers.ITunesTrailer trailer) { Uri uri = new Uri(trailer.RealPath); ProxyInfo proxyInfo = new ProxyInfo(uri.Host, uri.PathAndQuery, ProxyInfo.ITunesUserAgent, uri.Port); TrailerInfo trailerInfo = new TrailerInfo(TrailerType.Remote, proxyInfo.LocalFilename, trailer.ParentalRating, trailer.Genres); using (ChannelFactory <ITrailerProxy> factory = new ChannelFactory <ITrailerProxy>(new NetNamedPipeBinding(), "net.pipe://localhost/mbtrailers")) { ITrailerProxy proxyServer = factory.CreateChannel(); try { proxyServer.SetProxyInfo(proxyInfo); proxyServer.SetTrailerInfo(trailerInfo); } catch (Exception e) { Logger.ReportException("Error setting proxy info", e); Logger.ReportError("Inner Exception: " + e.InnerException.Message); } finally { (proxyServer as ICommunicationObject).Close(); } } var target = Path.Combine(cacheDir, proxyInfo.LocalFilename); return(File.Exists(target) ? target : string.Format("http://localhost:{0}/{1}", this.port, proxyInfo.LocalFilename)); }
private void SpawnTrailerRandomly() { var spawnPoint = FindClearSpawnPoint(SpawnPointTypes.Trailer); if (spawnPoint == null) { Log("No clear spawnpoints for trailers!"); return; } var targetPoint = _config.SpawnPoints.Shuffle().FirstOrDefault(sp => sp.Type == SpawnPointTypes.Destination); if (targetPoint == null) { Log("No destinations!"); return; } var trailerHash = _trailerHashes[_random.Next(0, _trailerHashes.Length)]; var trailerInfo = new TrailerInfo(API.createVehicle(trailerHash, spawnPoint.Position, spawnPoint.Rotation, 0, 0), targetPoint.Position); trailerInfo.Deleted += TrailerDeleted; trailerInfo.EnteredDestination += TrailerEnteredDestination; trailerInfo.DetachedOnDestination += TrailerDetachedOnDestination; _trailers.Add(trailerInfo); }
private void TrailerDeleted(TrailerInfo trailerInfo) { if (!_trailers.Contains(trailerInfo)) { return; } _trailers.Remove(trailerInfo); }
public List <string> GetMatchingTrailers(TrailerInfo searchInfo, float threshhold) { List <TrailerInfo> trailers = searchInfo.Type == TrailerType.Remote ? trailers = mbTrailers.Count > 0 ? mbTrailers.Values.ToList() : new List <TrailerInfo>() : trailers = myTrailers.Count > 0 ? myTrailers.Values.ToList() : new List <TrailerInfo>(); List <string> foundTrailers = new List <string>(); if (string.IsNullOrEmpty(searchInfo.Rating) && searchInfo.Genres == null) { // no search info - return all foreach (var info in trailers) { if (!info.Path.StartsWith(searchInfo.Path)) { foundTrailers.Add(info.Path); } } } else { Logger.ReportVerbose("Searching for matches. Rating: " + searchInfo.Rating); foreach (var genre in searchInfo.Genres) { Logger.ReportVerbose("Genre: " + genre); } Logger.ReportVerbose(trailers.Count + " " + searchInfo.Type + " trailers being searched."); foreach (var info in trailers) { if (info == null || info.Path == null) { Logger.ReportWarning("MBTrailers - Null item in trailer list..."); continue; } if (!string.IsNullOrEmpty(searchInfo.Rating) && ratings.Level(info.Rating) <= ratings.Level(searchInfo.Rating) && GenreMatches(searchInfo, info, threshhold) && !info.Path.StartsWith(searchInfo.Path)) { Logger.ReportVerbose("MATCH FOUND: " + info.Path + " Rating: " + info.Rating); foundTrailers.Add(info.Path); } else { Logger.ReportVerbose(info.Path + " doesn't match. Rating: " + info.Rating); if (info.Genres != null) { foreach (var genre in info.Genres) { Logger.ReportVerbose("Genre: " + genre); } } } } } Logger.ReportVerbose("Found " + foundTrailers.Count + " trailers. Returning..."); return(foundTrailers); }
public Task <MetadataResult <Trailer> > GetMetadata(TrailerInfo info, CancellationToken cancellationToken) { var result = new MetadataResult <Trailer>(); if (info.IsLocalTrailer) { return(Task.FromResult(result)); } return(GetMovieResult <Trailer>(info, cancellationToken)); }
private void TrailerEnteredDestination(TrailerInfo trailerInfo) { var driver = trailerInfo.GetTrailerDriver(); if (driver == null) { return; } API.sendNotificationToPlayer(driver, "Detach the trailer to finish delivery!"); }
public PermitView(Services services, NancyContext context) { User = context.CurrentUser as AuthUser; Hauler = User.ToHaulerInfo(); Company = new CompanyInfo(); Insurance = new InsuranceInfo(); Vehicle = new VehicleInfo(); Truck = new TruckInfo(); Axle = new AxleInfo(); Trailer = new TrailerInfo(); Load = new LoadInfo(); Movement = new MovementInfo(); }
private void TrailerDetachedOnDestination(TruckInfo truckInfo, TrailerInfo trailerInfo) { var driver = truckInfo.GetDriver(); if (driver == null) { return; } API.sendNotificationToPlayer(driver, "Well done!"); trailerInfo.Delete(); SpawnTrailers(); }
public void SetTrailerInfo(TrailerInfo info) { if (info != null) { switch (info.Type) { case TrailerType.Remote: //convert remote paths to full uri if not cached string key = info.Path; string target = Path.Combine(cacheDir, info.Path); info.Path = File.Exists(target) ? target : string.Format("http://localhost:{0}/{1}", this.port, key); mbTrailers[key] = info; break; case TrailerType.Local: myTrailers[info.Path] = info; break; } } }
private bool GenreMatches(TrailerInfo searchInfo, TrailerInfo info, float threshhold) { if (searchInfo.Genres.Count == 0) { return(true); //no search genres - everything matches } if (info.Genres == null || info.Genres.Count == 0) { return(false); //no target genres - no match } float matches = 0; foreach (var genre in searchInfo.Genres) { if (info.Genres.Contains(genre)) { matches++; } } return((matches / searchInfo.Genres.Count) > threshhold); }
public override void ValidateChildren() { System.Threading.Thread.Sleep(5000); //wait to be sure the service process is up... //only validate once per day or when forced or on service refresh if (Kernel.LoadContext == MBLoadContext.Service || Plugin.PluginOptions.Instance.Changed || DateTime.Now > lastUpdated.AddHours(23)) { Logger.ReportInfo("MBTrailers validating MyTrailers " + lastUpdated); Plugin.PluginOptions.Instance.Changed = false; Plugin.PluginOptions.Save(); lastUpdated = DateTime.Now; base.ValidateChildren(); Kernel.Instance.ItemRepository.SaveItem(this); } else { //just go through our existing children and be sure the proxy has them in the list using (ChannelFactory <ITrailerProxy> factory = new ChannelFactory <ITrailerProxy>(new NetNamedPipeBinding(), "net.pipe://localhost/mbtrailers")) { ITrailerProxy proxyServer = factory.CreateChannel(); try { foreach (Movie item in this.Children) { var trailerInfo = new TrailerInfo(TrailerType.Local, item.Path.ToLower(), item.ParentalRating, item.Genres); proxyServer.SetTrailerInfo(trailerInfo); } } catch (Exception e) { Logger.ReportException("Error setting trailer info", e); Logger.ReportError("Inner Exception: " + e.InnerException.Message); } finally { (proxyServer as ICommunicationObject).Close(); } } } }
public void SetTrailerInfo(MediaBrowser.Library.Entities.Show trailer) { TrailerInfo trailerInfo = new TrailerInfo(TrailerType.Local, trailer.Path.ToLower(), trailer.ParentalRating, trailer.Genres); using (ChannelFactory <ITrailerProxy> factory = new ChannelFactory <ITrailerProxy>(new NetNamedPipeBinding(), "net.pipe://localhost/mbtrailers")) { ITrailerProxy proxyServer = factory.CreateChannel(); try { proxyServer.SetTrailerInfo(trailerInfo); } catch (Exception e) { Logger.ReportException("Error setting trailer info", e); Logger.ReportError("Inner Exception: " + e.InnerException.Message); } finally { (proxyServer as ICommunicationObject).Close(); } } }
public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(TrailerInfo searchInfo, CancellationToken cancellationToken) { return(new List <RemoteSearchResult>()); }
public Task <IEnumerable <RemoteSearchResult> > GetSearchResults(TrailerInfo searchInfo, CancellationToken cancellationToken) { return(MovieDbProvider.Current.GetMovieSearchResults(searchInfo, cancellationToken)); }
public Task <MetadataResult <Trailer> > GetMetadata(TrailerInfo info, CancellationToken cancellationToken) { return(GetMovieResult <Trailer>(info, cancellationToken)); }
public Task <IEnumerable <RemoteSearchResult> > GetSearchResults(TrailerInfo searchInfo, CancellationToken cancellationToken) { return(GetSearchResultsInternal(searchInfo, true, cancellationToken)); }
public Task <IEnumerable <RemoteSearchResult> > GetSearchResults(TrailerInfo searchInfo, CancellationToken cancellationToken) { return(GetSearchResults(searchInfo, "movie", cancellationToken)); }
private ChannelMediaInfo GetMediaInfo(TrailerInfo info, bool isHd) { var mediaInfo = new ChannelMediaInfo { Path = info.TrailerUrl, Width = isHd ? 1280 : 720, Height = isHd ? 720 : 480, Container = Path.GetExtension(info.TrailerUrl), AudioCodec = AudioCodec.AAC, VideoCodec = VideoCodec.H264, AudioChannels = 2, VideoBitrate = isHd ? 11000000 : 1000000, AudioBitrate = isHd ? 128000 : 80000, AudioSampleRate = 44100, Framerate = (float)23.976, VideoProfile = isHd ? "high" : "main", VideoLevel = isHd ? (float)3.1 : 3 }; mediaInfo.RequiredHttpHeaders.Add("User-Agent", "QuickTime/7.7.4"); return mediaInfo; }