예제 #1
0
        private IEnumerable <BasicContent> CreateFoldersFromChannels(VideoFolder entryPoint)
        {
            var          type   = ContentTypeRepository.Service.Load <VideoFolder>();
            List <Album> albums = TwentyThreeVideoRepository.GetChannelList();

            foreach (var album in albums)
            {
                var folder = ContentFactory.Service.CreateContent(type, new BuildingContext(type)
                {
                    Parent            = entryPoint,
                    LanguageSelector  = LanguageSelector.AutoDetect(),
                    SetPropertyValues = true
                }) as VideoFolder;
                if (folder == null)
                {
                    continue;
                }
                if (album.AlbumId != null)
                {
                    var id = (int)album.AlbumId;
                    folder.ContentLink = new ContentReference(id, Constants.ProviderKey);
                    folder.Name        = album.Title;

                    var editorGroup = new EditorGroupChannelMappingRepository().GetEditorGroupForChannel(folder.Name);
                    if (!string.IsNullOrWhiteSpace(editorGroup))
                    {
                        folder.EditorGroup = editorGroup;
                    }

                    _log.Information("23Video: Channel {0} created.", album.Title);
                    yield return(folder);
                }
            }
        }
예제 #2
0
 public bool PopulateVideo(Video video, Photo item)
 {
     if (item.PhotoId != null)
     {
         try
         {
             int id = (int)(item.PhotoId);
             video.VideoUrl         = EmbedCode(item.PhotoId.ToString(), item.Token, item.VideoHD.Width ?? item.VideoMedium.Width ?? item.VideoSmall.Width, item.VideoHD.Height ?? item.VideoMedium.Height ?? item.VideoSmall.Height);
             video.ContentLink      = new ContentReference((id).GetHashCode(), 0, Constants.ProviderKey);
             video.Id               = id.ToString();
             video.ContentGuid      = StringToGuid(id.ToString());
             video.Name             = item.Title;
             video.BinaryData       = GetThumbnail(item);
             video.Thumbnail        = ThumbnailManager.Service.CreateImageBlob(video.BinaryData, "thumbnail", new ImageDescriptorAttribute(48, 48));
             video.oEmbedVideoName  = item.One;
             video.VideoDownloadUrl = GetVideoDownloadUrl(item.VideoHD);
             video.PublishedIn23    = item.Published ?? false;
             video.OriginalHeight   = item.Original?.Height ?? 1;
             video.OriginalWidth    = item.Original?.Width ?? 1;
             if (SettingsRepository.Service.oEmbedIsEnabled && item.Published == true)
             {
                 var oEmbedCode = TwentyThreeVideoRepository.GetoEmbedCodeForVideo(item.One);
                 if (string.IsNullOrWhiteSpace(oEmbedCode))
                 {
                     _log.Information(
                         "23Video: 23Video returned empty oembed code. Videoname from 23Video {0}",
                         item.One);
                     return(false);
                 }
                 video.oEmbedHtml = oEmbedCode;
             }
             PopulateStandardVideoProperties(video);
         }
         catch (Exception e)
         {
             _log.Error("VideoHelper: PopulateVideo failed: VideoID: {0}, PhotoID: {1}, Exception: {2}", video != null && video.Id != null ? video.Id : "null", item != null && item.PhotoId != null ? item.PhotoId : 0, e.Message);
             throw;
         }
     }
     return(true);
 }
예제 #3
0
        public List <BasicContent> LoadFromService()
        {
            try
            {
                var entryPoint       = ContentRepositry.Service.GetChildren <VideoFolder>(ContentReference.RootPage).FirstOrDefault();
                var videoFolders     = CreateFoldersFromChannels(entryPoint).ToList();
                var videoContentList = new ConcurrentBag <BasicContent>(videoFolders);
                var videoHelper      = new VideoHelper();

                var options = new ParallelOptions
                {
                    MaxDegreeOfParallelism = SettingsRepository.Service.MaxDegreeOfParallelism
                };

                if (options.MaxDegreeOfParallelism == 0)
                {
                    throw new ArgumentOutOfRangeException("23Video: MaxDegreeOfParallelism settings must be -1 or a positive number");
                }

                Parallel.ForEach(videoFolders, options, folder =>
                {
                    if (folder is VideoFolder)
                    {
                        var videos = TwentyThreeVideoRepository.GetVideoList(folder.ContentLink.ID);

                        foreach (var videoData in videos)
                        {
                            var type  = ContentTypeRepository.Service.Load <Video>();
                            var video =
                                ContentFactory.Service.CreateContent(type, new BuildingContext(type)
                            {
                                Parent            = folder,
                                LanguageSelector  = LanguageSelector.AutoDetect(),
                                SetPropertyValues = true
                            }) as Video;
                            if (video != null)
                            {
                                _log.Debug("23Video: Added video with name {0}", video.Name);
                                if (videoHelper.PopulateVideo(video, videoData))
                                {
                                    videoContentList.Add(video);
                                }
                                else
                                {
                                    _log.Warning(
                                        "23Video: Failed validation, skipping add. Videoname from 23Video {0}",
                                        videoData.One);
                                }
                            }
                            else
                            {
                                _log.Information(
                                    "23Video: Video from 23Video can not be loaded in EPiServer as Video. Videoname from 23Video {0}",
                                    videoData.One);
                            }
                        }
                    }
                }
                                 );
                return(videoContentList.Where(_ => _ != null).ToList());
            }
            catch (Exception e)
            {
                _log.Error("23Video: LoadFromService: Could not load videos from service. Exception {0}", e.Message);

                throw new Exception("Could not load videos from service.");
            }
        }