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(); } } } }
public void ImportVideos() { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Import articles with video enabled /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string publicKey = MyGlobals.VideoPublicKey; string secretKey = MyGlobals.VideoSecretKey; int feedNumber; int tempCatID; int tempEntryID; string tempSlug; int PageTabId = 1; //Validation below. I added these validation methods beneath the ImportVideos() method if (!int.TryParse(MyGlobals.VideoFeedText, out feedNumber)) { MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "Invalid video feed number. Stopping"; return; } if (!BraftonVideoClass.ValidateVideoPublicKey(publicKey)) { MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "Invalid video public key. Stopping."; return; } if (!BraftonVideoClass.ValidateGuid(secretKey)) { MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "Invalid video public key. Stopping."; return; } //This is establishing the URLs for the video api,creating a new videoClient object, and then using the client libraries to get the video articles from the feed - Ly //string baseUrl = "http://api.video.brafton.com"; //string basePhotoUrl = "http://pictures.directnews.co.uk/v2/"; string baseUrl = "http://" + MyGlobals.VideoBaseURL + "/v2/"; string basePhotoUrl = "http://" + MyGlobals.VideoPhotoURL + "/v2/"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "<br>***********************************************<br>"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "<br>***********Global base URL- brafton.cs***********************<br>"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + baseUrl; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "<br>***********************************************<br>"; AdferoVideoClient videoClient = new AdferoVideoClient(baseUrl, publicKey, secretKey); AdferoClient client = new AdferoClient(baseUrl, publicKey, secretKey); AdferoPhotoClient photoClient = new AdferoPhotoClient(basePhotoUrl); AdferoVideoOutputsClient xc = new AdferoVideoClient(baseUrl, publicKey, secretKey).VideoOutputs(); 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); MyGlobals.brafID = brafId; string brafIDForInsert = brafId.ToString(); string presplashLink; if (article.Fields.ContainsKey("preSplash")) { presplashLink = article.Fields["preSplash"]; } else { presplashLink = ""; } #region Build Embed /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Build the embed to be added to the content section of the blog entry /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string display = "<video id='video-" + brafIDForInsert + "' class='ajs-default-skin atlantis-js' controls preload='auto' width='512' height='288' poster='" + presplashLink + "'>"; // For each Video Output foreach (AdferoVideoDotNet.AdferoArticlesVideoExtensions.VideoOutputs.AdferoVideoOutputListItem vidOut in videoClient.VideoOutputs().ListForArticle(brafId, 0, 20).Items) { int vidid = vidOut.Id; string displayType = ""; var z = xc.Get(vidid); displayType = z.Path.Substring(z.Path.Length - 3); if (displayType == "flv") { displayType = "flash"; } if (displayType == "ebm") { displayType = "webm"; } string displayPath = z.Path; string displayHeight = z.Height.ToString(); display = display + "<source src='" + displayPath + "' type='video/" + displayType + "' data-resolution='" + displayHeight + "' />"; } // Add the closing tag and the atlantis script display = display + "</video><script type='text/javascript'>var atlantisVideo = AtlantisJS.Init({videos: [{id: 'video-" + brafIDForInsert + "'}]});</script>"; #endregion Build embed #region set globals /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Set Global Variables in Globals.cs /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //This area adds all the fields to the Global variables class so that they are accessible from the BraftonVideoClass //I know there is a better way to do this but I did it this was for simplicity and in case I needed them somewhere else string addDate = article.Fields["date"]; MyGlobals.tempID = brafIDForInsert; if (article.Fields.ContainsKey("title")) { MyGlobals.tempTitle = article.Fields["title"]; } else { MyGlobals.tempTitle = ""; } if (article.Fields.ContainsKey("extract")) { MyGlobals.tempExtract = article.Fields["extract"]; } else { MyGlobals.tempExtract = ""; } if (article.Fields.ContainsKey("content")) { MyGlobals.tempcontent = article.Fields["content"]; } else { MyGlobals.tempcontent = ""; } MyGlobals.tempDate = DateTime.Parse(addDate); MyGlobals.tempPaths = display; #endregion tempEntryID = BraftonVideoClass.InsertVideoPost(); tempSlug = article.Fields["title"]; #region Update Permalink /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Update permalink /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string permalink; string slug = strip(tempSlug); //Create Permalink using (DNNDataLayerDataContext dnnContext = new DNNDataLayerDataContext()) { Brafton.Modules.BraftonImporter7_02_02.dbDataLayer.Blog_Entry pk = dnnContext.Blog_Entries.FirstOrDefault(x => x.BraftonID == brafIDForInsert); //Update the permalink if (pk != null) { permalink = "/blog/EntryId/" + pk.EntryID + "/" + slug; pk.PermaLink = permalink; dnnContext.SubmitChanges(); } } #endregion Update Permalink #region Categories /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Add categories to Blog_Entry_Categories table /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// foreach (AdferoVideoDotNet.AdferoArticles.Categories.AdferoCategoryListItem cats in client.Categories().ListForArticle(brafId, 0, 20).Items) { int categoryId; int catTest = cats.Id; string catName = categories.Get(catTest).Name; if (catName == null) { catName = "Uncategorized"; } int pID = categories.Get(catTest).ParentId; string catslug = strip(catName) + ".aspx"; using (DNNDataLayerDataContext dnnContext = new DNNDataLayerDataContext()) { Brafton.Modules.BraftonImporter7_02_02.dbDataLayer.Blog_Category ca = dnnContext.Blog_Categories.FirstOrDefault(x => x.Category == catName); //Insert into category if (ca != null) { categoryId = ca.CatID; } else { Blog_Category newBlogCat = new Blog_Category(); newBlogCat.Category = catName; newBlogCat.Slug = catslug; newBlogCat.ParentID = pID; newBlogCat.PortalID = 0; dnnContext.Blog_Categories.InsertOnSubmit(newBlogCat); dnnContext.SubmitChanges(); categoryId = newBlogCat.CatID; } Brafton.Modules.BraftonImporter7_02_02.dbDataLayer.Blog_Entry_Category bec = dnnContext.Blog_Entry_Categories.FirstOrDefault(x => x.EntryID == tempEntryID && x.CatID == categoryId); if (bec == null) { Blog_Entry_Category newBlogEntryCat = new Blog_Entry_Category(); newBlogEntryCat.EntryID = tempEntryID; newBlogEntryCat.CatID = categoryId; dnnContext.Blog_Entry_Categories.InsertOnSubmit(newBlogEntryCat); dnnContext.SubmitChanges(); } } } #endregion Categories } #endregion Video Import }
public static void addPhotos(int brafId, string entry, string extract) { //AdferoVideoOutputsClient xc = new AdferoVideoClient(baseUrl, publicKey, secretKey).VideoOutputs(); string publicKey = MyGlobals.VideoPublicKey; string secretKey = MyGlobals.VideoSecretKey; string baseUrl = "http://" + MyGlobals.VideoBaseURL + "/v2/"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "************Just checking the BAseURL**********************<br>"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + baseUrl; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "<br>***********************************************<br>"; //in case there are no photos MyGlobals.CompleteContent = entry; MyGlobals.CompleteExtract = extract; AdferoClient client = new AdferoClient(baseUrl, publicKey, secretKey); AdferoVideoDotNet.AdferoArticles.ArticlePhotos.AdferoArticlePhotosClient photos = client.ArticlePhotos(); foreach (AdferoVideoDotNet.AdferoArticles.ArticlePhotos.AdferoArticlePhotoListItem phot in photos.ListForArticle(brafId, 0, 20).Items) { //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "////////////////////////Display entry Preimage///////////////////////////////<br>"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "Here is a photo" + phot.Id; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "<br>/////////////////////////////////////////////////////////////////////////<br>"; //string test = photos.Get(brafId).SourcePhotoId.ToString(); int imageID = phot.Id; int photoID = photos.Get(imageID).SourcePhotoId; string alttext = photos.Get(imageID).Fields["altText"]; string caption = photos.Get(imageID).Fields["caption"]; MyGlobals.imageID = photoID.ToString(); string photoURL = "http://" + MyGlobals.VideoPhotoURL + "/v2/photo/" + photoID + ".jpg"; //TODO still need to add global value here //string entry = "TEST CONTENT"; //string description = "TEST EXTRACT"; string appPath = HttpRuntime.AppDomainAppVirtualPath == "/" ? appPath = "" : appPath = HttpRuntime.AppDomainAppVirtualPath; GetImages retrieveImage2 = new GetImages(photoURL, entry, extract, appPath, caption); retrieveImage2.DownloadImageDebug(); MyGlobals.CompleteContent = retrieveImage2._entry; MyGlobals.CompleteExtract = retrieveImage2._description; } }