Exemple #1
0
 protected virtual bool CheckArguments(WebStreamMediaType mediatype, WebArtworkType filetype)
 {
     return(!(
                (mediatype == WebStreamMediaType.TV && FileType != WebArtworkType.Content) ||
                (mediatype == WebStreamMediaType.Recording && FileType != WebArtworkType.Content)
                ));
 }
        //
        // Streaming
        private int?GetProvider(WebStreamMediaType type)
        {
            switch (type)
            {
            case WebStreamMediaType.File:
                return(Settings.ActiveSettings.FileSystemProvider);

            case WebStreamMediaType.Movie:
                return(Settings.ActiveSettings.MovieProvider);

            case WebStreamMediaType.MusicAlbum:
            case WebStreamMediaType.MusicTrack:
                return(Settings.ActiveSettings.MusicProvider);

            case WebStreamMediaType.Picture:
                return(Settings.ActiveSettings.PicturesProvider);

            case WebStreamMediaType.Recording:
            case WebStreamMediaType.TV:
                return(0);

            case WebStreamMediaType.TVEpisode:
            case WebStreamMediaType.TVSeason:
            case WebStreamMediaType.TVShow:
                return(Settings.ActiveSettings.TVShowProvider);

            default:
                // this cannot happen
                return(0);
            }
        }
        public Stream ExtractImageResized(WebStreamMediaType type, int?provider, string itemId, int position, int maxWidth, int maxHeight)
        {
            int?calcMaxWidth  = maxWidth == 0 ? null : (int?)maxWidth;
            int?calcMaxHeight = maxHeight == 0 ? null : (int?)maxHeight;

            return(Images.ExtractImage(new MediaSource(type, provider, itemId), position, calcMaxWidth, calcMaxHeight));
        }
        public Stream GetImageResized(WebStreamMediaType type, int?provider, string id, int maxWidth, int maxHeight)
        {
            int?calcMaxWidth  = maxWidth == 0 ? null : (int?)maxWidth;
            int?calcMaxHeight = maxHeight == 0 ? null : (int?)maxHeight;

            return(Images.GetResizedImage(new ImageMediaSource(type, provider, id, WebArtworkType.Content, 0), calcMaxWidth, calcMaxHeight));
        }
        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));
        }
Exemple #6
0
 public static string GetMediaName(WebStreamMediaType type, string id)
 {
     try
     {
         switch (type)
         {
             case WebStreamMediaType.Movie:
                 return MPEServices.MAS.GetMovieBasicById(Settings.ActiveSettings.MovieProvider, id).Title;
             case WebStreamMediaType.MusicAlbum:
                 return MPEServices.MAS.GetMusicAlbumBasicById(Settings.ActiveSettings.MusicProvider, id).Title;
             case WebStreamMediaType.MusicTrack:
                 return MPEServices.MAS.GetMusicTrackBasicById(Settings.ActiveSettings.MusicProvider, id).Title;
             case WebStreamMediaType.Recording:
                 return MPEServices.TAS.GetRecordingById(Int32.Parse(id)).Title;
             case WebStreamMediaType.TV:
                 return MPEServices.TAS.GetChannelBasicById(Int32.Parse(id)).DisplayName;
             case WebStreamMediaType.TVEpisode:
                 return MPEServices.MAS.GetTVEpisodeBasicById(Settings.ActiveSettings.TVShowProvider, id).Title;
             case WebStreamMediaType.TVShow:
                 return MPEServices.MAS.GetTVShowBasicById(Settings.ActiveSettings.TVShowProvider, id).Title;
             case WebStreamMediaType.TVSeason:
             default:
                 return "";
         }
     }
     catch (Exception ex)
     {
         Log.Warn("Could not load display name of media", ex);
     }
     return "";
 }
 public MediaSource(WebStreamMediaType type, int? provider, string id)
 {
     this.MediaType = type;
     this.Id = id;
     this.Offset = 0;
     this.Provider = provider;
 }
        public ActionResult Download(WebStreamMediaType type, string item)
        {
            // Create URL to GetMediaItem
            var queryString = HttpUtility.ParseQueryString(String.Empty); // you can't instantiate that class manually for some reason
            queryString["type"] = ((int)type).ToString();
            queryString["itemId"] = item;
            string rootUrl = type == WebStreamMediaType.TV || type == WebStreamMediaType.Recording ? MPEServices.HttpTASStreamRoot : MPEServices.HttpMASStreamRoot;
            Uri fullUri = new Uri(rootUrl + "GetMediaItem?" + queryString.ToString());

            // Check stream type
            StreamType streamMode = Settings.ActiveSettings.StreamType;
            if (streamMode == StreamType.DirectWhenPossible)
            {
                streamMode = NetworkInformation.IsOnLAN(HttpContext.Request.UserHostAddress) ? StreamType.Direct : StreamType.Proxied;
            }

            // Do the actual streaming
            if (streamMode == StreamType.Proxied)
            {
                ProxyStream(fullUri.ToString());
            }
            else if (streamMode == StreamType.Direct)
            {
                return Redirect(fullUri.ToString());
            }
            return new EmptyResult();
        }
