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."); } }
private static string zCronDayOfWeekValue(MonthlySchedule schedule, WeekdayPosition?weekdayPosition, DayOfWeek?weekDay) { if (schedule.MonthlyRecurrenceType == MonthlyRecurrenceType.Weekdays) { if (weekdayPosition.HasValue && weekDay.HasValue) { if (weekdayPosition.Value == WeekdayPosition.Last) { return(String.Format("{0}L", (int)weekDay.Value + 1)); } else { return(String.Format("{0}#{1}", (int)weekDay.Value + 1, weekdayPosition.Value + 1)); } } else if (schedule.Weekdays.Count == 7) { return("*"); } else { return(DescriptionUtils.BuildDescriptiveList(schedule.Weekdays, false, false, wd => ((int)wd + 1).ToString())); } } else { return("?"); } }
private static string zCronMonthValue(MonthlySchedule schedule) { if (schedule.MonthlyRecurrence.Count == 12) { return("*"); } else { return(DescriptionUtils.BuildDescriptiveList(schedule.MonthlyRecurrence, false, false, m => ((int)m + 1).ToString())); } }
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); }
private static string zCronDayOfMonthValue(MonthlySchedule schedule) { if (schedule.MonthlyRecurrenceType == MonthlyRecurrenceType.OrdinalDays) { if ((schedule.OrdinalDays.Count == 31 && !schedule.OrdinalDays.Contains(-1)) || schedule.OrdinalDays.Count == 32) { return("*"); } else { //The documentation says that using L with a list could cause unexpected results. If this doesn't work, find other way to do this. return(DescriptionUtils.BuildDescriptiveList(schedule.OrdinalDays, false, false, od => od > -1 ? ((int)od + 1).ToString() : "L")); } } else { return("?"); } }
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); } }