Esempio n. 1
0
        /// <summary>
        /// Extracts the Episode detail information (e.g. Title)
        /// </summary>
        public async Task <bool> GetEpisodeDetail()
        {
            if (this.VodId == null)
            {
                log.LogError("GetEpisodeDetail - VodId IS NOT SET - cannot retrieve episode details");
                return(false);
            }

            var detail = await NhkApi.GetEpisode(this.VodId, log);

            if (detail != null)
            {
                this.Title    = (string)detail["title_clean"];
                this.Plot     = (string)detail["description_clean"];
                this.PgmNo    = (string)detail["pgm_no"];
                this.OnAir    = (string)detail["onair"];
                this.Duration = (string)detail["movie_duration"];
                return(true);
            }
            else
            {
                // Episode lookup does not work for all Playlist episodes
                // Set a dummy Title
                this.Title    = "From Playlist";
                this.PgmNo    = "0";
                this.Duration = "0";
                return(true);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets all the program details from NHK
        /// </summary>
        public async Task <bool> GetFromNHK()
        {
            bool success = false;

            this.ProgramUuid = await NhkApi.GetProgramUuid(this.VodId, log);

            if (this.ProgramUuid != null)
            {
                if (await GetAsset())
                {
                    if (await GetEpisodeDetail())
                    {
                        success = true;
                    }
                }
            }

            return(success);
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Populates CosmosDB with the latest list of programs
        /// </summary>
        /// <returns>Number of items written to CosmosDB</returns>
        public static async Task <bool> PopulateCloudCache(ILogger log)
        {
            var episodes = await NhkApi.GetVodIdList(log);

            // Get the existing entries from CosmosDB
            var                       sqlQueryText           = "SELECT c.id FROM c";
            QueryDefinition           queryDefinition        = new QueryDefinition(sqlQueryText);
            FeedIterator <VodProgram> queryResultSetIterator = Database.VodProgram.GetItemQueryIterator <VodProgram>(queryDefinition);


            var  dbEpisodes    = new List <VodProgram>();
            int  insertCounter = 0;
            int  deleteCounter = 0;
            bool success       = false;

            while (queryResultSetIterator.HasMoreResults)
            {
                FeedResponse <VodProgram> currentResultSet = await queryResultSetIterator.ReadNextAsync();

                dbEpisodes.AddRange(currentResultSet);
            }

            var dbVodIds = from p in dbEpisodes
                           select p.VodId;

            // Update CosmosDB with new entries
            foreach (var vodId in episodes)
            {
                // Check if vodId is already in CosmosDB
                if (!dbVodIds.Contains(vodId))
                {
                    // No, create it it!
                    success = false;
                    var program = new VodProgram(vodId, log);
                    success = await program.Get();

                    if (success)
                    {
                        insertCounter++;
                    }
                }
            }

            // Delete stale DB Entries
            foreach (var vodId in dbVodIds)
            {
                // Check if vodId no longer exists in NHK episode list
                if (!episodes.Contains(vodId))
                {
                    // It doesn't exist, delete it
                    success = false;
                    var program = new VodProgram(vodId, log);
                    success = await program.Delete();

                    if (success)
                    {
                        deleteCounter++;
                    }
                }
            }

            log.LogInformation(String.Format("Inserted {0} - deleted {1} episodes from CosmosDB", insertCounter, deleteCounter));

            return(true);
        }