Exemple #9
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));
 }
 private IWebStreamingService GetStreamControl(WebStreamMediaType type)
 {
     if (type == WebStreamMediaType.TV || type == WebStreamMediaType.Recording)
     {
         return(MPEServices.TASStreamControl);
     }
     else
     {
         return(MPEServices.MASStreamControl);
     }
 }
Exemple #11
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");
            }
        }
Exemple #12
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 WebMediaInfo GetMediaInfo(WebStreamMediaType type, int?provider, string itemId)
        {
            if (type == WebStreamMediaType.TV)
            {
                try
                {
                    itemId = _timeshiftings[itemId].TimeShiftFileName;
                }
                catch (KeyNotFoundException)
                {
                    Log.Error("Client tried to get mediainfo for non-existing timeshifting {0}", itemId);
                    return(null);
                }
            }

            return(MediaInfo.MediaInfoWrapper.GetMediaInfo(new MediaSource(type, provider, itemId)));
        }
        public bool InitStream(WebStreamMediaType type, int?provider, string itemId, string clientDescription, string identifier)
        {
            if (type == WebStreamMediaType.TV)
            {
                int channelId = Int32.Parse(itemId);
                lock (_timeshiftings)
                {
                    Log.Info("Starting timeshifting on channel {0} for client {1} with identifier {2}", channelId, clientDescription, identifier);
                    var card = MPEServices.TAS.SwitchTVServerToChannelAndGetVirtualCard("webstreamingservice-" + identifier, channelId);
                    Log.Debug("Timeshifting started!");
                    _timeshiftings[identifier] = card;
                    itemId = card.TimeShiftFileName;
                }
            }

            Log.Info("Called InitStream with type={0}; provider={1}; itemId={2}; clientDescription={3}; identifier={4}", type, provider, itemId, clientDescription, identifier);
            return(_stream.InitStream(identifier, clientDescription, new MediaSource(type, provider, itemId)));
        }
        public Stream GetMediaItem(WebStreamMediaType type, int?provider, string itemId)
        {
            MediaSource source = new MediaSource(type, provider, itemId);

            try
            {
                if (!source.Exists)
                {
                    throw new FileNotFoundException();
                }
                return(source.Retrieve());
            }
            catch (Exception ex)
            {
                WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound);
                Log.Info(String.Format("GetMediaItem() failed for {0}", source.GetDebugName()), ex);
                return(Stream.Null);
            }
        }
        //
        // Player
        public ActionResult Player(WebStreamMediaType type, string itemId, bool showVideo = true)
        {
            // TODO: insert proper support for non-resizing players
            // TODO: insert proper support for VLC player

            // get the profile
            string target = showVideo ? "pc-flash-video" : "pc-flash-audio";
            string preferredProfile = showVideo ? "Flash LQ" : "Flash Audio";
            string transcoderName = Request.Params["player"] != null ? Request.Params["player"] : preferredProfile;
            WebTranscoderProfile profile = MPEServices.MASStreamControl.GetTranscoderProfileByName(transcoderName);
            if (profile == null || profile.Target != target) {
                List<WebTranscoderProfile> profiles = MPEServices.MASStreamControl.GetTranscoderProfilesForTarget(target);
                if(profiles.Count == 0)
                    throw new ArgumentException("Profile does not exists");
                profile = profiles.First();
            }
            VideoPlayer player = VideoPlayer.Flash;
            string viewName = Enum.GetName(typeof(VideoPlayer), player) + "Player";

            // player size
            WebResolution playerSize;
            if (!showVideo)
            {
                playerSize = new WebResolution() { Width = 300, Height = 120 };
            }
            else
            {
                playerSize = MPEServices.MASStreamControl.GetStreamSize((WebStreamMediaType)type, GetProvider((WebStreamMediaType)type), itemId, profile.Name);
            }

            // generate url
            RouteValueDictionary parameters = new RouteValueDictionary();
            parameters["item"] = itemId;
            parameters["transcoder"] = transcoderName;

            // generate view
            return PartialView(viewName, new StreamModel
            {
                URL = Url.Action(Enum.GetName(typeof(WebStreamMediaType), type), parameters),
                Size = playerSize
            });
        }
        private ActionResult GenerateStream(WebStreamMediaType type, string itemId, string transcoder)
        {
            string identifier = "webmediaportal-" + Guid.NewGuid().ToString("D");

            if (!GetStreamControl(type).InitStream((WebStreamMediaType)type, GetProvider(type), itemId, "WebMediaPortal", identifier))
            {
                Log.Error("Streaming: InitStream failed");
                return(new EmptyResult());
            }

            string url = GetStreamControl(type).StartStream(identifier, transcoder, 0);

            if (String.IsNullOrEmpty(url))
            {
                Log.Error("Streaming: StartStream failed");
                return(new EmptyResult());
            }

            // redirect user to stream (WSS has automatic stream killing now)
            return(Redirect(url));
        }
