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

Generate params strings in code #16

Open
1 of 4 tasks
kuylar opened this issue May 30, 2023 · 1 comment
Open
1 of 4 tasks

Generate params strings in code #16

kuylar opened this issue May 30, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@kuylar
Copy link
Member

kuylar commented May 30, 2023

Most params strings are just base64 encoded protobufs, and we can definitely use them in places such as:

  • [Generating search filter params in code using Protobuf #23] Search Filters
  • Search continuations
    • this one will be hard, from what ive seen so far, theres an int value that acts as a hash
  • Channel/Playlist continuations
  • Comments
    • Instead of GetVideoCommentsAsync(string continuation) we can have GetVideoCommentsAsync(string videoId, CommentSortingType /* enum, TopComments or NewestFirst */ sortingType, object /* needs more research */ after)

& probably more!

@kuylar
Copy link
Member Author

kuylar commented Jul 15, 2023

Almost implemented channel continuations, but after implementing it for the videos tab i realized that every other tab's pagination is fucking stupidly complicated. leaving this protobuf for channel continuations here, for future me

// Channel Continuation
// I hate this one *so* much

message ChannelContinuationContainer {
  required ChannelContinuation PaginationInfo = 80226972;
}

message ChannelContinuation {
  required string ChannelId = 2;
  required string ContinuationInfoEncoded = 3;
}

// :3 fuck you youtube
message ChannelContinuationInfoContainer {
  optional ChannelContinuationInfoContainer Second = 3;
  optional ChannelContinuationInfo Third = 15;
  optional ChannelContinuationInfoContainer First = 110;
}

message ChannelContinuationInfo {
  enum SortOrder {
    LATEST = 1;
    POPULAR = 2;
    OLDEST = 3;
  }

  required SortOrder Sort = 3;
  required ChannelPaginationMetadata Metadata = 1;
}

message ChannelPaginationMetadata {
  required string SkipAmountEncoded = 1;
  required string SessionUUID = 2;
}

message SkipAmountContainer {
  required SkipAmountEncodedContainer Skip = 1;
  required int32 Zero = 2;
}

message SkipAmountEncodedContainer {
  required string SkipAmountEncoded = 1;
}

message SkipAmount {
  required string SkipAmount = 2;
}

message SkipAmountInt {
  required int32 Amount = 1;
}

also this snippet for getting a valid continuation from that protobuf

public static string PackChannelContinuation(string channelId, ChannelContinuationInfo.Types.SortOrder sortOrder, int skipAmount)
{
	SkipAmountInt amount = new()
	{
		Amount = skipAmount
	};

	SkipAmount skipAmountProto = new()
	{
		SkipAmount_ = $"ST:{ToBase64UrlString(amount.ToByteArray())}"
	};

	SkipAmountContainer skipContainer = new()
	{
		Zero = 0,
		Skip = new SkipAmountEncodedContainer
		{
			SkipAmountEncoded = ToBase64UrlString(skipAmountProto.ToByteArray())
		}
	};

	ChannelContinuationInfoContainer infoContainer = new()
	{
		First = new ChannelContinuationInfoContainer
		{
			Second = new ChannelContinuationInfoContainer
			{
				Third = new ChannelContinuationInfo
				{
					Sort = sortOrder,
					Metadata = new ChannelPaginationMetadata
					{
						SkipAmountEncoded = ToBase64UrlString(skipContainer.ToByteArray()),
						SessionUUID = Guid.NewGuid().ToString()
					}
				}
			}
		}
	};

	ChannelContinuationContainer final = new()
	{
		PaginationInfo = new ChannelContinuation
		{
			ChannelId = channelId,
			ContinuationInfoEncoded = ToBase64UrlString(infoContainer.ToByteArray())
		}
	};

	return ToBase64UrlString(final.ToByteArray());
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant