Beispiel #1
0
 protected virtual bool CheckArguments(WebStreamMediaType mediatype, WebArtworkType filetype)
 {
     return(!(
                (mediatype == WebStreamMediaType.TV && FileType != WebArtworkType.Content) ||
                (mediatype == WebStreamMediaType.Recording && FileType != WebArtworkType.Content)
                ));
 }
Beispiel #2
0
 protected override bool CheckArguments(WebStreamMediaType mediatype, WebArtworkType filetype)
 {
     if ((mediatype == WebStreamMediaType.TV || mediatype == WebStreamMediaType.Recording) && filetype == WebArtworkType.Logo)
     {
         return(true);
     }
     return(base.CheckArguments(mediatype, filetype));
 }
Beispiel #3
0
        public MediaSource(WebStreamMediaType type, int? provider, string id, WebArtworkType 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");
            }
        }
Beispiel #4
0
        public MediaSource(WebStreamMediaType type, int?provider, string id, WebArtworkType 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 Stream GetArtworkResized(WebStreamMediaType mediatype, int? provider, string id, WebArtworkType artworktype, int offset, int maxWidth, int maxHeight)
 {
     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);
 }
 public Stream GetArtwork(WebStreamMediaType mediatype, int? provider, string id, WebArtworkType artworktype, int offset)
 {
     return Images.GetImage(new ImageMediaSource(mediatype, provider, id, artworktype, offset));
 }
 public Stream GetArtworkResized(WebStreamMediaType mediatype, int? provider, string id, WebArtworkType artworktype, int offset, int maxWidth, int maxHeight)
 {
     return Images.GetResizedImage(new MediaSource(mediatype, provider, id, offset), artworktype, maxWidth, maxHeight);
 }
Beispiel #8
0
 public MediaSource(WebMediaType type, int? provider, string id, WebArtworkType filetype)
     : this((WebStreamMediaType)type, provider, id, filetype, 0)
 {
 }
Beispiel #9
0
 protected virtual bool CheckArguments(WebStreamMediaType mediatype, WebArtworkType filetype)
 {
     return !(
                 (mediatype == WebStreamMediaType.TV && FileType != WebArtworkType.Content) ||
                 (mediatype == WebStreamMediaType.Recording && FileType != WebArtworkType.Content)
             );
 }
Beispiel #10
0
 public Stream GetArtwork(WebStreamMediaType mediatype, int?provider, string id, WebArtworkType artworktype, int offset)
 {
     return(Images.GetImage(new ImageMediaSource(mediatype, provider, id, artworktype, offset)));
 }