Exemple #18
0
        public ActionResult Download(WebStreamMediaType type, string item)
        {
            // Create URL to GetMediaItem
            Log.Debug("User wants to download type={0}; item={1}", type, item);
            var queryString = HttpUtility.ParseQueryString(String.Empty); // you can't instantiate that class manually for some reason
            queryString["clientDescription"] = String.Format("WebMediaPortal download (user {0})", HttpContext.User.Identity.Name);
            queryString["type"] = ((int)type).ToString();
            queryString["itemId"] = item;
            string rootUrl = type == WebStreamMediaType.TV || type == WebStreamMediaType.Recording ? MPEServices.HttpTASStreamRoot : MPEServices.HttpMASStreamRoot;
            UriBuilder fullUri = new UriBuilder(rootUrl + "GetMediaItem?" + queryString.ToString());

            // Check stream type
            StreamType streamMode = Settings.ActiveSettings.StreamType;
            if (streamMode == StreamType.DirectWhenPossible)
            {
                streamMode = NetworkInformation.IsOnLAN(HttpContext.Request.UserHostAddress) ? StreamType.Direct : StreamType.Proxied;
            }

            // If we connect to the services at localhost, actually give the extern IP address to users
            if (fullUri.Host == "localhost" || fullUri.Host == "127.0.0.1")
            {
                fullUri.Host = NetworkInformation.GetIPAddresses().First();
            }

            // Do the actual streaming
            if (streamMode == StreamType.Proxied)
            {
                Log.Debug("Proxying download at {0}", fullUri.ToString());
                GetStreamControl(type).AuthorizeStreaming();
                ProxyStream(fullUri.ToString());
            }
            else if (streamMode == StreamType.Direct)
            {
                Log.Debug("Redirecting user to download at {0}", fullUri.ToString());
                GetStreamControl(type).AuthorizeRemoteHostForStreaming(HttpContext.Request.UserHostAddress);
                return Redirect(fullUri.ToString());
            }
            return new EmptyResult();
        }
Exemple #19
0
        public Stream Download(string clientDescription, WebStreamMediaType type, int? provider, string itemId)
        {
            // validate source first
            MediaSource source = new MediaSource(type, provider, itemId);
            if (!source.Exists)
            {
                throw new FileNotFoundException();
            }

            // create context
            DownloadContext context = new DownloadContext()
            {
                ClientDescription = clientDescription,
                Source = source,
                StartTime = DateTime.Now,
                Stream = new ReadTrackingStreamWrapper(source.Retrieve()),
                MediaInfo = MediaInfoHelper.LoadMediaInfoOrSurrogate(source) // for playerposition view
            };

            // see comment in Streaming.cs:151
            string realIp = WCFUtil.GetHeaderValue("forwardedFor", "X-Forwarded-For");
            context.ClientIP = realIp == null ? WCFUtil.GetClientIPAddress() : String.Format("{0} (via {1})", realIp, WCFUtil.GetClientIPAddress());

            // set headers for downloading
            WCFUtil.AddHeader("Content-Disposition", "attachment; filename=\"" + source.GetFileInfo().Name + "\"");
            WCFUtil.SetContentLength(source.GetFileInfo().Size);

            // FIXME: there has to be a better way to do this
            string mime = MIME.GetFromFilename(source.GetFileInfo().Name);
            if (mime != null)
            {
                WCFUtil.SetContentType(mime);
            }

            // finally, save the context and return
            runningDownloads.Add(context);
            return context.Stream;
        }
 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);
 }
