Exemplo n.º 1
0
 protected virtual bool CheckArguments(WebStreamMediaType mediatype, WebArtworkType filetype)
 {
     return(!(
                (mediatype == WebStreamMediaType.TV && FileType != WebArtworkType.Content) ||
                (mediatype == WebStreamMediaType.Recording && FileType != WebArtworkType.Content)
                ));
 }
Exemplo n.º 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));
 }
Exemplo n.º 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");
            }
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
0
 public Stream GetArtwork(WebStreamMediaType mediatype, int? provider, string id, WebArtworkType artworktype, int offset)
 {
     return Images.GetImage(new ImageMediaSource(mediatype, provider, id, artworktype, offset));
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 public MediaSource(WebMediaType type, int? provider, string id, WebArtworkType filetype)
     : this((WebStreamMediaType)type, provider, id, filetype, 0)
 {
 }
Exemplo n.º 9
0
 protected virtual bool CheckArguments(WebStreamMediaType mediatype, WebArtworkType filetype)
 {
     return !(
                 (mediatype == WebStreamMediaType.TV && FileType != WebArtworkType.Content) ||
                 (mediatype == WebStreamMediaType.Recording && FileType != WebArtworkType.Content)
             );
 }
Exemplo n.º 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)));
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 14
0
 public ImageMediaSource(WebStreamMediaType type, int?provider, string id, WebArtworkType filetype, int offset)
     : base(type, provider, id, filetype, offset)
 {
 }
Exemplo n.º 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);
 }
Exemplo n.º 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));
        }
Exemplo n.º 17
0
 public ImageMediaSource(WebStreamMediaType type, int? provider, string id, WebArtworkType filetype, int offset)
     : base(type, provider, id, filetype, offset)
 {
 }
Exemplo n.º 18
0
 public MediaSource(WebMediaType type, int?provider, string id, WebArtworkType filetype)
     : this((WebStreamMediaType)type, provider, id, filetype, 0)
 {
 }