Beispiel #11
0
        private static ImageSource ConvertToImageSource(MediaSource source, WebArtworkType artworktype)
        {
            // handle tv and recordings specially
            if (source.MediaType == WebStreamMediaType.TV || source.MediaType == WebStreamMediaType.Recording)
            {
                if (artworktype != WebArtworkType.Logo)
                {
                    Log.Info("Requested invalid artwork mediatype={0} artworktype={1}", source.MediaType, artworktype);
                    return null;
                }

                // get display name
                int idChannel = source.MediaType == WebStreamMediaType.TV ?
                    Int32.Parse(source.Id) :
                    MPEServices.TAS.GetRecordingById(Int32.Parse(source.Id)).IdChannel;
                string channelName = MPEServices.TAS.GetChannelBasicById(idChannel).DisplayName;

                // find directory
                string tvLogoDir = Configuration.Streaming.TVLogoDirectory;
                if (!Directory.Exists(tvLogoDir))
                {
                    Log.Warn("TV logo directory {0} does not exists", tvLogoDir);
                    return null;
                }

                // find image
                DirectoryInfo dirinfo = new DirectoryInfo(tvLogoDir);
                var matched = dirinfo.GetFiles().Where(x => Path.GetFileNameWithoutExtension(x.Name).ToLowerInvariant() == channelName.ToLowerInvariant());
                if(matched.Count() == 0)
                {
                    Log.Debug("Did not find tv logo for channel {0}", channelName);
                    return null;
                }

                // great, return it
                return new ImageSource(matched.First().FullName);
            }

            // handle all 'standard' media cases
            // validate arguments
            var pathlist = MPEServices.MAS.GetPathList(source.Provider, (WebMediaType)source.MediaType, (WebFileType)artworktype, source.Id);
            if (pathlist == null || pathlist.Count <= source.Offset)
            {
                Log.Info("Requested unavailable artwork (offset not found) artworktype={0} {1}", artworktype, source.GetDebugName());
                WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound);
                return null;
            }
            string path = pathlist.ElementAt(source.Offset);

            Stream data = null;
            WebFileInfo info = MPEServices.MAS.GetFileInfo(source.Provider, (WebMediaType)source.MediaType, (WebFileType)artworktype, source.Id, source.Offset);
            if (!info.Exists)
            {
                Log.Info("Requested unavailable artwork (file not found) artworktype={0} {1}", artworktype, source.GetDebugName());
                return null;
            }
            else if (!info.IsLocalFile)
            {
                data = MPEServices.MAS.RetrieveFile(source.Provider, (WebMediaType)source.MediaType, (WebFileType)artworktype, source.Id, source.Offset);
                return new ImageSource(data);
            }
            else
            {
                return new ImageSource(path);
            }
        }
Beispiel #12
0
        public static Stream GetResizedImage(MediaSource source, WebArtworkType artworktype, int maxWidth, int maxHeight)
        {
            // load file
            ImageSource src = ConvertToImageSource(source, artworktype);
            if (src == null)
            {
                WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound);
                return null;
            }

            // create cache path
            string tmpDir = Path.Combine(Path.GetTempPath(), "MPExtended", "imagecache");
            if (!Directory.Exists(tmpDir))
                Directory.CreateDirectory(tmpDir);
            string cachedPath = Path.Combine(tmpDir, String.Format("rs_{0}_{1}_{2}_{3}.jpg", source.GetUniqueIdentifier(), artworktype, maxWidth, maxHeight));

            // check for existence on disk
            if (!File.Exists(cachedPath))
            {
                Image orig = Image.FromStream(src.GetDataStream());
                if (!ResizeImage(orig, cachedPath, maxWidth, maxHeight))
                {
                    return null;
                }
            }

            return StreamImage(new ImageSource(cachedPath));
        }
Beispiel #13
0
        public static Stream GetImage(MediaSource msource, WebArtworkType artworktype)
        {
            ImageSource source = ConvertToImageSource(msource, artworktype);
            if (source == null)
            {
                WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound);
                return null;
            }

            return StreamImage(source);
        }
Beispiel #14
0
 public ImageMediaSource(WebStreamMediaType type, int?provider, string id, WebArtworkType filetype, int offset)
     : base(type, provider, id, filetype, offset)
 {
 }
Beispiel #15
0
 protected override bool CheckArguments(WebStreamMediaType mediatype, WebArtworkType filetype)
 {
     if ((mediatype == WebStreamMediaType.TV || mediatype == WebStreamMediaType.Recording) && filetype == WebArtworkType.Logo)
         return true;
     return base.CheckArguments(mediatype, filetype);
 }
Beispiel #16
0
        public Stream GetArtworkResized(WebStreamMediaType mediatype, int?provider, string id, WebArtworkType artworktype, int offset, int maxWidth, int maxHeight)
        {
            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));
        }
Beispiel #17
0
 public ImageMediaSource(WebStreamMediaType type, int? provider, string id, WebArtworkType filetype, int offset)
     : base(type, provider, id, filetype, offset)
 {
 }
Beispiel #18
0
 public MediaSource(WebMediaType type, int?provider, string id, WebArtworkType filetype)
     : this((WebStreamMediaType)type, provider, id, filetype, 0)
 {
 }