Exemple #21
0
 public MediaSource(WebStreamMediaType type, int?provider, string id, WebArtworkType filetype)
     : this(type, provider, id, filetype, 0)
 {
 }
        private ActionResult GenerateStream(WebStreamMediaType type, string itemId, string transcoder)
        {
            string identifier = "webmediaportal-" + Guid.NewGuid().ToString("D");
            if (!GetStreamControl(type).InitStream((WebStreamMediaType)type, GetProvider(type), itemId, "WebMediaPortal", identifier))
            {
                Log.Error("Streaming: InitStream failed");
                return new EmptyResult();
            }

            string url = GetStreamControl(type).StartStream(identifier, transcoder, 0);
            if (String.IsNullOrEmpty(url))
            {
                Log.Error("Streaming: StartStream failed");
                return new EmptyResult();
            }

            // redirect user to stream (WSS has automatic stream killing now)
            return Redirect(url);
        }
 public WebResolution GetStreamSize(WebStreamMediaType type, int?provider, string itemId, string profile)
 {
     return(_stream.CalculateSize(Configuration.Streaming.GetTranscoderProfileByName(profile), new MediaSource(type, provider, itemId)).ToWebResolution());
 }
 public Stream GetImage(WebStreamMediaType type, int? provider, string id)
 {
     return Images.GetImage(new ImageMediaSource(type, provider, id, WebArtworkType.Content, 0));
 }
 public Stream GetImage(WebStreamMediaType type, int?provider, string id)
 {
     return(Images.GetImage(new ImageMediaSource(type, provider, id, WebArtworkType.Content, 0)));
 }
        public WebMediaInfo GetMediaInfo(WebStreamMediaType type, int? provider, string itemId)
        {
            if (type == WebStreamMediaType.TV)
            {
                try
                {
                    itemId = _timeshiftings[itemId].TimeShiftFileName;
                }
                catch (KeyNotFoundException)
                {
                    Log.Error("Client tried to get mediainfo for non-existing timeshifting {0}", itemId);
                    return null;
                }
            }

            return MediaInfo.MediaInfoWrapper.GetMediaInfo(new MediaSource(type, provider, itemId));
        }
 public WebResolution GetStreamSize(WebStreamMediaType type, int? provider, string itemId, string profile)
 {
     return _stream.CalculateSize(Configuration.Streaming.GetTranscoderProfileByName(profile), new MediaSource(type, provider, itemId)).ToWebResolution();
 }
 public Stream ExtractImage(WebStreamMediaType type, int?provider, string itemId, int position)
 {
     return(Images.ExtractImage(new MediaSource(type, provider, itemId), position, null, null));
 }
 private IWebStreamingService GetStreamControl(WebStreamMediaType type)
 {
     if (type == WebStreamMediaType.TV || type == WebStreamMediaType.Recording)
     {
         return MPEServices.TASStreamControl;
     }
     else
     {
         return MPEServices.MASStreamControl;
     }
 }
Exemple #30
0
 public MediaSource(WebStreamMediaType type, int?provider, string id)
     : this(type, provider, id, WebArtworkType.Content, 0)
 {
 }
 public Stream GetArtwork(WebStreamMediaType mediatype, int?provider, string id, WebArtworkType artworktype, int offset)
 {
     return(Images.GetImage(new ImageMediaSource(mediatype, provider, id, artworktype, offset)));
 }
Exemple #32
0
 public ImageMediaSource(WebStreamMediaType type, int?provider, string id, WebArtworkType filetype, int offset)
     : base(type, provider, id, filetype, offset)
 {
 }
 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 ExtractImage(WebStreamMediaType type, int? provider, string itemId, int position)
 {
     return Images.ExtractImage(new MediaSource(type, provider, itemId), position, null, null);
 }
 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);
 }
