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(); } } } }
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 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; } }
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) { try { 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); } } } catch (Exception e) { Logger.ReportVerbose("Error searching for matching trailers.", e); } } } Logger.ReportVerbose("Found " + foundTrailers.Count + " trailers. Returning..."); return foundTrailers; }
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 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); }