Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
EOL (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuylar authored Nov 27, 2024
1 parent c08d882 commit 1c92630
Show file tree
Hide file tree
Showing 163 changed files with 144,147 additions and 7,435 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ obj/
riderModule.iml
/_ReSharper.Caches/
.idea
*.DotSettings*
*.DotSettings*
Protobuf/*.bin
Protobuf/*.json
14 changes: 14 additions & 0 deletions InnerTube.Parsers.GetTestData/InnerTube.Parsers.GetTestData.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\InnerTube\InnerTube.csproj" />
</ItemGroup>

</Project>
148 changes: 148 additions & 0 deletions InnerTube.Parsers.GetTestData/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System.Text.Json;
using Google.Protobuf.Collections;
using InnerTube;
using InnerTube.Models;
using InnerTube.Protobuf;
using InnerTube.Protobuf.Responses;

string[] languages =
[
"af", "az", "id", "ms", "bs", "ca", "cs", "da", "de", "et", "en-IN", "en-GB", "en", "es", "es-419", "es-US",
"eu", "fil", "fr", "fr-CA", "gl", "hr", "zu", "is", "it", "sw", "lv", "lt", "hu", "nl", "no", "uz", "pl",
"pt-PT", "pt", "ro", "sq", "sk", "sl", "sr-Latn", "fi", "sv", "vi", "tr", "be", "bg", "ky", "kk", "mk", "mn",
"ru", "sr", "uk", "el", "hy", "iw", "ur", "ar", "fa", "ne", "mr", "hi", "as", "bn", "pa", "gu", "or", "ta",
"te", "kn", "ml", "si", "th", "lo", "my", "ka", "am", "km", "zh-CN", "zh-TW", "zh-HK", "ja", "ko"
];

string[] channels =
[
"UCX6OQ3DkcsbYNE6H8uQQuVA", // million subscribers
"UCbKWv2x9t6u8yZoB3KcPtnw", // million subscribers, 1 decimal
"UCS0N5baNlQWJCUrhCEo8WlA", // million subscribers, 2 decimal
"UCB5zZAm0b5-EqWkOEwHBE_A", // thousand subscribers
"UCjdHbo8_vh3rxQ-875XGkvw", // thousand subscribers, 1 decimal
// TODO: "", // thousand subscribers, 2 decimal
"UCRS3ZUNqkEyTd9XZEphFRMA", // hundred subscribers
"UCPF-oYb2-xN5FbCXy0167Gg", // a lot of videos
];

string[] videos =
[
"Atvsg_zogxo", // Premiered
"jfKfPfyJRdk", // Streaming
"dv_YFDzCw2s", // Streamed
"7DKv5H5Frt0", // Published
"GfDXqY-V0EY", // Premiere. Update before every run
"Hr2Lm6oEo3c" // Scheduled livestream. Update before every run
];

string[] playlists =
[
"VLPLiDvcIUGEFPv2K8h3SRrpc7FN7Ks0Z_A7",
"VLPLWA4fx92eWNstZbKK52BK9Ox-I4KvxdkF",
"VLPLv3TTBr1W_9tppikBxAE_G6qjWdBljBHJ"
];

// todo: remember to borrow dates from https://github.com/TeamNewPipe/NewPipeExtractor/blob/dev/timeago-parser/raw/overview.json

InnerTube.InnerTube client = new();

Dictionary<string, Dictionary<string, List<string>>> finalResult = [];

for (int i = 0; i < languages.Length; i++)
{
string hl = languages[i];
Console.Write($"[{i + 1,2}/{languages.Length}] Getting data for {$"'{hl}'",-9}");

List<string> subscriberCounts = [];
List<string> videoDates = [];
List<string> viewCounts = [];
List<string> likeCounts = [];
List<string> lastUpdatedDates = [];
List<string> videoCounts = [];

Task[] channelTasks = channels.Select(channelId => GetSubscriptionCount(hl, channelId)).Cast<Task>().ToArray();
await Task.WhenAll(channelTasks);
subscriberCounts.AddRange(from Task<(string, string)> res in channelTasks select res.Result.Item1);
videoCounts.AddRange(from Task<(string, string)> res in channelTasks select res.Result.Item2);

Task[] videoTasks = videos.Select(videoId => GetVideoStrings(hl, videoId)).Cast<Task>().ToArray();
await Task.WhenAll(videoTasks);
videoDates.AddRange(from Task<(string, string, string)> res in videoTasks select res.Result.Item1);
viewCounts.AddRange(from Task<(string, string, string)> res in videoTasks select res.Result.Item2);
likeCounts.AddRange(from Task<(string, string, string)> res in videoTasks select res.Result.Item3);

Task[] playlistTasks = playlists.Select(playlistId => GetLastUpdated(hl, playlistId)).Cast<Task>().ToArray();
await Task.WhenAll(playlistTasks);
lastUpdatedDates.AddRange(from Task<(string, string)> res in playlistTasks select res.Result.Item1);
videoCounts.AddRange(from Task<(string, string)> res in playlistTasks select res.Result.Item2);

Console.Write("\n");
Dictionary<string, List<string>> languageResult = new()
{
["subscriberCounts"] = subscriberCounts,
["videoDates"] = videoDates,
["viewCounts"] = viewCounts,
["likeCounts"] = likeCounts,
["lastUpdatedDates"] = lastUpdatedDates,
["videoCounts"] = videoCounts
};

finalResult.Add(hl, languageResult);
}

string json = JsonSerializer.Serialize(finalResult);
File.WriteAllText($"out.{DateTimeOffset.Now:s}.json", json);

return;

async Task<(string, string)> GetSubscriptionCount(string hl, string channelId)
{
BrowseResponse channel = await client.BrowseAsync(channelId, language: hl);
string subscriberCountText = (channel.Header.RendererCase switch
{
RendererWrapper.RendererOneofCase.C4TabbedHeaderRenderer => new ChannelHeader(channel.Header
.C4TabbedHeaderRenderer, ""),
RendererWrapper.RendererOneofCase.PageHeaderRenderer => new ChannelHeader(
channel.Header.PageHeaderRenderer,
channel.Metadata.ChannelMetadataRenderer.ExternalId, ""),
_ => null
})!.SubscriberCountText;
string videoCountText = (channel.Header.RendererCase switch
{
RendererWrapper.RendererOneofCase.C4TabbedHeaderRenderer => new ChannelHeader(channel.Header
.C4TabbedHeaderRenderer, ""),
RendererWrapper.RendererOneofCase.PageHeaderRenderer => new ChannelHeader(
channel.Header.PageHeaderRenderer,
channel.Metadata.ChannelMetadataRenderer.ExternalId, ""),
_ => null
})!.VideoCountText;
Console.Write(".");
return (subscriberCountText, videoCountText);
}

async Task<(string, string, string)> GetVideoStrings(string hl, string videoId)
{
NextResponse next = await client.GetNextAsync(videoId, language: hl);
RepeatedField<RendererWrapper> firstColumnResults =
next.Contents.TwoColumnWatchNextResults.Results.ResultsContainer.Results;
VideoPrimaryInfoRenderer videoPrimaryInfoRenderer = firstColumnResults.First(x =>
x.RendererCase == RendererWrapper.RendererOneofCase.VideoPrimaryInfoRenderer).VideoPrimaryInfoRenderer;
string dateText = Utils.ReadRuns(videoPrimaryInfoRenderer.DateText);
string viewCountText = Utils.ReadRuns(videoPrimaryInfoRenderer.ViewCount?.VideoViewCountRenderer.ViewCount);
string likeCountText = videoPrimaryInfoRenderer.VideoActions.MenuRenderer.TopLevelButtons
.First(x => x.RendererCase == RendererWrapper.RendererOneofCase.SegmentedLikeDislikeButtonViewModel)
.SegmentedLikeDislikeButtonViewModel.LikeButtonViewModel.LikeButtonViewModel.ToggleButtonViewModel
.ToggleButtonViewModel.DefaultButtonViewModel.ButtonViewModel2.Title;
Console.Write(",");
return (dateText, viewCountText, likeCountText);
}

async Task<(string, string)> GetLastUpdated(string hl, string playlistId)
{
BrowseResponse browse = await client.BrowseAsync(playlistId, language: hl);
string lastUpdated = Utils.ReadRuns(browse.Header.PlaylistHeaderRenderer.Byline.PlaylistBylineRenderer.Text.Last());
string videoCount = Utils.ReadRuns(browse.Header.PlaylistHeaderRenderer.NumVideosText);
Console.Write(";");
return (lastUpdated, videoCount);
}
43 changes: 0 additions & 43 deletions InnerTube.Tests/AuthenticationTests.cs

This file was deleted.

Loading

0 comments on commit 1c92630

Please sign in to comment.