Exemple #36
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);
 }
 public Stream GetImageResized(WebStreamMediaType type, int? provider, string id, int maxWidth, int maxHeight)
 {
     int? calcMaxWidth = maxWidth == 0 ? null : (int?)maxWidth;
     int? calcMaxHeight = maxHeight == 0 ? null : (int?)maxHeight;
     return Images.GetResizedImage(new ImageMediaSource(type, provider, id, WebArtworkType.Content, 0), calcMaxWidth, calcMaxHeight);
 }
        public ActionResult Player(WebStreamMediaType type, string itemId, bool video = true)
        {
            // get transcoding profile
            IWebStreamingService streamControl = GetStreamControl(type);
            WebTranscoderProfile profile       = null;

            if (Request.QueryString["transcoder"] != null)
            {
                profile = GetStreamControl(type).GetTranscoderProfileByName(Request.QueryString["transcoder"]);
            }
            if (Request.Form["transcoder"] != null)
            {
                profile = GetStreamControl(type).GetTranscoderProfileByName(Request.Form["transcoder"]);
            }
            if (profile == null)
            {
                string defaultName = "";
                if (type == WebStreamMediaType.TV || type == WebStreamMediaType.Recording)
                {
                    defaultName = Settings.ActiveSettings.DefaultTVProfile;
                }
                else if (video)
                {
                    defaultName = Settings.ActiveSettings.DefaultMediaProfile;
                }
                else
                {
                    defaultName = Settings.ActiveSettings.DefaultAudioProfile;
                }
                profile = GetStreamControl(type).GetTranscoderProfileByName(defaultName);
            }

            // get all transcoder profiles
            List <StreamTarget> targets  = video ? StreamTarget.GetVideoTargets() : StreamTarget.GetAudioTargets();
            List <string>       profiles = new List <string>();

            foreach (StreamTarget target in targets)
            {
                profiles = profiles.Concat(GetStreamControl(type).GetTranscoderProfilesForTarget(target.Name).Select(x => x.Name)).ToList();
            }

            // get view properties
            VideoPlayer player   = targets.First(x => x.Name == profile.Target).Player;
            string      viewName = Enum.GetName(typeof(VideoPlayer), player) + "Player";

            // player size
            WebResolution playerSize;

            if (!video)
            {
                playerSize = new WebResolution()
                {
                    Width = 300, Height = 150
                };
            }
            else
            {
                playerSize = GetStreamControl(type).GetStreamSize(type, GetProvider(type), itemId, profile.Name);
            }

            // generate url
            RouteValueDictionary parameters = new RouteValueDictionary();

            parameters["item"]       = itemId;
            parameters["transcoder"] = profile.Name;

            // generate view
            return(PartialView(new PlayerViewModel
            {
                Transcoders = profiles,
                Transcoder = profile.Name,
                Player = player,
                PlayerViewName = viewName,
                URL = Url.Action(Enum.GetName(typeof(WebStreamMediaType), type), parameters),
                Size = playerSize
            }));
        }
 public Stream GetMediaItem(WebStreamMediaType type, int? provider, string itemId)
 {
     MediaSource source = new MediaSource(type, provider, itemId);
     try
     {
         if (!source.Exists)
         {
             throw new FileNotFoundException();
         }
         return source.Retrieve();
     }
     catch (Exception ex)
     {
         WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound);
         Log.Info(String.Format("GetMediaItem() failed for {0}", source.GetDebugName()), ex);
         return Stream.Null;
     }
 }
Exemple #40
0
 public MediaSource(WebStreamMediaType type, int? provider, string id)
     : this(type, provider, id, WebArtworkType.Content, 0)
 {
 }
        public bool InitStream(WebStreamMediaType type, int? provider, string itemId, string clientDescription, string identifier)
        {
            if (type == WebStreamMediaType.TV)
            {
                int channelId = Int32.Parse(itemId);
                lock (_timeshiftings)
                {
                    Log.Info("Starting timeshifting on channel {0} for client {1} with identifier {2}", channelId, clientDescription, identifier);
                    var card = MPEServices.TAS.SwitchTVServerToChannelAndGetVirtualCard("webstreamingservice-" + identifier, channelId);
                    Log.Debug("Timeshifting started!");
                    _timeshiftings[identifier] = card;
                    itemId = card.TimeShiftFileName;
                }
            }

            Log.Info("Called InitStream with type={0}; provider={1}; itemId={2}; clientDescription={3}; identifier={4}", type, provider, itemId, clientDescription, identifier);
            return _stream.InitStream(identifier, clientDescription, new MediaSource(type, provider, itemId));
        }
 public Stream GetImage(WebStreamMediaType type, int? provider, string id)
 {
     return Images.GetImage(new MediaSource(type, provider, id));
 }
 public Stream ExtractImageResized(WebStreamMediaType type, int? provider, string itemId, int position, int maxWidth, int maxHeight)
 {
     int? calcMaxWidth = maxWidth == 0 ? null : (int?)maxWidth;
     int? calcMaxHeight = maxHeight == 0 ? null : (int?)maxHeight;
     return Images.ExtractImage(new MediaSource(type, provider, itemId), position, calcMaxWidth, calcMaxHeight);
 }
 public Stream GetImageResized(WebStreamMediaType type, int? provider, string id, int maxWidth, int maxHeight)
 {
     return Images.GetResizedImage(new MediaSource(type, provider, id), maxWidth, maxHeight);
 }
