public void Create(string bundleName, WebFileType type, params string[] paths) { _bundles.TryAdd( bundleName, type == WebFileType.Css ? paths.Select(x => (IWebFile)new CssFile(x)) : paths.Select(x => (IWebFile)new JavaScriptFile(x))); }
public void Create(string bundleName, PreProcessPipeline pipeline, WebFileType type, params string[] paths) { _bundles.TryAdd( bundleName, type == WebFileType.Css ? paths.Select(x => (IWebFile)new CssFile(x) { Pipeline = pipeline }) : paths.Select(x => (IWebFile)new JavaScriptFile(x) { Pipeline = pipeline })); }
public BundleFileCollection Create(string bundleName, PreProcessPipeline pipeline, WebFileType type, params string[] paths) { var collection = type == WebFileType.Css ? new BundleFileCollection(paths.Select(x => (IWebFile)new CssFile(x) { Pipeline = pipeline }).ToList()) : new BundleFileCollection(paths.Select(x => (IWebFile)new JavaScriptFile(x) { Pipeline = pipeline }).ToList()); _bundles.TryAdd(bundleName, collection); return collection; }
public MediaSource(WebMediaType type, int? provider, string id, WebFileType filetype, int offset) { this.MediaType = type; this.Id = id; this.Provider = provider; this.Offset = offset; this.FileType = filetype; if (!CheckArguments(type, filetype)) { throw new ArgumentException("Invalid combination of mediatype and filetype"); } }
public static ActionResult ReturnFromService(WebMediaType mediaType, string id, WebFileType artworkType, int maxWidth, int maxHeight, string defaultFile = null) { IStreamingService service; int? provider = null; switch (mediaType) { case WebMediaType.Drive: case WebMediaType.File: case WebMediaType.Folder: service = Connections.Current.MASStream; provider = Settings.ActiveSettings.FileSystemProvider; break; case WebMediaType.Movie: service = Connections.Current.MASStream; provider = Settings.ActiveSettings.MovieProvider; break; case WebMediaType.MusicAlbum: case WebMediaType.MusicArtist: case WebMediaType.MusicTrack: service = Connections.Current.MASStream; provider = Settings.ActiveSettings.MusicProvider; break; case WebMediaType.Picture: service = Connections.Current.MASStream; provider = Settings.ActiveSettings.PicturesProvider; break; case WebMediaType.TVShow: case WebMediaType.TVSeason: case WebMediaType.TVEpisode: service = Connections.Current.MASStream; provider = Settings.ActiveSettings.TVShowProvider; break; case WebMediaType.TV: service = Connections.Current.TASStream; break; case WebMediaType.Recording: service = Connections.Current.TASStream; return ReturnFromService(service, () => service.ExtractImageResized(mediaType, provider, id, 15, maxWidth, maxHeight), defaultFile); default: throw new ArgumentException("Tried to load image for unknown mediatype " + mediaType); } string etag = String.Format("{0}_{1}_{2}_{3}_{4}_{5}", mediaType, provider, id, artworkType, maxWidth, maxHeight); return ReturnFromService(service, () => service.GetArtworkResized(mediaType, provider, id, artworkType, 0, maxWidth, maxHeight), defaultFile, etag); }
public virtual PreProcessPipeline GetDefault(WebFileType fileType) { switch (fileType) { case WebFileType.Js: return new PreProcessPipeline(new IPreProcessor[] { _allProcessors.OfType<JsMin>().Single() }); case WebFileType.Css: default: return new PreProcessPipeline(new IPreProcessor[] { _allProcessors.OfType<CssImportProcessor>().Single(), _allProcessors.OfType<CssUrlProcessor>().Single(), _allProcessors.OfType<CssMinifier>().Single() }); } }
public MediaSource(WebMediaType type, int? provider, string id, WebFileType filetype) : this(type, provider, id, filetype, 0) { }
public WebFileInfo GetFileInfo(int? provider, WebMediaType mediatype, WebFileType filetype, string id, int offset) { try { return GetLibrary(provider, mediatype).GetFileInfo(GetPathList(provider, mediatype, filetype, id).ElementAt(offset)).Finalize(provider, mediatype); } catch (Exception ex) { Log.Info("Failed to get file info for mediatype=" + mediatype + ", filetype=" + filetype + ", id=" + id + " and offset=" + offset, ex); WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound); return new WebFileInfo(); } }
public bool IsLocalFile(int?provider, WebMediaType mediatype, WebFileType filetype, string id, int offset) { WebFileInfo info = GetFileInfo(provider, mediatype, filetype, id, offset); return(info.Exists && info.IsLocalFile); }
protected virtual bool CheckArguments(WebMediaType mediatype, WebFileType filetype) { return !( (mediatype == WebMediaType.TV && FileType != WebFileType.Content) || (mediatype == WebMediaType.Recording && FileType != WebFileType.Content) ); }
public Stream GetArtwork(WebMediaType mediatype, int? provider, string id, WebFileType artworktype, int offset, string format = null) { return Images.GetImage(new ImageMediaSource(mediatype, provider, id, artworktype, offset), format); }
public WebBoolResult RequestImageResize(WebMediaType mediatype, int? provider, string id, WebFileType imagetype, int offset, int maxWidth, int maxHeight, string borders = null, string format = null) { int? calcMaxWidth = maxWidth == 0 ? null : (int?)maxWidth; int? calcMaxHeight = maxHeight == 0 ? null : (int?)maxHeight; return Images.CacheImage(new ImageMediaSource(mediatype, provider, id, imagetype, offset), calcMaxWidth, calcMaxHeight, borders, format); }
public ImageMediaSource(WebMediaType type, int?provider, string id, WebFileType filetype, int offset) : base(type, provider, id, filetype, offset) { }
public WebFileInfo GetFileInfo(int? provider, WebMediaType mediatype, WebFileType filetype, string id, int offset) { string path = ""; try { path = GetPathList(provider, mediatype, filetype, id).ElementAt(offset); WebFileInfo retVal = null; bool tryImpersonation = false; try { // first try it the usual way retVal = GetLibrary(provider, mediatype).GetFileInfo(path).Finalize(provider, mediatype); tryImpersonation = PathUtil.MightBeOnNetworkDrive(path) && (retVal == null || !retVal.Exists); } catch (UnauthorizedAccessException) { // access denied, try impersonation tryImpersonation = true; } if (tryImpersonation && Configuration.Services.NetworkImpersonation.IsEnabled()) { using (var context = NetworkContextFactory.CreateImpersonationContext()) { retVal = new WebFileInfo(context.RewritePath(path)); retVal.IsLocalFile = true; retVal.OnNetworkDrive = true; } } // Make sure to always the path property, even if the file doesn't exist. This makes debugging a lot easier, as you get actual paths in your logs now. if (String.IsNullOrEmpty(retVal.Path)) retVal.Path = PathUtil.StripFileProtocolPrefix(path); retVal.PID = ProviderHandler.GetProviderId(mediatype.ToProviderType(), provider); return retVal; } catch (ArgumentOutOfRangeException) { Log.Info("Cannot resolve mediatype={0}, filetype={1}, provider={2}, id={3}, offset={4}", mediatype, filetype, provider, id, offset); } catch (FileNotFoundException) { Log.Info("Failed to load fileinfo for non-existing file mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider); } catch (Exception ex) { Log.Info(String.Format("Failed to load fileinfo for mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider), ex); } return new WebFileInfo() { Exists = false, PID = ProviderHandler.GetProviderId(mediatype.ToProviderType(), provider), Path = String.IsNullOrWhiteSpace(path) ? null : PathUtil.StripFileProtocolPrefix(path) }; }
public static ActionResult ReturnFromService(WebMediaType mediaType, string id, WebFileType artworkType, string defaultFile = null) { return(ReturnFromService(mediaType, id, artworkType, 0, 0, defaultFile)); }
public static ActionResult ReturnFromService(WebMediaType mediaType, string id, WebFileType artworkType, int maxWidth, int maxHeight, string defaultFile = null) { IStreamingService service; int?provider = null; switch (mediaType) { case WebMediaType.Drive: case WebMediaType.File: case WebMediaType.Folder: service = Connections.Current.MASStream; provider = Settings.ActiveSettings.FileSystemProvider; break; case WebMediaType.Movie: service = Connections.Current.MASStream; provider = Settings.ActiveSettings.MovieProvider; break; case WebMediaType.MusicAlbum: case WebMediaType.MusicArtist: case WebMediaType.MusicTrack: service = Connections.Current.MASStream; provider = Settings.ActiveSettings.MusicProvider; break; case WebMediaType.Picture: service = Connections.Current.MASStream; provider = Settings.ActiveSettings.PicturesProvider; break; case WebMediaType.TVShow: case WebMediaType.TVSeason: case WebMediaType.TVEpisode: service = Connections.Current.MASStream; provider = Settings.ActiveSettings.TVShowProvider; break; case WebMediaType.TV: service = Connections.Current.MASStream; break; case WebMediaType.Recording: service = Connections.Current.MASStream; return(ReturnFromService(() => service.ExtractImageResized(mediaType, provider, id, 15, maxWidth, maxHeight), defaultFile)); default: throw new ArgumentException("Tried to load image for unknown mediatype " + mediaType); } string etag = String.Format("{0}_{1}_{2}_{3}_{4}_{5}", mediaType, provider, id, artworkType, maxWidth, maxHeight); return(ReturnFromService(() => service.GetArtworkResized(mediaType, provider, id, artworkType, 0, maxWidth, maxHeight), defaultFile, etag)); }
public Task <WebBoolResult> RequestImageResize(WebMediaType mediatype, int?provider, string id, WebFileType imagetype, int offset, int maxWidth, int maxHeight, string borders = null, string format = null) { Logger.Debug("WSS Request: {0}", Request.GetOwinContext().Request.Uri); return(ResourceAccess.WSS.json.General.RequestImageResize.ProcessAsync(Request.GetOwinContext(), mediatype, provider, id, imagetype, offset, maxWidth, maxHeight, borders, format)); }
public static async Task ProcessAsync(IOwinContext context, WebMediaType mediatype, string id, WebFileType artworktype, int offset, int maxWidth, int maxHeight, string borders = null) { int offsetInt = 0; if (id == null) { throw new BadRequestException("GetArtworkResized: id is null"); } string fanartType; string fanArtMediaType; MapTypes(artworktype, mediatype, out fanartType, out fanArtMediaType); bool isTvRadio = fanArtMediaType == FanArtMediaTypes.ChannelTv || fanArtMediaType == FanArtMediaTypes.ChannelRadio; bool isRecording = mediatype == WebMediaType.Recording; Guid idGuid; int idInt; if (!Guid.TryParse(id, out idGuid) && !isTvRadio) { throw new BadRequestException(String.Format("GetArtworkResized: Couldn't parse if '{0}' to Guid", id)); } if (int.TryParse(id, out idInt) && (fanArtMediaType == FanArtMediaTypes.ChannelTv || fanArtMediaType == FanArtMediaTypes.ChannelRadio)) { idGuid = IntToGuid(idInt); } ImageCache.CacheIdentifier identifier = ImageCache.GetIdentifier(idGuid, isTvRadio, maxWidth, maxHeight, borders, offsetInt, fanartType, fanArtMediaType); Stream resourceStream; byte[] data; if (ImageCache.TryGetImageFromCache(context, identifier, out data)) { Logger.Info("GetArtworkResized: got image from cache"); resourceStream = ImageFile(data); context.Response.ContentType = "image/*"; await SendWholeFileAsync(context, resourceStream, false); resourceStream.Dispose(); } IList <FanArtImage> fanart = GetFanArtImages(context, id, isTvRadio, isRecording, fanartType, fanArtMediaType); // get offset if (offsetInt >= fanart.Count) { Logger.Warn("GetArtwork: offset is too big! FanArt: {0} Offset: {1}", fanart.Count, offsetInt); offsetInt = 0; } byte[] resizedImage = Plugins.MP2Extended.WSS.Images.ResizeImage(fanart[offsetInt].BinaryData, maxWidth, maxHeight, borders); // Add to cache, but only if it is no dummy image if (fanart[offsetInt].Name != NO_FANART_IMAGE_NAME) { if (ImageCache.AddImageToCache(context, resizedImage, identifier)) { Logger.Info("GetArtworkResized: Added image to cache"); } } resourceStream = ImageFile(resizedImage); context.Response.ContentType = "image/*"; await SendWholeFileAsync(context, resourceStream, false); resourceStream.Dispose(); }
public Stream RetrieveFile(int? provider, WebMediaType mediatype, WebFileType filetype, string id, int offset) { try { WebFileInfo info = GetFileInfo(provider, mediatype, filetype, id, offset); if (!info.Exists) { Log.Warn("Requested non-existing file mediatype={0} filetype={1} id={2} offset={3}", mediatype, filetype, id, offset); return null; } return GetLibrary(provider, mediatype).GetFile(GetPathList(provider, mediatype, filetype, id).ElementAt(offset)); } catch (Exception ex) { Log.Info("Failed to retrieve file for mediatype=" + mediatype + ", filetype=" + filetype + ", id=" + id + " and offset=" + offset, ex); WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound); return null; } }
public IEnumerable<string> GetBundleNames(WebFileType type) { return _bundles.GetBundleNames(type); }
public ArtworkReaderParameters(WebFileType type, string dirname) : this() { this.FileType = type; this.DirectoryName = dirname; }
private async Task<IEnumerable<string>> GenerateUrlsAsync( IEnumerable<IWebFile> files, WebFileType fileType, PreProcessPipeline pipeline = null, bool debug = false) { var result = new List<string>(); if (debug) { return GenerateUrlsDebug(files); } else { if (pipeline == null) { pipeline = _processorFactory.GetDefault(fileType); } var compression = _request.GetClientCompression(); //Get the file collection used to create the composite URLs and the external requests var fileBatches = _fileBatcher.GetCompositeFileCollectionForUrlGeneration(files); foreach (var batch in fileBatches) { //if it's external, the rule is that a WebFileBatch can only contain a single external file // it's path will be normalized as an external url so we just use it if (batch.IsExternal) { result.Add(batch.Single().Original.FilePath); } else { //Get the URLs for the batch, this could be more than one resulting URL depending on how many // files are in the batch and the max url length var compositeUrls = _context.UrlCreator.GetUrls(batch.Select(x => x.Hashed), fileType == WebFileType.Css ? ".css" : ".js"); foreach (var u in compositeUrls) { //now we need to determine if these files have already been minified var compositeFilePath = _fileSystemHelper.GetCurrentCompositeFilePath(compression, u.Key); if (!File.Exists(compositeFilePath)) { //need to process/minify these files - need to use their original paths of course await ProcessWebFilesAsync(batch.Select(x => x.Original), pipeline); } result.Add(u.Url); } } } } return result; }
/// <summary> /// Generates the URLs for a dynamically registered set of files (non pre-defined bundle) /// </summary> /// <param name="files"></param> /// <param name="fileType"></param> /// <param name="pipeline"></param> /// <param name="debug"></param> /// <returns></returns> private async Task <IEnumerable <string> > GenerateUrlsAsync( IEnumerable <IWebFile> files, WebFileType fileType, PreProcessPipeline pipeline = null, bool debug = false) { var result = new List <string>(); var orderedFiles = _fileSetGenerator.GetOrderedFileSet(files, pipeline ?? _processorFactory.CreateDefault(fileType)); if (debug) { return(orderedFiles.Select(x => x.FilePath)); } var compression = _requestHelper.GetClientCompression(_httpContextAccessor.HttpContext.Request.Headers); //Get the file collection used to create the composite URLs and the external requests var fileBatches = _fileBatcher.GetCompositeFileCollectionForUrlGeneration(orderedFiles); var cacheBuster = _cacheBusterResolver.GetCacheBuster(_bundleManager.GetDefaultBundleOptions(debug).GetCacheBusterType()); foreach (var batch in fileBatches) { //if it's external, the rule is that a WebFileBatch can only contain a single external file // it's path will be normalized as an external url so we just use it if (batch.IsExternal) { result.Add(batch.Single().Original.FilePath); } else { //Get the URLs for the batch, this could be more than one resulting URL depending on how many // files are in the batch and the max url length var compositeUrls = _urlManager.GetUrls( batch.Select(x => x.Hashed), fileType == WebFileType.Css ? ".css" : ".js", cacheBuster); foreach (var u in compositeUrls) { //now we need to determine if these files have already been minified var compositeFilePath = _fileSystemHelper.GetCurrentCompositeFilePath(cacheBuster, compression, u.Key); if (!File.Exists(compositeFilePath)) { using (var bundleContext = BundleContext.CreateEmpty()) { //need to process/minify these files - need to use their original paths of course foreach (var file in batch.Select(x => x.Original)) { await _preProcessManager.ProcessAndCacheFileAsync(file, null, bundleContext); } } } result.Add(u.Url); } } } return(result); }
public IList<string> GetPathList(int? provider, WebMediaType mediatype, WebFileType filetype, string id) { if (filetype != WebFileType.Content) return GetOriginalArtworkList(provider, mediatype, id).Where(x => x.Type == filetype).Select(x => ((WebArtworkDetailed)x).Path).ToList(); else return GetMediaItem(provider, mediatype, id).Path; }
public SmidgeBundleContext(string bundleName, BundleManager bundleManager, WebFileType type) { _bundleName = bundleName; _bundleManager = bundleManager; _type = type; }
public Stream GetArtworkResized(WebMediaType mediatype, int? provider, string id, WebFileType artworktype, int offset, int maxWidth, int maxHeight, string borders = null, string format = null) { int? calcMaxWidth = maxWidth == 0 ? null : (int?)maxWidth; int? calcMaxHeight = maxHeight == 0 ? null : (int?)maxHeight; return Images.GetResizedImage(new ImageMediaSource(mediatype, provider, id, artworktype, offset), calcMaxWidth, calcMaxHeight, borders, format); }
public WebFileInfo GetFileInfo(int? provider, WebMediaType mediatype, WebFileType filetype, string id, int offset) { string path = ""; try { path = GetPathList(provider, mediatype, filetype, id).ElementAt(offset); WebFileInfo retVal = null; bool tryImpersonation = false; try { // first try it the usual way retVal = GetLibrary(provider, mediatype).GetFileInfo(path).Finalize(provider, mediatype); tryImpersonation = retVal == null || !retVal.Exists; } catch (UnauthorizedAccessException) { // access denied, try impersonation tryImpersonation = true; } if (tryImpersonation && new Uri(path).IsUnc && !FileUtil.IsAccessible(path)) { using (var impersonator = new NetworkShareImpersonator()) { retVal = new WebFileInfo(path); retVal.IsLocalFile = Configuration.Services.NetworkImpersonation.ReadInStreamingService; retVal.OnNetworkDrive = true; } } // Make sure to always the path property, even if the file doesn't exist. This makes debugging a lot easier, as you get actual paths in your logs now. retVal.Path = path; return retVal; } catch (ArgumentOutOfRangeException) { Log.Info("Cannot resolve mediatype={0}, filetype={1}, provider={2}, id={3}, offset={4}", mediatype, filetype, provider, id, offset); } catch (FileNotFoundException) { Log.Info("Failed to load fileinfo for non-existing file mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider); } catch (Exception ex) { Log.Info(String.Format("Failed to load fileinfo for mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider), ex); } return new WebFileInfo() { Exists = false, Path = String.IsNullOrWhiteSpace(path) ? null : path }; }
public WebBoolResult IsLocalFile(int? provider, WebMediaType mediatype, WebFileType filetype, string id, int offset) { WebFileInfo info = GetFileInfo(provider, mediatype, filetype, id, offset); return info.Exists && info.IsLocalFile; }
public IList <string> GetPathList(int?provider, WebMediaType mediatype, WebFileType filetype, string id) { if (mediatype == WebMediaType.File && filetype == WebFileType.Content) { return(FileSystemLibraries[provider].GetFileBasic(id).Path); } else if (mediatype == WebMediaType.Movie && filetype == WebFileType.Content) { return(MovieLibraries[provider].GetMovieDetailedById(id).Path); } else if (mediatype == WebMediaType.Movie && filetype == WebFileType.Backdrop) { return(MovieLibraries[provider].GetMovieDetailedById(id).Artwork.Where(x => x.Type == WebFileType.Backdrop).Select(x => ((WebArtworkDetailed)x).Path).ToList()); } else if (mediatype == WebMediaType.Movie && filetype == WebFileType.Cover) { return(MovieLibraries[provider].GetMovieDetailedById(id).Artwork.Where(x => x.Type == WebFileType.Cover).Select(x => ((WebArtworkDetailed)x).Path).ToList()); } else if (mediatype == WebMediaType.TVShow && filetype == WebFileType.Banner) { return(TVShowLibraries[provider].GetTVShowDetailed(id).Artwork.Where(x => x.Type == WebFileType.Banner).Select(x => ((WebArtworkDetailed)x).Path).ToList()); } else if (mediatype == WebMediaType.TVShow && filetype == WebFileType.Backdrop) { return(TVShowLibraries[provider].GetTVShowDetailed(id).Artwork.Where(x => x.Type == WebFileType.Backdrop).Select(x => ((WebArtworkDetailed)x).Path).ToList()); } else if (mediatype == WebMediaType.TVShow && filetype == WebFileType.Poster) { return(TVShowLibraries[provider].GetTVShowDetailed(id).Artwork.Where(x => x.Type == WebFileType.Poster).Select(x => ((WebArtworkDetailed)x).Path).ToList()); } else if (mediatype == WebMediaType.TVSeason && filetype == WebFileType.Backdrop) { return(TVShowLibraries[provider].GetSeasonDetailed(id).Artwork.Where(x => x.Type == WebFileType.Backdrop).Select(x => ((WebArtworkDetailed)x).Path).ToList()); } else if (mediatype == WebMediaType.TVSeason && filetype == WebFileType.Banner) { return(TVShowLibraries[provider].GetSeasonDetailed(id).Artwork.Where(x => x.Type == WebFileType.Banner).Select(x => ((WebArtworkDetailed)x).Path).ToList()); } else if (mediatype == WebMediaType.TVSeason && filetype == WebFileType.Poster) { return(TVShowLibraries[provider].GetSeasonDetailed(id).Artwork.Where(x => x.Type == WebFileType.Poster).Select(x => ((WebArtworkDetailed)x).Path).ToList()); } else if (mediatype == WebMediaType.TVEpisode && filetype == WebFileType.Content) { return(TVShowLibraries[provider].GetEpisodeBasic(id).Path); } else if (mediatype == WebMediaType.TVEpisode && filetype == WebFileType.Banner) { return(TVShowLibraries[provider].GetEpisodeDetailed(id).Artwork.Where(x => x.Type == WebFileType.Banner).Select(x => ((WebArtworkDetailed)x).Path).ToList()); } else if (mediatype == WebMediaType.Picture && filetype == WebFileType.Content) { return(PictureLibraries[provider].GetPictureDetailed(id).Path); } else if (mediatype == WebMediaType.MusicAlbum && filetype == WebFileType.Cover) { return(MusicLibraries[provider].GetAlbumBasicById(id).Artwork.Where(x => x.Type == WebFileType.Cover).Select(x => ((WebArtworkDetailed)x).Path).ToList()); } else if (mediatype == WebMediaType.MusicTrack && filetype == WebFileType.Content) { return(MusicLibraries[provider].GetTrackBasicById(id).Path); } Log.Warn("Invalid combination of filetype {0} and mediatype {1} requested", filetype, mediatype); return(null); }
protected override bool CheckArguments(WebMediaType mediatype, WebFileType filetype) { if ((mediatype == WebMediaType.TV || mediatype == WebMediaType.Recording) && filetype == WebFileType.Logo) return true; return base.CheckArguments(mediatype, filetype); }
public MediaSource(WebMediaType type, int?provider, string id, WebFileType filetype) : this(type, provider, id, filetype, 0) { }
public static Task <WebBoolResult> ProcessAsync(IOwinContext context, WebMediaType mediatype, WebFileType filetype, string id, int offset) { if (id == null) { throw new BadRequestException("IsLocalFile: id is null"); } ISet <Guid> necessaryMIATypes = new HashSet <Guid>(); necessaryMIATypes.Add(MediaAspect.ASPECT_ID); necessaryMIATypes.Add(ProviderResourceAspect.ASPECT_ID); necessaryMIATypes.Add(ImporterAspect.ASPECT_ID); ISet <Guid> optionalMIATypes = new HashSet <Guid>(); optionalMIATypes.Add(VideoAspect.ASPECT_ID); optionalMIATypes.Add(MovieAspect.ASPECT_ID); optionalMIATypes.Add(SeriesAspect.ASPECT_ID); optionalMIATypes.Add(AudioAspect.ASPECT_ID); optionalMIATypes.Add(ImageAspect.ASPECT_ID); MediaItem item = MediaLibraryAccess.GetMediaItemById(context, Guid.Parse(id), necessaryMIATypes, optionalMIATypes); if (item == null) { throw new NotFoundException(String.Format("IsLocalFile: No MediaItem found with id: {0}", id)); } var files = ResourceAccessUtils.GetResourcePaths(item); return(System.Threading.Tasks.Task.FromResult(new WebBoolResult { Result = files[offset].IsValidLocalPath })); }
public static ActionResult ReturnFromService(WebMediaType mediaType, string id, WebFileType artworkType, string defaultFile = null) { return ReturnFromService(mediaType, id, artworkType, 0, 0, defaultFile); }
public IEnumerable<string> GetBundleNames(WebFileType type) { return _bundles.Where(x => x.Value.Files.Any(f => f.DependencyType == type)).Select(x => x.Key); }
public IList<string> GetPathList(int? provider, WebMediaType mediatype, WebFileType filetype, string id) { if (mediatype == WebMediaType.File && filetype == WebFileType.Content) return FileSystemLibraries[provider].GetFileBasic(id).Path; else if (mediatype == WebMediaType.Movie && filetype == WebFileType.Content) return MovieLibraries[provider].GetMovieDetailedById(id).Path; else if (mediatype == WebMediaType.Movie && filetype == WebFileType.Backdrop) return MovieLibraries[provider].GetMovieDetailedById(id).Artwork.Where(x => x.Type == WebFileType.Backdrop).Select(x => ((WebArtworkDetailed)x).Path).ToList(); else if (mediatype == WebMediaType.Movie && filetype == WebFileType.Cover) return MovieLibraries[provider].GetMovieDetailedById(id).Artwork.Where(x => x.Type == WebFileType.Cover).Select(x => ((WebArtworkDetailed)x).Path).ToList(); else if (mediatype == WebMediaType.TVShow && filetype == WebFileType.Banner) return TVShowLibraries[provider].GetTVShowDetailed(id).Artwork.Where(x => x.Type == WebFileType.Banner).Select(x => ((WebArtworkDetailed)x).Path).ToList(); else if (mediatype == WebMediaType.TVShow && filetype == WebFileType.Backdrop) return TVShowLibraries[provider].GetTVShowDetailed(id).Artwork.Where(x => x.Type == WebFileType.Backdrop).Select(x => ((WebArtworkDetailed)x).Path).ToList(); else if (mediatype == WebMediaType.TVShow && filetype == WebFileType.Poster) return TVShowLibraries[provider].GetTVShowDetailed(id).Artwork.Where(x => x.Type == WebFileType.Poster).Select(x => ((WebArtworkDetailed)x).Path).ToList(); else if (mediatype == WebMediaType.TVSeason && filetype == WebFileType.Backdrop) return TVShowLibraries[provider].GetSeasonDetailed(id).Artwork.Where(x => x.Type == WebFileType.Backdrop).Select(x => ((WebArtworkDetailed)x).Path).ToList(); else if (mediatype == WebMediaType.TVSeason && filetype == WebFileType.Banner) return TVShowLibraries[provider].GetSeasonDetailed(id).Artwork.Where(x => x.Type == WebFileType.Banner).Select(x => ((WebArtworkDetailed)x).Path).ToList(); else if (mediatype == WebMediaType.TVSeason && filetype == WebFileType.Poster) return TVShowLibraries[provider].GetSeasonDetailed(id).Artwork.Where(x => x.Type == WebFileType.Poster).Select(x => ((WebArtworkDetailed)x).Path).ToList(); else if (mediatype == WebMediaType.TVEpisode && filetype == WebFileType.Content) return TVShowLibraries[provider].GetEpisodeBasic(id).Path; else if (mediatype == WebMediaType.TVEpisode && filetype == WebFileType.Banner) return TVShowLibraries[provider].GetEpisodeDetailed(id).Artwork.Where(x => x.Type == WebFileType.Banner).Select(x => ((WebArtworkDetailed)x).Path).ToList(); else if (mediatype == WebMediaType.Picture && filetype == WebFileType.Content) return PictureLibraries[provider].GetPictureDetailed(id).Path; else if (mediatype == WebMediaType.MusicArtist && filetype == WebFileType.Cover) return MusicLibraries[provider].GetArtistBasicById(id).Artwork.Where(x => x.Type == WebFileType.Cover).Select(x => ((WebArtworkDetailed)x).Path).ToList(); else if (mediatype == WebMediaType.MusicAlbum && filetype == WebFileType.Cover) return MusicLibraries[provider].GetAlbumBasicById(id).Artwork.Where(x => x.Type == WebFileType.Cover).Select(x => ((WebArtworkDetailed)x).Path).ToList(); else if (mediatype == WebMediaType.MusicTrack && filetype == WebFileType.Cover) return MusicLibraries[provider].GetTrackBasicById(id).Artwork.Where(x => x.Type == WebFileType.Cover).Select(x => ((WebArtworkDetailed)x).Path).ToList(); else if (mediatype == WebMediaType.MusicTrack && filetype == WebFileType.Content) return MusicLibraries[provider].GetTrackBasicById(id).Path; Log.Warn("Invalid combination of filetype {0} and mediatype {1} requested", filetype, mediatype); return null; }
public static Task <Stream> ProcessAsync(IOwinContext context, WebMediaType mediatype, WebFileType filetype, string id, int offset) { ISet <Guid> necessaryMIATypes = new HashSet <Guid>(); necessaryMIATypes.Add(MediaAspect.ASPECT_ID); necessaryMIATypes.Add(ProviderResourceAspect.ASPECT_ID); necessaryMIATypes.Add(ImporterAspect.ASPECT_ID); MediaItem item = MediaLibraryAccess.GetMediaItemById(context, id, necessaryMIATypes, null); if (item == null) { throw new NotFoundException("RetrieveFile: no media item found"); } var files = ResourceAccessUtils.GetResourcePaths(item); var ra = GetResourceAccessor(files[offset]); IFileSystemResourceAccessor fsra = ra as IFileSystemResourceAccessor; if (fsra == null) { throw new InternalServerException("RetrieveFile: failed to create IFileSystemResourceAccessor"); } return(fsra.OpenReadAsync()); }
public Stream RetrieveFile(int? provider, WebMediaType mediatype, WebFileType filetype, string id, int offset) { try { string path = GetPathList(provider, mediatype, filetype, id).ElementAt(offset); WebFileInfo info = GetFileInfo(provider, mediatype, filetype, id, offset); // first try to read the file if (info.IsLocalFile && File.Exists(path)) { return new FileStream(path, FileMode.Open, FileAccess.Read); } // maybe the plugin has some magic if (!info.IsLocalFile && info.Exists && !info.OnNetworkDrive) { return GetLibrary(provider, mediatype).GetFile(path); } // try to load it from a network drive if (info.OnNetworkDrive && info.Exists) { using (NetworkShareImpersonator impersonator = new NetworkShareImpersonator()) { return new FileStream(path, FileMode.Open, FileAccess.Read); } } // fail Log.Warn("Requested non-existing or non-accessible file mediatype={0} filetype={1} id={2} offset={3}", mediatype, filetype, id, offset); WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound); return Stream.Null; } catch (Exception ex) { Log.Info("Failed to retrieve file for mediatype=" + mediatype + ", filetype=" + filetype + ", id=" + id + " and offset=" + offset, ex); WCFUtil.SetResponseCode(System.Net.HttpStatusCode.InternalServerError); return Stream.Null; } }
public WebFileInfo GetFileInfo(int? provider, WebMediaType mediatype, WebFileType filetype, string id, int offset) { string path = ""; try { path = GetPathList(provider, mediatype, filetype, id).ElementAt(offset); try { // first try it the usual way return GetLibrary(provider, mediatype).GetFileInfo(path).Finalize(provider, mediatype); } catch (UnauthorizedAccessException) { // access denied, try impersonation if (new Uri(path).IsUnc) { using (NetworkShareImpersonator impersonation = new NetworkShareImpersonator()) { var ret = new WebFileInfo(path); ret.IsLocalFile = Configuration.Services.NetworkImpersonation.ReadInStreamingService; ret.OnNetworkDrive = true; return ret; } } } } catch (ArgumentOutOfRangeException) { Log.Info("Cannot resolve mediatype={0}, filetype={1}, provider={2}, id={3}, offset={4}", mediatype, filetype, provider, id, offset); } catch (FileNotFoundException) { Log.Info("Failed to load fileinfo for non-existing file mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider); } catch (Exception ex) { Log.Info(String.Format("Failed to load fileinfo for mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider), ex); } return new WebFileInfo() { Exists = false }; }
public ImageMediaSource(WebMediaType type, int? provider, string id, WebFileType filetype, int offset) : base(type, provider, id, filetype, offset) { }
/// <summary> /// Returns all bundle names registered /// </summary> /// <param name="type"></param> /// <returns></returns> public IEnumerable <string> GetBundleNames(WebFileType type) { return(_bundles.Where(x => x.Value.Files.Any(f => f.DependencyType == type)).Select(x => x.Key)); }