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);
        }
        private PhotoInstance?GetPhotoInstance(AdferoVideoDotNet.AdferoArticles.Articles.AdferoArticle article, AdferoVideoDotNet.AdferoArticles.ArticlePhotos.AdferoArticlePhotosClient photos, AdferoVideoDotNet.AdferoPhotos.AdferoPhotoClient photoClient, string scaleAxis, int scale)
        {
            PhotoInstance?inst = null;

            AdferoVideoDotNet.AdferoArticles.ArticlePhotos.AdferoArticlePhotoList photoList = photos.ListForArticle(article.Id, 0, 100);
            if (photoList.TotalCount > 0)
            {
                AdferoVideoDotNet.AdferoArticles.ArticlePhotos.AdferoArticlePhoto apho = photos.Get(photoList.Items[0].Id);
                int photoId = apho.SourcePhotoId;
                AdferoVideoDotNet.AdferoPhotos.Photos.AdferoPhoto pho = photoClient.Photos().GetScaleLocationUrl(photoId, scaleAxis, scale);
                string photoUrl     = pho.LocationUri;
                string photoCaption = photos.Get(photoList.Items[0].Id).Fields["caption"];

                enumeratedTypes.enumPhotoOrientation ori = enumeratedTypes.enumPhotoOrientation.Landscape;
                if (scaleAxis == AdferoVideoDotNet.AdferoPhotos.Photos.AdferoScaleAxis.Y)
                {
                    ori = enumeratedTypes.enumPhotoOrientation.Portrait;
                }

                string cleanedUrl = photoUrl;
                if (cleanedUrl.IndexOf('?') >= 0)
                {
                    cleanedUrl = cleanedUrl.Substring(0, cleanedUrl.IndexOf('?'));
                }

                inst = new PhotoInstance()
                {
                    AltText             = photoCaption,
                    Caption             = photoCaption,
                    DestinationFileName = Slugify(article.Fields["title"]) + "-" + scale + Path.GetExtension(cleanedUrl),
                    Height      = 0,
                    Id          = apho.Id,
                    Orientation = ori,
                    Type        = enumeratedTypes.enumPhotoInstanceType.Custom,
                    Url         = photoUrl,
                    Width       = 0
                };
            }

            return(inst);
        }
Ejemplo n.º 3
0
        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
        }
 private Post FindPost(AdferoVideoDotNet.AdferoArticles.Articles.AdferoArticle a)
 {
     return(Post.Posts.Find(p => p.Title.Trim() == a.Fields["title"].Trim()));
 }
        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();
                    }
                }
            }
        }