static YouTubeVideoSource()
        {
            All = new List<YouTubeVideoSource>();

            // Seed the global tags list with some interesting keywords/buzzwords that might not fit into local source tags
            GlobalTags = new HashSet<string>
            {
                "asp.net", ".net", "windows 10", "c#", "machine learning", "big data", "tutorial", "beginner", "mvc", "roslyn", "docker",
                "internet of things", "time series", "data model"
            };
            
            // Init all available sources
            PlanetCassandra = new VideosFromChannel("UCvP-AXuCr-naAeEccCfKwUA", new [] { "cassandra", "database", "nosql" });
            DataStaxMedia = new VideosFromChannel("UCqA6zOSMpQ55vvguq4Y0jAg", new[] { "datastax", "cassandra", "database", "nosql" });
            MicrosoftAzure = new VideosFromChannel("UC0m-80FnNY2Qb7obvTL_2fA", new[] { "microsoft", "azure", "cloud", "windows", "linux" });
            MicrosoftCloudPlatform = new VideosFromChannel("UCSgzRJMqIiCNtoM6Q7Q9Lqw", new[] { "microsoft", "azure", "cloud", "windows", "linux" });
            Hanselman = new VideosFromChannel("UCL-fHOdarou-CR2XUmK48Og", new[] { "microsoft", "windows", "linux", "azure" });
            CassandraDatabase = new VideosWithKeyword("cassandra database", new[] { "cassandra", "database", "nosql" });

            FunnyCatVideos = new VideosWithKeyword("funny cat videos", new[] { "cat", "funny" });
            GrumpyCat = new VideosFromChannel("UCTzVrd9ExsI3Zgnlh3_btLg", new[] { "grumpy cat", "funny" });
            MovieTrailers = new VideosFromChannel("UCi8e0iOVk1fEOogdfu4YgfA", new[] { "movie", "trailer", "preview" });
            Snl = new VideosFromChannel("UCqFzWxSCi39LnW1JKFR3efg", new[] { "snl", "saturday night live", "comedy" });
            KeyAndPeele = new VideosFromPlaylist("PL83DDC2327BEB616D", new[] { "key and peele", "comedy" });
        }
Пример #2
0
        static YouTubeVideoSource()
        {
            All = new List <YouTubeVideoSource>();

            // Seed the global tags list with some interesting keywords/buzzwords that might not fit into local source tags
            GlobalTags = new HashSet <string>
            {
                "asp.net", ".net", "windows 10", "c#", "machine learning", "big data", "tutorial", "beginner", "mvc", "roslyn", "docker",
                "internet of things", "time series", "data model"
            };

            // Init all available sources
            PlanetCassandra        = new VideosFromChannel("UCvP-AXuCr-naAeEccCfKwUA", new [] { "cassandra", "database", "nosql" });
            DataStaxMedia          = new VideosFromChannel("UCqA6zOSMpQ55vvguq4Y0jAg", new[] { "datastax", "cassandra", "database", "nosql" });
            MicrosoftAzure         = new VideosFromChannel("UC0m-80FnNY2Qb7obvTL_2fA", new[] { "microsoft", "azure", "cloud", "windows", "linux" });
            MicrosoftCloudPlatform = new VideosFromChannel("UCSgzRJMqIiCNtoM6Q7Q9Lqw", new[] { "microsoft", "azure", "cloud", "windows", "linux" });
            Hanselman         = new VideosFromChannel("UCL-fHOdarou-CR2XUmK48Og", new[] { "microsoft", "windows", "linux", "azure" });
            CassandraDatabase = new VideosWithKeyword("cassandra database", new[] { "cassandra", "database", "nosql" });

            FunnyCatVideos = new VideosWithKeyword("funny cat videos", new[] { "cat", "funny" });
            GrumpyCat      = new VideosFromChannel("UCTzVrd9ExsI3Zgnlh3_btLg", new[] { "grumpy cat", "funny" });
            MovieTrailers  = new VideosFromChannel("UCi8e0iOVk1fEOogdfu4YgfA", new[] { "movie", "trailer", "preview" });
            Snl            = new VideosFromChannel("UCqFzWxSCi39LnW1JKFR3efg", new[] { "snl", "saturday night live", "comedy" });
            KeyAndPeele    = new VideosFromPlaylist("PL83DDC2327BEB616D", new[] { "key and peele", "comedy" });
        }
        private static YouTubeVideo MapToYouTubeVideo(Row row, YouTubeVideoSource source, Random random)
        {
            // Map to video
            var video = new YouTubeVideo
            {
                Source         = source,
                PublishedAt    = row.GetValue <DateTimeOffset>("published_at"),
                YouTubeVideoId = row.GetValue <string>("youtube_video_id"),
                Name           = row.GetValue <string>("name"),
                Description    = row.GetValue <string>("description")
            };

            // Choose some tags for the video (this isn't a fantastic way to do this, but since it's sample data, it will do)
            var tags    = new HashSet <string>();
            int maxTags = random.Next(3, 6);

            string lowerName        = video.Name.ToLowerInvariant();
            string lowerDescription = video.Description.ToLowerInvariant();

            foreach (string possibleTag in source.PossibleTags)
            {
                if (lowerName.Contains(possibleTag) || lowerDescription.Contains(possibleTag))
                {
                    tags.Add(possibleTag);
                }

                if (tags.Count == maxTags)
                {
                    break;
                }
            }

            // If we didn't get any tags, just pick some random ones specific to the source
            if (tags.Count == 0)
            {
                foreach (string tag in source.SourceTags.Take(maxTags))
                {
                    tags.Add(tag);
                }
            }

            // Return video with suggested tags
            video.SuggestedTags = tags;
            return(video);
        }
        /// <summary>
        /// Gets a list of unused YouTubeVideos with the page size specified.
        /// </summary>
        public async Task <List <YouTubeVideo> > GetUnusedVideos(int pageSize)
        {
            // Statement for getting unused videos from a source
            PreparedStatement prepared =
                await _statementCache.NoContext.GetOrAddAsync("SELECT * FROM sample_data_youtube_videos WHERE sourceid = ?");

            // Iterate the list of sources in random order
            var random  = new Random();
            var indexes = Enumerable.Range(0, YouTubeVideoSource.All.Count).OrderBy(_ => random.Next());

            // Build a list of unused videos from the available sources in random order
            var unusedVideos = new List <YouTubeVideo>();

            foreach (int idx in indexes)
            {
                YouTubeVideoSource source = YouTubeVideoSource.All[idx];

                // Use automatic paging to page through all the videos from the source
                BoundStatement bound = prepared.Bind(source.UniqueId);
                bound.SetPageSize(MaxVideosPerRequest);
                RowSet rowSet = await _session.ExecuteAsync(bound).ConfigureAwait(false);

                foreach (Row row in rowSet)
                {
                    var used = row.GetValue <bool?>("used");
                    if (used == false || used == null)
                    {
                        unusedVideos.Add(MapToYouTubeVideo(row, source, random));
                    }

                    // If we've got enough videos, return them
                    if (unusedVideos.Count == pageSize)
                    {
                        return(unusedVideos);
                    }
                }
            }

            // We were unable to fill the quota, so throw
            throw new InvalidOperationException("Unable to get unused videos.  Time to add more sources?");
        }
 /// <summary>
 /// Refreshes the videos cached in Cassandra for the given source.
 /// </summary>
 public Task RefreshSource(YouTubeVideoSource source)
 {
     return(source.RefreshVideos(this));
 }