// Dictionary<MemberName(string), Dictionary<DataBaseName(string), DBProperty(IMongoCollection<RefactorScheme>)>> private static void GenerateDataBaseProperty(MongoClient client, Dictionary <string, Dictionary <string, ConfigScheme> > configComponent) { foreach (KeyValuePair <string, Dictionary <string, ConfigScheme> > groupedCorp in configComponent) { Dictionary <string, IMongoCollection <RefactorScheme> > collectionsBuf = new Dictionary <string, IMongoCollection <RefactorScheme> >(); IMongoDatabase targetDataBase = client.GetDatabase(groupedCorp.Key); AlExtension.ColorizeWriteLine(LogIndex.CONFIG_INFORMATION, " => Generate DataBase Property", new [] { ConsoleColor.Cyan, ConsoleColor.Green }); // AlConsole.WriteLine(CONFIG_INFORMATION, " => Generate DataBase Property"); AlExtension.ColorizeWriteLine(LogIndex.CONFIG_INFORMATION, $" ┏ ^DataBase[ ^{groupedCorp.Key} ^]", new [] { ConsoleColor.DarkGray, ConsoleColor.Green, ConsoleColor.Cyan, ConsoleColor.Green }); // AlConsole.WriteLine(CONFIG_INFORMATION, $" ┏ DataBase[ {groupedCorp.Key} ]"); foreach (KeyValuePair <string, ConfigScheme> configDict in groupedCorp.Value) { IMongoCollection <RefactorScheme> generatedCollection = targetDataBase.GetCollection <RefactorScheme>(configDict.Key); AlExtension.ColorizeWrite(LogIndex.CONFIG_INFORMATION, " ┣ ^Collection[ ^" + $"{configDict.Key, -26}" + " ^]", new [] { ConsoleColor.DarkGray, ConsoleColor.Magenta, ConsoleColor.Cyan, ConsoleColor.Magenta }); // AlConsole.WriteLine(CONFIG_INFORMATION, $" ┣ Collection[ " + $"{configDict.Key, -26}" + " ]"); collectionsBuf.Add(configDict.Key, generatedCollection); LoadedComponent.SetChannelIdComponent(configDict.Value.ChannelData[0].Details[0].ID.ToString(), configDict.Key); AlExtension.ColorizeWriteLine(LogIndex.CONFIG_INFORMATION, $" / ^ChannelId[ " + $"^{configDict.Value.ChannelData[0].Details[0].ID.ToString(), -16}" + " ^]", new [] { ConsoleColor.DarkGray, ConsoleColor.DarkMagenta, ConsoleColor.DarkCyan, ConsoleColor.DarkMagenta }, false); // AlConsole.WriteLine(CONFIG_INFORMATION, $" ┃ ┗ ChannelId[ " + $"{configDict.Value.ChannelData[0].Details[0].ID.ToString(), -16}" + " ]"); } LoadedComponent.SetCollectionDict(targetDataBase, collectionsBuf); AlExtension.ColorizeWriteLine(LogIndex.CONFIG_INFORMATION, $" ┗ ^[ EOT ]", new [] { ConsoleColor.DarkGray, ConsoleColor.Green }); // AlConsole.WriteLine(CONFIG_INFORMATION, $" ┗ [ EOT ]"); } }
public static async Task <string> requestAsync(HttpClient client, string channelId) { Uri url = new Uri("https://www.googleapis.com/youtube/v3/search") .AddQuery("part", "snippet") .AddQuery("channelId", channelId) .AddQuery("type", "video") .AddQuery("eventType", "upcoming") .AddQuery("key", getToken()); // AlConsole.WriteLine(DefaultScheme.REQUEST_SCHEME, url.ToString().Substring(0, 129) + "[SECRET TOKEN]"); AlExtension.ColorizeWrite(DefaultScheme.REQUEST_SCHEME, $"情報をリクエスト ^: ^ChannelId [ ^{channelId, -16} ^] ^/ ", new [] { ConsoleColor.Green, ConsoleColor.DarkGray, ConsoleColor.Magenta, ConsoleColor.Cyan, ConsoleColor.Magenta, ConsoleColor.DarkGray }); string result = ReSpell.Execute(5, 5, () => client.GetStringAsync(url).Result, (c) => { Console.Write($"Retry ({c})"); Console.CursorLeft = 124; Settings.UseQuota += 101; }, (c) => { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Failure \n"); Console.ResetColor(); }); Console.WriteLine("Success."); Settings.UseQuota += 101; return(result); }
private static void Initialization(IMongoDatabase db, string targetCollection) { AlExtension.ColorizeWrite(DefaultScheme.DB_INITIALIZE_SCHEME, $" ┣ ^Init Collection: ^{targetCollection, -26} ", new [] { ConsoleColor.DarkGray, ConsoleColor.Green, ConsoleColor.Cyan, ConsoleColor.Green }); // AlConsole.WriteLine(DefaultScheme.DB_INITIALIZE_SCHEME, $" ┣ Init Collection: {targetCollection}"); db.DropCollection(targetCollection); AlExtension.ColorizeWriteLine(DefaultScheme.DB_INITIALIZE_SCHEME, $"/ ^初期化しました。", new [] { ConsoleColor.DarkGray, ConsoleColor.DarkBlue, ConsoleColor.DarkGreen }, false); // AlConsole.WriteLine(DefaultScheme.DB_INITIALIZE_SCHEME, $" ┃ ┗ 初期化しました。"); }
public static void BundleModification(Dictionary <Item, ExtendItem> bundleScheme) { foreach (KeyValuePair <Item, ExtendItem> itemValue in bundleScheme) { Item item; ExtendItem exItem; if (itemValue.Key.Snippet == null || itemValue.Value.Details == null) { _needAdditionalData = true; Settings.CautData += 1; continue; // TODO : コラボ動画の追加処理を考える。 } else { item = itemValue.Key; exItem = itemValue.Value; } if (_needAdditionalData) { } AlExtension.ColorizeWrite( DefaultScheme.CONTROLLER, $"({count+1, 3}/{bundleScheme.Count}) ^[ ^{itemValue.Key.Id.VideoId} ^] キューに追加しています / ", new [] { ConsoleColor.White, ConsoleColor.Green, ConsoleColor.Blue, ConsoleColor.Green }); RefactorScheme refactorScheme = RefactorBuilder.Define .SetTitle(item.Snippet.Title) .SetDescription(item.Snippet.Description) .SetVideoId(item.Id.VideoId) .SetChannelId(item.Snippet.ChannelId) .SetChannelName(item.Snippet.ChannelTitle) .SetPublish(item.Snippet.PublishTime.ToString()) .SetStartTime(exItem.Details.ScheduledStartTime) .SetThumbnailData( ThumbnailDataBuilder.Define.SetUrl(new Uri($"https://i.ytimg.com/vi/{itemValue.Key.Id.VideoId}/maxresdefault_live.jpg")).Build()) .Build(); Console.Write("Validate... "); /* * RefactorScheme refactorScheme = new RefactorScheme() { * _id = GenUuid.Generate(), * Title = itemValue.Key.Snippet.Title, * Description = itemValue.Key.Snippet.Description, * VideoId = itemValue.Key.Id.VideoId, * ChannelName = itemValue.Key.Snippet.ChannelTitle, * ChannelId = itemValue.Key.Snippet.ChannelId, * Thumbnail = new ThumbnailsData() { * Url = new Uri($"https://i.ytimg.com/vi/{itemValue.Key.Id.VideoId}/maxresdefault_live.jpg"), //itemValue.Key.Snippet.Thumbnails.Medium.Url, * Height = "641", //itemValue.Key.Snippet.Thumbnails.Medium.Height.ToString(), * Width = "361" //itemValue.Key.Snippet.Thumbnails.Medium.Width.ToString() * }, * StartTime = itemValue.Value.Details.ScheduledStartTime, * Publish = itemValue.Key.Snippet.PublishTime.ToString(), * }; */ if (!LiveCheck.IsFreeChat(itemValue.Key) || (Settings.UseIgnoreDataFromConfig && Settings.IgnoreVideoId.Contains(item.Id.VideoId))) { if (!LiveCheck.IsFinishedLive(refactorScheme)) { _schemes.Add(refactorScheme); } else { if (LiveCheck.IsLazyLive(itemValue.Value)) { _schemes.Add(refactorScheme); LazyLivesDict.Add(item.Id.VideoId, item.Snippet.Title); } finishedLivesDict.Add(item.Id.VideoId, item.Snippet.Title); } } else { freechatLivesDict.Add(item.Id.VideoId, item.Snippet.Title); } Console.WriteLine("/ Finished"); count++; } }
// ReSharper disable all PossibleMultipleEnumeration static void Main(string[] args) { Console.CursorVisible = false; Settings.StartupTime = DateTime.Now; AlExtension.ArrayWrite(START_UP, Settings.Startup); ArgumentParser.Decomposition(args); //Thread.Sleep(50000); // Set Client for Environment (Windows or Linux). _mongoClient = Settings.isLocal ? new MongoClient($"mongodb://{Settings.User}:{Settings.Pass}@124.0.0.1") : new MongoClient($"mongodb://{Settings.User}:{Settings.Pass}@{Settings.NekomataAws}"); ConfigLoader.OnLoadEvent(_mongoClient); // Set Http Client. (For Reuse) // HttpClient isn't disposable, but is designed to "For Reuse". HttpClient httpClient = new HttpClient(); // Send Request to YoutubeAPI. LoadedComponent.GetChannelId().ForEach(channelId => { string result = Task.Run(() => YoutubeAPIResponce.requestAsync(httpClient, channelId)).Result; //Thread.Sleep(3000); ListAggregation.SetResultList(result); }); //ProductionHoloLive.GetAllKey().ForEach(channelId => { // string result = Task.Run(() => YoutubeAPIResponce.requestAsync(httpClient, channelId)).Result; // ListAggregation.SetResultList(result); //}); // Finish Message AlConsole.WriteLine(DefaultScheme.RESPONCE_SCHEME, $"Success. Number of Request ({ListAggregation.GetResultList().Count})"); // Youtube Response Json Deserialize ListAggregation.GetResultList().ForEach(result => { JsonScheme scheme = JsonConvert.DeserializeObject <JsonScheme>(result); ListAggregation.SetJsonSchemeDict(scheme); }); // Result List Re-Initialize. ListAggregation.ResultListInit(); IEnumerable <string> videoIdEnum = ListAggregation.GetVideoIdList().AsEnumerable <string>(); // Because it is possible to save Quota, // When I search for 50 items in a batch, I can add 50 VideoId to the Dictionary<page number(int), VideoId(string)> as a lump organized into. // Send Request to YoutubeAPI. (Start Time for ScheduleLive) AlConsole.WriteLine(DefaultScheme.REQUEST_SCHEME, "Extend Information Request..."); while (videoIdEnum.Any()) { string requestIds = String.Join(",", videoIdEnum.Take <string>(50)); string[] sliced = videoIdEnum.ToArray <string>(); string startTime = Task.Run(() => YoutubeAPIResponce.RequestStartTimeAsync(httpClient, requestIds)).Result; for (int i = 0; i < (sliced.Length % 50 > 0 ? sliced.Length / 50 + 1 : sliced.Length / 50); i++) { for (int j = 0; j < 5; j++) { AlExtension.ColorizeWrite(REQUEST_SCHEME, $" #-- ^[ ", new [] { ConsoleColor.DarkGray, ConsoleColor.Green }); AlExtension.ColorizeWrite(REQUEST_SCHEME, String.Join(", ", sliced.Take(5)), new [] { ConsoleColor.Magenta }, false); AlExtension.ColorizeWriteLine(REQUEST_SCHEME, $" ]", new [] { ConsoleColor.Green }, false); sliced = sliced.Skip <string>(5).ToArray(); } } // foreach (string splitValue in requestIds.Split(",")) { // AlConsole.WriteLine(DefaultScheme.REQUEST_SCHEME, $" #-- {splitValue, 15}"); // } // string startTime = Task.Run(() => YoutubeAPIResponce.RequestStartTimeAsync(httpClient, requestIds)).Result; ListAggregation.SetResultList(startTime); videoIdEnum = videoIdEnum.Skip <string>(50); } // Finish Message AlConsole.WriteLine(DefaultScheme.RESPONCE_SCHEME, "Success."); // Youtube Response Json Deserialize ListAggregation.GetResultList().ForEach(result => { StartTimeScheme scheme = JsonConvert.DeserializeObject <StartTimeScheme>(result); ListAggregation.SetTimeScheme(scheme); }); // Link JsonScheme and ExtendItem whose VideoId is the same. ListCombination.Scheme.SetBundleDict(ListAggregation.GetJsonSchemeList(), ListAggregation.GetTimeScheme()); // Organize necessary information and put it into a RefactorScheme and store it in List(RefactorScheme). /* * ReSpell.Execute(5, 5, * () => { SchemeOrthopedy.BundleModification(ListCombination.Scheme.GetBundleDict()); }, (count) => { * AlConsole.Write(AlStatusEnum.Caution, $"{"TASK RESUMED", -15}", $"{"Data Bundler", -15}", * "Failed to execute the task. Task will try again."); * Console.CursorLeft = 0; * }, (count) => { * AlConsole.WriteLine(AlStatusEnum.Error, $"{"TASK FAILURE", -15}", $"{"Data Bundler", -15}", * $"Failed to execute the task. TryCount: {count, -10}\n"); * }); */ SchemeOrthopedy.BundleModification(ListCombination.Scheme.GetBundleDict()); AlConsole.WriteLine(SORTLOG_SCHEME, $"{" ", -63}"); AlConsole.WriteLine(SORTLOG_SCHEME, "既に終了していたライブ : 以下のものは挿入タスクから除外されます。"); AlConsole.WriteLine(SORTLOG_SCHEME, "----------------------------- 対象 -----------------------------"); foreach (KeyValuePair <string, string> liveData in SchemeOrthopedy.GetFinishedLivesDict()) { AlExtension.ColorizeWriteLine(SORTLOG_SCHEME, $"[ ^{liveData.Key} ^] => \"^{liveData.Value}^\"", new [] { ConsoleColor.Green, ConsoleColor.Blue, ConsoleColor.Green, ConsoleColor.Gray, ConsoleColor.Green }); } // foreach (string lives in SchemeOrthopedy.GetFinishedLives()) { // AlConsole.WriteLine(SORTLOG_SCHEME, lives); // } AlConsole.WriteLine(SORTLOG_SCHEME, " "); AlConsole.WriteLine(SORTLOG_SCHEME, "フリーチャット専用枠 : 以下のものは挿入タスクから除外されます。"); AlConsole.WriteLine(SORTLOG_SCHEME, "----------------------------- 対象 -----------------------------"); foreach (KeyValuePair <string, string> liveData in SchemeOrthopedy.GetFreeChatLivesDict()) { AlExtension.ColorizeWriteLine(SORTLOG_SCHEME, $"[ ^{liveData.Key} ^] => \"^{liveData.Value}^\"", new [] { ConsoleColor.Green, ConsoleColor.Blue, ConsoleColor.Green, ConsoleColor.Gray, ConsoleColor.Green }); } string free = string.Join(',', SchemeOrthopedy.GetFreeChatLivesDict().Keys); AlConsole.WriteLine(SORTLOG_SCHEME, " "); AlConsole.WriteLine(SORTLOG_SCHEME, "遅刻ライブ : 以下のものは挿入タスクに追加されます。"); AlConsole.WriteLine(SORTLOG_SCHEME, "----------------------------- 対象 -----------------------------"); if (SchemeOrthopedy.GetLazyLivesDict().Count != 0) { foreach (KeyValuePair <string, string> liveData in SchemeOrthopedy.GetLazyLivesDict()) { AlExtension.ColorizeWriteLine(SORTLOG_SCHEME, $"[ ^{liveData.Key} ^] => \"^{liveData.Value}^\"", new [] { ConsoleColor.Green, ConsoleColor.Blue, ConsoleColor.Green, ConsoleColor.Gray, ConsoleColor.Green }); } } else { AlConsole.WriteLine(SORTLOG_SCHEME, "遅刻ライブはありません。"); } AlConsole.WriteLine(SORTLOG_SCHEME, " "); // foreach (string lives in SchemeOrthopedy.GetFreeChatLives()) { // AlConsole.WriteLine(SORTLOG_SCHEME, lives); // } // Serialize the organized information. SchemeOrthopedy.GetSchemes().ForEach(i => { serializedObject.Add(JsonConvert.SerializeObject(i)); }); // Displays serialized information. serializedObject.ForEach(i => AlConsole.WriteLine(DefaultScheme.SERIALIZELOG_SCHEME, $"{i.ToString().Substring(0, 64), -67}" + "......[OMT]")); // Send the serialize object to Database. DataBaseCollection.Insert(_mongoClient, SchemeOrthopedy.GetSchemes()); // Controller Task Finish Message long progressTicks = DateTime.Now.Ticks - Settings.StartupTime.Ticks; AlConsole.WriteLine(CONTROLLER, $"Task Finished ! / {progressTicks} Ticks" + $" ({TimeSpan.FromTicks(progressTicks).Seconds} Sec)" ); AlConsole.WriteLine(CONTROLLER, $"Number of Scheduled Live => {SchemeOrthopedy.GetSchemes().Count}"); AlConsole.WriteLine(CONTROLLER, $" Usage Quota => {Settings.UseQuota}"); AlConsole.WriteLine(CONTROLLER, $" Validated Caution Data => {Settings.CautData}"); AlConsole.WriteLine(CONTROLLER, $" Validated Warning Data => {Settings.WarnData}"); AlConsole.WriteLine(CONTROLLER, "Have a good live broadcast today !"); if (Settings.OutputFreeChatVideoId) { Console.WriteLine(free); } }