Exemple #45
0
 public ImageMediaSource(WebStreamMediaType type, int? provider, string id, WebArtworkType filetype, int offset)
     : base(type, provider, id, filetype, offset)
 {
 }
 public Stream GetMediaItem(WebStreamMediaType type, int? provider, string itemId)
 {
     MediaSource source = new MediaSource(type, provider, itemId);
     return source.Retrieve();
 }
 //
 // Streaming
 private int? GetProvider(WebStreamMediaType type)
 {
     switch (type)
     {
         case WebStreamMediaType.File:
             return Settings.ActiveSettings.FileSystemProvider;
         case WebStreamMediaType.Movie:
             return Settings.ActiveSettings.MovieProvider;
         case WebStreamMediaType.MusicAlbum:
         case WebStreamMediaType.MusicTrack:
             return Settings.ActiveSettings.MusicProvider;
         case WebStreamMediaType.Picture:
             return Settings.ActiveSettings.PicturesProvider;
         case WebStreamMediaType.Recording:
         case WebStreamMediaType.TV:
             return 0;
         case WebStreamMediaType.TVEpisode:
         case WebStreamMediaType.TVSeason:
         case WebStreamMediaType.TVShow:
             return Settings.ActiveSettings.TVShowProvider;
         default:
             // this cannot happen
             return 0;
     }
 }
 public Stream ExtractImageResized(WebStreamMediaType type, int? provider, string itemId, int position, int maxWidth, int maxHeight)
 {
     return Images.ExtractImage(new MediaSource(type, provider, itemId), position, maxWidth, maxHeight);
 }
        public ActionResult Player(WebStreamMediaType type, string itemId, bool video = true)
        {
            // get transcoding profile
            IWebStreamingService streamControl = GetStreamControl(type);
            WebTranscoderProfile profile = null;
            if (Request.QueryString["transcoder"] != null)
                profile = GetStreamControl(type).GetTranscoderProfileByName(Request.QueryString["transcoder"]);
            if (Request.Form["transcoder"] != null)
                profile = GetStreamControl(type).GetTranscoderProfileByName(Request.Form["transcoder"]);
            if (profile == null)
            {
                string defaultName = "";
                if(type == WebStreamMediaType.TV || type == WebStreamMediaType.Recording)
                {
                    defaultName = Settings.ActiveSettings.DefaultTVProfile;
                }
                else if(video)
                {
                    defaultName = Settings.ActiveSettings.DefaultMediaProfile;
                }
                else
                {
                    defaultName = Settings.ActiveSettings.DefaultAudioProfile;
                }
                profile = GetStreamControl(type).GetTranscoderProfileByName(defaultName);
            }

            // get all transcoder profiles
            List<StreamTarget> targets = video ? StreamTarget.GetVideoTargets() : StreamTarget.GetAudioTargets();
            List<string> profiles = new List<string>();
            foreach (StreamTarget target in targets)
            {
                profiles = profiles.Concat(GetStreamControl(type).GetTranscoderProfilesForTarget(target.Name).Select(x => x.Name)).ToList();
            }

            // get view properties
            VideoPlayer player = targets.First(x => x.Name == profile.Target).Player;
            string viewName = Enum.GetName(typeof(VideoPlayer), player) + "Player";

            // player size
            WebResolution playerSize;
            if (!video)
            {
                playerSize = new WebResolution() { Width = 300, Height = 150 };
            }
            else
            {
                playerSize = GetStreamControl(type).GetStreamSize(type, GetProvider(type), itemId, profile.Name);
            }

            // generate url
            RouteValueDictionary parameters = new RouteValueDictionary();
            parameters["item"] = itemId;
            parameters["transcoder"] = profile.Name;

            // generate view
            return PartialView(new PlayerViewModel
            {
                Transcoders = profiles,
                Transcoder = profile.Name,
                Player = player,
                PlayerViewName = viewName,
                URL = Url.Action(Enum.GetName(typeof(WebStreamMediaType), type), parameters),
                Size = playerSize
            });
        }
Exemple #50
0
 public MediaSource(WebStreamMediaType type, int? provider, string id, WebArtworkType filetype)
     : this(type, provider, id, filetype, 0)
 {
 }