Ejemplo n.º 1
0
        public async Task UpdateDescription(string channelId, Dictionary <string, string> replacements)
        {
            var videos = await this.YoutubeProvider.GetVideos(channelId);

            var localVideos = await this.videosService.GetChannelVideos(channelId);

            foreach (var video in videos
                     .Where(v => v.Snippet != null)
                     .OrderByDescending(v => v.Snippet.PublishedAt))
            {
                var localVideo = localVideos.FirstOrDefault(v => v.VideoId == video.Id);
                if (localVideo == null)
                {
                    this.Logger.LogTrace($"Video \"{video.Snippet.Title}\" skipped.");
                    continue;
                }

                this.Logger.LogTrace($"\"{video.Snippet.Title}\" processing...");
                var updatedVideo = await this.YoutubeProvider.UpdateDescription(video,
                                                                                DescriptionUtils.TransformDescription(
                                                                                    channelId,
                                                                                    localVideo.Description,
                                                                                    replacements));

                if (updatedVideo == null)
                {
                    continue;
                }

                this.Logger.LogTrace($"\"{video.Snippet.Title}\" completed.");
            }
        }
Ejemplo n.º 2
0
        public static Video ReplaceDescription(
            this Video video,
            Dictionary <string, string> replacements,
            string channelId)
        {
            if (video?.Snippet == null)
            {
                return(video);
            }

            video.Snippet.Title       = video.Snippet.Title.ReplaceWholeWords(replacements);
            video.Snippet.Description = DescriptionUtils.TransformDescription(
                channelId,
                video.Snippet.Description,
                replacements);

            return(video);
        }
Ejemplo n.º 3
0
        public async Task TransferMetadata(
            string sourceChannelId,
            string destChannelId,
            bool downloadIcon = false,
            Dictionary <string, string> replacements = null)
        {
            try
            {
                var sourceChannel = await this.YoutubeProvider.GetChannel(sourceChannelId);

                var destChannel = await this.YoutubeProvider.GetChannel(destChannelId);

                if (downloadIcon)
                {
                    var iconFilePath = await this.YoutubeProvider.DownloadIcon(sourceChannel, this.outputFolder);

                    this.Logger.LogTrace($"Icon downloaded to [{iconFilePath}].");
                }

                sourceChannel.BrandingSettings.Channel.Description = DescriptionUtils.TransformDescription(
                    destChannelId,
                    sourceChannel.BrandingSettings.Channel.Description,
                    replacements);

                if (destChannel != null)
                {
                    var destVideos = await this.videosService.GetTransferVideos(sourceChannelId, destChannelId);

                    // set trailer
                    var trailer = destVideos.FirstOrDefault(v =>
                                                            v.OriginalVideoId == sourceChannel.BrandingSettings.Channel.UnsubscribedTrailer);
                    if (trailer != null)
                    {
                        if (destChannel.BrandingSettings.Channel.UnsubscribedTrailer ==
                            trailer.VideoId)
                        {
                            return;
                        }

                        sourceChannel.BrandingSettings.Channel.UnsubscribedTrailer = trailer.VideoId;
                    }
                    else
                    {
                        sourceChannel.BrandingSettings.Channel.UnsubscribedTrailer = string.Empty;
                    }

                    // set featured channels
                    sourceChannel.BrandingSettings.Channel.FeaturedChannelsTitle = destChannel.BrandingSettings.Channel.FeaturedChannelsTitle;
                    sourceChannel.BrandingSettings.Channel.FeaturedChannelsUrls  = destChannel.BrandingSettings.Channel.FeaturedChannelsUrls;

                    // set country
                    sourceChannel.BrandingSettings.Channel.Country         = destChannel.BrandingSettings.Channel.Country;
                    sourceChannel.BrandingSettings.Channel.DefaultLanguage = destChannel.BrandingSettings.Channel.DefaultLanguage;

                    // preserve banner
                    sourceChannel.SetBannerUrl(destChannel.GetBannerUrl());
                }
                else
                {
                    sourceChannel.BrandingSettings.Channel.UnsubscribedTrailer   = string.Empty;
                    sourceChannel.BrandingSettings.Channel.FeaturedChannelsTitle = string.Empty;
                    sourceChannel.BrandingSettings.Channel.FeaturedChannelsUrls  = new List <string>();
                }


                await this.YoutubeProvider.UpdateMetadata(destChannelId, sourceChannel);

                await this.channelsService.AddOrUpdate(sourceChannelId, destChannelId, sourceChannel);
            }
            catch (Exception exc)
            {
                this.Logger.LogError(exc.Message);
            }
        }