Example #1
0
        /// <summary>
        /// Process performs a HLS transcode on a media item
        /// </summary>
        public void Process(UriWrapper uri, IHttpProcessor processor, User user)
        {
            // Verify ID received
            if (uri.Id == null)
            {
                processor.WriteJson(new TranscodeHlsResponse("Missing required parameter 'id'"));
                return;
            }

            try
            {
                // Get the media item associated with this id
                ItemType   itemType = Injection.Kernel.Get <IItemRepository>().ItemTypeForItemId((int)uri.Id);
                IMediaItem item     = null;
                if (itemType == ItemType.Song)
                {
                    item = Injection.Kernel.Get <ISongRepository>().SongForId((int)uri.Id);
                    logger.IfInfo("HLS transcoding for songs not currently supported");

                    // CURRENTLY DO NOT SUPPORT HLS STREAMING FOR SONGS
                    return;
                }
                else if (itemType == ItemType.Video)
                {
                    item = Injection.Kernel.Get <IVideoRepository>().VideoForId((int)uri.Id);
                    logger.IfInfo("Preparing video stream: " + item.FileName);
                }

                // Return an error if none exists
                if ((item == null) || (!File.Exists(item.FilePath())))
                {
                    processor.WriteJson(new TranscodeHlsResponse("No media item exists with ID: " + (int)uri.Id));
                    return;
                }

                // Generate the playlist file
                string   response       = null;
                string[] transQualities = uri.Parameters.ContainsKey("transQuality") ? uri.Parameters["transQuality"].Split(',') : new string[] { "Medium" };
                if (transQualities.Length == 1)
                {
                    // This is a single playlist
                    response = this.GeneratePlaylist(item, transQualities[0], uri);
                }
                else
                {
                    // This is a multi playlist
                    response = this.GenerateMultiPlaylist(item, transQualities, uri);
                }

                processor.WriteText(response, "application/x-mpegURL");
                logger.IfInfo("Successfully HLS transcoded file!");
            }
            catch (Exception e)
            {
                logger.Error(e);
            }
        }
        /// <summary>
        /// Process performs a HLS transcode on a media item
        /// </summary>
        public void Process(UriWrapper uri, IHttpProcessor processor, User user)
        {
            // Verify ID received
            if (uri.Id == null)
            {
                processor.WriteJson(new TranscodeHlsResponse("Missing required parameter 'id'"));
                return;
            }

            try
            {
                // Get the media item associated with this id
                ItemType itemType = Injection.Kernel.Get<IItemRepository>().ItemTypeForItemId((int)uri.Id);
                IMediaItem item = null;
                if (itemType == ItemType.Song)
                {
                    item = Injection.Kernel.Get<ISongRepository>().SongForId((int)uri.Id);
                    logger.IfInfo("HLS transcoding for songs not currently supported");

                    // CURRENTLY DO NOT SUPPORT HLS STREAMING FOR SONGS
                    return;
                }
                else if (itemType == ItemType.Video)
                {
                    item = Injection.Kernel.Get<IVideoRepository>().VideoForId((int)uri.Id);
                    logger.IfInfo("Preparing video stream: " + item.FileName);
                }

                // Return an error if none exists
                if ((item == null) || (!File.Exists(item.FilePath())))
                {
                    processor.WriteJson(new TranscodeHlsResponse("No media item exists with ID: " + (int)uri.Id));
                    return;
                }

                // Generate the playlist file
                string response = null;
                string[] transQualities = uri.Parameters.ContainsKey("transQuality") ? uri.Parameters["transQuality"].Split(',') : new string[] {"Medium"};
                if (transQualities.Length == 1)
                {
                    // This is a single playlist
                    response = this.GeneratePlaylist(item, transQualities[0], uri);
                }
                else
                {
                    // This is a multi playlist
                    response = this.GenerateMultiPlaylist(item, transQualities, uri);
                }

                processor.WriteText(response, "application/x-mpegURL");
                logger.IfInfo("Successfully HLS transcoded file!");
            }
            catch (Exception e)
            {
                logger.Error(e);
            }
        }