private void ImportVideos() { string publicKey = _settings.GetSingleValue("VideoPublicKey"); string secretKey = _settings.GetSingleValue("VideoSecretKey"); int feedNumber = -1; if (!int.TryParse(_settings.GetSingleValue("VideoFeedNumber"), out feedNumber)) { Log("Invalid video feed number. Stopping.", LogLevel.Error); return; } if (!ValidateVideoPublicKey(publicKey)) { Log("Invalid video public key. Stopping.", LogLevel.Error); return; } if (!ValidateGuid(secretKey)) { Log("Invalid video secret key. Stopping.", LogLevel.Error); return; } Log("Starting video import.", LogLevel.Debug); string baseUrl = "http://livevideo.api.brafton.com/v2/"; string basePhotoUrl = "http://pictures.brafton.com/v2/"; AdferoVideoClient videoClient = new AdferoVideoClient(baseUrl, publicKey, secretKey); AdferoClient client = new AdferoClient(baseUrl, publicKey, secretKey); AdferoPhotoClient photoClient = new AdferoPhotoClient(basePhotoUrl); AdferoVideoDotNet.AdferoArticles.ArticlePhotos.AdferoArticlePhotosClient photos = client.ArticlePhotos(); string scaleAxis = AdferoVideoDotNet.AdferoPhotos.Photos.AdferoScaleAxis.X; AdferoVideoDotNet.AdferoArticles.Feeds.AdferoFeedsClient feeds = client.Feeds(); AdferoVideoDotNet.AdferoArticles.Feeds.AdferoFeedList feedList = feeds.ListFeeds(0, 10); AdferoVideoDotNet.AdferoArticles.Articles.AdferoArticlesClient articles = client.Articles(); AdferoVideoDotNet.AdferoArticles.Articles.AdferoArticleList articleList = articles.ListForFeed(feedList.Items[feedNumber].Id, "live", 0, 100); int articleCount = articleList.Items.Count; AdferoVideoDotNet.AdferoArticles.Categories.AdferoCategoriesClient categories = client.Categories(); foreach (AdferoVideoDotNet.AdferoArticles.Articles.AdferoArticleListItem item in articleList.Items) { int brafId = item.Id; AdferoVideoDotNet.AdferoArticles.Articles.AdferoArticle article = articles.Get(brafId); Post p = FindPost(article); if (p == null) { Log(string.Format("Importing new post '{0}' (ID {1}).", article.Fields["title"].Trim(), article.Id), LogLevel.Info); p = ConvertToPost(article, categories, videoClient); ImportCategories(p); PhotoInstance? thumbnail = GetPhotoInstance(article, photos, photoClient, scaleAxis, 180); PhotoInstance? fullSizePhoto = GetPhotoInstance(article, photos, photoClient, scaleAxis, 500); ImportPhotos(p, thumbnail, fullSizePhoto); if (!p.Valid) { Log(string.Format("Error: post '{0}' invalid: '{1}'", p.ValidationMessage), LogLevel.Error); continue; } else p.Save(); } } }
private Post ConvertToPost(AdferoVideoDotNet.AdferoArticles.Articles.AdferoArticle article, AdferoVideoDotNet.AdferoArticles.Categories.AdferoCategoriesClient categories, AdferoVideoClient videoClient) { Post p = new Post(); p.Author = "Admin"; AdferoVideoDotNet.AdferoArticles.Categories.AdferoCategoryList categoryList = categories.ListForArticle(article.Id, 0, 100); for (int i = 0; i < categoryList.TotalCount; i++) { AdferoVideoDotNet.AdferoArticles.Categories.AdferoCategory category = categories.Get(categoryList.Items[i].Id); p.Categories.Add(new Category(GetCleanCategoryName(category.Name), "")); } string embedCode = videoClient.VideoPlayers().GetWithFallback(article.Id, AdferoVideoDotNet.AdferoArticlesVideoExtensions.VideoPlayers.AdferoPlayers.RedBean, new AdferoVideoDotNet.AdferoArticlesVideoExtensions.VideoPlayers.AdferoVersion(1,0,0),AdferoVideoDotNet.AdferoArticlesVideoExtensions.VideoPlayers.AdferoPlayers.RcFlashPlayer, new AdferoVideoDotNet.AdferoArticlesVideoExtensions.VideoPlayers.AdferoVersion(1,0,0)).EmbedCode; p.Content = string.Format("<div class=\"videoContainer\">{0}</div> {1}", embedCode, article.Fields["content"]); p.DateCreated = DateTime.Parse(article.Fields["date"]); p.DateModified = DateTime.Parse(article.Fields["lastModifiedDate"]); p.Description = article.Fields["extract"]; p.Slug = Slugify(article.Fields["title"]); p.Title = article.Fields["title"].Trim(); return p; }