Esempio n. 1
0
        /// <summary>
        /// Get all the assets (video) information (e.g. PlayPath)
        /// </summary>
        public async Task <bool> GetAsset()
        {
            if (this.ProgramUuid == null)
            {
                log.LogError("ProgramUuid IS NOT SET - cannot retrieve ReferenceFile");
                return(false);
            }
            var asset = await NhkApi.GetAsset(this.ProgramUuid, log);

            if (asset != null)
            {
                var referenceFile = (JObject)asset["referenceFile"];
                var assetFiles    = (JArray)asset["assetFiles"];

                // Collect all the information to create an M3U8 file
                var bitrate          = String.Empty;
                var aspect           = String.Empty;
                var width            = String.Empty;
                var height           = String.Empty;
                var playPath         = String.Empty;
                var hasReferenceFile = false;

                // Get the reference file (HD)
                playPath = (string)referenceFile["rtmp"]["play_path"];
                playPath = playPath.Split('?')[0];

                // Check if reference file actually exists (sometimes it doesn't)
                var reference_url = String.Format("https://nhkw-mzvod.akamaized.net/www60/mz-nhk10/_definst_/{0}/chunklist.m3u8", playPath);
                var response      = await AkamaiHttpClient.GetAsync(reference_url);

                if (response.IsSuccessStatusCode)
                {
                    // Exists, add it and use the metadata
                    bitrate          = (string)referenceFile["videoBitrate"];
                    aspect           = (string)referenceFile["aspectRatio"];
                    width            = (string)referenceFile["videoWidth"];
                    height           = (string)referenceFile["videoHeight"];
                    this.Path1080P   = reference_url;
                    hasReferenceFile = true;
                }

                // Get the 720P Version
                var asset720p = assetFiles[0];
                playPath      = (string)asset720p["rtmp"]["play_path"];
                playPath      = playPath.Split('?')[0];
                this.Path720P = String.Format("https://nhkw-mzvod.akamaized.net/www60/mz-nhk10/_definst_/{0}/chunklist.m3u8", playPath);

                // If we do not have a reference file
                // use the video information from 720P
                if (!hasReferenceFile)
                {
                    bitrate          = (string)asset720p["videoBitrate"];
                    aspect           = (string)asset720p["aspectRatio"];
                    width            = (string)asset720p["videoWidth"];
                    height           = (string)asset720p["videoHeight"];
                    hasReferenceFile = false;
                }

                this.Aspect           = aspect;
                this.Width            = width;
                this.Height           = height;
                this.HasReferenceFile = hasReferenceFile;
                return(true);
            }
            else
            {
                return(false);
            }
        }